Advertisement
Guest User

Javascript And Graphics

a guest
Oct 28th, 2018
2,735
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.25 KB | None | 0 0
  1. Just press ctrl+f and type in #.#.#
  2. ---------------------------
  3. 3.1.4
  4. /* This program should print out your
  5. * name, and a hobby you have */
  6. function start(){
  7. println("My name is ");
  8. println("I like to play sports");
  9. }
  10.  
  11. // Sample output:
  12. //
  13. // My name is Jeremy
  14. // I like to juggle
  15. //
  16.  
  17. ---------------------------
  18. 3.2.4
  19. var time = "";
  20. var timeOfDay = "";
  21.  
  22. function start(){
  23. time = "8.";
  24. timeOfDay = "morning, I wake up at ";
  25. println("In the " + timeOfDay + time);
  26.  
  27. // Evening
  28. time = "12.";
  29. timeOfDay = "afternoon, I eat lunch at ";
  30. println("In the " + timeOfDay + time);
  31.  
  32. // Afternoon
  33. time = "11.";
  34. timeOfDay = "evening, I go to bed at ";
  35. println("In the " + timeOfDay + time);
  36. }
  37.  
  38. ---------------------------
  39. 3.3.4
  40. function start(){
  41.  
  42. var name = readLine("Name?");
  43. println("Hi " + name);
  44.  
  45. var time = readInt("Time?");
  46. println("I will meet you at " + time);
  47. }
  48.  
  49. ---------------------------
  50. 3.4.6
  51. //Declare a constant here to represent the cost of a tshirt
  52. var COST_OF_SHIRT = 20;
  53.  
  54. // Starting function for the whole program
  55. function start(){
  56. var AMOUNT_OF_SHIRT = readInt("How Many Shirts: ");
  57. var TOTAL_COST = println("The total cost is " +COST_OF_SHIRT * AMOUNT_OF_SHIRT);
  58. }
  59.  
  60. ---------------------------
  61. 3.4.7
  62. // Variables
  63. var hour = 2;
  64.  
  65. // Starting function.
  66. function start(){
  67. var minutes = readFloat("Minutes: ");
  68. var mile = readInt("Miles: ");
  69. var mph = minutes*hour;
  70. var mphPrint = println("You ran " + mph + " M/PH");
  71. }
  72.  
  73. ---------------------------
  74. 3.5.7
  75. /* This program should draw the Netherlands flag. The
  76. * top third of the canvas is red, the middle third
  77. * is white, and the bottom third is blue. */
  78. function start(){
  79. redRectangle();
  80. blueRectangle();
  81. whiteRectangle();
  82. }
  83.  
  84. // Red Rectangle
  85. function redRectangle() {
  86. var rectRed = new Rectangle(400, 160);
  87. rectRed.setColor(Color.red);
  88. add(rectRed);
  89. }
  90.  
  91. // Blue Rectangle
  92. function blueRectangle() {
  93. var rectBlue = new Rectangle(400, 160);
  94. rectBlue.setPosition(0, 320);
  95. rectBlue.setColor(Color.blue);
  96. add(rectBlue);
  97. }
  98.  
  99. // White Rectangle
  100. function whiteRectangle() {
  101. var rectWhite = new Rectangle(400, 160);
  102. rectWhite.setPosition(0, 160);
  103. rectWhite.setColor(Color.white);
  104. add(rectWhite);
  105. }
  106.  
  107. ---------------------------
  108. 3.5.8
  109. /* Constants representing the radius of the top, middle,
  110. * and bottom snowball. */
  111. var BOTTOM_RADIUS = 100;
  112. var MID_RADIUS = 60;
  113. var TOP_RADIUS = 30;
  114.  
  115. // The starting function (Runs the entire program.)
  116. function start(){
  117. snowmanHead();
  118. snowmanMiddle();
  119. snowmanBottom();
  120. }
  121.  
  122. // The head of the snowman
  123. function snowmanHead() {
  124. var snowHead = new Circle(TOP_RADIUS);
  125. snowHead.setPosition(200, 100);
  126. snowHead.setColor(Color.gray);
  127. add(snowHead);
  128. }
  129.  
  130. // The middle of the snowman
  131. function snowmanMiddle() {
  132. var snowMid = new Circle(MID_RADIUS);
  133. snowMid.setPosition(200, 190);
  134. snowMid.setColor(Color.gray);
  135. add(snowMid);
  136. }
  137.  
  138. // The bottom of the snowman
  139. function snowmanBottom() {
  140. var snowBottom = new Circle(BOTTOM_RADIUS);
  141. snowBottom.setPosition(200, 350);
  142. snowBottom.setColor(Color.gray);
  143. add(snowBottom);
  144. }
  145.  
  146. ---------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement