xxxxxxxxxx
55
let img;
var song;
var button;
var xPos = [];
var yPos = [];
var speeds = [];
function preload(){
img=loadImage("taco.png");
}
function setup() {
createCanvas(400,400);
song = loadSound("Raining Tacos - Parry Gripp .mp3",loaded);
button = createButton("play");
button.mousePressed(togglePlaying);
background(0);
var count = 0;
while(count < 125){
append(xPos, random(400));
append(yPos, random(400));
append(speeds, random(1,2));
count++;
}
noStroke();
}
function loaded(){
console.log("loaded");
}
function togglePlaying(){
if(!song.isPlaying()){
song.play();
song.setVolume(0.5);
button.html("pause");
} else{
song.pause();
button.html("play");
}
}
function draw() {
background(104, 185, 217);
var i =0;
while(i < xPos.length){
fill(255);
image(img,xPos[i],yPos[i],50,50);
//ellipse(xPos[i],yPos[i], 7, 7);
yPos[i] = yPos[i] + speeds[i];
if(yPos[i] > 400){
yPos[i] = 0;
}
i++;
}
}