Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Circle(x, y) {
- this.x = x;
- this.y = y;
- this.r = floor(random(0, 255));
- this.g = floor(random(0, 255));
- this.b = floor(random(0, 255));
- this.radius = 15;
- this.minSpeed = 1;
- this.maxSpeed = 5;
- this.speedX = random(-this.maxSpeed, this.maxSpeed);
- this.speedY = random(-this.maxSpeed, this.maxSpeed);
- this.timer = 0;
- this.getColor = function () {
- this.r = floor(random(0, 255));
- this.g = floor(random(0, 255));
- this.b = floor(random(0, 255));
- }
- this.update = function () {
- this.timer++
- fill(this.r, this.g, this.b);
- ellipse(this.x, this.y, this.radius * 2, this.radius * 2);
- this.x = this.x + this.speedX;
- this.y = this.y + this.speedY;
- if (this.timer == 200) {
- this.radius = 30;
- }
- if (this.timer == 250) {
- this.radius = 0;
- circles.push(new Circle(width/2, height/2));
- }
- if (this.timer == 400) {
- this.radius = 10;
- this.timer = 0;
- }
- if (this.x + this.radius > width) {
- this.speedX = random(-this.minSpeed, -this.maxSpeed);
- this.getColor();
- } else if (this.x - this.radius < 0) {
- this.speedX = random(this.minSpeed, this.maxSpeed);
- this.getColor();
- } else if (this.y + this.radius > height) {
- this.speedY = random(-this.minSpeed, -this.maxSpeed);
- this.getColor();
- } else if (this.y - this.radius < 0) {
- this.speedY = random(this.minSpeed, this.maxSpeed);
- this.getColor();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment