xxxxxxxxxx
179
var song;
var c1, c2;
let diameter;
let a1 = 0 //flowerG
let a2 = 0 //flowerR
let a3 = 0 //flowerO
let a4 = 0 //flowerW
let e1, e2
let value1 = 0;
let value2 = 0;
let value3 = 0;
let value4 = 0;
function preload(){
song = loadSound('getsomerest.mp3');
}
function setup() {
createCanvas(1280, 780);
slider = createSlider (0, 1, 0.5, 0.01);
song.play();
diameter = height - 10;
push ();
e1 = new Eye(590, 360, 220);
e2 = new Eye(790, 360, 220);
pop ();
}
function draw() {
song.setVolume(slider.value());
c1 = color(189, 162, 244);
c2 = color(255, 241, 134);
setGradient(c1, c2);
noStroke ()
//flowerG
push();
translate(1200,690);
fill(255);
scale (value1);
for (let i = 0; i < 10; i ++) {
let d1 = 50 + (sin(a1 + PI / 2) * diameter) / 30 + diameter / 20;
ellipse(10, 40, 50, d1);
rotate(PI/3);
a1 += 0.0055;
} pop();
//flowerR
push();
translate(150,190);
fill(255);
scale (value2);
for (let i = 0; i < 10; i ++) {
let d1 = 50 + (sin(a2 + PI / 2) * diameter) / 30 + diameter / 20;
ellipse(10, 40, 50, d1);
rotate(PI/3);
a2 += 0.0055;
} pop();
//flowerO
push();
translate(330,580);
fill(43);
scale (value3);
for (let i = 0; i < 10; i ++) {
let d1 = 50 + (sin(a3 + PI / 2) * diameter) / 30 + diameter / 20;
ellipse(10, 40, 50, d1);
rotate(PI/3);
a3 += 0.007;
} pop();
//flowerW
push();
translate(1100,110);
fill(43);
scale (value4);
for (let i = 0; i < 10; i ++) {
let d1 = 50 + (sin(a4 + PI / 2) * diameter) / 30 + diameter / 20;
ellipse(10, 40, 50, d1);
rotate(PI/3);
a4 += 0.008;
} pop();
e1.update(mouseX, mouseY);
e1.display();
e2.update(mouseX, mouseY);
e2.display();
var sparkle = {
locationX: random(width),
locationY: random(height),
size: random(10, 15)
}
fill (255);
noStroke();
ellipse(mouseX, mouseY, sparkle.size, sparkle.size);
ellipse(sparkle.locationX, sparkle.locationY, sparkle.size, sparkle.size);
frameRate (40)
}
//eye
function Eye(tx, ty, ts) {
this.x = tx;
this.y = ty;
this.size = ts;
this.angle = 0;
this.update = function(mx, my) {
this.angle = atan2(my - this.y, mx - this.x);
};
this.display = function() {
push();
translate(this.x, this.y);
fill(255);
//eye shape
translate(-40, -10);
scale(1);
translate(width/0,height/0);
beginShape();
vertex(-80,0);
bezierVertex(-30,-50,30,-50,80,0);
bezierVertex(30,50,-30,50,-80,0)
endShape();
rotate(this.angle);
fill(43);
scale (0.85)
ellipse(this.size / 25, -0.5, this.size / 3.1, this.size / 3.1);
pop();
}
}
function setGradient(c1, c2) {
// noprotect
noFill();
for (var y = 0; y < height; y++) {
var inter = map(y, 0, height, 0, 1);
var c = lerpColor(c1, c2, inter);
stroke(c);
line(0, y, width, y);
}
}
function keyTyped() {
if (key === 'g') {
value1 = 2.8;
} else if (key === 'r') {
value2 = 1;
} else {
value3 = 1.5;
}
}
function keyReleased (){
if (key === 'w'){
value4 = 0.75;
} else if (key === 'x'){
value1 = 0;
value2 = 0;
value3 = 0;
value4 = 0;
}
}