Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. /**
  2. * Name : Chelsey Lin
  3. * PennKey : chelseyl
  4. * Recitation : 216
  5. */
  6.  
  7. public class StampSketch {
  8. public static void main(String[] args) {
  9. // is this the first time we are drawing the background?
  10. boolean firstTime = true;
  11.  
  12. // initializing and defining variables
  13. double xWave1 = 0.0;
  14. double xWave2 = 0.2;
  15. double yStar;
  16.  
  17. PennDraw.enableAnimation(5);
  18.  
  19. while (true) {
  20. // if a key is pressed, redraw background
  21. if (PennDraw.hasNextKeyTyped()) { // check keyboard input
  22. // basic background: sea and night sky
  23. PennDraw.clear();
  24. PennDraw.setPenColor(PennDraw.BLACK);
  25. PennDraw.filledSquare(0.5, 0.5, .5);
  26. PennDraw.setPenColor(PennDraw.BOOK_BLUE);
  27. PennDraw.filledRectangle(0.5, 0.1, 0.5, 0.2);
  28. // loop to create waves (iteration)
  29. double i;
  30. for (i = 0.0; i < 2; i = (i + .2) % 1) {
  31. System.out.println("Current value of i: " + i);
  32. System.out.println("Current value of xWave1: " + xWave1);
  33. System.out.println("Current value of xWave2: " + xWave2);
  34. PennDraw.setPenColor(PennDraw.BOOK_LIGHT_BLUE);
  35. PennDraw.filledArc(xWave1, 0.1, 0.1, 0, 180);
  36. PennDraw.filledArc(xWave2, 0.15, 0.1, 0, 180);
  37. xWave1 = (xWave1 + i) % 1;
  38. xWave2 = (xWave2 + i) % 1;
  39. PennDraw.advance();
  40. }
  41. // Math.random determine star position (random)
  42. if (Math.random() > .5) {
  43. yStar = Math.random();
  44. PennDraw.filledEllipse(Math.random(), yStar, .05, .05);
  45. }
  46. PennDraw.nextKeyTyped(); // read 1 character
  47. firstTime = false;
  48. }
  49.  
  50. // if the mouse is clicked
  51. if (PennDraw.mousePressed()) {
  52. // get the coordinates of the mouse cursor
  53. double x = PennDraw.mouseX();
  54. double y = PennDraw.mouseY();
  55. }
  56. // draw moon at location if above horizon
  57. if (y > .3) {
  58. PennDraw.filledEllipse(x, y, (1.0 - x), (1.0 - y);
  59. }
  60.  
  61. // TODO - check which region the mouse click was in
  62. // draw a scaled shape
  63. }
  64. }
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement