fundamentals of art with technology

3

Sketch 4

float x = 50.0; // X-coordinate

float y = 50.0; // Y-coordinate

float speedX = 1.0; // Speed of motion on the x-axis

float speedY = 0.4; // Speed of motion on the y-axis

int directionX = 1; // Direction of motion on the x-axis

int directionY = -1; // Direction of motion on the y-axis

float speed = 2.0;

float angle = 0.0;

void setup() {

size(500, 500);

smooth();

noStroke();

}

void draw() {

fill(0, 12);

rect(0, 0, width, height);

pushMatrix();

fill(280, 0, 15);

translate(300, 300);

angle = angle + 0.001;

rotate(angle);

rect(0, 0, 5, 100);

fill(234, 20, 182);

translate(10, 10);

angle = angle + 0.001;

rotate(angle);

rect(0, 100, 5, 150);

fill(34, 25, 52);

translate(10, 10);

angle = angle + 0.001;

rotate(angle);

rect(0, 100, 5, 200);

fill(246, 55, 126);

translate(10, 10);

angle = angle + 0.001;

rotate(angle);

rect(240, 0, 5, 250);

fill(200, 0, 255);

translate(10, 10);

angle = angle + 0.05;

rotate(angle);

rect(50, 100, 5, 300);

popMatrix();

}

3

Sketch 5

When clicked, image is compressed.

C myC1;

C myC2;

C myC3;

void setup() {

size(500,500);

background(0);

float r = random(100);

myC1 = new C (color(0,0,13,100),250,225, 50, 50, 1); // Parameters go inside the parentheses when the object is constructed.

myC2 = new C (color(255,0,0,100),250,200,60, 60, 5);

myC3 = new C (color(250,250,250,100),250,250, 30, 30, 30);

}

void draw() {

fill(30, 12);

rect(0, 0, width, height);

myC1.move();

myC1.display();

myC2.move();

myC2.display();

myC3.move();

myC3.display();

if (mousePressed){

myC1 = new C (color(250,250,250,100),250,250, 10, 10, 10);

myC2 = new C (color(255,0,0,100),250,200,30, 30, 5);

myC3 = new C (color(0,0,13,100),250,225,15, 15, 1);

} else {return;

}

}

class C { // Even though there are multiple objects, we still only need one class. No matter how many cookies we make, only one cookie cutter is needed. Isn’t object-oriented programming swell?

color c;

float xpos;

float ypos;

float xspeed = 0.4;

float angle = 2.4;

float offset = 30;

float direction = 4;

float ew;

float eh;

C (color tempC, float tempXpos, float tempYpos, float ewidth, float eheight, float tempXspeed) { // The Constructor is defined with arguments.

c = tempC;

xpos = tempXpos;

ypos = tempYpos;

xspeed = tempXspeed;

ew = ewidth;

eh = eheight;

}

void display() {

noStroke();

ellipseMode(CENTER);

float r = random(3);

ellipse(xpos,ypos,ew*r,eh*r);

}

void move() {

xpos += xspeed*direction;

if((xpos > width) || (xpos < 6)){

direction *= -1;

}

}

}