//6.914 HW4 #1 PFont myFont; void setup(){ size(300, 300); myFont = createFont("Tahoma", 16); textFont(myFont, 16); smooth(); } void draw(){ background(0); LittleBug lucy = new LittleBug(color(200), "Lucy Pevensie", 6, 50, 100, 100); LittleBug edmund = new LittleBug(color(100), "Edmund Pevensie", 9, 70, 200, 200); lucy.setLabels(true); // lucy has labels on edmund.setLabels(false); // edmund has labels off lucy.drawBug(); edmund.drawBug(); } class LittleBug{ color myColor; String myName; int myAge, xPos, yPos; float mySize; boolean labelShowing = false; LittleBug(color c, String n, int a, float s, int x, int y){ myColor = c; myName = n; myAge = a; mySize = s; xPos = x; yPos = y; } void drawBug(){ stroke(255); strokeWeight(5); fill(myColor); ellipse(xPos, yPos, mySize, mySize); if (labelShowing){ fill(255); text(myName, xPos - 40, yPos - mySize/2 - 10); } } void setBugSize(float newSize){ mySize = newSize; } void setLabels(boolean newSetting){ labelShowing = newSetting; } } // 6.914 HW4 #2 float oldxPos=0, oldyPos=0, xPos=0, yPos=0; int steps = 0; void setup(){ size(400, 400); background(0); colorMode(HSB, 100); strokeWeight(3); smooth(); } void draw(){ steps++; translate(width/8, height/8); stroke(random(40), 100, 75); fill(random(50, 90), 100, 100); ellipse(3*random(width/4), 3*random(height/4), random(10,30), random(5,50)); delay(int(random(300))); if (steps%10 == 0) yPos= oldyPos + random(-20, 25); else xPos = oldxPos+ random(-2, 3); stroke(100, 0, 100); line(oldxPos, oldyPos, xPos, yPos); oldxPos = xPos; oldyPos = yPos; } void mousePressed(){ saveFrame(); println("saving frame"); } // 6.914 HW4 #3 int counter = 1; void setup(){ size(200, 200); } void draw(){ switch (counter){ case (1): firstMethod(); break; case(2): secondMethod(); break; case(3): thirdMethod(); break; } } void keyPressed(){ switch (keyCode){ case (LEFT): if (counter > 1) counter--; else counter = 3; break; case (RIGHT): if (counter < 3) counter ++; else counter = 1; break; } } void firstMethod(){ background(255); stroke(0); line(0, 0, width, height); } void secondMethod(){ background(100); stroke(255); line(0, height, width, 0); } void thirdMethod(){ background(0); stroke(255); line(0, height/2, width, height/2); }