Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Name : Chelsey Lin
- * PennKey : chelseyl
- * Recitation : 216
- */
- public class StampSketch {
- public static void main(String[] args) {
- // is this the first time we are drawing the background?
- boolean firstTime = true;
- // initializing and defining variables
- double xWave1 = 0.0;
- double xWave2 = 0.2;
- double yStar;
- PennDraw.enableAnimation(5);
- while (true) {
- // if a key is pressed, redraw background
- if (PennDraw.hasNextKeyTyped()) { // check keyboard input
- // basic background: sea and night sky
- PennDraw.clear();
- PennDraw.setPenColor(PennDraw.BLACK);
- PennDraw.filledSquare(0.5, 0.5, .5);
- PennDraw.setPenColor(PennDraw.BOOK_BLUE);
- PennDraw.filledRectangle(0.5, 0.1, 0.5, 0.2);
- // loop to create waves (iteration)
- double i;
- for (i = 0.0; i < 2; i = (i + .2) % 1) {
- System.out.println("Current value of i: " + i);
- System.out.println("Current value of xWave1: " + xWave1);
- System.out.println("Current value of xWave2: " + xWave2);
- PennDraw.setPenColor(PennDraw.BOOK_LIGHT_BLUE);
- PennDraw.filledArc(xWave1, 0.1, 0.1, 0, 180);
- PennDraw.filledArc(xWave2, 0.15, 0.1, 0, 180);
- xWave1 = (xWave1 + i) % 1;
- xWave2 = (xWave2 + i) % 1;
- PennDraw.advance();
- }
- // Math.random determine star position (random)
- if (Math.random() > .5) {
- yStar = Math.random();
- PennDraw.filledEllipse(Math.random(), yStar, .05, .05);
- }
- PennDraw.nextKeyTyped(); // read 1 character
- firstTime = false;
- }
- // if the mouse is clicked
- if (PennDraw.mousePressed()) {
- // get the coordinates of the mouse cursor
- double x = PennDraw.mouseX();
- double y = PennDraw.mouseY();
- }
- // draw moon at location if above horizon
- if (y > .3) {
- PennDraw.filledEllipse(x, y, (1.0 - x), (1.0 - y);
- }
- // TODO - check which region the mouse click was in
- // draw a scaled shape
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement