void setup(){
size(600,400);
frameRate(1);
}
void draw(){
int i = 0;
for (int j=0; j
//background(255,255,255);
fill(0, i, 0);
ellipse(j, 200, 200, 200);
i+=5;
}
i = 0;
for (int j=width; j>0; j-=10){
//background(255,255,255);
fill(i, 0, 0);
ellipse(j, 0, 200, 200);
i+=5;
}
i = 0;
for (int j=width; j>0; j-=10){
//background(255,255,255);
fill(0, 0, i);
ellipse(j, 400, 200, 200);
i+=5;
}
}
Bouncing Ball Program
// initial position for our circle
float circle_x = 300;
float circle_y = 20;
// how much to move the circle on each frame
float move_x = 2;
float move_y = -2;
void setup() {
size(600, 400);
fill(0, 0, 255);
}
void draw() {
background(200, 200, 200);
ellipse(circle_x, circle_y, 80, 80);
circle_x = circle_x + move_x;
circle_y = circle_y + move_y;
if(circle_x > width-40) {
fill(random(0,255),random(0,255),random(0,255));
circle_x = width-40;
move_x = -move_x;
//println("too far right");
}
if(circle_y > height-40) {
fill(random(0,255),random(0,255),random(0,255));
circle_y = height-40;
move_y = -move_y;
//println("too far bottom");
}
if(circle_x < 40) {
fill(random(0,255),random(0,255),random(0,255));
circle_x = 40;
move_x = -move_x;
//println("too far left");
}
if(circle_y < 40) {
fill(random(0,255),random(0,255),random(0,255));
circle_y = 40;
move_y = -move_y;
//println("too far top");
}
}


No comments:
Post a Comment