This is an old revision of the document!
Yuna's crazyDog.js
function setup() {
createCanvas(1800,780) // Starts in the middle x = width / 2; y = height / 2;
noLoop();
}
class Sun {
constructor (sSize, sColor, cColor, startingX, startingY)
{ this.sunSize = sSize;
this.sunColor = sColor;
this.center = cColor;
this.positionX = startingX;
this.positionY = startingY;
}
draw () {
push();
noStroke();
fill(255, 244, 25);
translate(this.positionX+103, this.positionY+100);
rotate(radians(40)); ellipse(this.positionX+75, this.positionY+0, 45, 15); // start from 75 (tip of ellipse, 150/2), since ellipse is 150 wide rotate(radians(40)); ellipse(this.positionX+75, this.positionY+0, 45, 15); rotate(radians(40)); ellipse(this.positionX+75, this.positionY+0, 45, 15); rotate(radians(40)); ellipse(this.positionX+75, this.positionY+0, 45, 15); rotate(radians(40)); ellipse(this.positionX+75, this.positionY+0, 45, 15); rotate(radians(40)); ellipse(this.positionX+75, this.positionY+0, 45, 15); rotate(radians(40)); ellipse(this.positionX+75, this.positionY+0, 45, 15); rotate(radians(40)); ellipse(this.positionX+75, this.positionY+0, 45, 15); rotate(radians(40)); ellipse(this.positionX+75, this.positionY+0, 45, 15);
pop();
//center of Sun noStroke(); fill(255, 174, 13); ellipse(this.positionX+100, 107, 80, 80);
} } class CrazyDog {
constructor (cSize, cColor, colorarr, numberarr, startingX, startingY)
{ this.crazyDogSize = cSize;
this.crazyDogColor = cColor;
this.colorarr = colorarr;
this.numberarr = numberarr;
this.positionX = startingX;
this.positionY = startingY;
}
draw () {
//dog
for (let i = 0; i < 1; i++){
this.colorarr= [255, 500, 200]
let r = random(this.colorarr);
strokeWeight(2);
stroke(0);
let myRandoms = [Math.random()*r, Math.random()*r, Math.random()*r]
fill(myRandoms[0], myRandoms[1], myRandoms[2]);
//front left side feet
rect(this.positionX + 60, this.positionY+298, 10, 35, 20);
//front right side feet
rect(this.positionX + 65, this.positionY+298, 10, 35, 20);
//back left side feet
rect(this.positionX + 110, this.positionY+298, 10, 35, 20);
//back right side feet
rect(this.positionX + 115, this.positionY+298, 10, 35, 20);
//tail
for (let i = 0; i < 1; i++){
this.numberarr = [0, 15, 10, 5]
let r = random(this.numberarr)
rect(this.positionX + 130, this.positionY+283,40+r,8);
}
//body
rect(this.positionX + 50, this.positionY+253, 85, 55);
//head
circle(this.positionX + 50, this.positionY+253, 40);
//Left side ear
circle(this.positionX + 25, this.positionY+236, 20);
fill(Math.random()*r, Math.random()*r, Math.random()*r)
circle(this.positionX + 25, this.positionY + 236, 10);
//Right side ear
fill(myRandoms[0], myRandoms[1], myRandoms[2]);
circle(this.positionX + 65,this.positionY + 228, 20);
fill(Math.random()*r, Math.random()*r, Math.random()*r)
circle(this.positionX + 65, this.positionY+229, 10);
}
for (let i = 0; i < 1; i++){
this.numberarr = [0, 15, 10, 5]
let r = random(this.numberarr)
fill(0)
//Left eyes(black)
circle(this.positionX + 40, this.positionY+253, 7+r);
//Right eyes(black)
circle(this.positionX + 60, this.positionY+253, 7+r);
fill(255)
//Left eyes(white)
circle(this.positionX + 40, this.positionY+253, 3+r);
//Right eyes(white)
circle(this.positionX + 60, this.positionY+253, 3+r);
}
} }
function dogArray (n, y) {
let outputArray = [];
for (let i = 0; i < n ; i++) {
outputArray.push(new CrazyDog (10, Math.random(), 10, 10, 10+(i*150), 10 + y))
}
return outputArray
}
class Ground {
constructor (gSize, gColor, startingX, startingY)
{ this.groundSize = gSize;
this.groundColor = gColor;
this.positionX = startingX;
this.positionY = startingY;
}
draw () {
//ground
strokeWeight(2);
stroke(0);
fill(162, 232, 181);
rect(1, 344, 15400, 55);
rect(1, 644, 15400, 55);
} }
class Cloud {
constructor (cSize, cColor, startingX, startingY)
{ this.cloudSize = cSize;
this.cloudColor = cColor;
this.positionX = startingX;
this.positionY = startingY;
}
draw () {
noStroke();
fill(color(this.cloudColor));
ellipse(this.positionX+250,50,60,50);
ellipse(this.positionX+280,40,60,50);
ellipse(this.position+230,50,60,50);
ellipse(this.positionX+270,70,60,50);
ellipse(this.positionX+300,65,60,50);
}
}
function cloudArray (n) {
let outputArray = [];
for (let i = 0; i < n ; i++) {
outputArray.push(new Cloud (100, "white", 20+(i*130), 20))
}
return outputArray
}
let myClouds = cloudArray(114);
function draw() {
background(187, 226, 242); let sun1 = new Sun (10, "yellow", "orange", 10, 10) sun1.draw(); let ground1 = new Ground (10, "green", 10, 20); ground1.draw(); //let cloud1 = new Cloud (100, "white", 20, 20); //cloud1.draw();
let crazyDog1 = new CrazyDog (10, Math.random(), 10, 10, 10, 10); crazyDog1.draw();
x = 150;
// THE IMPORTANT LINE CONTROLLING THE ANIMATION UP AND DOWN!
// the center point the speed the range
y = -240 + (height * (1/2)) + (Math.sin(frameCount/10) * (height/5));
let myDogs = dogArray(12, y);
for(let i = 0; i < myDogs.length ; i++){
myDogs[i].draw()
}
for(let i = 0; i < myClouds.length ; i++){
myClouds[i].draw()
}
}> </Code>