// 6.914 HW1 #1 void setup(){ size(200, 200); } void draw(){ // specifying diameter of circle ellipse(100, 100, 50, 50); } void mousePressed(){ // must be no more than radius away from center of circle if (dist(mouseX, mouseY, 100, 100)<25){ println("Congratulations!"); } } // 6.914 HW1 #2 // create beziers - basically open-ended. // 6.914 HW1 #3 boolean goingDown = true; boolean goFastUp = true; int upInterval, downInterval, circleRad = 10; float yPos = circleRad; void setup(){ size(200, 400); } void draw(){ background(255); // setting speed based on whether we're going up fast if (goFastUp){ upInterval = 2; downInterval = 1; } else { upInterval = 1; downInterval = 2; } // setting change in position based on going up vs. down if (goingDown){ yPos += downInterval; } else { yPos -= upInterval; } // if we've reached the edge, turn around if ((yPos < circleRad) || (yPos > height-circleRad)){ goingDown = !goingDown; // switch directions } // draw the circle ellipse (width/2, yPos, circleRad*2, circleRad*2); } void keyPressed(){ if (key == 'S' || key == 's'){ // switch modes goFastUp = !goFastUp; } } // 6.914 HW1 #4 // picked 100 as an arbitrary background red level for the window float winRed = 100, winGreen, winBlue; void setup(){ size(255, 255); } void draw(){ winGreen = mouseX; winBlue = mouseY; background(winRed, winGreen, winBlue); // if color is (x, y, z), the inverse is (255-x, 255-y, 255-z) fill(255 - winRed, 255 - winGreen, 255 - winBlue); ellipse(120, 120, 50, 50); } // 6.914 HW1 #5 void setup(){ size(400, 400); background(255); } void draw(){ // strokeWeight does not depend on mousePressed or not strokeWeight(abs((mouseX+mouseY)%20)); line(pmouseX, pmouseY, mouseX, mouseY); } // just one possible set of functions void mouseMoved(){ stroke(mouseX*2, mouseY*2, mouseX/max(mouseY,1)); } // inverse of the color in mouseMoved void mouseDragged(){ stroke(255-mouseX/2, 255-mouseY*2, 255-mouseX/max(mouseY, 1)); } // 6.914 HW1 #6 int counter1=0, counter2 = 0, counter3 = 0, counter4 = 0; int colorsToTurn=5; void setup(){ size(400, 400); } void draw(){ if (counter1>0 || counter2>0 || counter3>0 || counter4>0){ fill(random(255), random(255), random(255)); delay(100); } if (counter1 > 0){ rect(0, 0, width/2, height/2); counter1--; } else if (counter2 > 0){ rect(width/2, 0, width/2, height/2); counter2--; } else if (counter3 > 0){ rect(0, height/2, width/2, height/2); counter3--; } else if (counter4 > 0){ rect(width/2, height/2, width/2, height/2); counter4--; } } void mousePressed(){ if (counter1 == 0 && counter2 == 0 && counter3 == 0 && counter4 == 0){ if (mouseX < width/2 && mouseY < height/2) counter1+=colorsToTurn; else if (mouseX > width/2 && mouseY < height/2) counter2 += colorsToTurn; else if (mouseX < width/2 && mouseY > height/2) counter3 += colorsToTurn; else if (mouseX > width/2 && mouseY > height/2) counter4 += colorsToTurn; } }