Justin - K

By Justin Chen
Ball A1; Ball A2; float x =50; float y =50; float radius = 40; float speedX =1; float speedY =2; int directionX =1; int directionY =1; void setup() { size (400, 400); smooth(); noStroke(); ellipseMode(RADIUS); A1 = new Ball(); A2 = new Ball(); A1.Values(200, 200, 50, A1); A2.Values(200, 200, 20, A2); } void draw() { fill (0, 20); rect ( 0,0, width, height); fill(234, 20, 40, 20); A1.move(); A1.display(); fill(0, 190, 243); A2.move(); A2.display(); } class Ball { float x; float y; float diameter = 10; float speed = 0.1; Ball A2; Ball() { } void Values (float centerx, float centery, float dia, Ball Ball2) { x = centerx; y = centery; diameter = dia; A2 =Ball2; } void move() { y += speedY * directionY; if ((y > width-radius) || (y < radius)) { directionY = -directionY; } x = x + random(-10, 10); y = y + random(-10, 10); x= constrain(x, 0, width); y= constrain(y, 0, height); x += speedX * directionX; if ((x > width-radius) || (x < radius)) { directionX = -directionX; } if (x>200) { fill(255); } if(y<200){ fill(255, 245,0); } } void display() { ellipse(x, y, diameter, diameter); } }

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*