turtles.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /**
  2. * Turtles!
  3. */
  4. //Blockly.HSV_SATURATION = 0.523;
  5. //Blockly.HSV_VALUE = 0.847;
  6. var Turtle_HUE = 237;
  7. Blockly.Blocks['turtle_create'] = {
  8. init: function() {
  9. this.appendDummyInput()
  10. .appendField("create new turtle");
  11. this.setPreviousStatement(true);
  12. this.setNextStatement(true);
  13. this.setOutput(false);
  14. this.setInputsInline(true);
  15. this.setColour(Turtle_HUE);
  16. this.setTooltip('');
  17. this.setHelpUrl('');
  18. }
  19. };
  20. Blockly.Blocks['turtle_color'] = {
  21. init: function() {
  22. this.appendValueInput("COLOR")
  23. .setCheck(null)
  24. .appendField("make turtle color");
  25. this.setPreviousStatement(true);
  26. this.setNextStatement(true);
  27. this.setOutput(false);
  28. this.setInputsInline(true);
  29. this.setColour(Turtle_HUE);
  30. this.setTooltip('');
  31. this.setHelpUrl('');
  32. }
  33. };
  34. Blockly.Blocks['turtle_forward'] = {
  35. init: function() {
  36. this.appendValueInput("DISTANCE")
  37. .setCheck(null)
  38. .appendField("make turtle move forward by");
  39. this.setPreviousStatement(true);
  40. this.setNextStatement(true);
  41. this.setInputsInline(true);
  42. this.setOutput(false);
  43. this.setColour(Turtle_HUE);
  44. this.setTooltip('');
  45. this.setHelpUrl('');
  46. }
  47. };
  48. Blockly.Blocks['turtle_backward'] = {
  49. init: function() {
  50. this.appendValueInput("DISTANCE")
  51. .setCheck(null)
  52. .appendField("make turtle move backward by");
  53. this.setPreviousStatement(true);
  54. this.setInputsInline(true);
  55. this.setNextStatement(true);
  56. this.setOutput(false);
  57. this.setColour(Turtle_HUE);
  58. this.setTooltip('');
  59. this.setHelpUrl('');
  60. }
  61. };
  62. Blockly.Blocks['turtle_left'] = {
  63. init: function() {
  64. this.appendValueInput("ANGLE")
  65. .setCheck(null)
  66. .appendField("make turtle turn left by");
  67. this.appendDummyInput("")
  68. .appendField("degree");
  69. this.setPreviousStatement(true);
  70. this.setNextStatement(true);
  71. this.setInputsInline(true);
  72. this.setOutput(false);
  73. this.setColour(Turtle_HUE);
  74. this.setTooltip('');
  75. this.setHelpUrl('');
  76. }
  77. };
  78. Blockly.Blocks['turtle_right'] = {
  79. init: function() {
  80. this.appendValueInput("ANGLE")
  81. .setCheck(null)
  82. .appendField("make turtle turn right by");
  83. this.appendDummyInput("")
  84. .appendField("degree");
  85. this.setPreviousStatement(true);
  86. this.setNextStatement(true);
  87. this.setInputsInline(true);
  88. this.setOutput(false);
  89. this.setColour(Turtle_HUE);
  90. this.setTooltip('');
  91. this.setHelpUrl('');
  92. }
  93. };
  94. Blockly.Blocks['turtle_shape'] = {
  95. init: function() {
  96. this.appendDummyInput()
  97. .appendField("make turtle shape")
  98. .appendField(new Blockly.FieldDropdown([["turtle","turtle"], ["circle","circle"], ["classic","classic"], ["square","square"], ["triangle","triangle"]]), "Shape");
  99. this.setInputsInline(true);
  100. this.setPreviousStatement(true, null);
  101. this.setNextStatement(true, null);
  102. this.setColour(Turtle_HUE);
  103. this.setTooltip("");
  104. this.setHelpUrl("");
  105. }
  106. };
  107. Blockly.Blocks['turtle_pen'] = {
  108. init: function() {
  109. this.appendDummyInput()
  110. .appendField("make turtle pen")
  111. .appendField(new Blockly.FieldDropdown([["up","up"], ["down","down"]]), "Pen");
  112. this.setInputsInline(true);
  113. this.setPreviousStatement(true, null);
  114. this.setNextStatement(true, null);
  115. this.setColour(Turtle_HUE);
  116. this.setTooltip("");
  117. this.setHelpUrl("");
  118. }
  119. };
  120. Blockly.Blocks['turtle_circle'] = {
  121. init: function() {
  122. this.appendValueInput("RADIUS")
  123. .setCheck("Number")
  124. .appendField("make turtle circle with radius:");
  125. this.setInputsInline(true);
  126. this.setPreviousStatement(true, null);
  127. this.setNextStatement(true, null);
  128. this.setColour(Turtle_HUE);
  129. this.setTooltip("");
  130. this.setHelpUrl("");
  131. }
  132. };
  133. Blockly.Blocks['turtle_goto'] = {
  134. init: function() {
  135. this.appendValueInput("X")
  136. .setCheck("Number")
  137. .appendField("make turtle goto location X:");
  138. this.appendValueInput("Y")
  139. .setCheck("Number")
  140. .appendField(",Y:");
  141. this.setInputsInline(true);
  142. this.setPreviousStatement(true, null);
  143. this.setNextStatement(true, null);
  144. this.setColour(Turtle_HUE);
  145. this.setTooltip("");
  146. this.setHelpUrl("");
  147. }
  148. };
  149. Blockly.Blocks['turtle_pos'] = {
  150. init: function() {
  151. this.appendDummyInput()
  152. .appendField("pos");
  153. this.setOutput(true, 'Turtle_Position');
  154. this.setColour(Turtle_HUE);
  155. this.setTooltip('Turtle position');
  156. this.setHelpUrl('');
  157. }
  158. };
  159. /*PythonToBlocks.KNOWN_ATTR_FUNCTIONS['pos'] = function(func, args, keywords, starargs, kwargs, node) {
  160. if (args.length != 0) {
  161. throw new Error("Incorrect number of arguments to turtle.pos!");
  162. }
  163. return [block("turtle_pos", {}, {}, {
  164. }, {"inline": "true"})];
  165. }*/
  166. Blockly.Blocks['turtle_stamp'] = {
  167. init: function() {
  168. this.appendDummyInput()
  169. .appendField("make turtle stamp");
  170. this.setInputsInline(true);
  171. this.setPreviousStatement(true, null);
  172. this.setNextStatement(true, null);
  173. this.setColour(Turtle_HUE);
  174. this.setTooltip("");
  175. this.setHelpUrl("");
  176. }
  177. };
  178. Blockly.Blocks['turtle_begin_fill'] = {
  179. init: function() {
  180. this.appendDummyInput()
  181. .appendField("make turtle begin fill");
  182. this.setInputsInline(true);
  183. this.setPreviousStatement(true, null);
  184. this.setNextStatement(true, null);
  185. this.setColour(Turtle_HUE);
  186. this.setTooltip("");
  187. this.setHelpUrl("");
  188. }
  189. };
  190. Blockly.Blocks['turtle_end_fill'] = {
  191. init: function() {
  192. this.appendDummyInput()
  193. .appendField("make turtle end fill");
  194. this.setInputsInline(true);
  195. this.setPreviousStatement(true, null);
  196. this.setNextStatement(true, null);
  197. this.setColour(Turtle_HUE);
  198. this.setTooltip("");
  199. this.setHelpUrl("");
  200. }
  201. };
  202. Blockly.Blocks['turtle_speed'] = {
  203. init: function() {
  204. this.appendValueInput("SPEED")
  205. .setCheck("Number")
  206. .appendField("make turtle speed");
  207. this.setInputsInline(true);
  208. this.setPreviousStatement(true, null);
  209. this.setNextStatement(true, null);
  210. this.setColour(Turtle_HUE);
  211. this.setTooltip("");
  212. this.setHelpUrl("");
  213. }
  214. };