Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.77 KB | None | 0 0
  1. /* On the first day at UCSC me and my partner saw people on bikes and the sun setting.
  2. We recreated that scene to demonstrate a bike moving to the right over and over again in UCSC and the sun setting*/
  3.  
  4. void setup() {
  5.   //the frame is made 500 by 500 pixels and made to look nice!//
  6.   size(500, 500);
  7.   smooth();
  8. }
  9.  
  10. //all magic numbers are turned into variables//
  11.  
  12. int trans1x = 250;
  13. int trans1y = 250;
  14.  
  15. int floor_leftx = 0;
  16. int floor_lefty = 300;
  17. int floor_rightx = 500;
  18. int floor_righty = 500;
  19. int floor_right2y = 350;
  20.  
  21. int floorx = 5;
  22. int floory = 320;
  23. int floor2x = 110;
  24. int floor2y = 330;
  25. int floor3x = 130;
  26. int floor4x = 235;
  27. int floor5x = 255;
  28. int floor6x = 360;
  29. int floor7x = 380;
  30. int floor8x = 485;
  31.  
  32. int floor_color1 = 255;
  33. int floor_color2 = 0;
  34. int floor_color3 = 0;
  35.  
  36. int wheel1x = 10;
  37. int wheel1y = 280;
  38. int wheel2x = 50;
  39. int wheel2y = 320;
  40. int wheel3x = 100;
  41. int wheel4x = 140;
  42.  
  43. int wheel_color = 127;
  44.  
  45. int thickness1 = 3;
  46. int thickness0 = 1;
  47. int stroke_color = 0;
  48.  
  49. int triangle1x = 30;
  50. int triangle2x = 80;
  51. int triangle3x = 55;
  52. int triangle4x = 120;
  53.  
  54. int triangle1y = 300;
  55. int triangle2y = 300;
  56. int triangle3y = 240;
  57. int triangle4y = 240;
  58.  
  59. int seat1x = 40;
  60. int seat2x = 70;
  61. int seat1y = 230;
  62. int seat2y = 250;
  63.  
  64. int front_rod1x = 120;
  65. int front_rod2x = 120;
  66. int front_rod1y = 220;
  67. int front_rod2y = 300;
  68.  
  69. int handlex = 100;
  70. int handle2x = 140;
  71. int handley = 220;
  72. int handle2y = 220;
  73.  
  74. int brake1x = 65;
  75. int brake2x = 90;
  76. int brake1y = 290;
  77. int brake2y = 310;
  78.  
  79. float rotater = 2;
  80.  
  81. int tree1x = 50;
  82. int tree2x = 120;
  83. int tree3x = 85;
  84. int tree4x = 160;
  85. int tree5x = 230;
  86. int tree6x = 195;
  87. int tree7x = 270;
  88. int tree8x = 340;
  89. int tree9x = 305;
  90. int tree10x = 380;
  91. int tree11x = 450;
  92. int tree12x = 415;
  93. int tree1y = 230;
  94. int tree2y = 230;
  95. int tree3y = 170;
  96.  
  97. int trunk1x = 70;
  98. int trunk2x = 100;
  99. int trunk3x = 180;
  100. int trunk4x = 210;
  101. int trunk5x = 290;
  102. int trunk6x = 320;
  103. int trunk7x = 400;
  104. int trunk8x = 430;
  105. int trunk1y = 230;
  106. int trunk2y = 300;
  107.  
  108. int trunk_color1 = 36;
  109. int trunk_color2 = 21;
  110.  
  111. void draw() {
  112.  
  113.   //creates the ground, makes it green, and makes the background blue//
  114.   rectMode(CORNERS);
  115.   ellipseMode(CORNERS);
  116.   background(floor_color2, floor_color3, floor_color1);
  117.   fill(floor_color2, floor_color1, floor_color3);
  118.   rect(floor_leftx, floor_lefty, floor_rightx, floor_righty);
  119.  
  120.   //creates the black concrete floor and makes the yellow tile dashed lines//
  121.   fill(floor_color2);
  122.   rect(floor_leftx, floor_lefty, floor_rightx, floor_right2y);
  123.  
  124.   fill(floor_color1, floor_color1, floor_color2);
  125.   rect(floorx, floory, floor2x, floor2y);
  126.  
  127.   fill(floor_color1, floor_color1, floor_color2);
  128.   rect(floor3x, floory, floor4x, floor2y);
  129.  
  130.   fill(floor_color1, floor_color1, floor_color2);
  131.   rect(floor5x, floory, floor6x, floor2y);
  132.  
  133.   fill(floor_color1, floor_color1, floor_color2);
  134.   rect(floor7x, floory, floor8x, floor2y);
  135.  
  136.   //creates the tree trunks and makes them dark-brown//
  137.   fill(trunk_color1, trunk_color2, trunk_color2);
  138.   noStroke();
  139.   rect(trunk1x, trunk1y, trunk2x, trunk2y);
  140.   rect(trunk3x, trunk1y, trunk4x, trunk2y);
  141.   rect(trunk5x, trunk1y, trunk6x, trunk2y);
  142.   rect(trunk7x, trunk1y, trunk8x, trunk2y);
  143.  
  144.   //creates the leaf part of the tree and makes them green//
  145.   fill(floor_color2, floor_color1, floor_color2);
  146.   noStroke();
  147.   triangle(tree1x, tree1y, tree2x, tree2y, tree3x, tree3y);
  148.   triangle(tree4x, tree1y, tree5x, tree2y, tree6x, tree3y);
  149.   triangle(tree7x, tree1y, tree8x, tree2y, tree9x, tree3y);
  150.   triangle(tree10x, tree1y, tree11x, tree2y, tree12x, tree3y);
  151.  
  152.   //creates the wheels, makes them red,and rotates at the same time//
  153.   pushMatrix();
  154.   strokeWeight(thickness1);
  155.   translate(trans1x, trans1y);
  156.   rotate(radians(rotater));
  157.   noFill();
  158.   stroke(floor_color1, floor_color2, floor_color2);
  159.   ellipse(wheel1x, wheel1y, wheel2x, wheel2y);
  160.   trans1x++;
  161.   rotater+=1;
  162.   popMatrix();
  163.  
  164.   noFill();
  165.   stroke(floor_color1, floor_color2, floor_color2);
  166.   ellipse(wheel3x, wheel1y, wheel4x, wheel2y);
  167.  
  168.   //creates the connecting rods of the bike itself, and makes it red//
  169.   strokeWeight(thickness0);
  170.   stroke(floor_color1, floor_color2, floor_color2);
  171.   triangle(triangle1x, triangle1y, triangle2x, triangle2y, triangle3x, triangle3y);
  172.  
  173.   stroke(floor_color1, floor_color2, floor_color2);
  174.   triangle(triangle2x, triangle1y, triangle3x, triangle3y, triangle4x, triangle4y);
  175.  
  176.   //creates the front rod that connects the front wheel and makes it red//
  177.   fill(floor_color1, floor_color1, floor_color2);
  178.   line(front_rod1x, front_rod1y, front_rod2x, front_rod2y);
  179.  
  180.   //creates the handle bars and makes them red//
  181.   line(handlex, handley, handle2x, handle2y);
  182.  
  183.   //creates the brakes and makes them red//
  184.   line(brake1x, brake1y, brake2x, brake2y);
  185.  
  186.   //creates the seat and makes it yellow//
  187.   fill(floor_color1, floor_color1, floor_color2);
  188.   noStroke();
  189.   ellipse(seat1x, seat1y, seat2x, seat2y);
  190.  
  191.   //increments the bicycle to the right//
  192.   triangle1x++;
  193.   triangle2x++;
  194.   triangle3x++;
  195.   triangle4x++;
  196.  
  197.   wheel1x++;
  198.   wheel2x++;
  199.   wheel3x++;
  200.   wheel4x++;
  201.  
  202.   seat1x++;
  203.   seat2x++;
  204.  
  205.   front_rod1x++;
  206.   front_rod2x++;
  207.  
  208.   handlex++;
  209.   handle2x++;
  210.  
  211.   brake1x++;
  212.   brake2x++;
  213.  
  214.   //if statement to return the bicycle to its original position once it reaches the end//
  215.   if (wheel1x >= 500 && triangle1x >=500 && seat1x >= 500 && front_rod1x >=500 && handlex >= 500 && brake1x >=500) {
  216.  
  217.     wheel1x = 10;
  218.     wheel2x = 50;
  219.     wheel3x = 100;
  220.     wheel4x = 140;
  221.  
  222.     triangle1x = 30;
  223.     triangle2x = 80;
  224.     triangle3x = 55;
  225.     triangle4x =120;
  226.  
  227.     seat1x = 40;
  228.     seat2x = 70;
  229.  
  230.     front_rod1x = 120;
  231.     front_rod2x =120;
  232.  
  233.     handlex = 100;
  234.     handle2x = 120;
  235.  
  236.     brake1x = 65;
  237.     brake2x = 90;
  238.   }
  239. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement