xxxxxxxxxx
122
let ice = [];
let sprink = [];
function setup() {
createCanvas(400, 400);
angleMode(DEGREES);
ellipseMode(CENTER);
let i = new iceCream(
width / 2, // x
height / 2, // y
50, // width
50, // height
2, // xspeed
3, // yspeed
1 // rspeed
);
ice.push(i);
}
function draw() {
background(220);
for (let i = 0; i < ice.length; i = i + 1) {
ice[i].update();
}
for (let i = 0; i < sprink.length; i = i + 1) {
sprink[i].update();
}
}
function mouseDragged() {
let s = new sprinkles(
mouseX, // x
mouseY, // y
10, // width
20, // height
random(-2, 2), // xspeed
random(-2, 2), // yspeed
random(1) // rspeed
);
sprink.push(s)
}
class iceCream {
constructor(x, y, w, h, xS, yS, rS) {
this.x = x;
this.y = y;
this.w = w;
this.h = h;
this.xS = xS;
this.yS = yS;
this.rS = rS;
this.a = 0;
}
update() {
push();
translate(this.x, this.y);
rotate(this.a);
noStroke();
fill(255, 255, 178);
ellipse(0, 20, this.w, this.h / 2);
ellipse(0, 0, this.w, this.h);
stroke(136, 39, 58);
fill(255, 0, 0);
ellipse(0, -30, this.w / 2, this.h / 2);
strokeWeight(3);
line(0, -35, 5, -60);
pop();
this.x = this.x + this.xS;
this.y = this.y + this.yS;
this.a = this.a + this.rS;
if (this.x >= width - this.w / 2 || this.x <= this.w / 2) {
this.xS = this.xS * -1;
}
if (this.y >= height - this.h / 2 || this.y <= this.h / 2) {
this.yS = this.yS * -1;
}
}
}
class sprinkles {
constructor(x, y, w, h, xS, yS, rS) {
this.x = x;
this.y = y;
this.w = w;
this.h = h;
this.xS = xS;
this.yS = yS;
this.rS = rS;
this.a = 0;
}
update() {
push();
translate(this.x, this.y);
rotate(this.a);
noStroke();
fill(200, 0, 200);
rect(0, 0, this.w, this.h, 5);
pop();
this.x = this.x + this.xS;
this.y = this.y + this.yS;
this.a = this.a + this.rS;
if (this.x >= width - this.w / 2 || this.x <= this.w / 2) {
this.xS = this.xS * -1;
}
if (this.y >= height - this.h / 2 || this.y <= this.h / 2) {
this.yS = this.yS * -1;
}
}
}
// mouse dragged sprinkles
// cone maybe