xxxxxxxxxx
140
let scounter = 0;
let star;
let roundc =0;
let sound;
function preload() {
sound = loadSound('spinmeround.wav');
}
function setup() {
createCanvas(500, 500);
}
function mousePressed(){
sound.setVolume(0.3);
sound.play();
sound.loop();
}
function mouseReleased(){
sound.stop();
}
function draw() {
background(0);
translate(width/2,height/2.1);
fill('red');
stroke(getRandomColor());
strokeWeight(8);
textSize(24);
textAlign(CENTER, CENTER);
text("SPIN ME!", 0, 225);
roundc+=1.8;
let a = map(roundc, 0, TWO_PI, 90, PI);
let b = map(roundc,TWO_PI,0,PI,90);
let r1;
let v0 = createVector(0,0);
if (mouseIsPressed === true) {
rectMode(CENTER);
rotate(a);
frameRate(10);
for(let i = 0; i < TWO_PI;i+=0.5){
r1 = 300;
v0.y = map(cos(a+i)*r1, TWO_PI, 0, PI, 0);
v0.x = map(sin(b+i)*r1, 0, TWO_PI, 0, PI);
star = new Stars(v0.x-15,v0.y-70);
star.show();
}
}
else{
frameRate(60);
for(let i = 0; i < TWO_PI;i+=0.5){
r1 = 150;
let x = cos(i)*r1;
let y = sin(i)*r1;
star = new Stars(x-15,y-70);
star.show();
}
}
if (scounter > 200){
scounter = 0;
}
scounter++;
noFill();
strokeWeight(1);
stroke('gray');
let r = 70;
let v = createVector(0,0);
let vybottom = map(scounter,100,80/TWO_PI,85,80);
let vytop = map(scounter,0,90,90,90);
fill('pink');
stroke('pink');
let innerRadius = 75;
let numPoints = 5;
let outerRadius = 110;
beginShape();
for (let i = 0; i < numPoints * 2; i++) {
let radius = i % 2 === 0 ? outerRadius : innerRadius;
let x = v.x+cos(i*5) * radius;
let y = vybottom+v.y+sin(i*5) * radius;
vertex(x, y-70);
}
endShape(CLOSE);
strokeWeight(5);
//mouth
stroke('red');
fill('orange');
beginShape();
vertex(v.x-3,vybottom+v.y-75);
bezierVertex(v.x+7,vytop+v.y-75,v.x+13,vytop+v.y-75,v.x+23,vybottom+v.y-75);
endShape();
noStroke();
//eyes
setPoint(v.x-3,vybottom+v.y-85,10);
setPoint(v.x+23,vybottom+v.y-85,10);
//pants
fill('lightgreen');
strokeWeight(1);
stroke('green');
// beginShape();
// vertex(v.x-71,vybottom+v.y-58);
// bezierVertex(v.x-33,vybottom+v.y+16,v.x,vybottom+v.y+16,v.x+61,vybottom+v.y-23);
// endShape(CLOSE);
beginShape();
vertex(v.x-71,vybottom+v.y-51);
vertex(v.x-73,vybottom+v.y-21);
bezierVertex(v.x-65,vybottom+v.y-17,v.x-45,vybottom+v.y-17,v.x-9,vybottom+v.y+3);
bezierVertex(v.x+25,vybottom+v.y-3,v.x+45,vybottom+v.y+1,v.x+54,vybottom+v.y+3);
vertex(v.x+61,vybottom+v.y-21);
endShape();
beginShape();
vertex(v.x-71,vybottom+v.y-58);
vertex(v.x-71,vybottom+v.y-51);
bezierVertex(v.x-33,vybottom+v.y-35,v.x,vybottom+v.y-18,v.x+61,vybottom+v.y-21);
vertex(v.x+61,vybottom+v.y-25);
bezierVertex(v.x,vybottom+v.y-28,v.x-33,vybottom+v.y-45,v.x-71,vybottom+v.y-58);
endShape();
}
function setPoint(x,y,w){
strokeWeight(w);
if(w == 6){
stroke('gray');
}
else{
stroke(getRandomColor());
}
point(x,y);
}
function getRandomColor(){
return color(random(255),random(255),random(255));
}