//Adam Kochen //Midterm takehome int onePress = 0; int day = 1; float birdX = 600; float octoY= 400, octoM = -3; float witchX = 620; String text = "Night"; String title = "CST112 Takehome-"; String name = "Adam Kochen "+birdX; void setup(){ size(600,500); } void draw(){ noStroke(); if(day == 1){//day background(50,200,255); //sky fill(255,255,0); sun(width*3/4,height*1/8); birdX-=5;//move bird bird(birdX,70); if(birdX + 200 < 0){ reset(); } } else if(day == 2){//night fill(200); background(0,0,120); sun(width*3/4,height*1/8); octoY=octoY+octoM; if(octoY < height*1/4+25 || octoY > height-70) { octoM = -octoM; } witchX-=1.7; witch(witchX,45); if(witchX+200 < 0){ reset(); } } fill(0); text(title+ name,240,20); //title noStroke(); fill(0,0,180); rect(0,height*1/4,width,height*3/4); //surface borders(); fill(0,255,0); //buttons onePress--; mousePressed(30,60,30,60,33,50); quit(30,60,70,100,33,90); fill(150,0,150); stroke(150,0,150); octopus(400,octoY,40); } void borders(){ //side borders for(float side = 0;side < height+10; side = side + 15){ fill(255,255,0); rect(0,side,10,10); //left ellipseMode(CENTER); fill(0,255,255); ellipse(width,side+5,10,10); //right } //top border for(float top = 0; top < width-15; top = top + 15){ fill(255,0,255); triangle(top+10,0,top+19,0,top+15,9); } stroke(0,255,0); //grass border for(float grassX = 15 ; grassX < width-10 ; grassX = grassX + 10){ strokeWeight(3); line(grassX,height,grassX,height-10); } } void bird(float bX, float bY){ noStroke(); //draw bird fill(120,0,120); triangle(bX,bY+5,bX,bY+15,bX-20,bY+10); triangle(bX+10,bY-5,bX+10,bY+25,bX-10,bY+10); } void reset(){ birdX = width+50; witchX = width+ 100; } void button(float x, float w, float y, float h, float tx, float ty,String text){ rect(x,y,w-x,h-y,15); fill(0); text(text,tx,ty); } void mousePressed(float x, float w, float y, float h, float tx, float ty){ button(x,w,y,h,tx,ty,text); if(onePress < 0){//doesn't switch every frame if mouse held if(mousePressed && mouseX < w && mouseX > x && mouseY < h && mouseY > y) { onePress = 50; if(day == 1) { day = 2; text = "Day"; reset(); } else { if(day == 2) { day = 1; text = "Night"; reset(); } } } } } void sun(float x, float y){ ellipse(x,y,50,50); } void octopus(float x,float y,float d){ //make octopus ellipseMode(CORNER); rectMode(CORNER); //body ellipse(x,y-d/2,d,d); rect(x,y,d,d); //legs strokeWeight(2); for(float leg = x;leg < x+41; leg = leg+5){ float sway = leg; if(octoM < 0){ if(frameCount/50%2 == 0) { sway = leg+5; } else { sway = leg-5; } } else { sway = leg; } line(leg,y+38,sway,y+58); } } void witch(float x, float y){ noStroke(); //make witch float w =20; float h =40; //body fill(100,50,10); rect(x,y,w,h); //head fill(255,100,100); ellipse(x,y-h/2,w,h/2); //eye fill(255); ellipse(x+w/6,y-h/2.5,7,7); //hat fill(0); triangle(x-5,y-h/2+3,x+w+5,y-h/2+3,x+w/2,y-w*2+5); strokeWeight(5); stroke(0); line(x-10,y-h/2+3,x+w+10,y-h/2+3); //broom strokeWeight(7); stroke(139,69,19); line(x-w,y+h,x+w*2,y+h); strokeWeight(3); line(x+w*2+3,y+h*1.5,x+w*2+3,y+h/2); for(float bristle= y+h/2; bristle < y+h*1.5; bristle = bristle +9.99999){ line(x+w*2+3,bristle,x+w*2+23,bristle); } //legs strokeWeight(7); stroke(100,255,100); line(x+5,y+h-5,x+5,y+h+30); line(x+w-5,y+h-5,x+w-5,y+h+30); } void quit(float x, float w, float y, float h, float tx, float ty){ fill(0,255,0); button(x,w,y,h,tx,ty,"Exit"); if(mousePressed && mouseX < w && mouseX > x && mouseY < h && mouseY > y) { exit(); } }