color.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. 'use strict';
  2. goog.provide('Blockly.Blocks.color');
  3. goog.require('Blockly.Blocks');
  4. goog.require('Blockly.Types');
  5. Blockly.Blocks.color.HUE = 330;
  6. Blockly.Blocks['color_analyzer_setup'] = {
  7. init: function() {
  8. this.appendDummyInput()
  9. // .appendField(new Blockly.FieldImage("http://cocorobo.cn/cocoblockly/blockly/media/cocomod_blockly_colorAnalyzer.png", 140, 40, "0"));
  10. .appendField(new Blockly.FieldImage("./../blockly/media/main-color.png", 50, 40, "0"));
  11. this.appendDummyInput()
  12. .appendField(Blockly.Msg.COLORANALYZER_SETUP);
  13. this.setColour(Blockly.Blocks.color.HUE);
  14. this.setTooltip('');
  15. this.setHelpUrl('');
  16. }
  17. };
  18. Blockly.Blocks['set_color'] = {
  19. init: function() {
  20. this.appendDummyInput()
  21. .appendField(Blockly.Msg.COLOR)
  22. .appendField(new Blockly.FieldColour("#ff0000"), "COLOR");
  23. this.setOutput(true, "String");
  24. this.setColour(Blockly.Blocks.color.HUE);
  25. this.setTooltip("");
  26. this.setHelpUrl("");
  27. }
  28. };
  29. Blockly.Blocks['read_r'] = {
  30. init: function() {
  31. this.appendDummyInput()
  32. .appendField(Blockly.Msg.READ_R);
  33. this.setOutput(true, Blockly.Types.NUMBER.output);
  34. this.setColour(Blockly.Blocks.color.HUE);
  35. this.setTooltip("");
  36. this.setHelpUrl("");
  37. },
  38. getBlockType: function() {
  39. return Blockly.Types.NUMBER;
  40. }
  41. }
  42. Blockly.Blocks['read_g'] = {
  43. init: function() {
  44. this.appendDummyInput()
  45. .appendField(Blockly.Msg.READ_G);
  46. this.setOutput(true, Blockly.Types.NUMBER.output);
  47. this.setColour(Blockly.Blocks.color.HUE);
  48. this.setTooltip("");
  49. this.setHelpUrl("");
  50. },
  51. getBlockType: function() {
  52. return Blockly.Types.NUMBER;
  53. }
  54. }
  55. Blockly.Blocks['read_b'] = {
  56. init: function() {
  57. this.appendDummyInput()
  58. .appendField(Blockly.Msg.READ_B);
  59. this.setOutput(true, Blockly.Types.NUMBER.output);
  60. this.setColour(Blockly.Blocks.color.HUE);
  61. this.setTooltip("");
  62. this.setHelpUrl("");
  63. },
  64. getBlockType: function() {
  65. return Blockly.Types.NUMBER;
  66. }
  67. }
  68. Blockly.Blocks['set_colorRGB'] = {
  69. init: function() {
  70. this.appendDummyInput()
  71. .appendField(Blockly.Msg.COLOR);
  72. this.appendValueInput("RED_VAL")
  73. .setCheck(null)
  74. .appendField(Blockly.Msg.RED);
  75. this.appendValueInput("GREEN_VAL")
  76. .setCheck(null)
  77. .appendField(Blockly.Msg.GREEN);
  78. this.appendValueInput("BLUE_VAL")
  79. .setCheck(null)
  80. .appendField(Blockly.Msg.BLUE);
  81. this.setInputsInline(true);
  82. this.setOutput(true, "String");
  83. this.setColour(Blockly.Blocks.color.HUE);
  84. this.setTooltip("");
  85. this.setHelpUrl("http://help.cocorobo.cn/#/cocomod/color-analyzer?id=rgb-%E5%8F%96%E8%89%B2%E5%99%A8");
  86. }
  87. }
  88. Blockly.Blocks['isColorRGB'] = {
  89. init: function() {
  90. this.appendDummyInput()
  91. .appendField(Blockly.Msg.ISCOLOR)
  92. .appendField(new Blockly.FieldDropdown([
  93. [Blockly.Msg.RED, "r"],
  94. [Blockly.Msg.GREEN, "g"],
  95. [Blockly.Msg.BLUE, "b"]
  96. ]), "COLOR");
  97. this.setOutput(true, "Boolean");
  98. this.setColour(Blockly.Blocks.color.HUE);
  99. this.setTooltip("");
  100. this.setHelpUrl("http://help.cocorobo.cn/#/cocomod/color-analyzer?id=rgb-%E5%8F%96%E8%89%B2%E5%99%A8");
  101. }
  102. }