homework week 4.2

int x=100;
int speed=5;
boolean freeze=false;
int y=100;
int w=50;
int h=50;
int t=100;
int p=50;
int r, g, b;

 
void setup() {
size(400, 400);
}
void draw () {
background(255);
if (freeze) {
x = x;
}
else {
x = x- speed;
t=t+speed;
r=r+speed;
}

line(width/2, 0, width/2, height);
line(0, height/2, width, height/2);

fill(255, 0, 0);

rect(p, 250, w, h);

fill(0, 255, 0);

ellipse(t, y, h, w);//new shape thats moving opposite
fill(0, 0, 255);
ellipse(x, y, h, w);
if (x>width) {
speed=speed*-1;
}

else if (x < 0) {
speed=speed*-1;
}
if (t >width) {
speed=speed*-1;
}
else if (t<0) {
speed=speed*-1;
}

if (mouseX> width/2 && mouseY < height/2) {
r++;
}
else {
r–;
}

if (mouseX < width/2 && mouseY < height/2) {
g++;
}
else {
g–;
}
if (mouseX < width/2 && mouseY > height/2) {
b++;
}
else {
b–;
}
{
r = constrain(r, 0, 255);
g = constrain(g, 0, 255);
b = constrain(b, 0, 255);
}
}

void mousePressed() {
if (mouseX>x &&mouseX <x+w &&mouseY >y && mouseY<y+h) {
freeze = !freeze;
}

}

 

 

~~~~side note i no i missed a few things..could u emailed me on how  to those missing items work ?tried many things with the void mousepressed + i used the prev homework as a guide for the background still not sured why it wasnt making the magic effects o.o~~~

 

 

found an error that didnt get called in my prog

new code is

int x=100;
int speed=5;
boolean freeze=false;
int y=100;
int w=50;
int h=50;
int t=100;
int p=50;
int r, g, b;

void setup() {
size(400, 400);
}
void draw () {
background(255);
if (freeze) {
x = x;
}
else {
x = x- speed;
t=t+speed;
r=r+speed;
}

line(width/2, 0, width/2, height);
line(0, height/2, width, height/2);

fill(255, 0, 0);

rect(p, 250, w, h);

fill(0, 255, 0);

ellipse(t, y, h, w);//new shape thats moving opposite
fill(0, 0, 255);
ellipse(x, y, h, w);
if (x>width) {
speed=speed*-1;
}

else if (x < 0) {
speed=speed*-1;
}
if (t >width) {
speed=speed*-1;
}
else if (t<0) {
speed=speed*-1;
}

}

void mousePressed() {
if (mouseX>x &&mouseX <x+w &&mouseY >y && mouseY<y+h) {
freeze = !freeze;
}

}

 

Print this page
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *