Professional Documents
Culture Documents
1. Animasi Acak
void setup() {
size(500, 500);
}
void draw() {
float x = random(500);
float y = random(500);
float w = random(100);
float h = random(100);
fill(random(255), random(255), random(255));
rect(x, y, w, h);
ellipse(x, y, w, h);
triangle(random(500),random(500),random(500),random(500),random(500),random(500));
}
2. Animasi Bola 1
float y = 50.0;
float speed = 2.0;
float radius = 15.0;
void setup() {
size(100, 100);
noStroke();
ellipseMode(RADIUS);
}
void draw() {
background(0);
ellipse(33, y, radius, radius);
y = y + speed;
if (y > height+radius) {
y = -radius;
}
}
void setup() {
size(100, 100);
noStroke();
ellipseMode(RADIUS);
}
void draw() {
fill(0, 12);
rect(0, 0, width, height);
fill(255);
ellipse(x, y, radius, radius);
x += speedX * directionX;
if ((x > width-radius) || (x < radius)) {
directionX = -directionX; // Change direction
}
y += speedY * directionY;
if ((y > height-radius) || (y < radius)) {
directionY = -directionY; // Change direction
}
}