led.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. /**
  2. * @license Licensed under the Apache License, Version 2.0 (the "License"):
  3. * http://www.apache.org/licenses/LICENSE-2.0
  4. */
  5. /**
  6. * @fileoverview Code generator for the test 2 blocks.
  7. */
  8. 'use strict';
  9. goog.provide('Blockly.Python.led');
  10. goog.require('Blockly.Python');
  11. var globalBrightness;
  12. Blockly.Python['led_neopixel_setup'] = function(block) {
  13. Blockly.Python.addInclude('Aadafruit_GFX', '#include <Adafruit_GFX.h>');
  14. Blockly.Python.addInclude('Adafruit_NeoMatrix', '#include <Adafruit_NeoMatrix.h>');
  15. Blockly.Python.addInclude('Adafruit_NeoPixel', '#include <Adafruit_NeoPixel.h>');
  16. var number_neopixel_initpin = block.getFieldValue('neopixel_initpin');
  17. var number_neopixel_initheight = block.getFieldValue('neopixel_initheight');
  18. var number_neopixel_initwidth = block.getFieldValue('neopixel_initwidth');
  19. var number_neopixel_initbright = block.getFieldValue('neopixel_initbright');
  20. Blockly.Python.addDeclaration('ledDeclA' + number_neopixel_initpin, '#ifndef PSTR\n' + ' #define PSTR\n' + '#endif\n', false);
  21. Blockly.Python.addDeclaration('ledDeclB' + number_neopixel_initpin, '#define\t' + 'PIN\t' + number_neopixel_initpin, false);
  22. Blockly.Python.addDeclaration('ledDeclC' + number_neopixel_initpin, 'Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(5,5,' + number_neopixel_initwidth + ',' + number_neopixel_initheight + ', PIN,NEO_TILE_TOP + NEO_TILE_LEFT + NEO_TILE_COLUMNS + NEO_TILE_PROGRESSIVE + NEO_MATRIX_TOP + NEO_MATRIX_LEFT + NEO_MATRIX_ROWS + NEO_MATRIX_PROGRESSIVE,NEO_GRB + NEO_KHZ800);');
  23. Blockly.Python.addSetup('ledSetup' + number_neopixel_initpin, 'matrix.begin();\n' + ' matrix.setBrightness(' + number_neopixel_initbright + ');\n');
  24. globalBrightness = number_neopixel_initbright;
  25. var code = '';
  26. return code;
  27. };
  28. Blockly.Python['led_setrotation'] = function(block) {
  29. var dropdown_led_setrotation_option = block.getFieldValue('led_setrotation_option');
  30. var code = 'matrix.setRotation(' + dropdown_led_setrotation_option + ');\n';
  31. return code;
  32. };
  33. Blockly.Python['led_setbright'] = function(block) {
  34. var bright_value = Blockly.Python.valueToCode(block, 'BRIGHTNESS', Blockly.Python.ORDER_ATOMIC);
  35. var code = 'matrix.setBrightness(' + bright_value + ');\n';
  36. return code;
  37. }
  38. Blockly.Python['led_set_width_height'] = function(block) {
  39. var width = Blockly.Python.valueToCode(block, 'WIDTH', Blockly.Python.ORDER_ATOMIC);
  40. var height = Blockly.Python.valueToCode(block, 'HEIGHT', Blockly.Python.ORDER_ATOMIC);
  41. var code = width + ', ' + height;
  42. return [code, Blockly.Python.ORDER_ATOMIC];
  43. };
  44. Blockly.Python['led_set_position'] = function(block) {
  45. var pos_x = Blockly.Python.valueToCode(block, 'POSX', Blockly.Python.ORDER_ATOMIC);
  46. var pos_y = Blockly.Python.valueToCode(block, 'POSY', Blockly.Python.ORDER_ATOMIC);
  47. var code = pos_x + ', ' + pos_y;
  48. return [code, Blockly.Python.ORDER_ATOMIC];
  49. };
  50. Blockly.Python['led_drawpixel'] = function(block) {
  51. var color;
  52. var color_val = Blockly.Python.valueToCode(block, 'COLOR', Blockly.Python.ORDER_ATOMIC);
  53. if (color_val[0] == "#") {
  54. color = hexToRgb(color_val);
  55. } else {
  56. color = color_val;
  57. }
  58. var position = Blockly.Python.valueToCode(block, 'POS', Blockly.Python.ORDER_ATOMIC);
  59. var code = 'matrix.drawPixel(' + position + ',matrix.Color' + color + ');\n';
  60. return code;
  61. };
  62. Blockly.Python['led_drawrect'] = function(block) {
  63. //var color = hexToRgb(Blockly.Python.valueToCode(block, 'COLOR', Blockly.Python.ORDER_ATOMIC));
  64. var color;
  65. var color_val = Blockly.Python.valueToCode(block, 'COLOR', Blockly.Python.ORDER_ATOMIC);
  66. if (color_val[0] == "#") {
  67. color = hexToRgb(color_val);
  68. } else {
  69. color = color_val;
  70. }
  71. var size = Blockly.Python.valueToCode(block, 'SIZE', Blockly.Python.ORDER_ATOMIC);
  72. var type = block.getFieldValue('rect_type');
  73. var position = Blockly.Python.valueToCode(block, 'POS', Blockly.Python.ORDER_ATOMIC);
  74. var code = 'matrix.' + type + 'Rect(' + position + ',' + size + ',matrix.Color' + color + ');\n';
  75. return code;
  76. };
  77. Blockly.Python['led_drawline'] = function(block) {
  78. //var color = hexToRgb(Blockly.Python.valueToCode(block, 'COLOR', Blockly.Python.ORDER_ATOMIC));
  79. var color;
  80. var color_val = Blockly.Python.valueToCode(block, 'COLOR', Blockly.Python.ORDER_ATOMIC);
  81. if (color_val[0] == "#") {
  82. color = hexToRgb(color_val);
  83. } else {
  84. color = color_val;
  85. }
  86. var type = Blockly.Python.valueToCode(block, 'TYPE', Blockly.Python.ORDER_ATOMIC);
  87. var positionA = Blockly.Python.valueToCode(block, 'POSA', Blockly.Python.ORDER_ATOMIC);
  88. var positionB = Blockly.Python.valueToCode(block, 'POSB', Blockly.Python.ORDER_ATOMIC);
  89. var code = 'matrix.drawLine(' + positionA + ',' + positionB + ',' + 'matrix.Color' + color + ');\n';
  90. return code;
  91. };
  92. Blockly.Python['led_showall'] = function(block) {
  93. var code = "matrix.show();\n" + "delayMicroseconds(500);\n" + "matrix.setBrightness(" + globalBrightness + ");\n";
  94. return code;
  95. };
  96. Blockly.Python['led_text'] = function(block) {
  97. var text_x_val = Number(block.getFieldValue('x_val'));
  98. var text_y_val = Number(block.getFieldValue('y_val'));
  99. var colour_text_color = hexToRgb(Blockly.Python.valueToCode(block, 'text_color', Blockly.Python.ORDER_ATOMIC));
  100. var colour_back_color = hexToRgb(Blockly.Python.valueToCode(block, 'back_color', Blockly.Python.ORDER_ATOMIC));
  101. var number_text_size = block.getFieldValue('text_size');
  102. var text_color = 'matrix.Color' + colour_text_color;
  103. var back_color = 'matrix.Color' + colour_back_color;
  104. var code = 'matrix.setCursor(' + text_x_val + ', ' + text_y_val + ');\n' +
  105. 'matrix.setTextColor(' + text_color + ', ' + back_color + ');\n' +
  106. 'matrix.setTextSize(' + number_text_size + ');\n' +
  107. 'matrix.setTextWrap(false);\n';
  108. return code;
  109. };
  110. Blockly.Python['led_clear'] = function(block) {
  111. Blockly.Python.addFunction("led_clear", "void ledClear() {\n" +
  112. ' matrix.fillScreen(0);\n' +
  113. ' matrix.show();\n' +
  114. ' delay(1);\n' +
  115. '}\n');
  116. var code = 'ledClear();\n';
  117. return code;
  118. };
  119. Blockly.Python['led_scrolling_text'] = function(block) {
  120. var text_led_scrolling_speed = block.getFieldValue('led_scrolling_speed');
  121. var colour_led_scrolling_color = hexToRgb(Blockly.Python.valueToCode(block, 'led_scrolling_color', Blockly.Python.ORDER_ATOMIC));
  122. Blockly.Python.addDeclarataddDion('led_scrolling_decl', 'int x = tiledMatrix.width() ;');
  123. var code = 'matrix.setTextWrap(false);\n' +
  124. 'matrix.setTextColor(matrix.Color' + colour_led_scrolling_color + ');\n' +
  125. 'matrix.setCursor(x, 0);\n' +
  126. 'int len = text.length()*6;\n' +
  127. 'len *= (-1);\n' +
  128. '//every word takes about 6 pixel wide\n' +
  129. 'if(--x < len) {\n' +
  130. 'x = matrix.width();\n' +
  131. '}\n' +
  132. 'matrix.show();\n' +
  133. 'delay(' + text_led_scrolling_speed + ');\n';
  134. return code;
  135. };
  136. Blockly.Python['led_pattern_5x5'] = function(block) {
  137. let pattern_5x5 = 'void setPattern(uint16_t patternMatrix[5][5]) {\n' +
  138. ' for (int row=0; row<5; row++) {\n' +
  139. ' for (int col=0; col<5; col++) {\n' +
  140. ' matrix.drawPixel(row, col, patternMatrix[col][row]);\n }\n }\n}\n';
  141. Blockly.Python.addFunction('pattern_5x5', pattern_5x5);
  142. let panel_init = 'uint16_t pattern[5][5] =\n{\n' +
  143. ' { matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0), },\n' +
  144. ' { matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0), },\n' +
  145. ' { matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0), },\n' +
  146. ' { matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0), },\n' +
  147. ' { matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0), }\n};\n';
  148. Blockly.Python.addDeclaration('pattern_5x5_dec', panel_init);
  149. let code = '';
  150. for (var i = 0; i < 5; i++) {
  151. for (var j = 0; j < 5; j++) {
  152. let color = "matrix.Color" + hexToRgb(block.getFieldValue(i + "_" + j));
  153. if (color === "matrix.Color(59, 85, 135)") {
  154. color = "matrix.Color(0, 0, 0)";
  155. }
  156. code += 'pattern[4-' + i + '][4-' + j + '] = ' + color + '; ';
  157. }
  158. code += '\n'
  159. }
  160. code += 'setPattern(pattern);\n';
  161. return code;
  162. };
  163. Blockly.Python['led_drawWord_5x5'] = function(block) {
  164. var word = Blockly.Python.valueToCode(block, 'WORD', Blockly.Python.ORDER_ATOMIC);
  165. var color;
  166. var color_val = Blockly.Python.valueToCode(block, 'COLOR', Blockly.Python.ORDER_ATOMIC);
  167. if (color_val[0] == "#") {
  168. color = hexToRgb(color_val);
  169. } else {
  170. color = color_val;
  171. }
  172. Blockly.Python.addInclude("myfont_5x5", "#include <Fonts/MyFont5pt7b.h>");
  173. Blockly.Python.addSetup("setTextWrap_false", "matrix.setTextWrap(false);");
  174. Blockly.Python.addSetup("font_5x5", "matrix.setFont(&MyFont5pt7b);\n");
  175. var code = 'matrix.setTextColor(matrix.Color' + color + ');\n' +
  176. 'matrix.setCursor(0, 4);\n' +
  177. 'matrix.print(F(' + word + '));\n';
  178. return code;
  179. };
  180. Blockly.Python['led_text_input'] = function(block) {
  181. var scroll = block.getFieldValue("scroll");
  182. var font = block.getFieldValue("font");
  183. var text = Blockly.Python.valueToCode(block, 'TEXT', Blockly.Python.ORDER_ATOMIC);
  184. //正则表达式判断拼接的积木是 text积木还是 variable积木
  185. var isString = /"/g.test(text)
  186. var color;
  187. var color_val = Blockly.Python.valueToCode(block, 'COLOR', Blockly.Python.ORDER_ATOMIC);
  188. if (color_val[0] == "#") {
  189. color = hexToRgb(color_val);
  190. } else {
  191. color = color_val;
  192. }
  193. var position = Blockly.Python.valueToCode(block, 'POS', Blockly.Python.ORDER_ATOMIC);
  194. var position_x = parseInt(position.split(',')[0]);
  195. var position_y = parseInt(position.split(',')[1]);
  196. var code = 'matrix.setTextColor(matrix.Color' + color + ');\n';
  197. Blockly.Python.addSetup("setTextWrap_false", "matrix.setTextWrap(false);");
  198. if (font == "1") {
  199. Blockly.Python.addInclude("myfont_5x5", "#include <Fonts/MyFont5pt7b.h>");
  200. Blockly.Python.addSetup("myfont_setup", "matrix.setFont(&MyFont5pt7b);\n");
  201. position_y += 4;
  202. Blockly.Python.addDeclaration("pixelPerChar_5", "int pixelPerChar = 5;")
  203. } else if (font == "3") {
  204. Blockly.Python.addInclude("FreeSansBold9pt7b", "#include <Fonts/FreeSansBold9pt7b.h>");
  205. Blockly.Python.addSetup("FreeSansBold9pt7b", "matrix.setFont(&FreeSansBold9pt7b);\n");
  206. position_y += 12;
  207. Blockly.Python.addDeclaration("pixelPerChar_9", "int pixelPerChar = 9;")
  208. } else {
  209. Blockly.Python.addDeclaration("pixelPerChar_5", "int pixelPerChar = 5;")
  210. }
  211. if (scroll == "1") {
  212. Blockly.Python.addDeclaration("scroll_" + position_x + "_" + position_y, "int scroll_" + position_x + "_" + position_y + " = matrix.width();");
  213. Blockly.Python.addDeclaration("maxDisplacement_" + position_x + "_" + position_y, "int maxDisplacement_" + position_x + "_" + position_y + ";");
  214. code += 'matrix.fillScreen(0);\n' +
  215. 'matrix.setRotation(2);\n'+
  216. 'matrix.setCursor(scroll_' + position_x + '_' + position_y + '+' + position_x + ', ' + position_y + ');\n ';
  217. if (isString) { // text积木处理
  218. code += 'matrix.print(F(' + text + '));\n' +
  219. "maxDisplacement_" + position_x + "_" + position_y + " = strlen(" + text + ")* pixelPerChar + matrix.width();\n";
  220. } else { // variable积木处理
  221. code += 'matrix.print(' + text + ');\n' +
  222. "maxDisplacement_" + position_x + "_" + position_y + " = " + text + ".length()* pixelPerChar + matrix.width();\n";
  223. }
  224. code += 'if(--scroll_' + position_x + '_' + position_y + ' < -maxDisplacement_' + position_x + '_' + position_y + ') {\n' +
  225. 'scroll_' + position_x + '_' + position_y + ' = matrix.width();\n' +
  226. '}\n';
  227. } else {
  228. code += 'matrix.setCursor(' + position_x + ',' + position_y + ');\n';
  229. if (isString) // text积木处理
  230. code += 'matrix.print(F(' + text + '));\n';
  231. else // variable积木处理
  232. code += 'matrix.print(' + text + ');\n';
  233. }
  234. return code;
  235. };
  236. Blockly.Python['led_draw_emotion'] = function(block) {
  237. let pattern_5x5 = 'void setPattern(uint16_t patternMatrix[5][5]) {\n' +
  238. ' for (int row=0; row<5; row++) {\n' +
  239. ' for (int col=0; col<5; col++) {\n' +
  240. ' matrix.drawPixel(row, col, patternMatrix[col][row]);\n }\n }\n}\n';
  241. Blockly.Python.addFunction('pattern_5x5', pattern_5x5);
  242. let panel_init = 'uint16_t pattern[5][5] =\n{\n' +
  243. ' { matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0), },\n' +
  244. ' { matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0), },\n' +
  245. ' { matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0), },\n' +
  246. ' { matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0), },\n' +
  247. ' { matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0),matrix.Color(0, 0, 0), }\n};\n';
  248. Blockly.Python.addDeclaration('pattern_5x5_dec', panel_init);
  249. var facetype = block.getFieldValue("face");
  250. block.updateImage_();
  251. var color;
  252. var color_val = Blockly.Python.valueToCode(block, 'COLOR', Blockly.Python.ORDER_ATOMIC);
  253. if (color_val[0] == "#") {
  254. color = hexToRgb(color_val);
  255. } else {
  256. color = color_val;
  257. }
  258. var code = "";
  259. switch (facetype) {
  260. case "1":
  261. code = "pattern[0][0] = matrix.Color(0, 0, 0); pattern[0][1] = matrix.Color(0, 0, 0); pattern[0][2] = matrix.Color(0, 0, 0); pattern[0][3] = matrix.Color(0, 0, 0); pattern[0][4] = matrix.Color(0, 0, 0);\n" +
  262. "pattern[1][0] = matrix.Color(0, 0, 0); pattern[1][1] = matrix.Color" + color + "; pattern[1][2] = matrix.Color(0, 0, 0); pattern[1][3] = matrix.Color" + color + "; pattern[1][4] = matrix.Color(0, 0, 0);\n" +
  263. "pattern[2][0] = matrix.Color(0, 0, 0); pattern[2][1] = matrix.Color(0, 0, 0); pattern[2][2] = matrix.Color(0, 0, 0); pattern[2][3] = matrix.Color(0, 0, 0); pattern[2][4] = matrix.Color(0, 0, 0);\n" +
  264. "pattern[3][0] = matrix.Color" + color + "; pattern[3][1] = matrix.Color(0, 0, 0); pattern[3][2] = matrix.Color(0, 0, 0); pattern[3][3] = matrix.Color(0, 0, 0); pattern[3][4] = matrix.Color" + color + ";\n" +
  265. "pattern[4][0] = matrix.Color(0, 0, 0); pattern[4][1] = matrix.Color" + color + "; pattern[4][2] = matrix.Color" + color + "; pattern[4][3] = matrix.Color" + color + "; pattern[4][4] = matrix.Color(0, 0, 0);\n" +
  266. "setPattern(pattern);\n"
  267. break;
  268. case "2":
  269. code = "pattern[0][0] = matrix.Color(0, 0, 0); pattern[0][1] = matrix.Color(0, 0, 0); pattern[0][2] = matrix.Color(0, 0, 0); pattern[0][3] = matrix.Color(0, 0, 0); pattern[0][4] = matrix.Color(0, 0, 0);\n" +
  270. "pattern[1][0] = matrix.Color" + color + "; pattern[1][1] = matrix.Color" + color + "; pattern[1][2] = matrix.Color(0, 0, 0); pattern[1][3] = matrix.Color" + color + "; pattern[1][4] = matrix.Color" + color + ";\n" +
  271. "pattern[2][0] = matrix.Color(0, 0, 0); pattern[2][1] = matrix.Color(0, 0, 0); pattern[2][2] = matrix.Color(0, 0, 0); pattern[2][3] = matrix.Color(0, 0, 0); pattern[2][4] = matrix.Color(0, 0, 0);\n" +
  272. "pattern[3][0] = matrix.Color(0, 0, 0); pattern[3][1] = matrix.Color" + color + "; pattern[3][2] = matrix.Color" + color + "; pattern[3][3] = matrix.Color" + color + "; pattern[3][4] = matrix.Color(0, 0, 0);\n" +
  273. "pattern[4][0] = matrix.Color(0, 0, 0); pattern[4][1] = matrix.Color(0, 0, 0); pattern[4][2] = matrix.Color(0, 0, 0); pattern[4][3] = matrix.Color(0, 0, 0); pattern[4][4] = matrix.Color(0, 0, 0);\n" +
  274. "setPattern(pattern);\n"
  275. break;
  276. case "3":
  277. code = "pattern[0][0] = matrix.Color(0, 0, 0); pattern[0][1] = matrix.Color(0, 0, 0); pattern[0][2] = matrix.Color(0, 0, 0); pattern[0][3] = matrix.Color(0, 0, 0); pattern[0][4] = matrix.Color(0, 0, 0);\n" +
  278. "pattern[1][0] = matrix.Color(0, 0, 0); pattern[1][1] = matrix.Color" + color + "; pattern[1][2] = matrix.Color(0, 0, 0); pattern[1][3] = matrix.Color" + color + "; pattern[1][4] = matrix.Color(0, 0, 0);\n" +
  279. "pattern[2][0] = matrix.Color(0, 0, 0); pattern[2][1] = matrix.Color(0, 0, 0); pattern[2][2] = matrix.Color(0, 0, 0); pattern[2][3] = matrix.Color(0, 0, 0); pattern[2][4] = matrix.Color(0, 0, 0);\n" +
  280. "pattern[3][0] = matrix.Color(0, 0, 0); pattern[3][1] = matrix.Color" + color + "; pattern[3][2] = matrix.Color" + color + "; pattern[3][3] = matrix.Color" + color + "; pattern[3][4] = matrix.Color(0, 0, 0);\n" +
  281. "pattern[4][0] = matrix.Color" + color + "; pattern[4][1] = matrix.Color(0, 0, 0); pattern[4][2] = matrix.Color(0, 0, 0); pattern[4][3] = matrix.Color(0, 0, 0); pattern[4][4] = matrix.Color" + color + ";\n" +
  282. "setPattern(pattern);\n"
  283. break;
  284. }
  285. return code;
  286. };
  287. Blockly.Python['led_draw_strip'] = function(block) {
  288. var color;
  289. var color_val = Blockly.Python.valueToCode(block, 'COLOR', Blockly.Python.ORDER_ATOMIC);
  290. if (color_val[0] == "#") {
  291. color = hexToRgb(color_val);
  292. } else {
  293. color = color_val;
  294. }
  295. var location = Blockly.Python.valueToCode(block, 'LOC', Blockly.Python.ORDER_ATOMIC);
  296. var position = location + " % 5 , " + location + " / 5";
  297. var code = 'matrix.drawPixel(' + position + ',matrix.Color' + color + ');\n';
  298. return code;
  299. };
  300. Blockly.Python['led_set_color'] = function(block) {
  301. var code = block.getFieldValue('COLOR');
  302. return [code, Blockly.Python.ORDER_ATOMIC];
  303. };
  304. Blockly.Python['led_set_colorRGB'] = function(block) {
  305. var r = Blockly.Python.valueToCode(block, 'RED_VAL', Blockly.Python.ORDER_ATOMIC);
  306. var g = Blockly.Python.valueToCode(block, 'GREEN_VAL', Blockly.Python.ORDER_ATOMIC);
  307. var b = Blockly.Python.valueToCode(block, 'BLUE_VAL', Blockly.Python.ORDER_ATOMIC);
  308. var code = '(' + r + ',' + g + ',' + b + ')';
  309. return [code, Blockly.Python.ORDER_ATOMIC];
  310. };