[OLD FALL 2020] 15-104 • Introduction to Computing for Creative Practice
https://courses.ideate.cmu.edu/15-104/f2020
Professor Tom Cortina • Fall 2020 • Introduction to Computing for Creative PracticeWed, 10 Nov 2021 04:12:55 +0000en-US
hourly
1 https://wordpress.org/?v=5.4.15COVID-19 Story
https://courses.ideate.cmu.edu/15-104/f2020/2021/11/09/covid-19-story/
https://courses.ideate.cmu.edu/15-104/f2020/2021/11/09/covid-19-story/#respondWed, 10 Nov 2021 03:35:32 +0000https://courses.ideate.cmu.edu/15-104/f2020/?p=64641Continue reading "COVID-19 Story"]]>
var anxiety; //sound for computer anxiety
var sing; //sound for birds singing
var doorclose; //sound for door closing
var alarm; //sound for the clock
var squish; //sound for the virus
var drawer;
function preload() { //loading sounds
anxiety = loadSound("https://courses.ideate.cmu.edu/15-104/f2020/wp-content/uploads/2021/11/Anxiety.wav");
sing = loadSound("https://courses.ideate.cmu.edu/15-104/f2020/wp-content/uploads/2021/11/birds.wav");
doorclose = loadSound("https://courses.ideate.cmu.edu/15-104/f2020/wp-content/uploads/2021/11/doorclose.m4a");
alarm = loadSound("https://courses.ideate.cmu.edu/15-104/f2020/wp-content/uploads/2021/11/clock.wav");
squish = loadSound("https://courses.ideate.cmu.edu/15-104/f2020/wp-content/uploads/2021/11/squish.wav")
drawer = loadSound("https://courses.ideate.cmu.edu/15-104/f2020/wp-content/uploads/2021/11/drawer.wav")
}
function soundSetup() {
//setting the volume for each sound
anxiety.setVolume(1);
sing.setVolume(0.2);
doorclose.setVolume(1);
alarm.setVolume(1);
squish.setVolume(1);
drawer.setVolume(1);
}
var virus = []; //array of "germs"
var painted = []; //paint on the wall
var x = [];
var y = [];
var reliefBubbles = [];
var landscape = []; //array that creates hills
var rock = []; //array that creates rock
var trees = []; //trees on the close side of the road
var trees2 = []; //trees on the far side of the road
var cars = []; //cars on the road
var flocks = []; //flocks of birds
var bx = 180; //bird coordinates and
var by = 180;
var bdx = 0;
var bdy= 0;
var textX = 100; //the scrolling text on the TV
var germShot = -1; //which germ has been "shot" with the syringe
var r = 40; //radius of clock
var theta = 0; // angle of rotation (starting) for clock
var c = 10; //to move the chart
var count = -10; //to control where the germs "stop" on the screen
var EamonnX = 100; //The x location of me as I walk
var opacity = 255;
var size = 10;
var noiseParam = 0;
var noiseStep = 0.03; //extremity of the slopes
function setup() {
createCanvas(400,300);
background(220);
frameRate(5)
noStroke();
fill(136,238,143); //first scene background
rect(0,0,400,height);
t1 = makeTurtle(380,200); //constructing turtles for the computer anxiety
t2 = makeTurtle(380,200);
t3 = makeTurtle(380,200);
t4 = makeTurtle(380,200);
t5 = makeTurtle(380,200);
//setting the color and weight
t1.lowerPen();
t1.setColor(color(0));
t1.setWeight(random(1,3));
t2.lowerPen();
t2.setColor(color(0));
t2.setWeight(random(1,3));
t3.lowerPen();
t3.setColor(color(0));
t3.setWeight(random(1,3));
t4.lowerPen();
t4.setColor(color(0));
t4.setWeight(random(1,3));
t5.lowerPen();
t5.setColor(color(0));
t5.setWeight(random(1,3));
noStroke();
for(var i=0;i<=width/5;i++){ //creating hills
var n= noise(noiseParam); //picks value 0-1
var value = map(n,0,1,150,250); //scales it to the canvas size
landscape.push(value); //adds to array
noiseParam+=noiseStep; //moves to the right for the next point in the array
}
for(var i=0;i<=width/5;i++){ //creating rocks
var n2= noise(noiseParam); //picks value 0-1
var value2 = map(n2,0,1,250,300); //scales it to the canvas size
rock.push(value2); //adds to array
noiseParam+=noiseStep; //moves to the right for the next point in the array
}
//plotting the starting objects
for (var i = 0; i < 30; i++){
var Tx = random(width);
var Ty = random(280,height);
trees[i] = makeTree(Tx,Ty);
}
for (var i = 0; i < 30; i++){
var Tx2 = random(width);
var Ty2 = random(240,260);
trees2[i] = makeTree(Tx2,Ty2);
}
for (var i = 0; i < 2; i++){
var Fx = random(width);
var Fy = random(0,200);
flocks[i] = makeFlock(Fx,Fy);
}
for (var i = 0; i < 10; i++){
var Cx = random(width);
cars[i] = makeCar(Cx);
}
useSound();
}
function draw() {
//storyboard for the animation
if(frameCount > 0 & frameCount<=100){
openingScene();
}
if(frameCount>100 & frameCount<=200){
anxiety.stop();
sceneTwo();
}
if(frameCount==100){
squish.play();
}
if(frameCount>200 & frameCount<=380){
sceneThree();
squish.stop();
}
if(frameCount==200){
alarm.play();
}
if(frameCount>380){
alarm.stop();
sing.play();
finalScene();
}
if(frameCount==380){
sing.play();
}
if(frameCount>1000){
sing.stop();
}
}
function openingScene(){
Window(100,50); //drawing the room
bed(0,200);
chair(270,190);
laptop(350,210);
Eamonn(295,160);
if(frameCount>20){ //initializing the computer anxiety
push();
computerAnxiety();
pop();
}
if(frameCount==20){
anxiety.play();
}
desk(340,210);
bird();
fill(255); //white
rect(147.5,50,5,150); //frames
rect(100,122.5,100,5);
}
//functions for the first scene
function Window(x,y){
push();
translate(x,y);
fill(155,245,245); //light blue
rect(0,0,100,150); //glass
fill(255); //white
rect(47.5,0,5,150); //frames
rect(0,72.5,100,5);
pop();
}
function bed(x,y){
push();
translate(x,y);
fill(10,95,193); //dark blue
rect(0,0,100,height,10); //beds
rect(200,0,200,height,10);
pop();
}
function chair(x,y){
push();
translate(x,y);
fill(255); //white
rect(0,0,8,110); //chair
rect(0,55,55,8);
rect(55,55,8,60);
pop();
}
function desk(x,y){
push();
translate(x,y);
fill(236,188,75); //yellow-brown
rect(0,0,75,100);
fill(131,92,3); //dark brown
rect(-227,0,75,100)
fill(166,123,21); //light brown
rect(-220,10,60,30);
fill(131,92,3); //dark brown
ellipse(-190,25,10,10); //knob
if(mouseX>110 & mouseX<180 && mouseY>220 && mouseY<250 && mouseIsPressed){ //if mouse is pressed on drawer, open it
fill(0); //black
rect(-217,10,54,30); //inside of drawer
fill(166,123,21);
rect(-220,20,60,30);
fill(131,92,3);
ellipse(-190,35,10,10); //knob
}
pop();
}
function laptop(x,y){
push();
translate(x,y);
fill(150); //gray
rect(1,-2,30,3); //laptop keyboard
quad(30,0,30,3,43,-20,41,-23); //screen
pop();
}
function Eamonn(x,y){
push();
translate(x,y);
fill(0); //black
rect(-10,65,65,20,10); //legs
rect(35,65,20,75,10);
fill(186); //gray
rect(32,130,30,10,10); //shoe
fill(255,220,200); //beige
ellipse(2,0,29); //head
rect(-2,0,8,20); //neck
fill(242,201,69); //golden brown
ellipse(-6,0,13,27); //hair
ellipse(4,-10,27,10);
fill(176,58,58); //maroon
rect(-13,20,30,60,15); //shirt
fill(176); //gray
push();
rotate(radians(-80)); //reaching out to laptop
rect(-40,5,15,50,15); //arm
pop();
fill(255,220,200); //beige
ellipse(47,41,15); //head
pop();
}
function bird(){
push();
if(mouseX>90 &mouseX<190 &&mouseY>50 &&mouseY<190){ //is mouse is on window, show bird
bdx = mouseX-bx; //"easing" the bird
bdy= mouseY-by;
bx = bx + 0.1*bdx;
by = by + 0.1*bdy;
fill(138,102,18); //dark brown
triangle(bx,by-5,bx,by+5,bx+20,by+random(-5,5)); //wings
triangle(bx,by-5,bx,by+5,bx-20,by+random(-5,5));
fill(213,99,12); //red brown
triangle(bx+1,by-13,bx+1,by-8,bx+11,by-10); //beak
fill(182,139,54); //dark brown
ellipse(bx,by,12,15); //head
fill(138,102,18); //light brown
ellipse(bx,by-10,10,10);
}
pop();
}
function computerAnxiety(){
var EamonnHeadX = 295; //coordinates of my head
var EamonnHeadY = 160;
t1.forward(random(1,3)); //move at varying speeds
t2.forward(random(1,3));
t3.forward(random(1,3));
t4.forward(random(1,3));
t5.forward(random(1,3));
t1.turnToward(EamonnHeadX, EamonnHeadY, 80); //move toward my head
t2.turnToward(EamonnHeadX, EamonnHeadY, 20);
t3.turnToward(EamonnHeadX, EamonnHeadY, 50);
t4.turnToward(EamonnHeadX, EamonnHeadY, 60);
t5.turnToward(EamonnHeadX, EamonnHeadY, 70);
t1.left(random(-1, 1)); //to make the movement erratic
t2.left(random(-1, 1));
t3.left(random(-1, 1));
t4.left(random(-1, 1));
t5.left(random(-1, 1));
}
function sceneTwo(){
fill(255,200,104); //orange
rect(0,0,width,height); //background
Television(70,50);
fill(161,105,9); //brown
rect(45,235,300,100); //desk
chart(135,65);
TVAnxiety();
syringe();
if (mouseIsPressed & (germShot > -1)) { //if mouse is pressed on germ, remove it from array
virus.splice(germShot,1);
}
}
function Television(x,y){
push();
translate(x,y);
stroke(0);
strokeWeight(10);
fill(166,250,255); //light blue
rect(0,0,250,150); //screen
rect(115,150,10,20); //stand (stroke color)
rect(25,175,200,5); //stand
fill(252,49,49); //red
noStroke();
rect(5,115,240,15); //news banner
textSize(10);
fill(255); //white
text("CORONAVIRUS RISING IN US",textX,127);
textX-=5; //move text
if(textX<5){ //reset text if reaches end of TV
textX = 100;
}
pop();
}
function chart(x,y){
push();
translate(x,y);
fill(255); //white
strokeWeight(2);
stroke(0);
rect(0,0,120,90); //chart background
line(10,20,10,80); //axis
line(10,80,100,80);
fill(255,0,0); //red
textSize(20);
text("CASES", 30,20);
strokeWeight(5);
var ttl = makeTurtle(12,78); //create a turtle
ttl.setWeight(5);
ttl.setColor(color(255,0,0)); //red
ttl.left(45); //making graph line
ttl.forward(30);
ttl.right(90);
ttl.forward(15);
ttl.left(90);
ttl.forward(c);
c+=2 //chart is going up
pop();
}
function TVAnxiety(){
if(frameCount % 4 == 0){ //every 4 frames, make new germ
virus.push(makeGerm(200,150));
}
for(var i=0;i<virus.length;i++){ //move and show germs
virus[i].show();
virus[i].move();
}
count+=1;
}
function makeGerm(startX,startY){ //germ constructor
var germ = {x: startX,
y:startY,
dx: random(-10,10), //speeds
dy:random(-10,10),
breadth:random(20,40), //width of germ
color:color(0),
moving:true,
show: showGerm,
move: moveGerm
}
return germ;
}
function showGerm(){ //germ drawing
push();
fill(6,158,31); //dark green
ellipse(this.x,this.y,this.breadth,this.breadth); //germ body
var t=makeTurtle(this.x,this.y) //make a turtle for each germ
t.setWeight(5);
t.setColor(color(6,158,31)); //dark green
for(var i=0;i<7;i++){ //creating the "spikes"
t.forward(this.breadth-5); //one spike
t.raisePen();
t.back(this.breadth-5); //going back to center, turning
t.right(60);
t.lowerPen();
}
pop();
}
function moveGerm(){
if(this.moving==true){ //move germ diagonally
this.x += this.dx;
this.y += this.dy;
}
if(this.x>width - count || this.x<0+count || this.y>height-count || this.y<0+count){ //if it hits a boundary, defined by a count
this.moving=false;
}
}
function syringe(){
push();
rectMode(CENTER);
translate(mouseX,mouseY);
rotate(radians(45));
fill(220); //light gray
rect(0,0,20,50); //bottle
rectMode(CORNER);
rect(-5,25,10,5); //cap
rect(-10,25,20,2);
fill(247,131,236); //pink
rect(-10,0,20,25); //syringe liquid
strokeWeight(2);
stroke(220); //gray
line(0,-25,0,-50); //needle
pop();
}
function sceneThree(){
fill(250,240,191); //beige
rect(0,0,width,height); //background
paint();
clock(300,100);
fill(164,115,1); //brown
rect(0,250,width,height); //floor
fill(245,217,152); //white-beige
rect(width-20,0,20,height); //wall
table(180,160);
fill(121,61,2); //dark brown
rect(375,115,5,155); //door(closed)
push();
frameRate(20)
if(frameCount<=320){ //animating me walking
if(frameCount%4 ==0){ //alternating animations
EamonnWalk(EamonnX,130);
}else{
EamonnStand(EamonnX,130);
}
EamonnX+=2 //moving me
}
if(frameCount>=320 & frameCount<340){ //reaching out to the door
arm();
EamonnStand(335,130);
}
if(frameCount>330 & frameCount<360){
fill(121,61,2); //dark brown
rect(315,115,60,155); //door(open)
fill(232,219,108); //gold
ellipse(325,200,9,9); //knob
}
if(frameCount==310){
doorclose.play();
}
pop();
}
//functions for scene three
function EamonnStand(x,y){
push();
translate(x,y);
fill(255,220,200); //beige
ellipse(0,0,29); //head
rect(-4,0,8,20); //neck
fill(242,201,69); //golden brown
ellipse(-6,0,13,27); //hair
ellipse(4,-10,27,10);
fill(176,58,58); //maroon
rect(-13,20,25,60,15); //shirt
fill(0); //black
quad(-13,70,12,70,9,130,-10,130); //leg
fill(176); //gray
rect(-8,20,15,50,15); //arm
fill(255,220,200); //beige
ellipse(-1,70,15); //hand
fill(186); //gray
rect(-13,130,30,10,10); //shoe
pop();
}
function EamonnWalk(x,y){
push();
translate(x,y);
fill(255,220,200);
ellipse(0,0,29);
rect(-4,0,8,20);
fill(242,201,69);
ellipse(-6,0,13,27);
ellipse(4,-10,27,10);
fill(176,58,58);
rect(-13,20,25,60,15);
fill(0);
quad(-13,70,12,70,-5,130,-24,130); //legs
quad(-13,70,12,70,25,130,5,130);
fill(176)
rect(-8,20,15,50,15);
fill(255,220,200)
ellipse(-1,70,15)
fill(186,186,186);
rotate(radians(5)); //rotated shoes
rect(-15,130,30,10,10);
rotate(radians(-10));
rect(-7,130,30,10,10);
pop();
}
function arm(){
push();
fill(176);
rotate(radians(-35));
rect(180,320,15,50,15); //arm reaching out to door
pop();
fill(255,220,200); //beige
ellipse(366,196,15); //hand
}
function clock(x,y){
push();
translate(x,y);
var shake = random(-3,3); //to shake the clock
fill(0);
ellipse(0+shake,0+shake,50,50); //clock
fill(255);
ellipse(0+shake,0+shake,r,r);
frameRate(20);
var clockX = r/2 * cos(radians(theta));
var clockY = r/2 * sin(radians(theta));
stroke(0);
line(0+shake, 0+shake, clockX, clockY); //clock hand
theta +=10; //turn the hand
pop();
}
function table(x,y){
push();
translate(x,y);
fill(121,61,2); //brown
rect(0,0,60,70); //body
rect(0,70,10,30); //legs
rect(50,70,10,30);
pop();
}
function paint(){ //draw function for paint object
push();
x.push(mouseX); //draw a line to where the mouse is
y.push(mouseY);
for (var i=0; i < x.length-1; i++) {
strokeWeight(map(mouseY,0,height,0,10)); //chamge stroke weight with y position
stroke(color(random(255),random(255),random(255))); //change color randomly
line(x[i],y[i],x[i+1],y[i+1]); //draw line from one position to next (mouse positions)
}
pop();
}
//functions for the final scene
function finalScene(){
sunset(2);
fill(255,252,229); //white-yellow
ellipse(200,200,50,50); //sun
hills();
fill(189); //gray
rect(0,260,width,20); //road
removeFlock();
newFlock();
removeCar();
newCar();
//showing and moving objects
for(var i=0;i<trees2.length;i++){
trees2[i].show();
}
for(var i=0;i<cars.length;i++){
cars[i].show();
cars[i].move();
}
for(var i=0;i<trees.length;i++){
trees[i].show();
}
for(var i=0;i<flocks.length;i++){
flocks[i].show();
flocks[i].move();
}
fill(240,221,159,60); //opaque orange
rect(0,0,width,height); //create haze
rocks();
relief();
Eamonn3(260,200);
textSize(20);
fill(0,0,255);
text("THE END",300,100);
}
function sunset(size) {
var green=215;
var blue=238;
var red=141
for (var y = size/2; y < height + 50; y += size) { //nested loop for grid
for (var x = size/2; x < width + 50; x += size) {
fill(red,green,blue);
rect(x, y, size, size);
}
red += (200/(width/size)); //create gradient
green +=(100/(height/size));
blue -=(50/(height/size));
}
}
function makeTree(startX,startY){ //tree constructor
var tree = {x: startX,
y:startY,
breadth:5,
color: color(random(130,200),random(100,150),0),
show: showTree
}
return tree;
}
function showTree(){
push();
translate(this.x, this.y); //appear at width,280
fill(121,90,5); //gray
rect(0,-20,this.breadth,20); //draw railing markers
fill(this.color);
ellipse(2,-30,20,20); //leaves
pop();
}
function removeCar(){ //remove car from array once out of sight
var carsToKeep = [];
for (var i = 0; i < cars.length; i++){
if (cars[i].x > 0) {
carsToKeep.push(cars[i]);
}
}
cars = carsToKeep;
}
function newCar() { //create a new car at a given probability
var newCarChance = 0.05;
if (random(0,1) < newCarChance) {
cars.push(makeCar(width)); //create new car at the edge
}
}
function moveCar(){
this.x += this.speed; //mpve cars
}
function showCar(){
push();
noStroke();
translate(this.x, 260);
fill(this.color)
rect(0,-7,this.breadth,this.height); //body of car
if(this.speed>0){
rect(25,0,10,10); //car facing right
}else{
rect(-10,0,10,10); //car facing left
}
fill(0); //black
ellipse(5,10,10,10); //wheels
ellipse(25,10,10,10);
pop();
}
function makeCar(startX){
var car = {x: startX,
breadth:25,
height:random(15,20),
speed: random(-5,5),
color: color(random(0,255),random(0,255),random(0,255)),
move: moveCar,
show: showCar
}
return car;
}
function moveFlock(){
this.x += this.speed; //move horizontally
this.y -= this.speed/2;
}
function removeFlock(){
var flocksToKeep = [];
for (var i = 0; i < flocks.length; i++){
if (flocks[i].x > 0) {
flocksToKeep.push(flocks[i]);
}
}
flocks = flocksToKeep;
}
function newFlock() {
var newFlockChance = 0.01;
if (random(0,1) < newFlockChance) {
flocks.push(makeFlock(0,random(0,200)));
}
}
function showFlock(){
push();
stroke(0);
translate(this.x,this.y);
for(var i=0;i<this.numBirds;i++){
line(0+(2*i)+random(-1,1),0+(2*i),5+(2*i),5+(2*i)); //wings of birds
line(5+(2*i),5+(2*i),10+(2*i),0+(2*i)+random(-1,1));
}
pop();
}
function makeFlock(startX,startY){
var flock = {x: startX,
y: startY,
numBirds: random(3,7),
speed:2,
move: moveFlock,
show: showFlock
}
return flock;
}
function hills(){
beginShape();
noStroke();
fill(60,131,67); //green
for (i=0;i<width/5; i++){
curveVertex(i*5,landscape[i]) //creates slopes by connecting two points
curveVertex((i+1)*5,landscape[i+1]);
}
curveVertex(width,height); //stable values that create the green fill
curveVertex(0,height);
endShape(CLOSE); //end shape and fill it
}
function rocks(){
beginShape();
noStroke();
fill(129); //gray
for (i=0;i<width/5; i++){
curveVertex(i*5,rock[i]) //creates slopes by connecting two points
curveVertex((i+1)*5,rock[i+1]);
}
curveVertex(width,height); //stable values that create the gray fill
curveVertex(0,height);
endShape(CLOSE); //end shape and fill it
}
function relief(){
if(frameCount % 10 == 0){ //every 4 frames, make new Bubble
reliefBubbles.push(makeBubble(260,200));
}
for(var i=0;i<reliefBubbles.length;i++){ //move and show Bubbles
reliefBubbles[i].show();
reliefBubbles[i].move();
}
}
function makeBubble(startX,startY){ //bubble constructor
var bubble = {x: startX,
y:startY,
opacity:255,
size:10,
show: showBubble,
move: moveBubble
}
return bubble;
}
function showBubble(){
push();
fill(220,this.opacity); //light gray
ellipse(this.x,this.y,this.size,this.size); //germ body
pop();
}
function moveBubble(){
this.size+=1; //grow bubbles
this.opacity-=3; //fade
}
function Eamonn3(x,y){
push();
translate(x,y);
fill(255,220,200); //beige
ellipse(0,0,40,40); //head
rect(-8,12,15,15); //neck
fill(242,201,69); //golden brown
ellipse(0,-2,38,35); //hair
push();
fill(0);
rotate(radians(50)); //legs in criss cross
rect(63,0,25,70,15);
rotate(radians(-100));
rect(-87,0,25,70,15)
pop();
fill(176,58,58);
rect(-23,25,45,70,15);
pop();
}
function mousePressed(){
if(frameCount<100){ //play drawer sound if mouse is pressed on drawer
if(mouseX>110 & mouseX<180 && mouseY>220 && mouseY<250){
drawer.play();
}
}
germShot = -1;
for (var i = 0; i < virus.length; i++) {
var d = dist(mouseX, mouseY,
virus[i].x, virus[i].y)
if (d < virus[i].breadth) { //if clicked within a given germ
germShot = i; //pass this index to the splice function
}
}
}
//turtle code, courtesy of Tom Cortina
function makeTurtle(tx, ty) {
var turtle = {x: tx, y: ty,
angle: 0.0,
penDown: true,
color: color(128),
weight: 1,
left: turtleLeft, right: turtleRight,
forward: turtleForward, back: turtleBack,
lowerPen: turtleLowerPen, raisePen: turtleRaisePen,
goto: turtleGoTo, angleto: turtleAngleTo,
turnToward: turtleTurnToward,
distanceTo: turtleDistTo, angleTo: turtleAngleTo,
setColor: turtleSetColor, setWeight: turtleSetWeight,
face: turtleFace};
return turtle;
}
function turtleLeft(d) {
this.angle -= d;
}
function turtleRight(d) {
this.angle += d;
}
function turtleForward(p) {
var rad = radians(this.angle);
var newx = this.x + cos(rad) * p;
var newy = this.y + sin(rad) * p;
this.goto(newx, newy);
}
function turtleBack(p) {
this.forward(-p);
}
function turtleLowerPen() {
this.penDown = true;
}
function turtleRaisePen() {
this.penDown = false;
}
function turtleGoTo(newx, newy) {
if (this.penDown) {
stroke(this.color);
strokeWeight(this.weight);
line(this.x, this.y, newx, newy);
}
this.x = newx;
this.y = newy;
}
function turtleDistTo(x, y) {
return sqrt(sq(this.x - x) + sq(this.y - y));
}
function turtleAngleTo(x, y) {
var absAngle = degrees(atan2(y - this.y, x - this.x));
var angle = ((absAngle - this.angle) + 360) % 360.0;
return angle;
}
function turtleTurnToward(x, y, d) {
var angle = this.angleTo(x, y);
if (angle < 180) {
this.angle += d;
} else {
this.angle -= d;
}
}
function turtleSetColor(c) {
this.color = c;
}
function turtleSetWeight(w) {
this.weight = w;
}
function turtleFace(angle) {
this.angle = angle;
this.angle %= 360;
}
When I saw the prompt for the project this week, I immediately thought of doing something with a noise function. I felt as though mountains wouldn’t allow for enough variability, so I decided to do a beach. I laid out the very basic sand, water, and sky, and then added embellishing elements to try to create a drive by beach scene.
var boats = []; //arrays to hold respective objects
var clouds = [];
var umbrellas = [];
var planes = [];
var buildings = [];
var railings = [];
var people = [];
var towels = [];
var landscape = []; //array that creates slope of shoreline
var noiseParam = 0;
var noiseStep = 0.005; //defines extremity of shoreline slope
function setup() {
createCanvas(480,300);
for (var i = 0; i < 3; i++){ //make a certain amount of (object) to start out, at random locations within a constraint
var rx = random(width);
var ry = random(80,150)
boats[i] = makeBoat(rx,ry);
}
for (var i = 0; i < 3; i++){
var Cx = random(width);
var Cy = random(0,60)
clouds[i] = makeCloud(Cx,Cy);
}
for (var i = 0; i < people.length; i++){
var Tx = random(width);
var Ty = random(250,300)
towels[i] = makeTowel(Tx,Ty);
}
for (var i = 0; i < people.length; i++){
var Px = random(width);
var Py = random(250,300)
people[i] = makePerson(Px,Py);
}
for (var i = 0; i < 5; i++){
var Ux = random(width);
var Uy = random(250,300)
umbrellas[i] = makeUmbrella(Ux,Uy);
}
for (var i = 0; i < 15; i++){
var Bx = random(width);
buildings[i] = makeBuilding(Bx);
}
for (var i = 0; i < 0.9; i++){
var Px = random(width);
var Py = random(0,20)
planes[i] = makePlane(Px,Py);
}
for(var i = 0;i <= width / 5;i++){
var n = noise(noiseParam); //picks value 0-1
var value = map(n,0,1,50,height); //scales it to the canvas size
landscape.push(value); //adds to array
noiseParam += noiseStep; //moves to the right for the next point in the array
}
frameRate(5);
}
function draw() {
background(3,220,245);
fill(13,66,212,230); //dark blue
rect(0,height / 4,width,height); //body of water
fill(227,232,164,175); //pale beige
rect(0,height / 4-7,width,7); //distant shoreline
//call the functions to spawn and despawn respective obejcts
removeBoat();
newBoat();
removeCloud();
newCloud();
removeUmbrella();
removePlane();
newPlane();
removeBuilding();
newBuilding();
removeRailing();
newRailing();
removePerson();
removeTowel();
//call the move and show functions to continually draw and redraw objects after updated coordinates
for (var i = 0; i < clouds.length; i++){
clouds[i].move();
clouds[i].show();
}
for (var i = 0; i < buildings.length; i++){
buildings[i].move();
buildings[i].show();
}
for (var i = 0; i < boats.length; i++){
boats[i].move();
boats[i].show();
}
displayHorizon();
for (var i = 0; i < towels.length; i++){
towels[i].move();
towels[i].show();
}
for (var i = 0; i < people.length; i++){
people[i].move();
people[i].show();
}
for (var i = 0; i < umbrellas.length; i++){
umbrellas[i].move();
umbrellas[i].show();
}
for (var i = 0; i < planes.length; i++){
planes[i].move();
planes[i].show();
}
fill(159,159,159);
rect(0,height-50,width,40);
fill(110,110,110);
rect(0,height-45,width,30);
for (var i = 0; i < railings.length; i++){
railings[i].move();
railings[i].show();
}
}
//functions to remove an object from a displayed array once "out of sight"
function removeBoat(){
var boatsToKeep = []; //the boats that should still be displayed
for (var i = 0; i < boats.length; i++){
if (boats[i].x + boats[i].breadth > 0) { //if the boat is closer than it's width to the edge
boatsToKeep.push(boats[i]); //add this boat to the boats that will be displayed
}
}
boats = boatsToKeep; // only display the baots currently being kept
}
function removeCloud(){
var cloudsToKeep = [];
for (var i = 0; i < clouds.length; i++){
if (clouds[i].x + clouds[i].breadth > 0) {
cloudsToKeep.push(clouds[i]);
}
}
clouds = cloudsToKeep;
}
function removeUmbrella(){
var umbrellasToKeep = [];
for (var i = 0; i < umbrellas.length; i++){
if (umbrellas[i].x + umbrellas[i].breadth > 0) {
umbrellasToKeep.push(umbrellas[i]);
}
}
umbrellas = umbrellasToKeep;
}
function removePlane(){
var planesToKeep = [];
for (var i = 0; i < planes.length; i++){
if (planes[i].x + 150 > 0) {
planesToKeep.push(planes[i]);
}
}
planes = planesToKeep;
}
function removeBuilding(){
var buildingsToKeep = [];
for (var i = 0; i < buildings.length; i++){
if (buildings[i].x > 0) {
buildingsToKeep.push(buildings[i]);
}
}
buildings = buildingsToKeep;
}
function removeRailing(){
var railingsToKeep = [];
for (var i = 0; i < railings.length; i++){
if (railings[i].x > 0) {
railingsToKeep.push(railings[i]);
}
}
railings = railingsToKeep;
}
function removePerson(){
var peopleToKeep = [];
for (var i = 0; i < people.length; i++){
if (people[i].x > 0) {
peopleToKeep.push(people[i]);
}
}
people = peopleToKeep;
}
function removeTowel(){
var towelsToKeep = [];
for (var i = 0; i < towels.length; i++){
if (towels[i].x > 0) {
towelsToKeep.push(towels[i]);
}
}
towels = towelsToKeep;
}
//functions to create new objects that come into sight
function newBoat() {
var newBoatChance = 0.009; //the chance that a new boat will appear
if (random(0,1) < newBoatChance) { //activate probability
boats.push(makeBoat(width,random(100,150))); //add a new boat if the porbability condition is met
}
}
function newCloud() {
var newCloudChance = 0.001;
if (random(0,1) < newCloudChance) {
clouds.push(makeCloud(width,random(0,60)));
}
}
function newPlane() {
var newPlaneChance = 0.003;
if (random(0,1) < newPlaneChance) {
planes.push(makePlane(width, random(0,50)));
}
}
function newBuilding() {
var newBuildingChance = 0.1;
if (random(0,1) < newBuildingChance) {
buildings.push(makeBuilding(width));
}
}
function newRailing() {
var newRailingChance = 0.8;
if (frameCount % 2 == 0 & random(0,1) < newRailingChance) { //spawn every two frames, if probability condition is met
railings.push(makeRailing(width));
}
}
//functions to move the objects across the screen
function moveBoat() {
this.x += this.speed; //add a speed value to the the x position to chance it every frame
}
function moveCloud(){
this.x += this.speed;
}
function moveUmbrella(){
this.x += this.speed;
}
function movePlane(){
this.x += this.speed;
}
function moveBuilding(){
this.x += this.speed;
}
function moveRailing(){
this.x += this.speed;
}
function movePerson(){
this.x += this.Xspeed;
this.y += this.Yspeed/3; //move very slightly in Y direction
}
function moveTowel(){
this.x += this.speed;
}
//functions to show (object) by drawing it at the requested coordinates
function showBoat() {
var floorHeight = 10;
push();
translate(this.x, this.y); //plot the drawing at the the coordinates given
noStroke();
for (var i = 0; i < this.nFloors; i++) {
fill(this.color,this.y*2); //random color, with varying opacity based on y value (distance from viewer)
rect(0, -15 - (i * floorHeight), this.breadth-10*i, 10); //the boat levels
if(this.nFloors == 3){
fill(255,this.y*2); //white, varying opacity
rect(3,-15-(i*floorHeight), this.breadth-12*i,7) //to make a "yacht"
}
if(this.nFloors == 2){
fill(161,227,238,this.y*2); //light blue, varying opacity
rect(5,-13-(floorHeight),this.windowBreadth,7); //window
}
if(this.nFloors == 1){
strokeWeight(5);
stroke(this.color,this.y*2); //rnadom color of boat, varying opacity
line(7,0-(floorHeight),-6,-15-(floorHeight)); //fishing gig
strokeWeight(2);
line(-6,-15-(floorHeight),random(-12,-16),5-(floorHeight)); //fishing line
}
}
pop();
}
function showCloud(){
var cloudHeight = 10; //height of a cloud
var cHeight = this.nClouds * cloudHeight; //height dpends on how many clouds
fill(255,200); //pale white
noStroke();
push();
translate(this.x, this.y); //appear at width, and random y in a constraint
for (var i = 0; i < this.nClouds; i++) {
ellipse(0, -15 - (i * cHeight), this.breadth-10, 30); //draw cloud
}
pop();
}
function showUmbrella(){
var umbrellaHeight = 10;
noStroke();
push();
translate(this.x, this.y+15); //appear at width, random y between shoreline and height(adjusted to ensure no umbrellas in water)
noStroke();
fill(255); //white
rect(0,0, this.breadth, this.height); //umbrella stand
fill(this.color); //random color
rotate(radians(this.angle)); //turn at different angles
arc(0,10,40,40,180,TWO_PI); //umbrella dome
pop();
}
function showPlane(){
push();
translate(this.x, this.y); //appear at width, random y within constraint
noStroke();
scale(this.scale); //scale randomly
fill(220,this.scale*400); //opacity deoends on size
ellipse(50,42.5,10,30); //plane body and wings
ellipse(50,50,50,15);
ellipse(50,60,10,30);
fill(50,this.scale*400); //dark gray, varying opacity
ellipse(33,47,4,4); //cockpit window
for(var x=39;x < 55;x+=4) //plane windows
ellipse(x,50,4,4);
strokeWeight(1);
stroke(0,this.scale*400); //black
line(55,57.5,110,57.5); //flag ropes
line(55,42.5,110,42.5);
fill(this.color); //random color
noStroke();
rect(110,37.5,45+random(-2,2),25); //flag, moving
pop();
}
function showBuilding(){
// var floorHeight = 2; //height of a floor
//var buildingHeight = this.nFloors * floorHeight; //building height depends on how many floors
fill(this.color);
push();
noStroke();
translate(this.x, 70); //appear at width,70 (far shoreline)
rect(0, -10, this.breadth, this.height*2); //draw building
pop();
}
function showRailing(){
push();
translate(this.x, 280); //appear at width,280
fill(200,200,200); //gray
stroke(0); //black
rect(0, -20,this.breadth,20); //draw railing markers
pop();
}
function showPerson(){
push();
translate(this.x, this.y+20); //appear at width, and a random heught between shoreline and bottom of canvas(adjusted to ensure nobody in the water)
fill(this.skinColor); //random brown tone
ellipse(0,-5,5,5); //head
rectMode(CENTER);
fill(this.shirtColor); //random color
rect(0,10,this.breadth,this.height); //body
fill(this.pantsColor); //random color
rect(0,25,this.breadth,this.height); //legs
pop();
}
function showTowel(){
push();
translate(this.x, this.y+30); //appear at width, random y between shoreline and height
fill(this.towelColor); //random color
rect(0,0,this.breadth,this.height); //draw towel
pop();
}
//constructors for each object
function makeBoat(startX,startY) {
var boat = {x: startX, //where it gets translated to
y:startY,
breadth: round(random(20,40)), //it's width
windowBreadth: random(5,10), //window width
speed: random(-2,-0.1), //how fast it moves across canvas
nFloors: round(random(1,3)), //how many floors there are
color: random(150,255), //color of boat
move: moveBoat, //functions to move and show the boat
show: showBoat}
return boat;
}
function makeCloud(startX,startY){
var cloud = {x: startX,
y:startY,
breadth: round(random(60,100)),
speed: random(-0.7,-0.3),
nClouds: round(random(1,3)),
move: moveCloud,
show: showCloud}
return cloud;
}
function makeUmbrella(startX,startY){
var umbrella = {x: startX,
y:startY,
breadth: round(random(2,4)),
speed: round(random(-5,-4.99)),
height: random(25,30),
color: color(random(0,255),random(0,255),random(0,255)), //color of hood
angle: random(-20,20), //angle of hood rotation
move: moveUmbrella,
show: showUmbrella
}
return umbrella;
}
function makePlane(startX,startY){
var plane = {x: startX,
y:startY,
scale: random(1 / 4,1), //size of plane
speed: random(-7,-5),
color: color(random(0,255),random(0,255),random(0,255)),
move: movePlane,
show: showPlane
}
return plane;
}
function makeBuilding(startX){
var building = {x: startX,
breadth: 10,
height:10,
speed: -1.0,
color: random(50,200),
//distance: random(100,200),
//nFloors: round(random(2,8)),
move: moveBuilding,
show: showBuilding
}
return building;
}
function makeRailing(startX){
var railing = {x: startX,
breadth:10,
speed: -20,
move: moveRailing,
show: showRailing
}
return railing;
}
function makePerson(startX,startY){
var person = {x: startX,
y:startY,
breadth: random(5,8),
height: random(14,17),
skinColor: color(random(200,250),random(100,150),random(20,100)),
shirtColor: color(random(0,255), random(0,255),random(0,255)),
pantsColor: color(random(0,255), random(0,255),random(0,255)),
Xspeed: random(-7,-4),
Yspeed: random(-0.5,0.5),
move: movePerson,
show: showPerson}
return person;
}
function makeTowel(startX,startY){
var towel = {x: startX,
y:startY,
breadth: random(10,20),
height: random(5,15),
towelColor: color(random(0,255), random(0,255),random(0,255)),
speed: -5,
move: moveTowel,
show: showTowel}
return towel;
}
function displayHorizon(){
landscape.shift(); //removes the first array element
n = noise(noiseParam); //selecting a noise value
value = map(n,0,1,50,height); //plotting it onto the canvas by mapping
landscape.push(value); //adding it to the lanscape array
noiseParam+=noiseStep; //adding step to parameter
push();
beginShape();
noStroke();
fill(227,232,164); //green
for (i=0;i<width/5; i++){
var newUmbrellaChance = 0.001; //frequencies for objects
var newPersonChance = 0.003;
var newTowelChance = 0.002;
var r = random(0,1); //predictor
if (r < newUmbrellaChance){
umbrellas.push(makeUmbrella(width,random(landscape[i],height))); //construct an object between slope line and the bottom of the canvas
}
if(r<newPersonChance){
people.push(makePerson(width,random(landscape[i],height)));
}
if(r<newTowelChance){
towels.push(makeTowel(width,random(landscape[i],height)));
}
curveVertex(i*5,landscape[i]) //creates slopes by connecting two points
curveVertex((i+1)*5,landscape[i+1])
}
curveVertex(width,height+50); //stable values that create the green fill
curveVertex(0,height+50);
endShape(CLOSE); //end shape and fill it
pop();
}
This code simulates a dynamic factory environment, with variable elements including functionality of the factory, speed of the factory, the background factories, and the time of day. The idea for gears came from another class of mine in which we used squares to create interesting compositions. One of mine was created by overlaying two squares to create a “gear” so I knew I wanted to visualize it in motion for this project. I coded the gears to that they appear to work together, and appear to create an output when doing so. The rest stemmed from this “factory” theme.
var boats = []; //arrays to hold respective objects
var clouds = [];
var umbrellas = [];
var planes = [];
var buildings = [];
var railings = [];
var people = [];
var towels = [];
var landscape = []; //array that creates slope of shoreline
var noiseParam = 0;
var noiseStep = 0.005; //defines extremity of shoreline slope
function setup() {
createCanvas(480,300);
for (var i = 0; i < 3; i++){ //make a certain amount of (object) to start out, at random locations within a constraint
var rx = random(width);
var ry = random(80,150)
boats[i] = makeBoat(rx,ry);
}
for (var i = 0; i < 3; i++){
var Cx = random(width);
var Cy = random(0,60)
clouds[i] = makeCloud(Cx,Cy);
}
for (var i = 0; i < people.length; i++){
var Tx = random(width);
var Ty = random(250,300)
towels[i] = makeTowel(Tx,Ty);
}
for (var i = 0; i < people.length; i++){
var Px = random(width);
var Py = random(250,300)
people[i] = makePerson(Px,Py);
}
for (var i = 0; i < 5; i++){
var Ux = random(width);
var Uy = random(250,300)
umbrellas[i] = makeUmbrella(Ux,Uy);
}
for (var i = 0; i < 15; i++){
var Bx = random(width);
buildings[i] = makeBuilding(Bx);
}
for (var i = 0; i < 0.9; i++){
var Px = random(width);
var Py = random(0,20)
planes[i] = makePlane(Px,Py);
}
for(var i=0;i<=width/5;i++){
var n= noise(noiseParam); //picks value 0-1
var value = map(n,0,1,50,height); //scales it to the canvas size
landscape.push(value); //adds to array
noiseParam+=noiseStep; //moves to the right for the next point in the array
}
frameRate(5);
}
function draw() {
background(3,220,245);
fill(13,66,212,230); //dark blue
rect(0,height/4,width,height); //body of water
fill(227,232,164,175); //pale beige
rect(0,height/4-7,width,7); //distant shoreline
//call the functions to spawn and despawn respective obejcts
removeBoat();
newBoat();
removeCloud();
newCloud();
removeUmbrella();
removePlane();
newPlane();
removeBuilding();
newBuilding();
removeRailing();
newRailing();
removePerson();
removeTowel();
//call the move and show functions to continually draw and redraw objects after updated coordinates
for (var i = 0; i < clouds.length; i++){
clouds[i].move();
clouds[i].show();
}
for (var i = 0; i < buildings.length; i++){
buildings[i].move();
buildings[i].show();
}
for (var i = 0; i < boats.length; i++){
boats[i].move();
boats[i].show();
}
displayHorizon();
for (var i = 0; i < towels.length; i++){
towels[i].move();
towels[i].show();
}
for (var i = 0; i < people.length; i++){
people[i].move();
people[i].show();
}
for (var i = 0; i < umbrellas.length; i++){
umbrellas[i].move();
umbrellas[i].show();
}
for (var i = 0; i < planes.length; i++){
planes[i].move();
planes[i].show();
}
fill(159,159,159);
rect(0,height-50,width,40);
fill(110,110,110);
rect(0,height-45,width,30);
for (var i = 0; i < railings.length; i++){
railings[i].move();
railings[i].show();
}
}
//functions to remove an object from a displayed array once "out of sight"
function removeBoat(){
var boatsToKeep = []; //the boats that should still be displayed
for (var i = 0; i < boats.length; i++){
if (boats[i].x + boats[i].breadth > 0) { //if the boat is closer than it's width to the edge
boatsToKeep.push(boats[i]); //add this boat to the boats that will be displayed
}
}
boats = boatsToKeep; // only display the baots currently being kept
}
function removeCloud(){
var cloudsToKeep = [];
for (var i = 0; i < clouds.length; i++){
if (clouds[i].x + clouds[i].breadth > 0) {
cloudsToKeep.push(clouds[i]);
}
}
clouds = cloudsToKeep;
}
function removeUmbrella(){
var umbrellasToKeep = [];
for (var i = 0; i < umbrellas.length; i++){
if (umbrellas[i].x + umbrellas[i].breadth > 0) {
umbrellasToKeep.push(umbrellas[i]);
}
}
umbrellas = umbrellasToKeep;
}
function removePlane(){
var planesToKeep = [];
for (var i = 0; i < planes.length; i++){
if (planes[i].x + 150 > 0) {
planesToKeep.push(planes[i]);
}
}
planes = planesToKeep;
}
function removeBuilding(){
var buildingsToKeep = [];
for (var i = 0; i < buildings.length; i++){
if (buildings[i].x > 0) {
buildingsToKeep.push(buildings[i]);
}
}
buildings = buildingsToKeep;
}
function removeRailing(){
var railingsToKeep = [];
for (var i = 0; i < railings.length; i++){
if (railings[i].x > 0) {
railingsToKeep.push(railings[i]);
}
}
railings = railingsToKeep;
}
function removePerson(){
var peopleToKeep = [];
for (var i = 0; i < people.length; i++){
if (people[i].x > 0) {
peopleToKeep.push(people[i]);
}
}
people = peopleToKeep;
}
function removeTowel(){
var towelsToKeep = [];
for (var i = 0; i < towels.length; i++){
if (towels[i].x > 0) {
towelsToKeep.push(towels[i]);
}
}
towels = towelsToKeep;
}
//functions to create new objects that come into sight
function newBoat() {
var newBoatChance = 0.009; //the chance that a new boat will appear
if (random(0,1) < newBoatChance) { //activate probability
boats.push(makeBoat(width,random(100,150))); //add a new boat if the porbability condition is met
}
}
function newCloud() {
var newCloudChance = 0.001;
if (random(0,1) < newCloudChance) {
clouds.push(makeCloud(width,random(0,60)));
}
}
function newPlane() {
var newPlaneChance = 0.003;
if (random(0,1) < newPlaneChance) {
planes.push(makePlane(width, random(0,50)));
}
}
function newBuilding() {
var newBuildingChance = 0.1;
if (random(0,1) < newBuildingChance) {
buildings.push(makeBuilding(width));
}
}
function newRailing() {
var newRailingChance = 0.8;
if (frameCount % 2 == 0 & random(0,1)
]]>https://courses.ideate.cmu.edu/15-104/f2020/2020/12/17/beach/feed/0Final Project
https://courses.ideate.cmu.edu/15-104/f2020/2020/12/17/final-project-23/
https://courses.ideate.cmu.edu/15-104/f2020/2020/12/17/final-project-23/#respondThu, 17 Dec 2020 05:12:18 +0000https://courses.ideate.cmu.edu/15-104/f2020/?p=64510Continue reading "Final Project"]]>
For this project, I chose to create a short animation that depicted some of the major events that occurred in 2020. The increasing use of technology and social media platforms has definitely raised awareness for important causes and happenings during this year. For example, one of the biggest contributors for raising awareness and protests was social media and the sharing of information through these platforms.
My inspiration for this project was a typical commercial, one that can be watched through advertisements or on TV. I tried to imitate the basic form of story-like commercial with a message at the end. The main message that I am conveying through this short clip is spread more awareness about the importance of masks. With the currently increasing cases of COVID-19, I decided to focus on this specific theme because unfortunately, masks are still being refused by many people around the world.
If I had more time, I would have liked to add an additional scene that depicted the detrimental effects of contracting COVID-19. I believe that this would have added more of an impact to my “commercial”.
To interact with my program, simply click on the canvas to start the clip. Note: Use volume for sound.
]]>https://courses.ideate.cmu.edu/15-104/f2020/2020/12/17/final-project-23/feed/0Final Project
https://courses.ideate.cmu.edu/15-104/f2020/2020/12/15/final-project-22/
https://courses.ideate.cmu.edu/15-104/f2020/2020/12/15/final-project-22/#respondTue, 15 Dec 2020 20:39:00 +0000https://courses.ideate.cmu.edu/15-104/f2020/?p=64503Continue reading "Final Project"]]>
For my project I created a game to raise awareness towards mask wearing so the person is trying to move through covid particles to reach the mask. And basically gets saved if he does so without colliding with a covid body. If you reach the mask, the words, “You were saved show up” while if you collide with a cover particle it says, “You’ve been infected, happy recovery!” If I had more time I would have implemented multiple levels where the speed of the covid particles begin to vary making it more difficult and instead of a generic score the levels would be how many months you have gone without being infected. Thus, again endorsing mask wearing as a norm.
Instructions use your mouse and YOU DO NOT WANT TO GET COVID SO STAY AWAY FROM THOSE NASTY RED THINGS!!
//Aadya Bhartia
//Section A
/* The objective of the game is for the user to reach the mask and to
avoid the covid particles! Once you reach the mask you win the game and if you
bang into a particle you lose. The purpose of the game is to encourage mask wearing
*/
var mask;//parameter for object creation
var rad = 40; // for size of covid particle
//person
var personX;
var personY;
//array to store covid symbols
var covidX = [];
var covidY = [];
var dx = [];
var dy = [];
//variables to store images
var covid;
var person;
var maskImg;
function preload(){
//preloading images
covid = loadImage("https://i.imgur.com/uT2allv.png");
person = loadImage("https://i.imgur.com/uVjRV7S.png");
maskImg = loadImage("https://i.imgur.com/1olzsvy.png");
}
function setup() {
createCanvas(500, 500);
background(220);
//storing covid particles random x and position as well as speed
for(var i = 0; i<15; i++){
covidX[i] = random(width);
covidY[i] = random(height);
dx[i] = random(-5,5);
dy[i] = random(-5,5);
}
mask = makeMask();
//text formatting
frameRate(10);
textAlign(CENTER);
textFont('New Roman');
textStyle(BOLD);
}
function draw() {
//constraining mouse within canvas
var x = constrain(mouseX, 0, width-10);
var y = constrain(mouseY, 0, height-10);
background(220);
//displaying mask and checking if person has touched maks
mask.show();
mask.check();
for(var i = 0; i<10; i++){
fill(0);
image(covid, covidX[i], covidY[i], rad, rad);
covidX[i] += dx[i];
covidY[i] += dy[i];
//to bounce covid particles off the sides
if(covidX[i] >= (width) || covidX[i] <= 0){
dx[i] = -1*dx[i];
}
if(covidY[i] >= (height) || covidY[i] <= 0){
dy[i] = -1*dy[i];
}
//when person bangs into covid particle
if(covidY[i]> y-15 & covidY[i]< y+15 ){
if(covidX[i]> x-15 && covidX[i]< x+15 ){
finishGame();
}
}
}
//person
fill(255,0,0);
//displaying mouse as person
image(person,x, y, 60,100);
}
//displaying mask
function maskDisplay(){
image(maskImg, this.x, this.y, 60,60);
}
//game won if person reaches the maks
function achieved(){
var d = dist(mouseX, mouseY, this.x, this.y);
if(d<20){
wonGame();
}
}
//constructor
function makeMask(){
var m = {x : random(30, width-30),
y : random(30, height-30),
show : maskDisplay, check : achieved}
return m;
}
//message for when game has been lost
function finishGame(){
fill("black");
textSize(30);
text("You've been infected, happy recovery!", width/2, height/2);
noLoop();
}
//message for when game has been won
function wonGame(){
fill("black");
textSize(40);
text("YOU WERE SAVED!!!", width/2, height/2);
noLoop();
}
]]>https://courses.ideate.cmu.edu/15-104/f2020/2020/12/15/final-project-22/feed/0Final Project
https://courses.ideate.cmu.edu/15-104/f2020/2020/12/14/final-project-21/
https://courses.ideate.cmu.edu/15-104/f2020/2020/12/14/final-project-21/#respondMon, 14 Dec 2020 17:35:59 +0000https://courses.ideate.cmu.edu/15-104/f2020/?p=64492Continue reading "Final Project"]]>
2020 was full of surprises that shook our world and changed the lives of many. My final project comments on the concept of misfortune and plays with the sense of control that many felt like they didn’t have in the face of a global pandemic, monumental election, civil rights movements, wildfires, and more. The 2020 slot machine presents the user with an attractive and exciting prospect of winning, but ultimately delivers the raw reality of this year.
To play, click and drag down on the lever, then release. The reels will spin and generate your 2020. Observe the effects of a jackpot!
I was inspired to create a slot machine for my final project because when presented with the project theme “2020,” I couldn’t narrow down to one single event that I wanted to focus on. I instead wanted to take a more macro approach and reflect on the year as a whole and satirize it with a classic casino game. With more time, I would add a greater jackpot effect, more buttons, and user interaction opportunities to the slot machine.
//2020 SLOT MACHINE
//Elysha Tsai
//All illustrated assets made by me
var bg;
var symbolLinks = [
"https://i.imgur.com/gj4Ztah.png", //COVID
"https://i.imgur.com/a8qsuTb.png", //AUSTRALIAN BUSHFIRES
"https://i.imgur.com/TLZnWQ9.png", //BLM
"https://i.imgur.com/1tdvXwb.png", //ELECTION
"https://i.imgur.com/SsV7YIF.png", //2020
"https://i.imgur.com/EHQEMEP.png", //MURDER HORNETS
]
var textLinks = [
"https://i.imgur.com/qBgKflt.png", //COVID
"https://i.imgur.com/jTMJxU5.png", //AUSTRALIAN BUSHFIRES
"https://i.imgur.com/L47KJMN.png", //BLM
"https://i.imgur.com/IAmvG2D.png", //ELECTION
"https://i.imgur.com/051k4xi.png", //2020
"https://i.imgur.com/sRj9Ipi.png", //MURDER HORNETS
]
var maxlinks = 6;
//assign links to 3 separate reels
var reelA;
var reelB;
var reelC;
var reelimages=[];
var reeltext=[];
var reelAindex=0
var defaultText;
var textimage;
var jackpotWin;
var count =0;
var doneReel=0;
var jackpotindex=0;
//light object variables
var light =[];
var x; //position of light
var speed;
var leverpull;
//var jackpotwin;
var ball;
var slotmachine;
var chair;
function preload() {
//IMAGES
bg= loadImage("https://i.imgur.com/Mt81CeD.jpg"); //green gradient background
ball= loadImage("https://i.imgur.com/5UZk7nN.png"); //lever ball
slotmachine= loadImage("https://i.imgur.com/3OioKHj.png");
chair= loadImage("https://i.imgur.com/KXMlSo1.png");
defaultText= loadImage("https://i.imgur.com/dcfoYh5.png");
jackpotWin= loadImage("https://i.imgur.com/ih2wbgn.png");
for (var i=0; i<maxlinks; i++) {
reelimages[i] = loadImage(symbolLinks[i]);
}
for (var i=0; i<maxlinks; i++) {
reeltext[i] = loadImage(textLinks[i]);
}
//initial array assignment
reelA=reelimages[2];
reelB=reelimages[0];
reelC=reelimages[4];
}
function setup() {
createCanvas(600, 450);
frameRate(10); //mechanical feeling of lever
//textimage = defaultText;
//setup light object
var dist =0;
for (var i =0; i<1000; i++){
light[i]= varLight(dist);
dist +=12; //distance b/w lights
}
}
/*
function soundSetup() {
leverpull.setVolume(1);
jackpotwin.setVolume(1.2);
*/
function draw() {
image(bg, -50, -50, 700, 550);
//draw lightstrip
push();
noStroke();
fill(110, 186, 173); //green
rect(0, 14, width, 12);
pop();
//draw lights
for(var i = 0; i < light.length; i++){
light[i].display();
light[i].move();
}
image(slotmachine, 0, 0, 600, 450);
image(chair, 0, 0, 600, 450);
//draw text
push();
//imageMode(CENTER)
//image(jackpotWin, 0, 0);
pop();
//JACKPOT
//background flashes when hit jackpot after reels stop changing
if ((reelA == reelB) & (reelB == reelC) && doneReel){
//background flashes when hit jackpot after reels stop changing
rect(0, 0, 600, 450);
image(slotmachine, 0, 0, 600, 450);
image(chair, 0, 0, 600, 450);
image(chair, 0, 0, 600, 450);
count ++;
if(count==1){
fill(255, 0, 0);
}else if(count==2){
fill(0, 255, 0);
}else if(count==3){
fill(0, 0, 255);
count = 0;
}
image(jackpotWin, 0, 0);
//textimage= reeltext[jackpotindex];
//assign jackpot symbol to text
//displayText();
}
//draw images in a row
image(reelA, 119.5, 181.5, 53, 138);
image(reelB, 178.5, 181.5, 53, 138);
image(reelC, 237.5, 181.5, 53, 138);
lever();
}
function lever(){
//hold down mouse to pull down lever
if (mouseIsPressed
& mouseX> 330 && mouseX < 370){
var x1 = 350; //base x
var y1 = 293; //base y
var x2 = constrain(mouseX, 350, 350);//lever only moves vertically
var y2 = constrain(mouseY, 191, 333);
//stick
strokeWeight(8);
stroke(248, 230, 194); //cream
strokeCap(ROUND);
line(x1, y1 + (y2/40), x2, y2);
//ball handle
push();
imageMode(CENTER)
image(ball, x2, y2, 25, 25);
pop();
var d = dist(x1, y1, x2, y2); //line length determined by distance from base and handle
}else{ //default lever state
//stick
strokeWeight(8);
stroke(248, 230, 194);
strokeCap(ROUND);
line(350, 293, 350, 191);
//ball handle
push();
imageMode(CENTER)
image(ball, 350, 191, 25, 25);
pop();
}
}
// sleep time expects milliseconds
function sleep (time) {
return new Promise((resolve) => setTimeout(resolve, time));
}
// based on https://stackoverflow.com/questions/951021/what-is-the-javascript-version-of-sleep
// actual wait time based on clock
function waittime(milliseconds) {
const date = Date.now();
let currentDate = null;
do {
currentDate = Date.now();
} while (currentDate - date < milliseconds);
}
function mouseReleased(){
if (mouseX> 330 & mouseX < 370){ //end position of lever
reelA=reelimages[int(random(0,maxlinks))];
reelB=reelimages[int(random(0,maxlinks))];
reelC=reelimages[int(random(0,maxlinks))];
doneReel=0 // start reel turning, not done yet
//randomize symbol display with lever push
// for each reel sleep for a random time between 0 and 200ms then show image
// left to right
for (var i =0; i<20; i++){
sleep(50).then (()=> {
reelAindex=int(random(0,maxlinks));
reelA=reelimages[reelAindex];
sleep(50).then(()=> {
reelB=reelimages[int(random(0,maxlinks))];
sleep(50).then(()=> {
reelC=reelimages[int(random(0,maxlinks))];
});
});
})
waittime(int(random(0,50))) // wait random time up to 100ms before changing
}
// wait some time for all reels to settle before calling it done
sleep(500).then(()=> {
doneReel=1
})
}
}
//lightstrip functions
function varLight(basex){
var light ={lighty:20,
x: basex,
lightw:4,
display: createLight,
move: movestrip,
speed: 4.0,
}
return light;
}
function createLight(){
strokeWeight(1.5);
stroke(227, 88, 158);//pink outline
fill(248, 230, 194); //cream
ellipse(this.x, this.lighty, this.lightw, this.lightw);
}
function movestrip(){
this.x -= this.speed
}
/*
function displayText(){
push();
imageMode(CENTER);
image(reeltext[jackpotindex], 200, 148);
pop();
}
/*
/*
function mousePressed(){
if (mouseX>330 & mouseX<370 &&){
jackpotwin.stop();
leverpull.play();
}
}
*/
]]>https://courses.ideate.cmu.edu/15-104/f2020/2020/12/14/final-project-21/feed/0FINAL PROJECT
https://courses.ideate.cmu.edu/15-104/f2020/2020/12/14/final-project-20/
https://courses.ideate.cmu.edu/15-104/f2020/2020/12/14/final-project-20/#respondMon, 14 Dec 2020 11:51:55 +0000https://courses.ideate.cmu.edu/15-104/f2020/?p=64434Continue reading "FINAL PROJECT"]]>
I was inspired by digital interactive infographics and how they are able to relay important information to educate the audience in a very effective and engaging way. I thought it was important to show the visuals in order to help visual learners better understand and connect the information to the real world. I feel that 2020 was a rough year for many things but the current world has always been harsh to the environment. I had my infographic focused on the environment because I didn’t want people to forget about the horrible things happening to the environment because of the pandemic. I had my birds turn to grayscale to show the decrease in biodiversity due to the accelerating extinction of birds. I intended for the hills to turn to a dimmer color in order to fit the final image where the clouds and sky look gloomy with trees on fire and stone like birds flying across the page. However, I originally intended it to show how satellite images showed that the Amazon Forest is slowly becoming less green and less efficient at processing carbon dioxide due to the pollution. I am pretty happy with how the project turned out and I think I learned a lot during the debugging process and problem solving!
var trees = [];
var bird = [];
var cloud = [];
var hillVar= 0.009
var r = 188
var g = 219
var b = 245
var tr =14
var tg = 99
var tb = 42
var sky = 0
var newTreeLikelihood = 0.03;
var newBirdLikelihood= 0.2;
var newCloudLikelihood=0.04;
var textShown = 1
var hillCondition = 0
var clickCondition = 0
var fire = 0
var fx = []
var fy = []
var birdcolor = 0
var birdDiv = ["https://i.imgur.com/L7k89AJ.png",
"https://i.imgur.com/dnY7u7s.png",
"https://i.imgur.com/a1m3PWp.png"]
function preload() {
img = loadImage("https://i.imgur.com/W9zRul7.png");
brd = loadImage(random(birdDiv));
brdgray = loadImage("https://i.imgur.com/ile7nc8.png")
//crackling = loadSound('https://courses.ideate.cmu.edu/15-104/f2020/wp-content/uploads/2020/12/414767__samarobryn__crackling-fire.wav')
}
function soundSetup(){
crackling.setVolume(7)
}
function setup() {
createCanvas(480, 480);
// create an initial collection of buildings
for (var i = 0; i < 10; i++){
var rx = random(width);
var ry = random(10, 50);
trees[i] = makeTree(rx);
bird[i] = makeBird(rx);
for(var f = 0; f< 8; f++){
fx[f] = trees[i].x-trees[i].breadth*2-350//random(trees[i].x-1,trees[i].x+1);
fy[f] = -trees[i].nFloors*20//random(trees[i].nFloors*20,-90)
}
}
frameRate(10);
}
function draw() {
background(r, g, b);
if (sky == 0) {
r = 188
g = 219
b = 245
}
else if (sky==1) {
r = 177
g = 194
b = 199
} else if (sky == 2) {
r = 167
g = 169
b = 171
}
drawHill()
updateAndDisplayCloud();
removeCloud();
addNewCloud()
displayHorizon();
updateAndDisplayTrees();
removeTreesThatHaveSlippedOutOfView();
addNewTreesWithSomeRandomProbability();
updateAndDisplayBird();
removeBird();
addNewBird()
instructionbox()
}
function makeclouds(birthLocationX) {
var k ={x: birthLocationX,
y:round(random(10,180)),
sizer:round(random(25,30)),
speed:-3,
move:cloudMove,
display:cloudDisplay,
click:cloudClick,
}
return k
//noStroke()
}
function cloudClick(cx,cy) {
push()
let dc = dist(cx,cy,this.x+20,this.y);
if (dc < 30 ) {
newCloudLikelihood += 0.1
this.sizer += 3
textShown = 4
}
pop()
}
function cloudMove() {
this.x += this.speed;
this.y += random(-3,3);
}
function cloudDisplay() {
push();
noStroke();
fill(r-20,g-20,b-20);
ellipse(this.x,this.y,this.sizer,this.sizer)
ellipse(this.x+10,this.y+10,this.sizer,this.sizer)
ellipse(this.x+30,this.y+10,this.sizer,this.sizer)
ellipse(this.x+30,this.y-10,this.sizer,this.sizer)
ellipse(this.x+20,this.y-10,this.sizer,this.sizer)
ellipse(this.x+40,this.y,this.sizer,this.sizer)
pop()
}
function updateAndDisplayCloud(){
for (var i = 0; i <cloud.length; i++){
cloud[i].move();
cloud[i].display()
}
}
function removeCloud(){
var cloudToKeep = [];
for (var i = 0; i <cloud.length; i++){
if (cloud[i].x+40>0){
cloudToKeep.push(cloud[i])
}
}
cloud = cloudToKeep
}
function addNewCloud(){
if(random(0,1)<newCloudLikelihood){
cloud.push(makeclouds(width));
}
}
function instructionbox() {
push()
rectMode(CENTER)
fill(255)
strokeWeight(8)
rect(240,400,440,100)
noStroke()
fill(0)
textSize(19.7)
if (textShown==1){
text("Click on objects to see how WE affected them",40,405)
} else if (textShown==2) {
textSize(15)
text("Scientists have recently found that birds are going extinct",40,395)
text("much quicker than we thought. Help by donating to RSPB!",40,415)
} else if ( textShown ==3) {
textSize(16.5)
text("Wildfire has burned more than 4% of California in 2020",40,395)
text("Help by donating to California's wildfire relief fund!",40,415)
} else if (textShown == 4) {
textSize(15)
text("China has surpassed pre-COVID air pollution levels soon",40,395)
text("after business returned to normal.",40,415)
} else if (textShown == 5) {
textSize(15)
text("Satelite image shows that Amazon forest has became less ",40,395)
text("green over time due to pollution",40,415)
}
pop()
}
function birdbox() {
push()
rectMode(CENTER)
fill(255)
strokeWeight(8)
rect(240,400,440,100)
noStroke()
fill(0)
textSize(20)
text("Bird are ded",40,405)
pop()
}
function mouseClicked(){
sky += 1
if (sky>2){
r -= 10
g -= 10
b -= 10
}
clickCondition = 1
for (var i = 0; i <bird.length; i++){
bird[i].click(mouseX, mouseY)
}
for (var i = 0; i <trees.length; i++){
trees[i].click(mouseX, mouseY)
}
for (var i = 0; i <cloud.length; i++){
cloud[i].click(mouseX, mouseY)
}
}
function makeBird(birthLocationX) {
var k ={x: birthLocationX,
y:round(random(-60,-280)),
breadth:round(random(40,70)),
speed:2,
birdHeight:round(random(9,15)),
move:birdMove,
display:birdDisplay,
click:birdClick,
color:color(random(50,240),random(50,240),random(50,240))}
return k
}
function birdClick(bx, by) {
let d = dist(bx, by, this.x, height-190+this.y)
if (d <= this.breadth){
this.color = color(40)
textShown = 2
birdcolor = 1
}
}
function birdMove() {
this.x += this.speed
}
function birdDisplay() {
push();
fill(this.color)
translate(this.x, height-190);
strokeWeight(1);
stroke(0);
push()
if (birdcolor == 1){
image(brdgray,-0,this.y,this.breadth,this.breadth)
} else {
image(brd,-0,this.y,this.breadth,this.breadth)
}
pop()
pop()
}
function updateAndDisplayBird(){
for (var i = 0; i <bird.length; i++){
bird[i].move();
bird[i].display()
}
}
function removeBird(){
var birdToKeep = [];
for (var i = 0; i <bird.length; i++){
if (bird[i].x+bird[i].breadth>0){
birdToKeep.push(bird[i])
}
}
bird = birdToKeep
}
function addNewBird(){
var newBirdLikelihood=0.1;
if(random(0,1)<newBirdLikelihood){
bird.push(makeBird(0));
}
}
function drawHill() {
push()
noStroke()
fill(tr, tg, tb)
beginShape()
for (var h = 0; h<width; h++){
var a = (h*hillVar)+(millis()*0.0002)
var y = map(noise(a),0,1,height/8,height/9*5);
vertex(h,y)
if (mouseY < h & y-1< mouseX =72 && tg <=87 && tb >=77){
tr = 72
tg = 87
tb = 77
}
pop()
vertex(480,480);
vertex(0,480)
endShape()
pop()
}
function updateAndDisplayTrees(){
for (var i = 0; i < trees.length; i++){
trees[i].move();
trees[i].display();
}
}
function removeTreesThatHaveSlippedOutOfView(){
var treesToKeep = [];
for (var i = 0; i < trees.length; i++){
if (trees[i].x + trees[i].breadth > 0) {
treesToKeep.push(trees[i]);
}
}
trees = treesToKeep;
}
function addNewTreesWithSomeRandomProbability() {
if (random(0,1) < newTreeLikelihood) {
trees.push(makeTree(width));
}
}
function treeMove() {
this.x += this.speed;
}
function treeDisplay() {
push()
var floorHeight = 20;
var bHeight = this.nFloors * floorHeight;
fill(74, 21, 22);
push();
translate(this.x, height - 170);
rect(0, -bHeight, this.breadth, bHeight);
noStroke()
for (var i = 0; i < this.nFloors; i++) {
fill(2, 61, 21)
noStroke()
triangle(this.breadth/2,0-(i * floorHeight)-60,-20,20-(i * floorHeight)-40,this.breadth+20,20-(i * floorHeight)-40);
}
var fireSize = random(10,80)
if( fire == 1){
for(var f = 0; f < 8; f++){
image(img,fx[f],fy[f],fireSize,fireSize)
}
}
strokeWeight(3)
pop();
}
function makeTree(birthLocationX) {
var bldg = {x: birthLocationX,
breadth: 15,
speed: -3.0,
nFloors: round(random(2,8)),
move: treeMove,
click: treeClick,
display: treeDisplay}
return bldg;
}
function treeClick(tx,ty) {
var floorHeight = 20;
var bHeight = this.nFloors * floorHeight;
let dtx = dist( tx, height-170, this.x+this.breadth/2, height-170)
let dty = dist( this.x , ty, this.x, -bHeight/2+height-170 )
if (dtx<20+this.breadth/2 & dty
]]>https://courses.ideate.cmu.edu/15-104/f2020/2020/12/14/final-project-20/feed/0Final Project – Responsive Wearables
https://courses.ideate.cmu.edu/15-104/f2020/2020/12/14/final-project-responsive-wearables/
https://courses.ideate.cmu.edu/15-104/f2020/2020/12/14/final-project-responsive-wearables/#respondMon, 14 Dec 2020 11:44:08 +0000https://courses.ideate.cmu.edu/15-104/f2020/?p=64487Continue reading "Final Project – Responsive Wearables"]]>
In 2020, one of the biggest treasure is to experience the time in outdoor. In the time when we need to carefully think about distancing to other people and gearing up ourselves with masks, gloves and sanitizer, I design this interactive game to explore with the idea of using garments as an responsive exterior shell to protect ourselves and create personal boundaries.
By moving the mouse, the character is able to wondering in this projected scenery with colorful reference object. For the design of the character, there are two mode in response to two situations. The character begins with wearing a normal scale clothes. When the player pressed the mouse, the character switch to the inflatables garment set with an “alert” sign.
One of the biggest challenge I encountered with when programming this game is making paneling affect on the canvas. The canvas visually works as a camera frame that shifting with the location of the mouse. If I further develop this program, I hope to have the alert character setting on when the character intersect with every bubble in the arrays.
//Isabel Xu
//Section A
//Final Project
var cX = 0;
var cY = 0;
var cdx = 0;
var cdy = 0;
var start_locationX = 300;
var start_locationY = 200;
var cir_X = [];
var cir_Y = [];
var cir_c = [];
var animGreen = [];
function preload(){
//green character image arrays
let green1 = loadImage("https://i.imgur.com/OXFFPY7.png");
let green2 = loadImage("https://i.imgur.com/gIvd44d.png");
let green3 = loadImage("https://i.imgur.com/p7dyFj3.png");
animGreen = [green1, green2, green3];
//red character image
redAlert = loadImage("https://i.imgur.com/BhCQ0FG.png");
}
function setup() {
createCanvas(600,400);
frameRate(20);
//create level of randomness to the bubble
for (var i = 0; i < 7000; i++) {
cir_X[i] = random(-5000, width+5000);
cir_Y[i] = random(-4000, height+4000);
cir_c[i] = color(235, random(255), random(255));
}
imageMode(CENTER);
}
function draw() {
background(235, 218, 199);
//movement of the bubble inversely to the character
let cir_dx = ((mouseX)-300)/20*-1;
let cir_dy = ((mouseY)-200)/20*-1;
//create colorful bubble background for visual reference
for (var i = 0; i < 7000; i++) {
noStroke();
drawShape(cir_X[i], cir_Y[i], cir_c[i]);
cir_X[i] += cir_dx;
cir_Y[i] += cir_dy;
}
drawFigure(cir_X[i], cir_Y[i]);
}
function drawShape(cir_X, cir_Y, cir_c) {
fill(cir_c);
ellipse(cir_X, cir_Y, 30, 15);
}
function drawFigure(){
if (mouseIsPressed) {
drawRedCharacter();
}else{
drawGreenCharacter();
}
}
function drawGreenCharacter(){
//limit the character movement
cX = constrain(mouseX,250,350);
cY = constrain(mouseY,175,225);
//shadow
fill(110);
ellipse(start_locationX+5,start_locationY+80,130,40)
//draw green character
//create animation effect with multiple image
let randomGreen = random(animGreen);
image(randomGreen,start_locationX,start_locationY,150,180);
//speed is inversely proportional to the mouse distance
cdx = (cX - start_locationX)/20;
cdy = (cY - start_locationY)/20;
start_locationX += cdx;
start_locationY += cdy;
}
function drawRedCharacter (){
cX = constrain(mouseX,250,350);
cY = constrain(mouseY,175,225);
fill(255,0,0);
image(redAlert,start_locationX,start_locationY,200,250);
cdx = (cX - start_locationX)/20;
cdy = (cY - start_locationY)/20;
start_locationX += cdx;
start_locationY += cdy;
}
]]>https://courses.ideate.cmu.edu/15-104/f2020/2020/12/14/final-project-responsive-wearables/feed/0Final Project
https://courses.ideate.cmu.edu/15-104/f2020/2020/12/14/final-project-19/
https://courses.ideate.cmu.edu/15-104/f2020/2020/12/14/final-project-19/#respondMon, 14 Dec 2020 08:04:57 +0000https://courses.ideate.cmu.edu/15-104/f2020/?p=64479Continue reading "Final Project"]]>
For my final project, I wanted to address something we have all been doing a lot of during quarantine, which is impulsive online shopping. Seeing all the devastating climate crisis we’ve experienced this year I wanted to do a little research on how the actual cost of fast fashion and its damage to the environment. It’s easy to purchase a cute shirt when they’re 15 dollars even if you didn’t need it, but in reality, it’s contributing to so many problems that we are actually paying for: forest fires, unpaid labor, toxic waste, etc.. The program is very simple, you hover over with your mouse to see the environmental cost of each of these clothing items, and when you click on them it will be placed into your shopping bag. A certain number of the three symbols will pop up on the screen to show you how much you’ve spent. When you’ve used up around 50,000 litres of water (which doesn’t take a lot to achieve), the end screen will pop up. If I had more time I would make the symbols pop up in a more organized manner and add more levels of interactions.
//keep track of number of runs
var count = 0;
//used for locating each item of clothing
var item;
//array for textbox, textbox is t
var t = [];
var textInfo = [
'COTTON T-SHIRT:\n2,700 litres of water\n15kg of CO2\n200+ years to\ndecompose',
'JEANS:\n7000 litres of water\n33kg of CO2\n50 years to decompose',
'SNEAKERS:\n8500 litres of water\n10kg of CO2\n40 years to decompose'
];
var textY = [30, 165, 355];
var textColor = ["lavender", "DarkSlateBlue"];
function preload(){
rack = loadImage('https://i.imgur.com/YpMqJ3Z.png');
shirt = loadImage('https://i.imgur.com/54EAgyC.png');
jeans = loadImage('https://i.imgur.com/qzkFSXI.png');
shoes = loadImage('https://i.imgur.com/D7paBLS.png');
bag = loadImage('https://i.imgur.com/Xyv6IGe.png');
water = loadImage('https://i.imgur.com/3ONgfhP.png');
co2 = loadImage('https://i.imgur.com/me0Lg0A.png');
clock = loadImage('https://i.imgur.com/gw7QVpQ.png');
}
//draw water
function drawWater() {
image(water, this.x, this.y, 20, 20);
}
//draw co2
function drawCarbon(cx, cy) {
image(co2, this.x, this.y, 20, 20);
}
//draw clock
function drawClock(clx, cly) {
image(clock, this.x, this.y, 20, 20);
}
//create new water bucket object with position
function makeWater(wx, wy) {
w = {x: wx, y: wy,
drawFunction: drawWater
}
return w;
}
//create new co2 object with position
function makeCarbon(cx, cy) {
c = {x: cx, y: cy,
drawFunction: drawCarbon
}
return c;
}
//create new clock object with position
function makeClock(clx, cly) {
cl = {x: clx, y: cly,
drawFunction: drawClock
}
return cl;
}
//arrays to store new symbol
var waters = [];
var carbons = [];
var clocks = [];
function setup() {
createCanvas(400, 500);
background("lightsteelblue");
//set up the base rack
image(rack, 200, 0, 200, 500);
imageMode(CENTER);
image(shirt, 300, 80, 120, 100);
image(jeans, 300, 250, 80, 150);
image(shoes, 300, 450, 100, 60);
//create array of objects of the three info textboxes
for (var i = 0; i < 3; i ++) {
t[i] = new Object();
t[i].info = textInfo[i];
t[i].x = 170;
t[i].y = textY[i];
t[i].w = 110;
t[i].h = 70;
t[i].size = 10;
t[i].c = textColor[i];
t[i].font = 'verdana';
t[i].stroke = "thistle"
t[i].sWeight = 5;
}
//make a water bucket
for (var i = 0; i < 20; i ++) {
var w = makeWater(random(100), random(20, 100));
waters.push(w);
}
//make a co2
for (var i = 0; i < 20; i ++) {
var w = makeCarbon(random(100), random(100, 200));
carbons.push(c);
}
//make a clock
for (var i = 0; i < 20; i ++) {
var cl = makeClock(random(50), random(200, 300));
clocks.push(cl);
}
}
function draw() {
//instruction
textSize(20);
fill("white");
textFont(t[0].font);
text('click to shop, hover to see price!', 20, 18);
//draw textbox
if(mouseX >= 200 & mouseX <= 400) {
if(mouseY >= 3 && mouseY <= 120) {
stroke(t[0].stroke);
strokeWeight(t[0].sWeight);
fill(t[0].c);
rect(t[0].x-5, t[0].y-5, t[0].w+10, t[0].h+10);
noStroke();
textSize(t[0].size);
fill(t[1].c);
text(t[0].info, t[0].x, t[0].y, t[0].w, t[0].h);
item = 1;
}
else if(mouseY >= 150 & mouseY <= 300) {
stroke(t[0].stroke);
strokeWeight(t[0].sWeight);
fill(t[0].c);
rect(t[1].x-5, t[1].y-5, t[1].w+10, t[1].h+10);
noStroke();
textSize(t[0].size);
fill(t[1].c);
text(t[1].info, t[1].x, t[1].y, t[0].w, t[0].h);
item = 2;
}
else if(mouseY >= 330 & mouseY <= 480) {
stroke(t[0].stroke);
strokeWeight(t[0].sWeight);
fill(t[0].c);
rect(t[2].x-5, t[2].y-5, t[2].w+10, t[2].h+10);
noStroke();
textSize(t[0].size);
fill(t[1].c);
text(t[2].info, t[2].x, t[2].y, t[2].w, t[2].h);
item = 3;
}
}
//place shopping bag
shoppingBag();
//place key
drawKey(0, 400);
//if 50 buckets of water used, display end page
if(count >= 50) {
endPage();
}
}
function mousePressed() {
//when clicked into each area, item goes to shopping bag
if(item == 1) {
buyShirt(120, 450);
//3 water buckets
push();
for (var i = 0; i < 3; i ++) {
var w = waters[i];
w.drawFunction();
translate(random(10, 15), random(10, 15));
}
pop();
//3 co2
push();
for (var i = 0; i < 3; i ++) {
var c = carbons[i];
c.drawFunction();
translate(random(10, 15), random(10, 15));
}
pop();
//20 clocks
push();
for (var i = 0; i < 20; i ++) {
var cl = clocks[i];
cl.drawFunction();
translate(random(5, 10), random(5, 10));
}
pop();
//add 3 to overall count
count += 3;
}
else if(item == 2) {
buyJeans(120, 470);
//7 water buckets
push();
for (var i = 0; i < 7; i ++) {
var w = waters[i];
w.drawFunction();
translate(random(10, 15), random(10, 15));
}
pop();
//6 co2
push();
for (var i = 0; i < 6; i ++) {
var c = carbons[i];
c.drawFunction();
translate(random(10, 15), random(10, 15));
}
pop();
//5 clocks
push();
for (var i = 0; i < 5; i ++) {
var cl = clocks[i];
cl.drawFunction();
translate(random(5, 10), random(5, 10));
}
pop();
//add 7 to overall count
count += 7;
}
else {
buyShoes(120, 450);
//8 water buckets
push();
for (var i = 0; i < 8; i ++) {
var w = waters[i];
w.drawFunction();
translate(random(10, 15), random(10, 15));
}
pop();
//2 co2
push();
for (var i = 0; i < 2; i ++) {
var c = carbons[i];
c.drawFunction();
translate(random(10, 15), random(10, 15));
}
pop();
//4 clocks
push();
for (var i = 0; i < 4; i ++) {
var cl = clocks[i];
cl.drawFunction();
translate(random(5, 10), random(5, 10));
}
pop();
//add 8 to overall count
count += 8;
}
}
function shoppingBag() {
image(bag, 120, 470, 170, 170);
fill("white");
textSize(20);
text('your bag', 75, 480);
}
function drawKey(x, y) {
//key box
stroke("thistle");
strokeWeight(5);
fill("lavender");
rect(x, y, 70, 80);
//symbols
image(water, x+15, y+20, 20, 20);
image(co2, x+15, y+45, 20, 20);
image(clock, x+15, y+65, 20, 20);
//text
textSize(7);
fill("black");
noStroke();
text('1000L water\n\n5kg co2\n\n10 years', x+30, y+15, 40, 80);
stroke("thistle");
}
//clothing item goes into shopping bag
function buyShirt(x, y) {
push();
rotate(radians(random(-2, 2)));
image(shirt, x, y, 120, 100);
pop();
}
function buyJeans(x, y) {
push();
rotate(radians(random(-2, 2)));
image(jeans, x, y, 80, 150);
pop();
}
function buyShoes(x, y) {
push();
rotate(radians(random(-2, 2)));
image(shoes, x, y, 100, 60);
pop();
}
function endPage() {
background("steelblue");
fill("lavender");
noStroke();
textSize(30);
text('Sorry,\nYou have used up \n50 years worth of \ndrinking water.\n\nRefresh to shop again',
50, 100)
}