For this assignment, I have worked with class and objects.
I based the idea on the work I replicated for Assignment 6 and came up with the code with the help of Getting started with Processing and online resources.
Here is the code that I used:
CrazyShape circle1, circle2, square3;
void setup() {
size(500,500);
smooth();
circle1 = new CrazyShape(20, 1.5, color(random(255), 125, 0));
circle2 = new CrazyShape(10, 3, color(255, 0, random(155)));
square3 = new CrazyShape(30, 2.5, color(0, random(125), 255));
}
void draw() {
circle1.move();
circle1.displayCircle();
circle2.move();
circle2.displayCircle();
square3.move();
square3.displaySquare();
}
CrazyShape
class CrazyShape {
float x;
float y;
int diameter;
float speed;
color c;
CrazyShape(int id, float ispeed, color ic) {
x = random(width);
y = random(height);
speed = ispeed;
diameter = id;
c = ic;
}
void move() {
x += random(-speed, speed);
y += random(-speed, speed);
if (x < 0+diameter) {
x = random(width);
c = color(random(255), random(255), random(255));
} else if (x > width-diameter) {
x = random(width);
c = color(random(255), random(255), random(255));
}
if (y < 0+diameter) {
y = random(height);
c = color(random(255), random(255), random(255));
} else if (y > height-diameter) {
y = random(height);
c = color(random(255), random(255), random(255));
}
}
void displayCircle() {
fill(c);
ellipse(x, y, diameter, diameter);
}
void displaySquare() {
fill(c);
rect(x, y, diameter, diameter);
}
}