Commit 0f187fc3 authored by Neil Fraser's avatar Neil Fraser

Add starting blocks to JS generator/interpreter demos.

parent 0798e24e
......@@ -63,9 +63,60 @@
</category>
</xml>
<xml id="startBlocks" style="display: none">
<block type="controls_if" inline="false" x="20" y="20">
<mutation else="1"></mutation>
<value name="IF0">
<block type="logic_compare" inline="true">
<field name="OP">EQ</field>
<value name="A">
<block type="math_arithmetic" inline="true">
<field name="OP">MULTIPLY</field>
<value name="A">
<block type="math_number">
<field name="NUM">6</field>
</block>
</value>
<value name="B">
<block type="math_number">
<field name="NUM">7</field>
</block>
</value>
</block>
</value>
<value name="B">
<block type="math_number">
<field name="NUM">42</field>
</block>
</value>
</block>
</value>
<statement name="DO0">
<block type="text_print" inline="false">
<value name="TEXT">
<block type="text">
<field name="TEXT">Don't panic</field>
</block>
</value>
</block>
</statement>
<statement name="ELSE">
<block type="text_print" inline="false">
<value name="TEXT">
<block type="text">
<field name="TEXT">Panic</field>
</block>
</value>
</block>
</statement>
</block>
</xml>
<script>
Blockly.inject(document.getElementById('blocklyDiv'),
{toolbox: document.getElementById('toolbox')});
Blockly.Xml.domToWorkspace(Blockly.mainWorkspace,
document.getElementById('startBlocks'));
function showCode() {
// Generate JavaScript code and display it.
......
......@@ -71,9 +71,60 @@
<category name="Functions" custom="PROCEDURE"></category>
</xml>
<xml id="startBlocks" style="display: none">
<block type="variables_set" inline="true" x="20" y="20">
<field name="VAR">n</field>
<value name="VALUE">
<block type="math_number">
<field name="NUM">1</field>
</block>
</value>
<next>
<block type="controls_repeat_ext" inline="true">
<value name="TIMES">
<block type="math_number">
<field name="NUM">4</field>
</block>
</value>
<statement name="DO">
<block type="variables_set" inline="true">
<field name="VAR">n</field>
<value name="VALUE">
<block type="math_arithmetic" inline="true">
<field name="OP">MULTIPLY</field>
<value name="A">
<block type="variables_get">
<field name="VAR">n</field>
</block>
</value>
<value name="B">
<block type="math_number">
<field name="NUM">2</field>
</block>
</value>
</block>
</value>
</block>
</statement>
<next>
<block type="text_print" inline="false">
<value name="TEXT">
<block type="variables_get">
<field name="VAR">n</field>
</block>
</value>
</block>
</next>
</block>
</next>
</block>
</xml>
<script>
Blockly.inject(document.getElementById('blocklyDiv'),
{toolbox: document.getElementById('toolbox')});
Blockly.Xml.domToWorkspace(Blockly.mainWorkspace,
document.getElementById('startBlocks'));
var myInterpreter = null;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment