// 6.914 HW3 #1 String filePath = "http://web.mit.edu/mish/Public/bells/"; PImage i1 = loadImage(filePath+"1.gif"), i2 = loadImage(filePath+"2.jpg"), i3 = loadImage(filePath+"3.jpg"), i4 = loadImage(filePath+"4.gif"), i5 = loadImage(filePath+"5.jpg"); void setup(){ size(500, 500); colorMode(RGB, 100); } void draw(){ background(0); // leftmost tint(100, 0, 0, 80); image(i1, 10, 100, i1.width/4, i1.height/4); tint(100, 100, 100, 80); image(i3, 70, 250, i3.width, i3.height); tint(30, 30, 90, 80); image(i4, 220, 0, i4.width, i4.height); tint(90, 30, 30, 80); image(i5, 100, 30, i5.width*.75, i5.height*.75); // rightmost tint(0, 0, 100, 80); image(i2, 350, 200, i2.width/2, i2.height/2); } // 6.914 HW3 #2 void setup(){ size(300, 300); frameRate(10); } void draw(){ background(255); translate(mouseX, mouseY); translate(random(-30, 30), random(-30, 30)); rotate(random(-PI/3, PI/3)); quad(0, 0, 4, 10, 10, 15, 9, 4); } // 6.914 HW3 #3 void setup(){ size(100, 100); colorMode(HSB, 100); frameRate(3); } void draw(){ for (int i = 0; i < 100; i++){ for (int j = 0; j < 100; j++){ // circle around mouse if (dist(mouseX, mouseY, i, j)<5){ stroke((i + 50)%100, 100, 100-j); } // background else { stroke(i, 100, 100-j); } point(i, j); } } } // 6.914 HW3 #4 char[] letters = new char[18]; int keyWidth = 20; PFont myFont; void setup(){ for (int i = 0; i < letters.length; i++){ letters[i] = ' '; } size(400, 80); myFont = createFont("Courier", 32); textFont(myFont); background(0); fill(255); } void draw(){ // to make the program keep looping } void keyPressed(){ if (key != CODED && key != BACKSPACE){ background(0); // fix array for (int i = 1; i < letters.length; i++) letters[i-1] = letters[i]; // add current key letters[letters.length-1] = key; // printing all letters for (int i = 0; i < letters.length; i++) text(letters[i], 20+keyWidth*i, 50); } } // 6.914 HW3 #5 // petalCount can be updated to change drawing int turnsSoFar = 0, petalCount = 11; PFont myFont; void setup(){ size(300, 300); smooth(); myFont = createFont("Courier", 20); textFont(myFont); } void draw(){ background(255); /// the word turn fill(0, 0, 200); text("turn", width-55, height-5); // apply these transformations to everything else pushMatrix(); translate(width/2, height/2); rotate(turnsSoFar*(PI/4)); // the stem stroke(0, 200, 0); line(0, 0, 0, height/2); // the leaves fill(0, 200, 0); pushMatrix(); translate(0, height/3); // draw left leaf, -x quad(0, 0, -5, 0, -40, -40, 0, -5); // draw right leaf, +x quad(0, 0, 5, 0, 40, -40, 0, -5); popMatrix(); // the petals pushMatrix(); noStroke(); fill(255, 0, 100); for (int i = 0; i < petalCount; i ++){ // rotate around top of flower rotate((2*PI)/petalCount); // draw petal quad(0, 0, 10, 0, 30, 30, 0, 10); } //transform back from petals popMatrix(); // middle of flower fill(255, 255, 0); ellipse(0, 0, 18, 18); // transform back overall popMatrix(); } void mousePressed(){ // if clear is pressed if (mouseX > 55 && mouseY > width-30){ // turn flower turnsSoFar++; } } // 6.914 HW3 #6 int currentHue, circleOn = 0; void setup(){ size(500, 500); colorMode(HSB, 100); noStroke(); } void draw(){ background(0, 0, 0); translate(width/2, height/2); for (int i = 5; i>0; i--){ currentHue = i*15; pushMatrix(); scale(i); for (int j = 100; j > 0; j-=4){ fill(currentHue, j, 100-j); ellipse(0, 0, j, j); } popMatrix(); } }