Programing > Blockly2017 > ֥åκ

final.png

ǤϡBlocklyΥǥɤơ֥åɲäޤ

BlocklyΥ֥åϡBlocklyΥǥUIˤꡢɥåɥåפǺ뤳ȤǤޤ

ϡ֥åä塢Google Closure toolsǺư̤ȤƤɡ줬פʤΤǡäñǤ

ǥ

ˤʤǥϡBlocklyΥǥ˴ޤޤGenerating JavaScriptǤΥǥǤϡBlocklyȤäơJavascriptΥɤԽǤޤ

ɲä֥å

ToolboxMathƥˡrandomץ֥åɲäޤ

֥å

֥åǥ󤹤

֥åΥǥϡBlockly DemoˤBlockly Developer ToolsǹԤޤ

  1. Blockly Developer Tools򳫤
  2. Block Factoryץ֤򥯥å
  3. ޤΤ褦˥֥åȤ߹碌
  4. Save ""ץܥޤ Update ""ץܥ򥯥å
block_factoy_s3.png

¸ɤϡ֥饦Υ륹ȥ졼ˡ֥饤֥פȤ¸ޤ

֥å򥨥ݡȤ

  1. Block Exporterץ֤򥯥å
  2. ¦ǡݡȤ֥åΥåܥå򥪥ˤ
  3. Export Settings
    • Block Definition(s): ֥å
      • Format: Javascript
      • File Name()random_block.js
    • Generator Stub(s): Ѵ
      • Language: Javascript
      • File Name:()random.js
  4. Exportץܥ򥯥åơΥե˳Ǽ
    • ֥å /blocks/random_block.js
    • Ѵ /generators/javaScript/random.js
block_expoter_s.png

ݡȻʣΥ֥å򤷤ƤȡȤΥեˤޤȤ롣θΡѴɤɲáפ񤭤ƤޤΤա

Ȥ߹

ɤ

BlocklyΥɤ򡢼Τɤ餫ɤŸޤ

ǥץ¹Ԥ

Generating JavaScriptϡɤե/demos/generatorˤޤ

ǥץʣ

/demos/generatorեƱ/demosե˴ݤʣޤ

ǤȤơ/demos/testȤʣƤޤ

index.html򳫤ơưǧƤޤ礦

֥åȤ߹

Ѵɤɲä

random.jsԽơ֥åѴ륳ɤ򵭽Ҥޤ(5)

Blockly.JavaScript['random'] = function(block) {
  var value_min = Blockly.JavaScript.valueToCode(block, 'min', Blockly.JavaScript.ORDER_ATOMIC);
  var value_max = Blockly.JavaScript.valueToCode(block, 'max', Blockly.JavaScript.ORDER_ATOMIC);
  // TODO: Assemble JavaScript into code variable.
  var code = 'Math.floor( Math.random() * (' + value_max + ' - ' + value_min + ' + 1 )) + ' +  value_min;
  // TODO: Change ORDER_NONE to the correct strength.
  return [code, Blockly.JavaScript.ORDER_NONE];
};

index.html˥֥åɤ߹

/demos/test/index.html򳫤ơrandom_block.jsפȡrandom.jsפɤ߹ߤǤ褦ˤޤ(6ܤ7)

<title>Blockly Demo: Generating JavaScript</title>
<script src="../../blockly_compressed.js"></script>
<script src="../../blocks_compressed.js"></script>
<script src="../../javascript_compressed.js"></script>
<script src="../../msg/js/en.js"></script>
<script src="../../blocks/random_block.js"></script>
<script src="../../generators/javaScript/random.js"></script>

Toolbox˥֥åɲä

Tooboxϡ<xml id="toolbox" style="display: none"> - </xml>ǡindex.htmlƤޤ

ToolboxMathƥˡrandomץ֥åɲäޤ(5)

<category name="Math">
  <block type="math_number"></block>
  <block type="math_arithmetic"></block>
  <block type="math_single"></block>
  <block type="random"></block>
</category>

ưǧ

Խ/demos/test/index.html򳫤ȡMathƥrandom֥åɲäƤޤ

add_toolbox.png

󡢤Υ֥åȤäơץȤΩƤꡢǧꡢ¹ԤǤޤ

final.png

¾

֥åοѹ

֥åοѤˡ3Ĥ롣

/**
 * The richness of block colours, regardless of the hue.
 * Must be in the range of 0 (inclusive) to 1 (exclusive).
 */
Blockly.HSV_SATURATION = 0.45;
/**
 * The intensity of block colours, regardless of the hue.
 * Must be in the range of 0 (inclusive) to 1 (exclusive).
 */
Blockly.HSV_VALUE = 0.65;
this.setColour("#808080");

ͻ

ΥСϡpythonΥץ(build.py)ưɬפäϡGoogle Clusur template(GCT)JSΥץȤޡܥߥ˥ޥƤΤǤϤʤ

̤GCTȤɬפϤʤΤǡʬιߤΥġǥߥ˥ޥФȻפ

Ϣڡ


  ȥå   ʬ Хåå   ñ측 ǽ   إ   ǽRSS
Last-modified: 2018-03-30 () 21:46:48 (422d)