動く図形の例
float x1 = 50, y1 = 50, vx1 = 1, vy1 = 1; float x2 = 50, y2 = 50, vx2 = 1, vy2 = 1; float x3 = 50, y3 = 50, vx3 = 1, vy3 = 3; float x4 = 50, y4 = 50, angle4 = 1, vAngle4 = 2; float x5 = 50, y5 = 50, angle5 = 1; void setup(){ size(400,400); } void draw(){ background(255); fill(0,0,0); ellipse(x1, y1, 32, 32); x1 += vx1; if(x1 > 200){ vx1 = -1; } else if(x1 < 50){ vx1 = 1; } fill(255,0,0); ellipse(x2, y2, 32, 32); y2 += vy2; if(y2 > 200){ vy2 = -1; } else if(y2 < 50){ vy2 = 1; } fill(255,255,0); ellipse(x3, y3, 32, 32); x3 += vx3; if(x3 > 200){ vx3 = -1; } else if(x3 < 50){ vx3 = 1; } y3 += vy3; if(y3 > 200){ vy3 = -3; } else if(y3 < 50){ vy3 = 3; } fill(255,0,255); x4 = sin(radians(angle4)) * 50 + 200; y4 = cos(radians(angle4)) * 50 + 200; ellipse(x4, y4, 32, 32); angle4 += vAngle4; if(angle4 > 180){ vAngle4 = -2; } else if(angle4 < 0){ vAngle4 = 2; } fill(0,0,255); x5 = sin(radians(angle5)) * 50 + 200; ellipse(x5, y5, 32, 32); angle5 += 5; y5 += 1; if(y5 > 300){ y5 = 0; } }
Copy