xxxxxxxxxx
458
//Hit the play button and the design will change!
// Starting code for Lab 7 - Tant de Forets
var numFrogs, numPads, numF, numWC;
var frogX = [];
var frogY = [];
var frogSC = [];
var frogROT = [];
var frogG = [];
var frogRB = [];
var newX = [];
var velocity = [];
var jumpDist = [];
var jDV = [];
var lpX = [];
var lpY = [];
var lpSC = [];
var lpROT = [];
var lpG = [];
var lpRB = [];
var wcX = [];
var wcY = [];
var wcSC = [];
var flowerX = [];
var flowerY = [];
function setup()
{
createCanvas(400, 400);
colorMode(RGB,255,255,255,1);
frogAcc = 0.05;
numFrogs = 6;
numWC = 6;
numPads = 20;
numF = 6;
for (var i=0; i<numFrogs; i++)
{
newX.push(0);
frogX.push(random(50, 350));
frogY.push(random(50, 350));
frogSC.push(random(0.75, 1.25));
velocity.push(random(1, 2));
jumpDist.push(frogSC[i]*30);
jDV.push(jumpDist[i]);
frogG.push(random(100, 255));
frogRB.push(random(0, 100));
if ((frogX[i] < width / 2) && (frogY[i] < height / 2))
{
frogROT.push(random(0, PI/2));
}
else if ((frogX[i] > width / 2) && (frogY[i] < height / 2))
{
frogROT.push(random(PI/2, PI));
}
else if ((frogX[i] > width / 2) && (frogY[i] > height / 2))
{
frogROT.push(random(-PI/2, -PI));
}
else
{
frogROT.push(random(-PI/2, 0));
}
}
for (var i=0; i<numPads; i++)
{
lpX.push(random(0, 400));
lpY.push(random(0, 400));
lpSC.push(random(0.75, 1.5));
lpROT.push(random(0, 2*PI));
lpG.push(random(50, 255));
lpRB.push(random(0, 25));
}
for (var i=0; i<numF; i++)
{
flowerX.push(random(50, 350));
flowerY.push(random(50, 350));
}
for (var i=0; i<numWC; i++)
{
wcX.push(random(0, 400));
wcY.push(random(0, 400));
wcSC.push(random(1, 2));
}
}
function draw()
{
background(0, 54, 75);
for (var i=0; i<numWC; i++)
{
push();
drawWaterCirc(wcX[i], wcY[i], wcSC[i]);
pop();
}
for (var i=0; i<numF; i++)
{
push();
scale(1.5);
drawRipple(flowerX[i], flowerY[i]);
pop();
}
for (var i=0; i<numPads; i++)
{
push();
drawLilyPad(lpX[i], lpY[i], lpROT[i], lpSC[i], lpG[i], lpRB[i]);
pop();
}
for (var i=0; i<numF; i++)
{
push();
scale(1.5);
drawFlower(flowerX[i], flowerY[i])
pop();
}
for (var i=0; i<numFrogs; i++)
{
push();
if (velocity[i] <= 0)
{
jumpDist[i] += jDV[i];
}
if (newX[i] < jumpDist[i]/2)
{
velocity[i] += frogAcc;
}
else if (newX[i] >= jumpDist[i]/2)
{
velocity[i] -= frogAcc;
}
noStroke();
drawFrog(frogX[i], frogY[i], newX[i], frogROT[i], frogSC[i], frogG[i], frogRB[i]);
newX[i] += velocity[i];
pop();
}
push();
translate(mouseX, mouseY);
strokeWeight(1);
stroke(0);
line(-10, 0, 10, 0);
line(0, -10, 0, 10);
strokeWeight(0);
fill(0);
textSize(10);
text('x: ' + mouseX, 20, 10);
text('y: ' + mouseY, 20, 20);
text(frogAcc, 20, 30);
pop();
}
function drawFrog(x, y, nX, rot, sc, g, rb)
{
push();
translate(x, y);
scale(sc);
rotate(rot);
translate(nX, 0);
push();
rotate(PI/2);
//
// fill(rb, g, rb);
// fill(rb, g-30, rb);
// fill(rb, g-60, rb);
// fill(rb-30, g-90, rb-30);
//
fill(0);
ellipse(-8.7, -27.3, 5.6);
ellipse(8.7, -27.3, 5.6);
fill(rb, g-30, rb);
rect(-12.2, 1.3, 24.5, 11.7);
quad(-12.2, 13, 0, 13, 12.2, 13, 0, 32.5);
quad(-2.5, -37.6, -2.5, -30.1, -5.6, -30.1, -8.7, -30.1);
quad(2.5, -37.6, 2.5, -30.1, 5.6, -30.1, 8.7, -30.1);
fill(rb, g, rb);
rect(-8.7, -30.1, 17.4, 31.4);
rect(-12.2, -9.9, 24.5, 11.1);
rect(-2.5, -37.6, 5, 7.4);
quad(-4.5, -0.6, 0, -0.6, 4.5, -0.6, 0, 19.7);
//
beginShape();
curveVertex(7.5, -13.1);
curveVertex(7.5, -13.1);
curveVertex(9.9, -12.8);
curveVertex(15.9, -9.1);
curveVertex(22.2, -2.4);
curveVertex(24.1, 3.3);
curveVertex(24.1, 3.3);
curveVertex(22, 2.8);
curveVertex(15.1, -1.2);
curveVertex(9.5, -8.4);
endShape();
beginShape();
curveVertex(24.1, 3.3);
curveVertex(24.1, 3.3);
curveVertex(26.4, -4.7);
curveVertex(26.2, -8.6);
curveVertex(23.7, -13);
curveVertex(23.7, -13);
curveVertex(22.7, -10.7);
curveVertex(21.3, -6);
curveVertex(22.1, -.5);
endShape();
fill(211, 178, 52);
quad(25.2, 25.3, 33.4, 21.1, 17.7, 37.6, 22.6, 29.5);
fill(rb, g-60, rb);
beginShape();
curveVertex(29.1, 8.5);
curveVertex(29.1, 8.5);
curveVertex(29.5, 14.1);
curveVertex(28.1, 22.3);
curveVertex(23.5, 30.4);
curveVertex(17.7, 37.6);
curveVertex(17.7, 37.6);
curveVertex(18.2, 28.8);
curveVertex(19.1, 23.5);
curveVertex(22.4, 16.2);
endShape();
fill(rb-30, g-90, rb-30);
beginShape();
curveVertex(29.1, 8.5);
curveVertex(29.1, 8.5);
curveVertex(28.1, 13.5);
curveVertex(26.1, 19.4);
curveVertex(21.9, 26.6);
curveVertex(18.1, 30.6);
curveVertex(18.1, 30.6);
curveVertex(18.4, 27.5);
curveVertex(19.1, 23.5);
curveVertex(20.9, 18.5);
curveVertex(24.6, 12.6);
curveVertex(27, 10.2);
endShape();
fill(rb, g, rb);
beginShape();
curveVertex(29.1, 8.5);
curveVertex(29.1, 8.5);
curveVertex(21.9, 11.6);
curveVertex(14.9, 15.7);
curveVertex(10, 20.4);
curveVertex(6.2, 26.5);
curveVertex(2.5, 35.3);
curveVertex(2.5, 35.3);
curveVertex(14.2, 30);
curveVertex(20.8, 23.7);
curveVertex(27.2, 13.3);
endShape();
drawFoot(23.7, -13, 0);
drawFoot(33.7, 20.8, PI/4);
//
push();
scale(-1, 1);
beginShape();
curveVertex(7.5, -13.1);
curveVertex(7.5, -13.1);
curveVertex(9.9, -12.8);
curveVertex(15.9, -9.1);
curveVertex(22.2, -2.4);
curveVertex(24.1, 3.3);
curveVertex(24.1, 3.3);
curveVertex(22, 2.8);
curveVertex(15.1, -1.2);
curveVertex(9.5, -8.4);
endShape();
beginShape();
curveVertex(24.1, 3.3);
curveVertex(24.1, 3.3);
curveVertex(26.4, -4.7);
curveVertex(26.2, -8.6);
curveVertex(23.7, -13);
curveVertex(23.7, -13);
curveVertex(22.7, -10.7);
curveVertex(21.3, -6);
curveVertex(22.1, -.5);
endShape();
fill(211, 178, 52);
quad(25.2, 25.3, 33.4, 21.1, 17.7, 37.6, 22.6, 29.5);
fill(rb, g-60, rb);
beginShape();
curveVertex(29.1, 8.5);
curveVertex(29.1, 8.5);
curveVertex(29.5, 14.1);
curveVertex(28.1, 22.3);
curveVertex(23.5, 30.4);
curveVertex(17.7, 37.6);
curveVertex(17.7, 37.6);
curveVertex(18.2, 28.8);
curveVertex(19.1, 23.5);
curveVertex(22.4, 16.2);
endShape();
fill(rb-30, g-90, rb-30);
beginShape();
curveVertex(29.1, 8.5);
curveVertex(29.1, 8.5);
curveVertex(28.1, 13.5);
curveVertex(26.1, 19.4);
curveVertex(21.9, 26.6);
curveVertex(18.1, 30.6);
curveVertex(18.1, 30.6);
curveVertex(18.4, 27.5);
curveVertex(19.1, 23.5);
curveVertex(20.9, 18.5);
curveVertex(24.6, 12.6);
curveVertex(27, 10.2);
endShape();
fill(rb, g, rb);
beginShape();
curveVertex(29.1, 8.5);
curveVertex(29.1, 8.5);
curveVertex(21.9, 11.6);
curveVertex(14.9, 15.7);
curveVertex(10, 20.4);
curveVertex(6.2, 26.5);
curveVertex(2.5, 35.3);
curveVertex(2.5, 35.3);
curveVertex(14.2, 30);
curveVertex(20.8, 23.7);
curveVertex(27.2, 13.3);
endShape();
drawFoot(23.7, -13, 0);
drawFoot(33.7, 20.8, PI/4);
pop();
fill(rb, g-60, rb);
ellipse(-6.1, -26.3, 5.2);
ellipse(6.8, -27, 3.9);
ellipse(-2.9, -23.7, 1.6);
ellipse(-7, -20.8, 2.2);
ellipse(-3.8, -20.8, 3.1);
ellipse(-5.4, -16.6, 3.1);
ellipse(-6.5, -7.2, 3.1);
ellipse(-5.4, -2.8, 2.4);
ellipse(-2.3, -2.3, 1.7);
ellipse(-5.3, 1.8, 2);
ellipse(-10.6, 4.2, 3.3);
ellipse(-3.2, 4.2, 3.1);
ellipse(-7.4, 6.7, 2);
ellipse(-7.4, 9.8, 1.5);
ellipse(-9.4, 11.9, 1.9);
ellipse(6.5, 6, 1.9);
ellipse(8.4, 11.4, 3.1);
ellipse(8.4, 16.5, 2.6);
ellipse(4.2, 16.2, 2.1);
ellipse(18.5, 15.1, 2.8);
ellipse(20.7, 18.3, 1.8);
ellipse(14.3, 19.9, 4.2);
ellipse(16.1, 24.7, 1.8);
ellipse(12.2, 29.2, 2.8);
ellipse(7.1, 29.9, 1.8);
ellipse(-18.5, 15.1, 2.8);
ellipse(-14.4, 20.3, 3.5);
ellipse(-16.1, 24.7, 1.8);
ellipse(-10.5, 24.7, 1.1);
pop();
pop();
}
function drawFoot(x, y, rot)
{
push();
translate(x, y);
rotate(rot);
noFill();
strokeWeight(3);
stroke(211, 178, 52);
line(0, 0, 6.6, -6.6);
line(0, 0, 0, -10.6);
line(0, 0, -6.6, -6.6);
noStroke();
fill(211, 178, 52);
ellipse(7.9, -7.9, 3.7);
ellipse(0, -12.5, 3.7);
ellipse(-7.9, -7.9, 3.7);
fill(161, 124, 45);
ellipse(7.9, -7.9, 1.5);
ellipse(0, -12.5, 1.5);
ellipse(-7.9, -7.9, 1.5);
pop();
}
function drawLilyPad(x, y, rot, sc, g, rb)
{
push();
translate(x, y);
rotate(rot);
scale(sc);
noStroke();
fill(rb, g, rb);
arc(0, 0, 75, 75, 0, ((2*PI)-(PI/6)), PIE)
pop();
}
function drawWaterCirc(x, y, sc)
{
push();
translate(x, y);
scale(sc);
noStroke();
fill(0, 30, 30, .5);
ellipse(0, 0, 125);
pop();
}
function drawFlower(x, y)
{
push();
noStroke();
translate(x, y);
push();
rotate(PI/8);
fill(200);
star(0, 0, 10, 25, 8);
pop();
fill(255);
star(0, 0, 7.5, 20, 8);
fill(234, 156, 35);
ellipse(0, 0, 10);
pop();
}
function star(x, y, radius1, radius2, npoints) {
let angle = TWO_PI / npoints;
let halfAngle = angle / 2.0;
beginShape();
for (let a = 0; a < TWO_PI; a += angle) {
let sx = x + cos(a) * radius2;
let sy = y + sin(a) * radius2;
vertex(sx, sy);
sx = x + cos(a + halfAngle) * radius1;
sy = y + sin(a + halfAngle) * radius1;
vertex(sx, sy);
}
endShape(CLOSE);
}
function drawRipple(x, y)
{
push();
translate(x, y);
noFill();
stroke(56, 101, 119);
strokeWeight(1.5);
ellipse(0, 0, 50);
ellipse(0, 0, 75);
pop();
}
//Hit the play button and the design will change!