初始化提交
This commit is contained in:
1
boards/default_src/python_skulpt/.eslintignore
Normal file
1
boards/default_src/python_skulpt/.eslintignore
Normal file
@@ -0,0 +1 @@
|
||||
others/skulpt
|
||||
3
boards/default_src/python_skulpt/.npmignore
Normal file
3
boards/default_src/python_skulpt/.npmignore
Normal file
@@ -0,0 +1,3 @@
|
||||
node_modules
|
||||
build
|
||||
origin
|
||||
1127
boards/default_src/python_skulpt/blocks/data.js
Normal file
1127
boards/default_src/python_skulpt/blocks/data.js
Normal file
File diff suppressed because it is too large
Load Diff
202
boards/default_src/python_skulpt/blocks/inout.js
Normal file
202
boards/default_src/python_skulpt/blocks/inout.js
Normal file
@@ -0,0 +1,202 @@
|
||||
import * as Blockly from 'blockly/core';
|
||||
|
||||
const INOUT_HUE = 20;
|
||||
|
||||
export const inout_input = {
|
||||
init: function () {
|
||||
this.setColour(INOUT_HUE);
|
||||
this.appendValueInput("VAR")
|
||||
.appendField(Blockly.Msg.blockpy_inout_raw_input)
|
||||
.setCheck(String);
|
||||
this.setOutput(true);
|
||||
this.setTooltip(Blockly.Msg.INOUT_input_TOOLTIP);
|
||||
}
|
||||
}
|
||||
|
||||
export const inout_print = {
|
||||
init: function () {
|
||||
this.setColour(INOUT_HUE);
|
||||
this.appendValueInput("VAR")
|
||||
.appendField(Blockly.Msg.MIXLY_SERIAL_PRINTLN);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setTooltip(Blockly.Msg.BLOCKPY_PRINT_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const inout_print_inline = {
|
||||
init: function () {
|
||||
this.setColour(INOUT_HUE);
|
||||
this.appendValueInput("VAR")
|
||||
.appendField(Blockly.Msg.MIXLY_SERIAL_PRINT);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setTooltip(Blockly.Msg.TEXT_PRINT_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const inout_print_end = {
|
||||
init: function () {
|
||||
this.setColour(INOUT_HUE);
|
||||
this.appendValueInput("VAR")
|
||||
.appendField(Blockly.Msg.MIXLY_SERIAL_PRINT);
|
||||
this.appendValueInput("END")
|
||||
.appendField(Blockly.Msg.MIXLY_ENDSWITH);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setInputsInline(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_PYTHON_INOUT_PRINT_END_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const inout_type_input = {
|
||||
init: function () {
|
||||
|
||||
var input_type =
|
||||
[[Blockly.Msg.LANG_MATH_STRING, 'str'], [Blockly.Msg.LANG_MATH_INT, 'int']
|
||||
, [Blockly.Msg.LANG_MATH_FLOAT, 'float']];
|
||||
this.setColour(INOUT_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.MIXLY_MICROBIT_PY_STORAGE_GET)
|
||||
.appendField(new Blockly.FieldDropdown(input_type), 'DIR')
|
||||
this.appendValueInput("VAR")
|
||||
.appendField(Blockly.Msg.PROCEDURES_MUTATORCONTAINER_TITLE)
|
||||
.setCheck(String);
|
||||
|
||||
this.setInputsInline(true);
|
||||
this.setOutput(true);
|
||||
var thisBlock = this;
|
||||
this.setTooltip(function () {
|
||||
var mode = thisBlock.getFieldValue('DIR');
|
||||
var TOOLTIPS = {
|
||||
'str': Blockly.Msg.MIXLY_MIXPY_INOUT_STR_INPUT_TOOLTIP,
|
||||
'int': Blockly.Msg.MIXLY_MIXPY_INOUT_INT_INPUT_TOOLTIP,
|
||||
'float': Blockly.Msg.MIXLY_MIXPY_INOUT_FLOAT_INPUT_TOOLTIP
|
||||
};
|
||||
return TOOLTIPS[mode];
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const inout_print_many = {
|
||||
|
||||
init: function () {
|
||||
this.setColour(INOUT_HUE);
|
||||
|
||||
this.itemCount_ = 2;
|
||||
this.updateShape_();
|
||||
this.setPreviousStatement(false);
|
||||
this.setNextStatement(false);
|
||||
this.setInputsInline(true);
|
||||
this.setMutator(new Blockly.icons.MutatorIcon(['inout_print_item'], this));
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_MIXPY_INOUT_PRINT_MANY_TOOLTIP);
|
||||
},
|
||||
|
||||
mutationToDom: function () {
|
||||
var container = document.createElement('mutation');
|
||||
container.setAttribute('items', this.itemCount_);
|
||||
return container;
|
||||
},
|
||||
|
||||
domToMutation: function (xmlElement) {
|
||||
this.itemCount_ = parseInt(xmlElement.getAttribute('items'), 10);
|
||||
this.updateShape_();
|
||||
},
|
||||
|
||||
decompose: function (workspace) {
|
||||
var containerBlock =
|
||||
workspace.newBlock('inout_print_container');
|
||||
containerBlock.initSvg();
|
||||
var connection = containerBlock.getInput('STACK').connection;
|
||||
for (var i = 0; i < this.itemCount_; i++) {
|
||||
var itemBlock = workspace.newBlock('inout_print_item');
|
||||
itemBlock.initSvg();
|
||||
connection.connect(itemBlock.previousConnection);
|
||||
connection = itemBlock.nextConnection;
|
||||
}
|
||||
return containerBlock;
|
||||
},
|
||||
|
||||
compose: function (containerBlock) {
|
||||
var itemBlock = containerBlock.getInputTargetBlock('STACK');
|
||||
// Count number of inputs.
|
||||
var connections = [];
|
||||
var i = 0;
|
||||
while (itemBlock) {
|
||||
connections[i] = itemBlock.valueConnection_;
|
||||
itemBlock = itemBlock.nextConnection &&
|
||||
itemBlock.nextConnection.targetBlock();
|
||||
i++;
|
||||
}
|
||||
this.itemCount_ = i;
|
||||
this.updateShape_();
|
||||
// Reconnect any child blocks.
|
||||
for (var i = 0; i < this.itemCount_; i++) {
|
||||
if (connections[i]) {
|
||||
this.getInput('ADD' + i)
|
||||
.connection.connect(connections[i]);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
saveConnections: function (containerBlock) {
|
||||
var itemBlock = containerBlock.getInputTargetBlock('STACK');
|
||||
var i = 0;
|
||||
while (itemBlock) {
|
||||
var input = this.getInput('ADD' + i);
|
||||
itemBlock.valueConnection_ = input && input.connection.targetConnection;
|
||||
i++;
|
||||
itemBlock = itemBlock.nextConnection &&
|
||||
itemBlock.nextConnection.targetBlock();
|
||||
}
|
||||
},
|
||||
|
||||
updateShape_: function () {
|
||||
// Delete everything.
|
||||
if (this.getInput('EMPTY')) {
|
||||
this.removeInput('EMPTY');
|
||||
} else {
|
||||
var i = 0;
|
||||
while (this.getInput('ADD' + i)) {
|
||||
this.removeInput('ADD' + i);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
// Rebuild block.
|
||||
if (this.itemCount_ == 0) {
|
||||
this.appendDummyInput('EMPTY')
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_INOUT_PRINT_EMPTY);
|
||||
} else {
|
||||
for (var i = 0; i < this.itemCount_; i++) {
|
||||
var input = this.appendValueInput('ADD' + i);
|
||||
if (i == 0) {
|
||||
input.appendField(Blockly.Msg.MIXLY_SERIAL_PRINTLN);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
export const inout_print_container = {
|
||||
init: function () {
|
||||
this.setColour(INOUT_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_SERIAL_PRINTLN);
|
||||
this.appendStatementInput('STACK');
|
||||
this.setTooltip(Blockly.Msg.MIXLY_MIXPY_INOUT_PRINT_MANY_CONTAINER_TOOLTIP);
|
||||
this.contextMenu = false;
|
||||
}
|
||||
};
|
||||
|
||||
export const inout_print_item = {
|
||||
init: function () {
|
||||
this.setColour(INOUT_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.LISTS_CREATE_WITH_ITEM_TITLE);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_MIXPY_INOUT_PRINT_MANY_ITEM_TOOLTIP);
|
||||
this.contextMenu = false;
|
||||
}
|
||||
};
|
||||
270
boards/default_src/python_skulpt/blocks/iot.js
Normal file
270
boards/default_src/python_skulpt/blocks/iot.js
Normal file
@@ -0,0 +1,270 @@
|
||||
import * as Blockly from 'blockly/core';
|
||||
import * as Mixly from 'mixly';
|
||||
|
||||
const IOT_HUE = '#526FC3';
|
||||
//'#2FAD7A';
|
||||
|
||||
export const iot_mixio_connect = {
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_CREATE_MQTT_CLIENT_AND_CONNECT);
|
||||
this.appendValueInput('SERVER')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.MIXLY_EMQX_SERVER)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
this.appendValueInput('USERNAME')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.MIXLY_WIFI_USERNAME)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
this.appendValueInput('PASSWORD')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.MIXLY_IOT_PASSWORD)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
this.appendValueInput('PROJECT')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.MIXLY_EMQX_PROJECT)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const IOT_MIXIO_PUBLISH = {
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField("MixIO")
|
||||
this.appendValueInput('TOPIC')
|
||||
.appendField(Blockly.Msg.MIXLY_EMQX_PUBLISH_NEW)
|
||||
.appendField(Blockly.Msg.MIXLY_EMQX_PUBLISH_TOPIC);
|
||||
this.appendValueInput('MSG')
|
||||
.appendField(Blockly.Msg.HTML_BODY);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_ESP32_IOT_EMQX_PUBLISH_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const IOT_MIXIO_SUBSCRIBE = {
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField("MixIO")
|
||||
this.appendValueInput('TOPIC')
|
||||
.appendField(Blockly.Msg.MIXLY_EMQX_SUBSCRIBE + Blockly.Msg.MIXLY_MICROBIT_MSG)
|
||||
.appendField(Blockly.Msg.MIXLY_EMQX_PUBLISH_TOPIC);
|
||||
this.appendValueInput('METHOD')
|
||||
.appendField(Blockly.Msg.MIXLY_EMQX_SET_METHOD);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_ESP32_IOT_EMQX_SUBSCRIBE_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const IOT_MIXIO_UNSUBSCRIBE = {
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField("MixIO")
|
||||
this.appendValueInput('TOPIC')
|
||||
.appendField(Blockly.Msg.MSG.stop + Blockly.Msg.MIXLY_EMQX_SUBSCRIBE)
|
||||
.appendField(Blockly.Msg.MIXLY_EMQX_PUBLISH_TOPIC);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_ESP32_IOT_EMQX_SUBSCRIBE_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const iot_mixio_disconnect = {
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField("MixIO")
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_ESP32_DISCONNECT_ONENET);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
// this.setTooltip(Blockly.Msg.MIXLY_ESP32_IOT_ONENET_DISCONNECT_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const iot_mixio_connect_only = {
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField("MixIO")
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_EMQX_CONNECT);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
// this.setTooltip(Blockly.Msg.MIXLY_ESP32_IOT_ONENET_DISCONNECT_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const iot_mixio_check = {
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField("MixIO")
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_ESP32_CHECK_ONENET);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
// this.setTooltip(Blockly.Msg.MIXLY_ESP32_IOT_ONENET_CHECK_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const iot_mixio_format_topic = {
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MICROPYTHON_FORMAT)
|
||||
.appendField(Blockly.MQTT_Topic);
|
||||
this.setInputsInline(true);
|
||||
this.setOutput(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const iot_mixio_format_msg = {
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MICROPYTHON_FORMAT)
|
||||
.appendField(Blockly.Msg.MIXLY_EMQX_PUBLISH_MSG);
|
||||
this.setInputsInline(true);
|
||||
this.setOutput(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const IOT_FORMATTING = {
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendValueInput('VAR')
|
||||
.appendField(Blockly.Msg.MIXLY_ESP32_IOT_MAP_FORMATING);
|
||||
this.setOutput(true);
|
||||
// this.setTooltip();
|
||||
}
|
||||
};
|
||||
|
||||
export const IOT_FORMAT_STRING = {
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendValueInput('VAR')
|
||||
.appendField(Blockly.Msg.MIXLY_MICROPYTHON_FORMAT + '(Json)');
|
||||
this.setOutput(true);
|
||||
// this.setTooltip();
|
||||
}
|
||||
};
|
||||
|
||||
export const IOT_EMQX_PING = {
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
// this.appendValueInput('VAR')
|
||||
// .setCheck("var")
|
||||
this.appendDummyInput()
|
||||
.appendField("MixIO")
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_EMQX_PING);
|
||||
this.setInputsInline(true);
|
||||
this.setOutput(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_ESP32_IOT_EMQX_PING_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const IOT_MIXIO_NTP = {
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
// this.appendValueInput('VAR')
|
||||
// .setCheck("var")
|
||||
this.appendDummyInput()
|
||||
.appendField("MixIO")
|
||||
.appendField(Blockly.Msg.MIXLY_GET_NTP)
|
||||
this.appendValueInput('addr')
|
||||
.appendField(Blockly.blynk_SERVER_ADD);
|
||||
this.setInputsInline(true);
|
||||
this.setOutput(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const IOT_EMQX_INIT_AND_CONNECT_BY_SHARE_CODE = {
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_CREATE_MQTT_CLIENT_AND_CONNECT);
|
||||
this.appendValueInput('SERVER')
|
||||
.appendField(Blockly.Msg.MIXLY_EMQX_SERVER)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT);
|
||||
this.appendValueInput('KEY')
|
||||
.appendField(Blockly.Msg.CONTROLS_FOR_INPUT_WITH + Blockly.Msg.MIXLY_MIXIO_SHARE_KEY)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const IOT_EMQX_INIT_AND_CONNECT_BY_MIXLY_CODE = {
|
||||
init: function () {
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_CREATE_MQTT_CLIENT_AND_CONNECT);
|
||||
this.appendValueInput('SERVER')
|
||||
.appendField(Blockly.Msg.MIXLY_EMQX_SERVER)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT);
|
||||
this.appendValueInput('KEY')
|
||||
.appendField(Blockly.Msg.CONTROLS_FOR_INPUT_WITH + "Mixly Key")
|
||||
.setAlign(Blockly.inputs.Align.RIGHT);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const iot_mixly_key = {
|
||||
init: function () {
|
||||
this.VISITOR_ID = Mixly.Config.BOARD.visitorId.str32.substring(0, 8).toUpperCase();
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(new Blockly.FieldTextInput(this.visitorId), 'VISITOR_ID');
|
||||
this.setOutput(true, null);
|
||||
},
|
||||
onchange: function () {
|
||||
const nowVisitorId = this.getFieldValue('VISITOR_ID');
|
||||
if (this.VISITOR_ID !== nowVisitorId)
|
||||
this.setFieldValue(this.VISITOR_ID, 'VISITOR_ID');
|
||||
}
|
||||
};
|
||||
|
||||
export const iot_mixly_key_py = {
|
||||
init: function () {
|
||||
this.VISITOR_ID = Mixly.Config.BOARD.visitorId.str32.substring(0, 8).toUpperCase();
|
||||
this.setColour(IOT_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(this.newQuote_(true))
|
||||
.appendField(new Blockly.FieldTextInput(this.visitorId), 'VISITOR_ID')
|
||||
.appendField(this.newQuote_(false));
|
||||
this.setOutput(true, null);
|
||||
},
|
||||
onchange: function () {
|
||||
const nowVisitorId = this.getFieldValue('VISITOR_ID');
|
||||
if (this.VISITOR_ID !== nowVisitorId)
|
||||
this.setFieldValue(this.VISITOR_ID, 'VISITOR_ID');
|
||||
},
|
||||
newQuote_: function (open) {
|
||||
if (open == this.RTL) {
|
||||
var file = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAKCAQAAAAqJXdxAAAAqUlEQVQI1z3KvUpCcRiA8ef9E4JNHhI0aFEacm1o0BsI0Slx8wa8gLauoDnoBhq7DcfWhggONDmJJgqCPA7neJ7p934EOOKOnM8Q7PDElo/4x4lFb2DmuUjcUzS3URnGib9qaPNbuXvBO3sGPHJDRG6fGVdMSeWDP2q99FQdFrz26Gu5Tq7dFMzUvbXy8KXeAj57cOklgA+u1B5AoslLtGIHQMaCVnwDnADZIFIrXsoXrgAAAABJRU5ErkJggg==';
|
||||
} else {
|
||||
var file = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAKCAQAAAAqJXdxAAAAn0lEQVQI1z3OMa5BURSF4f/cQhAKjUQhuQmFNwGJEUi0RKN5rU7FHKhpjEH3TEMtkdBSCY1EIv8r7nFX9e29V7EBAOvu7RPjwmWGH/VuF8CyN9/OAdvqIXYLvtRaNjx9mMTDyo+NjAN1HNcl9ZQ5oQMM3dgDUqDo1l8DzvwmtZN7mnD+PkmLa+4mhrxVA9fRowBWmVBhFy5gYEjKMfz9AylsaRRgGzvZAAAAAElFTkSuQmCC';
|
||||
}
|
||||
return new Blockly.FieldImage(file, 12, 12, '"');
|
||||
}
|
||||
};
|
||||
126
boards/default_src/python_skulpt/blocks/system.js
Normal file
126
boards/default_src/python_skulpt/blocks/system.js
Normal file
@@ -0,0 +1,126 @@
|
||||
import * as Blockly from 'blockly/core';
|
||||
|
||||
const SYSTEM_HUE = 120;
|
||||
|
||||
export const base_delay = {
|
||||
init: function () {
|
||||
this.setColour(SYSTEM_HUE);
|
||||
this.appendValueInput("DELAY_TIME", Number)
|
||||
.appendField(Blockly.Msg.MIXLY_DELAY + '(' + Blockly.Msg.MIXLY_MILLIS + ')')
|
||||
.setCheck(Number);
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setInputsInline(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_CONTROL_DELAY);
|
||||
}
|
||||
};
|
||||
|
||||
export const controls_millis = {
|
||||
init: function () {
|
||||
this.setColour(SYSTEM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.blockpy_time_time);
|
||||
this.setOutput(true, Number);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_CONTROL_MILLIS);
|
||||
}
|
||||
};
|
||||
|
||||
export const time_localtime = {
|
||||
init: function () {
|
||||
this.setColour(SYSTEM_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.MIXLY_SYSTEM_TIME_LOCALTIME)
|
||||
this.appendDummyInput()
|
||||
.appendField(new Blockly.FieldDropdown([
|
||||
[Blockly.Msg.MIXLY_SYSTEM_TIME_LOCALTIME_ALL, "all"],
|
||||
[Blockly.Msg.MIXLY_SYSTEM_TIME_LOCALTIME_YEAR, "0"],
|
||||
[Blockly.Msg.MIXLY_SYSTEM_TIME_LOCALTIME_MONTH, "1"],
|
||||
[Blockly.Msg.MIXLY_SYSTEM_TIME_LOCALTIME_DATE, "2"],
|
||||
[Blockly.Msg.MIXLY_SYSTEM_TIME_LOCALTIME_HOUR, "3"],
|
||||
[Blockly.Msg.MIXLY_SYSTEM_TIME_LOCALTIME_MINUTE, "4"],
|
||||
[Blockly.Msg.MIXLY_SYSTEM_TIME_LOCALTIME_SECOND, "5"],
|
||||
[Blockly.Msg.MIXLY_SYSTEM_TIME_LOCALTIME_INWEEK, "6"],
|
||||
[Blockly.Msg.MIXLY_SYSTEM_TIME_LOCALTIME_INYEAR, "7"],
|
||||
[Blockly.Msg.MIXLY_SYSTEM_TIME_LOCALTIME_DST, "8"]
|
||||
]), "op");
|
||||
this.setOutput(true);
|
||||
this.setInputsInline(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const Panic_with_status_code = {
|
||||
init: function () {
|
||||
this.setColour(SYSTEM_HUE);
|
||||
this.appendValueInput("STATUS_CODE", Number)
|
||||
.appendField(Blockly.Msg.MIXLY_MICROBIT_Panic_with_status_code)
|
||||
.setCheck(Number);
|
||||
this.setPreviousStatement(true, null);
|
||||
// this.setNextStatement(true, null);
|
||||
this.setInputsInline(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_CONTROL_DELAY);
|
||||
}
|
||||
};
|
||||
|
||||
export const reset = {
|
||||
init: function () {
|
||||
this.setColour(SYSTEM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MICROBIT_Reset_micro);
|
||||
this.setPreviousStatement(true);
|
||||
// this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const controls_mstimer2 = {
|
||||
init: function () {
|
||||
this.setColour(SYSTEM_HUE);
|
||||
this.appendValueInput('TIME')
|
||||
.setCheck(Number)
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField('MsTimer2')
|
||||
.appendField(Blockly.Msg.MIXLY_MSTIMER2_EVERY);
|
||||
this.appendDummyInput()
|
||||
.appendField('ms');
|
||||
this.appendStatementInput('DO')
|
||||
.appendField(Blockly.Msg.MIXLY_MSTIMER2_DO);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const controls_mstimer2_start = {
|
||||
init: function () {
|
||||
this.setColour(SYSTEM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField('MsTimer2')
|
||||
.appendField(Blockly.Msg.MIXLY_MSTIMER2_START);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const controls_mstimer2_stop = {
|
||||
init: function () {
|
||||
this.setColour(SYSTEM_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField('MsTimer2')
|
||||
.appendField(Blockly.Msg.MIXLY_STOP);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const time_sleep = {
|
||||
init: function () {
|
||||
this.setColour(SYSTEM_HUE);
|
||||
this.appendValueInput("DELAY_TIME", Number)
|
||||
.appendField(Blockly.Msg.MIXLY_DELAY)
|
||||
.setCheck(Number);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_SECOND)
|
||||
this.setPreviousStatement(true, null);
|
||||
this.setNextStatement(true, null);
|
||||
this.setInputsInline(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_CONTROL_DELAY);
|
||||
}
|
||||
};
|
||||
877
boards/default_src/python_skulpt/blocks/turtle.js
Normal file
877
boards/default_src/python_skulpt/blocks/turtle.js
Normal file
@@ -0,0 +1,877 @@
|
||||
import * as Blockly from 'blockly/core';
|
||||
|
||||
const TURTLE_HUE = 180;
|
||||
|
||||
export const turtle_create = {
|
||||
init: function () {
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendDummyInput("")
|
||||
|
||||
.appendField(Blockly.Msg.blockpy_turtle_create)
|
||||
.appendField(new Blockly.FieldTextInput('tina'), 'VAR')
|
||||
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip(Blockly.Msg.blockpy_turtle_create_TOOLTIP);
|
||||
},
|
||||
getVars: function () {
|
||||
return [this.getFieldValue('VAR')];
|
||||
},
|
||||
renameVar: function (oldName, newName) {
|
||||
if (Blockly.Names.equals(oldName, this.getFieldValue('VAR'))) {
|
||||
this.setTitleValue(newName, 'VAR');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const turtle_done = {
|
||||
init: function () {
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.blockpy_TURTLE_DONE);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_exitonclick = {
|
||||
init: function () {
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_PYTHON_TURTLE_EXITONCLICK);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_move = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
var front_back =
|
||||
[[Blockly.Msg.blockpy_forward, 'forward'], [Blockly.Msg.blockpy_backward, 'backward']];
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('VAR')
|
||||
// .setCheck(String)
|
||||
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_MOVE_BY)
|
||||
.appendField(new Blockly.FieldDropdown(front_back), 'DIR')
|
||||
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_MOVE_BY_num);
|
||||
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
var thisBlock = this;
|
||||
this.setTooltip(function () {
|
||||
var mode = thisBlock.getFieldValue('DIR');
|
||||
var TOOLTIPS = {
|
||||
'forward': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_FORWARD,
|
||||
'backward': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_BACKWARD
|
||||
};
|
||||
return TOOLTIPS[mode];
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_rotate = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
var front_back =
|
||||
[[Blockly.Msg.blockpy_left, 'left'], [Blockly.Msg.blockpy_right, 'right']];
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('VAR')
|
||||
// .setCheck(String)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_rotate)
|
||||
.appendField(new Blockly.FieldDropdown(front_back), 'DIR')
|
||||
.appendField(Blockly.Msg.MIXLY_MICROBIT_JS_BY_ANGLE);
|
||||
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
var thisBlock = this;
|
||||
this.setTooltip(function () {
|
||||
var mode = thisBlock.getFieldValue('DIR');
|
||||
var TOOLTIPS = {
|
||||
'left': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_LEFT,
|
||||
'right': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_RIGHT
|
||||
};
|
||||
return TOOLTIPS[mode];
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_setheading = {
|
||||
init: function () {
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.appendValueInput('data')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.blockpy_setheading);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.blockpy_setheading_degree);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_screen_delay = {
|
||||
init: function () {
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.appendValueInput('data')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.MIXLY_TURTLE_SCREEN_DELAY);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_MILLIS);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_TURTEL_SCREEN_DELAY);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_goto = {
|
||||
init: function () {
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.appendValueInput('data')
|
||||
.setCheck(Number)
|
||||
|
||||
.appendField(Blockly.Msg.blockpy_turtle_goto);
|
||||
this.appendValueInput('val')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_goto_y);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.blockpy_turtle_goto_position);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_setxy = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
var set_xy =
|
||||
[[Blockly.Msg.PYLAB_LABEL_X, 'x'], [Blockly.Msg.PYLAB_LABEL_Y, 'y']];
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('VAR')
|
||||
.appendField(new Blockly.FieldDropdown(set_xy), 'DIR')
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_TURTLE_SETXY);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_MIXPY_TURTLE_SETXY_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_pos_shape = {
|
||||
|
||||
init: function () {
|
||||
this.setColour(TURTLE_HUE);
|
||||
var pos_shape =
|
||||
[[Blockly.Msg.TURTLE_POS, 'pos'], [Blockly.Msg.TURTLE_SHAPE, 'shape'], [Blockly.Msg.TURTLE_HEADING, 'heading'], [Blockly.Msg.MIXLY_MIXPY_TURTLE_WIDTH, 'width'], [Blockly.Msg.MIXLY_TURTEL_GET_SHAPESIZE, 'shapesize'], [Blockly.Msg.MIXLY_SPEED, 'speed']];
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.TURTLE_POS_SHAPE)
|
||||
.appendField(new Blockly.FieldDropdown(pos_shape), 'DIR')
|
||||
var thisBlock = this;
|
||||
this.setTooltip(function () {
|
||||
var mode = thisBlock.getFieldValue('DIR');
|
||||
var TOOLTIPS = {
|
||||
'pos': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_POS,
|
||||
'shape': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_SHAPE,
|
||||
'heading': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_HEADING,
|
||||
'width': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_WIDTH,
|
||||
'speed': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_GET_SPEED,
|
||||
'shapesize': Blockly.Msg.MIXLY_TURTEL_GET_SHAPESIZE_TOOLTIP
|
||||
};
|
||||
return TOOLTIPS[mode];
|
||||
});
|
||||
this.setOutput(true);
|
||||
this.setInputsInline(true);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const turtle_clear = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
var clear_reset =
|
||||
[[Blockly.Msg.MIXLY_LCD_STAT_CLEAR, 'clear'], [Blockly.Msg.blockpy_turtle_reset, 'reset']
|
||||
, [Blockly.Msg.blockpy_turtle_home, 'home']];
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(new Blockly.FieldDropdown(clear_reset), 'DIR')
|
||||
|
||||
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
var thisBlock = this;
|
||||
this.setTooltip(function () {
|
||||
var mode = thisBlock.getFieldValue('DIR');
|
||||
var TOOLTIPS = {
|
||||
'clear': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_CLEAR,
|
||||
'reset': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_RESET,
|
||||
'home': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_HOME
|
||||
};
|
||||
return TOOLTIPS[mode];
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_penup = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
var penup_down =
|
||||
[[Blockly.Msg.blockpy_turtle_penup, 'penup'], [Blockly.Msg.blockpy_turtle_pendown, 'pendown']];
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(new Blockly.FieldDropdown(penup_down), 'DIR')
|
||||
|
||||
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
var thisBlock = this;
|
||||
this.setTooltip(function () {
|
||||
var mode = thisBlock.getFieldValue('DIR');
|
||||
var TOOLTIPS = {
|
||||
'penup': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_PENUP,
|
||||
'pendown': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_PENDOWN
|
||||
};
|
||||
return TOOLTIPS[mode];
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_fill = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
var fill =
|
||||
[[Blockly.Msg.blockpy_turtle_beginfill, 'begin'], [Blockly.Msg.blockpy_turtle_endfill, 'end']];
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(new Blockly.FieldDropdown(fill), 'DIR')
|
||||
|
||||
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
var thisBlock = this;
|
||||
this.setTooltip(function () {
|
||||
var mode = thisBlock.getFieldValue('DIR');
|
||||
var TOOLTIPS = {
|
||||
'begin': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_BEGINFILL,
|
||||
'end': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_ENDFILL
|
||||
};
|
||||
return TOOLTIPS[mode];
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const turtle_size_speed = {
|
||||
init: function () {
|
||||
this.appendDummyInput("")
|
||||
.appendField(new Blockly.FieldTextInput('tina'), 'TUR')
|
||||
var size_speed =
|
||||
[[Blockly.Msg.blockpy_turtle_size, 'pensize'], [Blockly.Msg.MIXLY_SPEED, 'speed']];
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('VAR')
|
||||
// .setCheck(String)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_set)
|
||||
.appendField(new Blockly.FieldDropdown(size_speed), 'DIR')
|
||||
.appendField(Blockly.Msg.blockpy_turtle_set_num);
|
||||
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
var thisBlock = this;
|
||||
this.setTooltip(function () {
|
||||
var mode = thisBlock.getFieldValue('DIR');
|
||||
var TOOLTIPS = {
|
||||
'pensize': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_SIZE,
|
||||
'speed': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_SPEED
|
||||
};
|
||||
return TOOLTIPS[mode];
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_size = {
|
||||
init: function () {
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.appendValueInput('data')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_set_size);
|
||||
|
||||
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_TURTEL_SIZE);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const turtle_speed = {
|
||||
init: function () {
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.appendValueInput('data')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_set_speed);
|
||||
|
||||
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_TURTEL_SPEED);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_circle = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
var circle_dot =
|
||||
[[Blockly.Msg.blockpy_turtle_circle, 'circle'], [Blockly.Msg.blockpy_turtle_dot, 'dot']];
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('VAR')
|
||||
// .setCheck(String)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_draw)
|
||||
.appendField(new Blockly.FieldDropdown(circle_dot), 'DIR')
|
||||
.appendField(Blockly.Msg.blockpy_turtle_radius);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
var thisBlock = this;
|
||||
this.setTooltip(function () {
|
||||
var mode = thisBlock.getFieldValue('DIR');
|
||||
var TOOLTIPS = {
|
||||
'circle': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_CIRCLE,
|
||||
'dot': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_DOT
|
||||
};
|
||||
return TOOLTIPS[mode];
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_circle_advanced = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('VAR')
|
||||
// .setCheck(String)
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_TURTLE_DRAW_CIRCLE)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_radius);
|
||||
this.appendValueInput('data')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_angle);
|
||||
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_TURTEL_CIRCLE);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_visible = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
var visible =
|
||||
[[Blockly.Msg.blockpy_turtle_hide, 'hideturtle'], [Blockly.Msg.blockpy_turtle_show, 'showturtle']];
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(new Blockly.FieldDropdown(visible), 'DIR')
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
var thisBlock = this;
|
||||
this.setTooltip(function () {
|
||||
var mode = thisBlock.getFieldValue('DIR');
|
||||
var TOOLTIPS = {
|
||||
'hideturtle': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_HIDE,
|
||||
'showturtle': Blockly.Msg.MIXLY_TOOLTIP_TURTEL_SHOW
|
||||
};
|
||||
return TOOLTIPS[mode];
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const turtle_bgcolor = {
|
||||
init: function () {
|
||||
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.blockpy_turtle_bgcolor)
|
||||
.appendField(new Blockly.FieldColour('#ff0000'), 'FIELDNAME');
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_pencolor = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.blockpy_turtle_pencolor)
|
||||
.appendField(new Blockly.FieldColour('#ff0000'), 'FIELDNAME');
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_fillcolor = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.blockpy_turtle_fillcolor)
|
||||
.appendField(new Blockly.FieldColour('#ff0000'), 'FIELDNAME');
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_clone = {
|
||||
|
||||
init: function () {
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.TURTLE_CLONE);
|
||||
this.setTooltip(Blockly.Msg.TURTLE_CLONE_TOOLTIP);
|
||||
this.setOutput(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_bgcolor_hex_new = {
|
||||
init: function () {
|
||||
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('VAR')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_bgcolor);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_pencolor_hex_new = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('VAR')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_pencolor);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_fillcolor_hex_new = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('VAR')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_fillcolor);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_color = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.blockpy_turtle_pencolor)
|
||||
.appendField(new Blockly.FieldColour('#ff0000'), 'FIELDNAME');
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.blockpy_turtle_fillcolor)
|
||||
.appendField(new Blockly.FieldColour('#ff0000'), 'FIELDNAME2');
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_color_hex = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('VAR1')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_pencolor);
|
||||
this.appendValueInput('VAR2')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_fillcolor);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_bgcolor_hex = {
|
||||
init: function () {
|
||||
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('VAR')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_bgcolor_hex);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_pencolor_hex = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('VAR')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_pencolor_hex);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_fillcolor_hex = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('VAR')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_fillcolor_hex);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_shape = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
var shape = [
|
||||
[Blockly.Msg.blockpy_turtle_shape_arrow, 'arrow'], [Blockly.Msg.blockpy_turtle_shape_turtle, 'turtle'],
|
||||
[Blockly.Msg.blockpy_turtle_shape_circle, 'circle'], [Blockly.Msg.blockpy_turtle_shape_square, 'square'],
|
||||
[Blockly.Msg.blockpy_turtle_shape_triangle, 'triangle'], [Blockly.Msg.blockpy_turtle_shape_classic, 'classic']
|
||||
];
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.blockpy_turtle_shape)
|
||||
.appendField(new Blockly.FieldDropdown(shape), 'DIR');
|
||||
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip(Blockly.Msg.TURTLE_SHAPE_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_shapesize = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.MIXLY_TURTEL_SHAPESIZE);
|
||||
this.appendValueInput('WID')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.MIXLY_TURTEL_SHAPESIZE_WID);
|
||||
this.appendValueInput('LEN')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.MIXLY_TURTEL_SHAPESIZE_LEN);
|
||||
this.appendValueInput('OUTLINE')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.MIXLY_TURTEL_SHAPESIZE_OUTLINE);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_TOOLTIP_SHAPESIZE);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_numinput = {
|
||||
init: function () {
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_TURTLE_NUMINPUT)
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('TITLE')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_TURTLE_TEXTINPUT_TITLE);
|
||||
this.appendValueInput('PROMPT')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_TURTLE_TEXTINPUT_PROMPT);
|
||||
this.appendValueInput('DEFAULT')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.DICTS_DEFAULT_VALUE);
|
||||
this.appendValueInput('MIN')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.MATH_ONLIST_OPERATOR_MIN);
|
||||
this.appendValueInput('MAX')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.MATH_ONLIST_OPERATOR_MAX);
|
||||
this.setInputsInline(true);
|
||||
this.setOutput(true, Number);
|
||||
this.setTooltip(Blockly.Msg.TURTLE_NUMINPUT_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_textinput = {
|
||||
init: function () {
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_TURTLE_TEXTINPUT)
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('TITLE')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_TURTLE_TEXTINPUT_TITLE);
|
||||
this.appendValueInput('PROMPT')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.MIXLY_MIXPY_TURTLE_TEXTINPUT_PROMPT);
|
||||
this.setInputsInline(true);
|
||||
this.setOutput(true, String);
|
||||
this.setTooltip(Blockly.Msg.TURTLE_TEXTINPUT_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_write = {
|
||||
init: function () {
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('VAR')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_write);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip(Blockly.Msg.TURTLE_WRITE_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_write_format = {
|
||||
init: function () {
|
||||
var move =
|
||||
[[Blockly.Msg.MIXLY_TURTLE_WRITE_MOVE_FALSE, 'False'], [Blockly.Msg.MIXLY_TURTLE_WRITE_MOVE_TRUE, 'True']];
|
||||
var align =
|
||||
[[Blockly.Msg.MIXLY_TURTLE_WRITE_ALIGN_LEFT, 'left'], [Blockly.Msg.MIXLY_TURTLE_WRITE_ALIGN_CENTER, 'center'], [Blockly.Msg.MIXLY_TURTLE_WRITE_ALIGN_RIGHT, 'right']];
|
||||
var fonttype =
|
||||
[[Blockly.Msg.MIXLY_TURTLE_WRITE_FONT_TYPE_NORMAL, 'normal'], [Blockly.Msg.MIXLY_TURTLE_WRITE_FONT_TYPE_BOLD, 'bold'], [Blockly.Msg.MIXLY_TURTLE_WRITE_FONT_TYPE_ITALIC, 'italic'], [Blockly.Msg.MIXLY_TURTLE_WRITE_FONT_TYPE_BOLD_ITALIC, 'bold","italic']];
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('VAR')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_write);
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.MIXLY_TURTLE_WRITE_MOVE)
|
||||
.appendField(new Blockly.FieldDropdown(move), 'MOVE');
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.MIXLY_TURTLE_WRITE_ALIGN)
|
||||
.appendField(new Blockly.FieldDropdown(align), 'ALIGN');
|
||||
this.appendValueInput('FONTNAME')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.MIXLY_TURTLE_WRITE_FONT_NAME);
|
||||
this.appendValueInput('FONTNUM')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.MIXLY_TURTLE_WRITE_FONT_NUM);
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.MIXLY_TURTLE_WRITE_FONT_TYPE)
|
||||
.appendField(new Blockly.FieldDropdown(fonttype), 'FONTTYPE');
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip(Blockly.Msg.TURTLE_WRITE_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_write_format_skulpt = {
|
||||
init: function () {
|
||||
var move =
|
||||
[[Blockly.Msg.MIXLY_TURTLE_WRITE_MOVE_FALSE, 'False'], [Blockly.Msg.MIXLY_TURTLE_WRITE_MOVE_TRUE, 'True']];
|
||||
var align =
|
||||
[[Blockly.Msg.MIXLY_TURTLE_WRITE_ALIGN_LEFT, 'left'], [Blockly.Msg.MIXLY_TURTLE_WRITE_ALIGN_CENTER, 'center'], [Blockly.Msg.MIXLY_TURTLE_WRITE_ALIGN_RIGHT, 'right']];
|
||||
var fonttype =
|
||||
[[Blockly.Msg.MIXLY_TURTLE_WRITE_FONT_TYPE_NORMAL, 'normal'], [Blockly.Msg.MIXLY_TURTLE_WRITE_FONT_TYPE_BOLD, 'bold'], [Blockly.Msg.MIXLY_TURTLE_WRITE_FONT_TYPE_ITALIC, 'italic']];
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('VAR')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.blockpy_turtle_write);
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.MIXLY_TURTLE_WRITE_MOVE)
|
||||
.appendField(new Blockly.FieldDropdown(move), 'MOVE');
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.MIXLY_TURTLE_WRITE_ALIGN)
|
||||
.appendField(new Blockly.FieldDropdown(align), 'ALIGN');
|
||||
this.appendValueInput('FONTNAME')
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.MIXLY_TURTLE_WRITE_FONT_NAME);
|
||||
this.appendValueInput('FONTNUM')
|
||||
.setCheck(Number)
|
||||
.appendField(Blockly.Msg.MIXLY_TURTLE_WRITE_FONT_NUM);
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.MIXLY_TURTLE_WRITE_FONT_TYPE)
|
||||
.appendField(new Blockly.FieldDropdown(fonttype), 'FONTTYPE');
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip(Blockly.Msg.TURTLE_WRITE_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const turtle_color_seclet = {
|
||||
init: function () {
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendDummyInput("")
|
||||
.setAlign(Blockly.inputs.Align.RIGHT)
|
||||
.appendField(new Blockly.FieldColour("ff0000"), "COLOR");
|
||||
this.setInputsInline(true);
|
||||
this.setOutput(true, String);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_getscreen = {
|
||||
init: function () {
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('TUR')
|
||||
.setCheck('Turtle')
|
||||
this.appendDummyInput("")
|
||||
|
||||
.appendField(Blockly.Msg.MIXLY_TURTEL_GETSCREEN)
|
||||
.appendField(new Blockly.FieldTextInput('screen'), 'VAR')
|
||||
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_TURTEL_GETSCREEN_TOOLTIP);
|
||||
},
|
||||
getVars: function () {
|
||||
return [this.getFieldValue('VAR')];
|
||||
},
|
||||
renameVar: function (oldName, newName) {
|
||||
if (Blockly.Names.equals(oldName, this.getFieldValue('VAR'))) {
|
||||
this.setTitleValue(newName, 'VAR');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const turtle_onkey = {
|
||||
init: function () {
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('TUR')
|
||||
this.appendValueInput('VAR')
|
||||
.appendField(Blockly.Msg.MIXLY_TURTEL_EVENT_ONKEY);
|
||||
this.appendValueInput('callback')
|
||||
.appendField(Blockly.Msg.MIXLY_PYTHON_CONTROLS_THREAD_USE)
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setInputsInline(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_TURTEL_EVENT_ONKEY_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_onclick = {
|
||||
init: function () {
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('TUR')
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.MIXLY_TURTEL_EVENT_ONCLICK);
|
||||
this.appendValueInput('callback')
|
||||
.appendField(Blockly.Msg.MIXLY_PYTHON_CONTROLS_THREAD_USE)
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setInputsInline(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_TURTEL_EVENT_ONCLICK_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_ontimer = {
|
||||
init: function () {
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('TUR')
|
||||
this.appendValueInput('VAR')
|
||||
.appendField(Blockly.Msg.MIXLY_TURTEL_EVENT_ONTIMER);
|
||||
this.appendDummyInput("")
|
||||
.appendField(Blockly.Msg.MIXLY_mSecond);
|
||||
this.appendValueInput('callback')
|
||||
.appendField(Blockly.Msg.MIXLY_PYTHON_CONTROLS_THREAD_USE)
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setInputsInline(true);
|
||||
this.setTooltip(Blockly.Msg.MIXLY_TURTEL_EVENT_ONTIMER_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_listen = {
|
||||
init: function () {
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('TUR')
|
||||
this.appendDummyInput()
|
||||
.appendField(Blockly.Msg.MIXLY_TURTEL_SCREEN_LISTEN);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
}
|
||||
};
|
||||
|
||||
export const turtle_screen_savefig = {
|
||||
init: function () {
|
||||
this.setColour(TURTLE_HUE);
|
||||
this.appendValueInput('TUR')
|
||||
this.appendValueInput("FILE")
|
||||
.setCheck(String)
|
||||
.appendField(Blockly.Msg.mixpy_PL_SAVEFIG);
|
||||
this.setInputsInline(true);
|
||||
this.setPreviousStatement(true);
|
||||
this.setNextStatement(true);
|
||||
this.setOutput(false);
|
||||
this.setTooltip(Blockly.Msg.mixpy_TURTLE_SAVEFIG_TOOLTIP);
|
||||
}
|
||||
};
|
||||
|
||||
1512
boards/default_src/python_skulpt/converters/data.js
Normal file
1512
boards/default_src/python_skulpt/converters/data.js
Normal file
File diff suppressed because it is too large
Load Diff
74
boards/default_src/python_skulpt/converters/inout.js
Normal file
74
boards/default_src/python_skulpt/converters/inout.js
Normal file
@@ -0,0 +1,74 @@
|
||||
'use strict';
|
||||
|
||||
pbc.globalFunctionD['input'] = function(py2block, func, args, keywords, starargs, kwargs, node){
|
||||
if (args.length !== 1 && args.length !== 0) {
|
||||
throw new Error("Incorrect number of arguments");
|
||||
}
|
||||
if (args.length == 1){
|
||||
var argblock = py2block.convert(args[0]);
|
||||
return block("inout_type_input", func.lineno, {
|
||||
"DIR":"str"
|
||||
}, {
|
||||
'VAR':argblock
|
||||
}, {
|
||||
"inline": "true"
|
||||
});}
|
||||
if (args.length == 0){
|
||||
|
||||
return block("inout_type_input", func.lineno, {
|
||||
"DIR":"str"
|
||||
}, {
|
||||
//'VAR':argblock
|
||||
}, {
|
||||
"inline": "true"
|
||||
});}
|
||||
}
|
||||
|
||||
|
||||
//int(input('prompt'))在math.js中实现
|
||||
//float(input('prompt'))在lists.js中实现
|
||||
|
||||
pbc.globalFunctionD['print'] = function(py2block, func, args, keywords, starargs, kwargs, node){
|
||||
if (args.length === 1 && keywords.length === 1
|
||||
&& py2block.identifier(keywords[0].arg) === "end"
|
||||
&& keywords[0].value._astname === "Str"
|
||||
//&& py2block.Str_value(keywords[0].value) === ""
|
||||
) { if(py2block.Str_value(keywords[0].value) === ""){//print('Hello',end ="")
|
||||
var argblock = py2block.convert(args[0]);
|
||||
return [block("inout_print_inline", func.lineno, {}, {
|
||||
'VAR':argblock
|
||||
}, {
|
||||
"inline": "false"
|
||||
})];
|
||||
}
|
||||
else{
|
||||
var argblock = py2block.convert(args[0]);
|
||||
return [block("inout_print_end", func.lineno, {
|
||||
}, {
|
||||
'VAR':argblock,
|
||||
'END':py2block.convert(keywords[0].value)
|
||||
}, {
|
||||
"inline": "true"
|
||||
})];
|
||||
}
|
||||
}else if (args.length === 1 && keywords.length === 0) { //print('Hello')
|
||||
var argblock = py2block.convert(args[0]);
|
||||
return [block("inout_print", func.lineno, {}, {
|
||||
'VAR':argblock
|
||||
}, {
|
||||
"inline": "false"
|
||||
})];
|
||||
}else if (args.length != 1 && keywords.length === 0) { //print()
|
||||
var d = py2block.convertElements("ADD", args);
|
||||
|
||||
return [block("inout_print_many", node.lineno, {
|
||||
}, d, {
|
||||
"inline": "true",
|
||||
}, {
|
||||
"@items":args.length
|
||||
})];
|
||||
|
||||
}else{
|
||||
throw new Error("Incorrect number of arguments");
|
||||
}
|
||||
}
|
||||
162
boards/default_src/python_skulpt/converters/iot.js
Normal file
162
boards/default_src/python_skulpt/converters/iot.js
Normal file
@@ -0,0 +1,162 @@
|
||||
'use strict';
|
||||
|
||||
var mqtt_client = 'mixiot.MixIO';
|
||||
pbc.assignD.get('MixIO_init_by_mixly_key')['check_assign'] = function(py2block, node, targets, value) {
|
||||
if(value._astname != "Call" || value.func._astname != "Attribute" || value.func.value._astname != "Name"){
|
||||
return false;
|
||||
}
|
||||
var funcName = py2block.identifier(value.func.attr);
|
||||
var moduleName = py2block.identifier(value.func.value.id);
|
||||
if(moduleName === "mixiot" && funcName === "MixIO_init_by_mixly_key" && value.args.length === 4)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
pbc.assignD.get('MixIO_init_by_mixly_key')['create_block'] = function(py2block, node, targets, value){
|
||||
var arg0block = py2block.convert(value.args[0]);
|
||||
var arg2block = py2block.convert(value.args[2]);
|
||||
return block("IOT_EMQX_INIT_AND_CONNECT_BY_MIXLY_CODE", node.lineno, {}, {
|
||||
'SERVER': arg0block,
|
||||
'KEY':arg2block,
|
||||
});
|
||||
}
|
||||
|
||||
pbc.assignD.get('MixIO_init_by_share_key')['check_assign'] = function(py2block, node, targets, value) {
|
||||
if(value._astname != "Call" || value.func._astname != "Attribute" || value.func.value._astname != "Name"){
|
||||
return false;
|
||||
}
|
||||
var funcName = py2block.identifier(value.func.attr);
|
||||
var moduleName = py2block.identifier(value.func.value.id);
|
||||
if(moduleName === "mixiot" && funcName === "MixIO_init_by_share_key" && value.args.length === 4)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
pbc.assignD.get('MixIO_init_by_share_key')['create_block'] = function(py2block, node, targets, value){
|
||||
var arg0block = py2block.convert(value.args[0]);
|
||||
var arg2block = py2block.convert(value.args[2]);
|
||||
return block("IOT_EMQX_INIT_AND_CONNECT_BY_SHARE_CODE", node.lineno, {}, {
|
||||
'SERVER': arg0block,
|
||||
'KEY':arg2block,
|
||||
});
|
||||
}
|
||||
|
||||
pbc.assignD.get('MixIO')['check_assign'] = function(py2block, node, targets, value) {
|
||||
if(value._astname != "Call" || value.func._astname != "Attribute" || value.func.value._astname != "Name"){
|
||||
return false;
|
||||
}
|
||||
var funcName = py2block.identifier(value.func.attr);
|
||||
var moduleName = py2block.Name_str(value.func.value);
|
||||
if(moduleName === "mixiot" && funcName === "MixIO" && value.args.length === 6)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
pbc.assignD.get('MixIO')['create_block'] = function(py2block, node, targets, value){
|
||||
var arg0block = py2block.convert(value.args[0]);
|
||||
var arg2block = py2block.convert(value.args[2]);
|
||||
var arg3block = py2block.convert(value.args[3]);
|
||||
var arg4block = py2block.convert(value.args[4]);
|
||||
return block("iot_mixio_connect", node.lineno, {}, {
|
||||
'SERVER': arg0block,
|
||||
'USERNAME':arg2block,
|
||||
'PASSWORD': arg3block,
|
||||
'PROJECT':arg4block
|
||||
});
|
||||
}
|
||||
|
||||
pbc.objectFunctionD.get('publish')[mqtt_client] = function (py2block, func, args, keywords, starargs, kwargs, node) {
|
||||
if (args.length != 2) {
|
||||
throw new Error("Incorrect number of arguments");
|
||||
}
|
||||
var argblock = py2block.convert(args[0]);
|
||||
var arg1block = py2block.convert(args[1]);
|
||||
return [block('IOT_MIXIO_PUBLISH', func.lineno, {}, {
|
||||
'TOPIC': argblock,
|
||||
'MSG': arg1block
|
||||
}, {
|
||||
"inline": "true"
|
||||
})];
|
||||
}
|
||||
|
||||
pbc.objectFunctionD.get('unsubscribe')[mqtt_client] = function (py2block, func, args, keywords, starargs, kwargs, node) {
|
||||
if (args.length != 1) {
|
||||
throw new Error("Incorrect number of arguments");
|
||||
}
|
||||
var argblock = py2block.convert(args[0]);
|
||||
return [block('IOT_MIXIO_UNSUBSCRIBE', func.lineno, {}, {
|
||||
'TOPIC': argblock
|
||||
}, {
|
||||
"inline": "true"
|
||||
})];
|
||||
}
|
||||
|
||||
pbc.objectFunctionD.get('subscribe')[mqtt_client] = function (py2block, func, args, keywords, starargs, kwargs, node) {
|
||||
if (args.length != 2) {
|
||||
throw new Error("Incorrect number of arguments");
|
||||
}
|
||||
var argblock = py2block.convert(args[0]);
|
||||
var arg1block = py2block.convert(args[1]);
|
||||
return [block('IOT_MIXIO_SUBSCRIBE', func.lineno, {}, {
|
||||
'TOPIC': argblock,
|
||||
'METHOD': arg1block
|
||||
}, {
|
||||
"inline": "true"
|
||||
})];
|
||||
}
|
||||
|
||||
pbc.objectFunctionD.get('check_msg')[mqtt_client] = function (py2block, func, args, keywords, starargs, kwargs, node) {
|
||||
if (args.length != 0) {
|
||||
throw new Error("Incorrect number of arguments");
|
||||
}
|
||||
|
||||
return [block('iot_mixio_check', func.lineno, {}, {}, {
|
||||
"inline": "true"
|
||||
})];
|
||||
}
|
||||
|
||||
pbc.objectFunctionD.get('connect')[mqtt_client] = function (py2block, func, args, keywords, starargs, kwargs, node) {
|
||||
if (args.length != 0) {
|
||||
throw new Error("Incorrect number of arguments");
|
||||
}
|
||||
|
||||
return [block('iot_mixio_connect_only', func.lineno, {}, {}, {
|
||||
"inline": "true"
|
||||
})];
|
||||
}
|
||||
|
||||
pbc.objectFunctionD.get('disconnect')[mqtt_client] = function (py2block, func, args, keywords, starargs, kwargs, node) {
|
||||
if (args != null) {
|
||||
throw new Error("Incorrect number of arguments");
|
||||
}
|
||||
|
||||
return [block('iot_mixio_disconnect', func.lineno, {}, {}, {
|
||||
"inline": "true"
|
||||
})];
|
||||
}
|
||||
|
||||
pbc.moduleFunctionD.get('mixpy')['format_content'] = function(py2block, func, args, keywords, starargs, kwargs, node) {
|
||||
if (args.length != 2) {
|
||||
throw new Error("Incorrect number of arguments");
|
||||
}
|
||||
var argblock = py2block.convert(args[0]);
|
||||
|
||||
return block('IOT_FORMATTING', func.lineno, {}, {
|
||||
'VAR': argblock,
|
||||
}, {
|
||||
"inline": "true"
|
||||
});
|
||||
}
|
||||
|
||||
pbc.moduleFunctionD.get('mixpy')['format_str'] = function(py2block, func, args, keywords, starargs, kwargs, node) {
|
||||
if (args.length != 1) {
|
||||
throw new Error("Incorrect number of arguments");
|
||||
}
|
||||
var argblock = py2block.convert(args[0]);
|
||||
|
||||
return block('IOT_FORMAT_STRING', func.lineno, {}, {
|
||||
'VAR': argblock,
|
||||
}, {
|
||||
"inline": "true"
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
function defDict(type) {
|
||||
var dict = {};
|
||||
return {
|
||||
get: function (key) {
|
||||
if (!dict[key]) {
|
||||
dict[key] = type.constructor();
|
||||
}
|
||||
return dict[key];
|
||||
},
|
||||
dict: dict
|
||||
};
|
||||
}
|
||||
|
||||
function Py2blockConfig (){
|
||||
this.initIgnoreS();
|
||||
this.initModuleAttrD();
|
||||
this.initKnownModuleS();
|
||||
this.initObjectTypeD();
|
||||
}
|
||||
|
||||
var pbc = Py2blockConfig.prototype;
|
||||
pbc.MIXPY = "MIXPY";
|
||||
pbc.board = pbc.MIXPY;
|
||||
pbc.objectFunctionD = defDict({});
|
||||
pbc.moduleFunctionD = defDict({});
|
||||
pbc.moduleAttrD = defDict({});
|
||||
pbc.objectAttrD = defDict({});
|
||||
pbc.globalFunctionD = {};
|
||||
pbc.assignD = defDict({});
|
||||
pbc.ifStatementD= defDict({});
|
||||
pbc.whileStatementD= defDict({});
|
||||
pbc.forStatementD= defDict({});
|
||||
pbc.reservedNameD= {};
|
||||
pbc.knownModuleS = new Set();
|
||||
pbc.objectTypeD = {}; //key:变量名,value:变量类型,如{'a':'List'}
|
||||
pbc.ignoreS = new Set();
|
||||
pbc.pinType = null;
|
||||
pbc.inScope = null;
|
||||
pbc.formatModuleKeyL = [];
|
||||
pbc.formatModuleL = [];
|
||||
|
||||
//忽略某些方法、类、赋值
|
||||
pbc.initIgnoreS = function(){
|
||||
var pythonIgnoreL = [
|
||||
];
|
||||
var boardIgnoreL = [];
|
||||
|
||||
var ignoreL = pythonIgnoreL.concat(boardIgnoreL);
|
||||
for (var i = 0; i < ignoreL.length; i++) {
|
||||
this.ignoreS.add(ignoreL[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pbc.initModuleAttrD = function(){
|
||||
}
|
||||
|
||||
pbc.initKnownModuleS = function(){
|
||||
var pythonModuleL = [
|
||||
'math', 'random'
|
||||
];
|
||||
var boardModuleL = [];
|
||||
|
||||
var moduleL = pythonModuleL.concat(boardModuleL);
|
||||
for (var i = 0; i < moduleL.length; i++) {
|
||||
this.knownModuleS.add(moduleL[i]);
|
||||
}
|
||||
}
|
||||
|
||||
pbc.initObjectTypeD = function () {
|
||||
this.objectTypeD = {
|
||||
'tina': 'turtle.Turtle',
|
||||
'f': 'open'
|
||||
}
|
||||
}
|
||||
|
||||
pbc.reset = function(){
|
||||
this.initObjectTypeD();
|
||||
}
|
||||
|
||||
var py2block_config = new Py2blockConfig();
|
||||
|
||||
45
boards/default_src/python_skulpt/converters/system.js
Normal file
45
boards/default_src/python_skulpt/converters/system.js
Normal file
@@ -0,0 +1,45 @@
|
||||
'use strict';
|
||||
|
||||
pbc.globalFunctionD['exit'] = function (py2block, func, args, keywords, starargs, kwargs, node) {
|
||||
if (args.length != 0) {
|
||||
throw new Error("Incorrect number of arguments");
|
||||
}
|
||||
return [block("controls_end_program", func.lineno, {}, {}, {
|
||||
"inline": "true"
|
||||
})];
|
||||
}
|
||||
|
||||
|
||||
|
||||
pbc.moduleFunctionD.get('time')['time'] = function(py2block, func, args, keywords, starargs, kwargs, node) {
|
||||
if (args.length != 0) {
|
||||
throw new Error("Incorrect number of arguments");
|
||||
}
|
||||
return block("controls_millis", func.lineno, {}, {}, {
|
||||
"inline": "true"
|
||||
});
|
||||
}
|
||||
|
||||
pbc.moduleFunctionD.get('time')['localtime'] = function(py2block, func, args, keywords, starargs, kwargs, node) {
|
||||
if (args.length != 0) {
|
||||
throw new Error("Incorrect number of arguments");
|
||||
}
|
||||
return block("time_localtime", func.lineno, {
|
||||
"op":'all'
|
||||
}, {}, {
|
||||
"inline": "true"
|
||||
});
|
||||
}
|
||||
|
||||
pbc.moduleFunctionD.get('time')['sleep'] = function(py2block, func, args, keywords, starargs, kwargs, node) {
|
||||
if (args.length != 1) {
|
||||
throw new Error("Incorrect number of arguments");
|
||||
}
|
||||
var argblock = py2block.convert(args[0]);
|
||||
return [block("time_sleep", func.lineno, {}, {
|
||||
|
||||
"DELAY_TIME":argblock
|
||||
}, {
|
||||
"inline": "true"
|
||||
})];
|
||||
}
|
||||
1127
boards/default_src/python_skulpt/converters/turtle.js
Normal file
1127
boards/default_src/python_skulpt/converters/turtle.js
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,143 @@
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(1) > div.blocklyTreeRow > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/inout.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(1) > div.blocklyTreeRow.blocklyTreeSelected > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/inout2.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(2) > div.blocklyTreeRow > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/ctrl.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(2) > div.blocklyTreeRow.blocklyTreeSelected > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/ctrl2.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(3) > div.blocklyTreeRow > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/math.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(3) > div.blocklyTreeRow.blocklyTreeSelected > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/math2.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(4) > div.blocklyTreeRow > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/logic.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(4) > div.blocklyTreeRow.blocklyTreeSelected > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/logic2.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(5) > div.blocklyTreeRow > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/text.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(5) > div.blocklyTreeRow.blocklyTreeSelected > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/text2.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(6) > div.blocklyTreeRow > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/list3.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(6) > div.blocklyTreeRow.blocklyTreeSelected > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/list4.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(7) > div.blocklyTreeRow > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/tuple.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(7) > div.blocklyTreeRow.blocklyTreeSelected > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/tuple2.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(8) > div.blocklyTreeRow > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/dict.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(8) > div.blocklyTreeRow.blocklyTreeSelected > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/dict2.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
|
||||
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(9) > div.blocklyTreeRow > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/set.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(9) > div.blocklyTreeRow.blocklyTreeSelected > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/set2.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(10) > div.blocklyTreeRow > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/var.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(10) > div.blocklyTreeRow.blocklyTreeSelected > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/var2.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(11) > div.blocklyTreeRow > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/func.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(11) > div.blocklyTreeRow.blocklyTreeSelected > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/func2.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(12) > div.blocklyTreeRow > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/mixio.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(12) > div.blocklyTreeRow.blocklyTreeSelected > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/mixio2.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
#catMixIO.blocklyTreeRow > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/mixio.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
#catMixIO.blocklyTreeRow.blocklyTreeSelected > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/mixio2.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(13) > div.blocklyTreeRow > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/turtle.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(13) > div.blocklyTreeRow.blocklyTreeSelected > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/turtle2.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(14) > div.blocklyTreeRow > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/data.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(14) > div.blocklyTreeRow.blocklyTreeSelected > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/data2.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
/*div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(14) > div.blocklyTreeRow > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/machine_learning.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(14) > div.blocklyTreeRow.blocklyTreeSelected > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/machine_learning2.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}*/
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(15) > div:nth-child(2) > div > div.blocklyTreeRow > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/algorithm.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
div.blocklyToolboxDiv > div.blocklyToolboxContents > div:nth-child(15) > div:nth-child(2) > div > div.blocklyTreeRow.blocklyTreeSelected > div.blocklyTreeRowContentContainer > span.blocklyTreeIcon{
|
||||
background:url('../../../../common/media/mark/algorithm2.png') no-repeat;
|
||||
background-size: 100% auto;
|
||||
}
|
||||
9
boards/default_src/python_skulpt/export.js
Normal file
9
boards/default_src/python_skulpt/export.js
Normal file
@@ -0,0 +1,9 @@
|
||||
import * as MicropythonESP32Pins from './blocks/esp32_profile';
|
||||
import * as MicropythonESP32PinsBlocks from './blocks/pins';
|
||||
import * as MicropythonESP32PinsGenerators from './generators/pins';
|
||||
|
||||
export {
|
||||
MicropythonESP32Pins,
|
||||
MicropythonESP32PinsBlocks,
|
||||
MicropythonESP32PinsGenerators
|
||||
};
|
||||
430
boards/default_src/python_skulpt/generators/data.js
Normal file
430
boards/default_src/python_skulpt/generators/data.js
Normal file
@@ -0,0 +1,430 @@
|
||||
import * as Blockly from 'blockly/core';
|
||||
|
||||
export const series_create = function (_, generator) {
|
||||
generator.definitions_.import_pandas = "import pandas";
|
||||
var varName1 = generator.valueToCode(this, 'SER', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var varName = generator.variableDB_.getName(this.getFieldValue('VAR'),
|
||||
Blockly.Variables.NAME_TYPE);
|
||||
var code = varName + ' = ' + 'pandas.Series(' + varName1 + ')\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const series_create_from_index = function (_, generator) {
|
||||
generator.definitions_.import_pandas = "import pandas";
|
||||
var varName1 = generator.valueToCode(this, 'SER', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var varName2 = generator.valueToCode(this, 'INDEX', generator.ORDER_ATOMIC) || '\'\'';
|
||||
var varName = generator.variableDB_.getName(this.getFieldValue('VAR'),
|
||||
Blockly.Variables.NAME_TYPE);
|
||||
var code = varName + ' = ' + 'pandas.Series(' + varName1 + ',' + 'index=' + varName2 + ')\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const dataframe_create = function (_, generator) {
|
||||
generator.definitions_.import_pandas = "import pandas";
|
||||
var varName1 = generator.valueToCode(this, 'SER', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var varName = generator.variableDB_.getName(this.getFieldValue('VAR'),
|
||||
Blockly.Variables.NAME_TYPE);
|
||||
var code = varName + ' = ' + 'pandas.DataFrame(' + varName1 + ')\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const dataframe_create_from_index = function (_, generator) {
|
||||
generator.definitions_.import_pandas = "import pandas";
|
||||
var varName1 = generator.valueToCode(this, 'SER', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var varName2 = generator.valueToCode(this, 'INDEX_COLUMN', generator.ORDER_ATOMIC) || '\'\'';
|
||||
var varName3 = generator.valueToCode(this, 'INDEX_RAW', generator.ORDER_ATOMIC) || '\'\'';
|
||||
var varName = generator.variableDB_.getName(this.getFieldValue('VAR'),
|
||||
Blockly.Variables.NAME_TYPE);
|
||||
var code = varName + ' = ' + 'pandas.DataFrame(' + varName1 + ',' + 'columns=' + varName2 + ',index=' + varName3 + ')\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const dataframe_create_from_one_index = function (_, generator) {
|
||||
generator.definitions_.import_pandas = "import pandas";
|
||||
var name = this.getFieldValue('COLUMN_RAW');
|
||||
var varName1 = generator.valueToCode(this, 'SER', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var varName2 = generator.valueToCode(this, 'INDEX', generator.ORDER_ATOMIC) || '\'\'';
|
||||
var varName = generator.variableDB_.getName(this.getFieldValue('VAR'),
|
||||
Blockly.Variables.NAME_TYPE);
|
||||
var code = varName + ' = ' + 'pandas.DataFrame(' + varName1 + ',' + name + '=' + varName2 + ')\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const series_create_from_text = function (_, generator) {
|
||||
generator.definitions_.import_pandas = "import pandas";
|
||||
var varName = generator.variableDB_.getName(this.getFieldValue('VAR'),
|
||||
Blockly.Variables.NAME_TYPE);
|
||||
var text = this.getFieldValue('TEXT');
|
||||
var code = varName + ' = ' + 'pandas.Series([' + text + '])\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const series_index_value = function (_, generator) {
|
||||
generator.definitions_.import_pandas = "import pandas";
|
||||
var varName = generator.valueToCode(this, 'SERIES', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var name = this.getFieldValue('INDEX_VALUE');
|
||||
var code = varName + '.' + name;
|
||||
return [code, generator.ORDER_ATOMIC];
|
||||
}
|
||||
|
||||
export const series_get_num = function (_, generator) {
|
||||
// Indexing into a list is the same as indexing into a string.
|
||||
var varName = generator.valueToCode(this, 'SER', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var argument0 = generator.valueToCode(this, 'AT',
|
||||
generator.ORDER_ADDITIVE) || '1';
|
||||
var code = varName + '[' + argument0 + ']';
|
||||
return [code, generator.ORDER_ATOMIC];
|
||||
}
|
||||
|
||||
export const pl_show = function (_, generator) {
|
||||
generator.definitions_.import_pylab = "import pylab";
|
||||
var code = 'pylab.show()\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const pl_axes = function (_, generator) {
|
||||
generator.definitions_.import_pylab = "import pylab";
|
||||
var code = 'pylab.axes(aspect=1)\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const pl_plot_easy = function (_, generator) {
|
||||
generator.definitions_.import_pylab = "import pylab";
|
||||
var varName = generator.valueToCode(this, 'SER', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var code = 'pylab.plot(' + varName + ")\n";
|
||||
return code;
|
||||
}
|
||||
|
||||
export const pl_plot = function (_, generator) {
|
||||
generator.definitions_.import_pylab = "import pylab";
|
||||
var line = this.getFieldValue('LINE');
|
||||
var color = this.getFieldValue('COLOR');
|
||||
var dot = this.getFieldValue('DOT');
|
||||
var varName = generator.valueToCode(this, 'SER', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var code = 'pylab.plot(' + varName + ",'" + dot + line + color + "')\n";
|
||||
return code;
|
||||
}
|
||||
|
||||
export const pl_legend = function (_, generator) {
|
||||
generator.definitions_.import_pylab = "import pylab";
|
||||
generator.definitions_.import_matplotlib_font_manager = "import matplotlib.font_manager";
|
||||
var code = 'pylab.legend(' + 'prop=matplotlib.font_manager.FontProperties("' + "STSong" + '")' + ')\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const pl_title = function (_, generator) {
|
||||
generator.definitions_.import_pylab = "import pylab";
|
||||
var a = generator.valueToCode(this, 'TITLE', generator.ORDER_ATOMIC);
|
||||
var code = 'pylab.title(' + a + ', fontproperties = "' + "STSong" + '")\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const pl_label = function (_, generator) {
|
||||
generator.definitions_.import_pylab = "import pylab";
|
||||
var direction = this.getFieldValue('DIR');
|
||||
var a = generator.valueToCode(this, 'LABEL', generator.ORDER_ATOMIC);
|
||||
var code = 'pylab.' + direction + 'label(' + a + ', fontproperties = "' + "STSong" + '")\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const array_create = function (_, generator) {
|
||||
generator.definitions_.import_numpy = "import numpy";
|
||||
var from = generator.valueToCode(this, "FROM", generator.ORDER_NONE) || "0";
|
||||
var end = generator.valueToCode(this, "TO", generator.ORDER_NONE) || "0";
|
||||
var step = generator.valueToCode(this, "STEP", generator.ORDER_NONE) || "1";
|
||||
var code = "numpy.arange(" + from + ", " + end + ", " + step + ")";
|
||||
return [code, generator.ORDER_ATOMIC];
|
||||
}
|
||||
|
||||
export const pl_plot_bar = function (_, generator) {
|
||||
generator.definitions_.import_pylab = "import pylab";
|
||||
var direction = this.getFieldValue('DIR');
|
||||
var a = generator.valueToCode(this, 'A', generator.ORDER_ATOMIC) || '\'\'';
|
||||
var b = generator.valueToCode(this, 'B', generator.ORDER_ATOMIC) || '\'\'';
|
||||
var code = 'pylab.' + direction + '(' + a + ',' + b + ")\n";
|
||||
return code;
|
||||
}
|
||||
|
||||
export const pl_plot_scatter = function (_, generator) {
|
||||
generator.definitions_.import_pylab = "import pylab";
|
||||
var a = generator.valueToCode(this, 'A', generator.ORDER_ATOMIC) || '\'\'';
|
||||
var b = generator.valueToCode(this, 'B', generator.ORDER_ATOMIC) || '\'\'';
|
||||
var s = generator.valueToCode(this, 'S', generator.ORDER_ATOMIC) || '\'\'';
|
||||
var color = this.getFieldValue('COLOR');
|
||||
var dot = this.getFieldValue('DOT');
|
||||
var tag = generator.valueToCode(this, 'TAG', generator.ORDER_ATOMIC) || '\'\'';
|
||||
var code = 'pylab.scatter(' + a + ',' + b + ",s=" + s + ",c='" + color + "',marker='" + dot + "',label=" + tag + ")\n";
|
||||
return code;
|
||||
}
|
||||
|
||||
export const pl_plot_xy = function (_, generator) {
|
||||
generator.definitions_.import_pylab = "import pylab";
|
||||
var a = generator.valueToCode(this, 'A', generator.ORDER_ATOMIC) || '\'\'';
|
||||
var b = generator.valueToCode(this, 'B', generator.ORDER_ATOMIC) || '\'\'';
|
||||
var line = this.getFieldValue('LINE');
|
||||
var color = this.getFieldValue('COLOR');
|
||||
var dot = this.getFieldValue('DOT');
|
||||
var tag = generator.valueToCode(this, 'TAG', generator.ORDER_ATOMIC) || '\'\'';
|
||||
var code = 'pylab.plot(' + a + ',' + b + ",'" + dot + line + color + "'" + ',label=' + tag + ")\n";
|
||||
return code;
|
||||
}
|
||||
|
||||
export const pl_bar = function (_, generator) {
|
||||
generator.definitions_.import_pylab = "import pylab";
|
||||
var a = generator.valueToCode(this, 'A', generator.ORDER_ATOMIC) || '\'\'';
|
||||
var b = generator.valueToCode(this, 'B', generator.ORDER_ATOMIC) || '\'\'';
|
||||
var tag = generator.valueToCode(this, 'TAG', generator.ORDER_ATOMIC) || '\'\'';
|
||||
var width = generator.valueToCode(this, 'WIDTH', generator.ORDER_RELATIONAL) || '0';
|
||||
var color = this.getFieldValue('COLOR')
|
||||
var align = this.getFieldValue('ALIGN');
|
||||
var code = 'pylab.bar(' + a + ',' + b + ',align="' + align + '",color="' + color + '",width=' + width + ',label=' + tag + ")\n";
|
||||
return code;
|
||||
}
|
||||
|
||||
export const pl_pie = function (_, generator) {
|
||||
generator.definitions_.import_pylab = "import pylab";
|
||||
var a = generator.valueToCode(this, 'A', generator.ORDER_ATOMIC) || '\'\'';
|
||||
var b = generator.valueToCode(this, 'B', generator.ORDER_ATOMIC) || '\'\'';
|
||||
var explode = generator.valueToCode(this, 'EXPLODE', generator.ORDER_ATOMIC) || '\'\'';
|
||||
var shadow = this.getFieldValue('SHADOW');
|
||||
var autopct = this.getFieldValue('autopct');
|
||||
if (autopct != 'None') { autopct = "'" + autopct + "'" }
|
||||
var code = 'pylab.pie(' + a + ',explode=' + explode + ',labels=' + b + ',autopct=' + autopct + ',shadow=' + shadow + ")\n";
|
||||
return code;
|
||||
}
|
||||
|
||||
export const pl_hist = function (_, generator) {
|
||||
generator.definitions_.import_pylab = "import pylab";
|
||||
var a = generator.valueToCode(this, 'A', generator.ORDER_ATOMIC) || '\'\'';
|
||||
var b = generator.valueToCode(this, 'B', generator.ORDER_ATOMIC) || '\'\'';
|
||||
var code = 'pylab.hist(' + a + ',' + b + ")\n";
|
||||
return code;
|
||||
}
|
||||
|
||||
export const pl_ticks = function (_, generator) {
|
||||
generator.definitions_.import_pylab = "import pylab";
|
||||
var direction = this.getFieldValue('DIR');
|
||||
var a = generator.valueToCode(this, 'A', generator.ORDER_ATOMIC) || '\'\'';
|
||||
var b = generator.valueToCode(this, 'B', generator.ORDER_ATOMIC) || '\'\'';
|
||||
var code = 'pylab.' + direction + 'ticks(' + a + ',' + b + ",fontproperties = '" + "STSong" + "')\n";
|
||||
return code;
|
||||
}
|
||||
|
||||
export const numpy_trig = function (_, generator) {
|
||||
generator.definitions_.import_numpy = "import numpy";
|
||||
var argument0 = generator.valueToCode(this, 'NUM', generator.ORDER_NONE) || '0';
|
||||
var operator = this.getFieldValue('OP');
|
||||
var code = "";
|
||||
code = "numpy." + operator + '(' + argument0 + ')';
|
||||
return [code, generator.ORDER_ATOMIC];
|
||||
}
|
||||
|
||||
export const pl_subplot = function (_, generator) {
|
||||
generator.definitions_.import_numpy = "import numpy";
|
||||
var from = generator.valueToCode(this, "VET", generator.ORDER_NONE) || "0";
|
||||
var end = generator.valueToCode(this, "HOR", generator.ORDER_NONE) || "0";
|
||||
var step = generator.valueToCode(this, "NUM", generator.ORDER_NONE) || "0";
|
||||
var code = "pylab.subplot(" + from + ", " + end + ", " + step + ")\n";
|
||||
return code
|
||||
}
|
||||
|
||||
export const pandas_readcsv = function (_, generator) {
|
||||
// For each loop.
|
||||
generator.definitions_.import_pandas = "import pandas";
|
||||
var fn = generator.valueToCode(this, 'FILENAME', generator.ORDER_ATOMIC);
|
||||
var mode = this.getFieldValue('MODE');
|
||||
var code = 'pandas.read_csv(' + fn + ', header=' + mode + ')\n';
|
||||
return [code, generator.ORDER_ATOMIC];
|
||||
}
|
||||
|
||||
export const dataframe_get = function (_, generator) {
|
||||
var mode = this.getFieldValue('MODE');
|
||||
var varName = generator.valueToCode(this, 'DICT', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var text = generator.valueToCode(this, 'KEY', generator.ORDER_ASSIGNMENT);
|
||||
if (mode == "column") {
|
||||
var code = varName + "[" + text + "]";
|
||||
} else if (mode == 'raw') {
|
||||
var code = varName + ".loc[" + text + "]";
|
||||
}
|
||||
return [code, generator.ORDER_ATOMIC];
|
||||
}
|
||||
|
||||
export const pl_savefig = function (_, generator) {
|
||||
generator.definitions_.import_pylab = "import pylab";
|
||||
var file = generator.valueToCode(this, 'FILE', generator.ORDER_ATOMIC);
|
||||
var code = "pylab.savefig(" + file + ")\n";
|
||||
return code;
|
||||
}
|
||||
|
||||
export const pl_text = function (_, generator) {
|
||||
generator.definitions_.import_numpy = "import numpy";
|
||||
var from = generator.valueToCode(this, "VET", generator.ORDER_NONE) || "0";
|
||||
var end = generator.valueToCode(this, "HOR", generator.ORDER_NONE) || "0";
|
||||
var step = generator.valueToCode(this, "NUM", generator.ORDER_NONE) || "0";
|
||||
var halign = this.getFieldValue('HALIGN');
|
||||
var valign = this.getFieldValue('VALIGN');
|
||||
var fontnum = generator.valueToCode(this, 'FONTNUM', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var code = "pylab.text(" + from + ", " + end + ", " + step + ", ha='" + halign + "', va='" + valign + "', fontsize=" + fontnum + ")\n";
|
||||
return code
|
||||
}
|
||||
|
||||
export const array_toarray = function (_, generator) {
|
||||
var str = generator.valueToCode(this, 'VAR', generator.ORDER_ATOMIC) || '0';
|
||||
generator.definitions_['import_numpy'] = 'import numpy';
|
||||
var code = 'numpy.array(' + str + ')';
|
||||
return [code, generator.ORDER_ATOMIC];
|
||||
}
|
||||
|
||||
export const plot_show = function (_, generator) {
|
||||
generator.definitions_.import_matplotlib_pyplot = "import matplotlib.pyplot";
|
||||
var code = 'matplotlib.pyplot.show()\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const plot_axes = function (_, generator) {
|
||||
generator.definitions_.import_matplotlib_pyplot = "import matplotlib.pyplot";
|
||||
var code = 'matplotlib.pyplot.axes(aspect=1)\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const plot_plot_easy = function (_, generator) {
|
||||
generator.definitions_.import_matplotlib_pyplot = "import matplotlib.pyplot";
|
||||
var varName = generator.valueToCode(this, 'SER', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var code = 'matplotlib.pyplot.plot(' + varName + ")\n";
|
||||
return code;
|
||||
}
|
||||
|
||||
export const plot_plot = function (_, generator) {
|
||||
generator.definitions_.import_matplotlib_pyplot = "import matplotlib.pyplot";
|
||||
var line = this.getFieldValue('LINE');
|
||||
var color = this.getFieldValue('COLOR');
|
||||
var dot = this.getFieldValue('DOT');
|
||||
var varName = generator.valueToCode(this, 'SER', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var code = 'matplotlib.pyplot.plot(' + varName + ",'" + dot + line + color + "')\n";
|
||||
return code;
|
||||
}
|
||||
|
||||
export const plot_legend = function (_, generator) {
|
||||
generator.definitions_.import_matplotlib_pyplot = "import matplotlib.pyplot";
|
||||
generator.definitions_.import_matplotlib_font_manager = "import matplotlib.font_manager";
|
||||
var code = 'matplotlib.pyplot.legend(' + 'prop=matplotlib.font_manager.FontProperties("' + "STSong" + '")' + ')\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const plot_title = function (_, generator) {
|
||||
generator.definitions_.import_matplotlib_pyplot = "import matplotlib.pyplot";
|
||||
var a = generator.valueToCode(this, 'TITLE', generator.ORDER_ATOMIC);
|
||||
var code = 'matplotlib.pyplot.title(' + a + ')\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const plot_label = function (_, generator) {
|
||||
generator.definitions_.import_matplotlib_pyplot = "import matplotlib.pyplot";
|
||||
var direction = this.getFieldValue('DIR');
|
||||
var a = generator.valueToCode(this, 'LABEL', generator.ORDER_ATOMIC);
|
||||
var code = 'matplotlib.pyplot.' + direction + 'label(' + a + ')\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const plot_plot_bar = function (_, generator) {
|
||||
generator.definitions_.import_matplotlib_pyplot = "import matplotlib.pyplot";
|
||||
var direction = this.getFieldValue('DIR');
|
||||
var a = generator.valueToCode(this, 'A', generator.ORDER_ATOMIC) || '\'\'';
|
||||
var b = generator.valueToCode(this, 'B', generator.ORDER_ATOMIC) || '\'\'';
|
||||
var code = 'matplotlib.pyplot.' + direction + '(' + a + ',' + b + ")\n";
|
||||
return code;
|
||||
}
|
||||
|
||||
export const plot_plot_scatter = function (_, generator) {
|
||||
generator.definitions_.import_matplotlib_pyplot = "import matplotlib.pyplot";
|
||||
var a = generator.valueToCode(this, 'A', generator.ORDER_ATOMIC) || '\'\'';
|
||||
var b = generator.valueToCode(this, 'B', generator.ORDER_ATOMIC) || '\'\'';
|
||||
var s = generator.valueToCode(this, 'S', generator.ORDER_ATOMIC) || '\'\'';
|
||||
var color = this.getFieldValue('COLOR');
|
||||
var dot = this.getFieldValue('DOT');
|
||||
var tag = generator.valueToCode(this, 'TAG', generator.ORDER_ATOMIC) || '\'\'';
|
||||
var code = 'matplotlib.pyplot.scatter(' + a + ',' + b + ",s=" + s + ",color='" + color + "',marker='" + dot + "',label=" + tag + ")\n";
|
||||
return code;
|
||||
}
|
||||
|
||||
export const plot_plot_xy = function (_, generator) {
|
||||
generator.definitions_.import_matplotlib_pyplot = "import matplotlib.pyplot";
|
||||
var a = generator.valueToCode(this, 'A', generator.ORDER_ATOMIC) || '\'\'';
|
||||
var b = generator.valueToCode(this, 'B', generator.ORDER_ATOMIC) || '\'\'';
|
||||
var line = this.getFieldValue('LINE');
|
||||
var color = this.getFieldValue('COLOR');
|
||||
var dot = this.getFieldValue('DOT');
|
||||
var tag = generator.valueToCode(this, 'TAG', generator.ORDER_ATOMIC) || '\'\'';
|
||||
var code = 'matplotlib.pyplot.plot(' + a + ',' + b + ",'" + dot + line + color + "'" + ',label=' + tag + ")\n";
|
||||
return code;
|
||||
}
|
||||
|
||||
export const plot_bar = function (_, generator) {
|
||||
generator.definitions_.import_matplotlib_pyplot = "import matplotlib.pyplot";
|
||||
var a = generator.valueToCode(this, 'A', generator.ORDER_ATOMIC) || '\'\'';
|
||||
var b = generator.valueToCode(this, 'B', generator.ORDER_ATOMIC) || '\'\'';
|
||||
var tag = generator.valueToCode(this, 'TAG', generator.ORDER_ATOMIC) || '\'\'';
|
||||
var width = generator.valueToCode(this, 'WIDTH', generator.ORDER_RELATIONAL) || '0';
|
||||
var color = this.getFieldValue('COLOR')
|
||||
var align = this.getFieldValue('ALIGN');
|
||||
var code = 'matplotlib.pyplot.bar(' + a + ',' + b + ',align="' + align + '",color="' + color + '",width=' + width + ',label=' + tag + ")\n";
|
||||
return code;
|
||||
}
|
||||
|
||||
export const plot_pie = function (_, generator) {
|
||||
generator.definitions_.import_matplotlib_pyplot = "import matplotlib.pyplot";
|
||||
var a = generator.valueToCode(this, 'A', generator.ORDER_ATOMIC) || '\'\'';
|
||||
var b = generator.valueToCode(this, 'B', generator.ORDER_ATOMIC) || '\'\'';
|
||||
var explode = generator.valueToCode(this, 'EXPLODE', generator.ORDER_ATOMIC) || '\'\'';
|
||||
var shadow = this.getFieldValue('SHADOW');
|
||||
var autopct = this.getFieldValue('autopct');
|
||||
if (autopct != 'None') { autopct = "'" + autopct + "'" }
|
||||
var code = 'matplotlib.pyplot.pie(' + a + ',explode=' + explode + ',labels=' + b + ',autopct=' + autopct + ',shadow=' + shadow + ")\n";
|
||||
return code;
|
||||
}
|
||||
|
||||
export const plot_hist = function (_, generator) {
|
||||
generator.definitions_.import_matplotlib_pyplot = "import matplotlib.pyplot";
|
||||
var a = generator.valueToCode(this, 'A', generator.ORDER_ATOMIC) || '\'\'';
|
||||
var b = generator.valueToCode(this, 'B', generator.ORDER_ATOMIC) || '\'\'';
|
||||
var code = 'matplotlib.pyplot.hist(' + a + ',' + b + ")\n";
|
||||
return code;
|
||||
}
|
||||
|
||||
export const plot_ticks = function (_, generator) {
|
||||
generator.definitions_.import_matplotlib_pyplot = "import matplotlib.pyplot";
|
||||
var direction = this.getFieldValue('DIR');
|
||||
var a = generator.valueToCode(this, 'A', generator.ORDER_ATOMIC) || '\'\'';
|
||||
var b = generator.valueToCode(this, 'B', generator.ORDER_ATOMIC) || '\'\'';
|
||||
var code = 'matplotlib.pyplot.' + direction + 'ticks(' + a + ',' + b + ",fontproperties = '" + "STSong" + "')\n";
|
||||
return code;
|
||||
}
|
||||
|
||||
export const plot_subplot = function (_, generator) {
|
||||
generator.definitions_.import_numpy = "import numpy";
|
||||
generator.definitions_.import_matplotlib_pyplot = "import matplotlib.pyplot";
|
||||
var from = generator.valueToCode(this, "VET", generator.ORDER_NONE) || "0";
|
||||
var end = generator.valueToCode(this, "HOR", generator.ORDER_NONE) || "0";
|
||||
var step = generator.valueToCode(this, "NUM", generator.ORDER_NONE) || "0";
|
||||
var code = "matplotlib.pyplot.subplot(" + from + ", " + end + ", " + step + ")\n";
|
||||
return code
|
||||
}
|
||||
|
||||
export const plot_savefig = function (_, generator) {
|
||||
generator.definitions_.import_matplotlib_pyplot = "import matplotlib.pyplot";
|
||||
var code = "matplotlib.pyplot.savefig('1.png')\n";
|
||||
return code;
|
||||
}
|
||||
|
||||
export const plot_text = function (_, generator) {
|
||||
generator.definitions_.import_numpy = "import numpy";
|
||||
generator.definitions_.import_matplotlib_pyplot = "import matplotlib.pyplot";
|
||||
var from = generator.valueToCode(this, "VET", generator.ORDER_NONE) || "0";
|
||||
var end = generator.valueToCode(this, "HOR", generator.ORDER_NONE) || "0";
|
||||
var step = generator.valueToCode(this, "NUM", generator.ORDER_NONE) || "0";
|
||||
var halign = this.getFieldValue('HALIGN');
|
||||
var valign = this.getFieldValue('VALIGN');
|
||||
var fontnum = generator.valueToCode(this, 'FONTNUM', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var code = "matplotlib.pyplot.text(" + from + ", " + end + ", " + step + ", ha='" + halign + "', va='" + valign + "', fontsize=" + fontnum + ")\n";
|
||||
return code
|
||||
}
|
||||
44
boards/default_src/python_skulpt/generators/inout.js
Normal file
44
boards/default_src/python_skulpt/generators/inout.js
Normal file
@@ -0,0 +1,44 @@
|
||||
export const inout_input = function (_, generator) {
|
||||
var str = generator.valueToCode(this, 'VAR', generator.ORDER_ATOMIC) || '""';
|
||||
return ['input(' + str + ')', generator.ORDER_ATOMIC];
|
||||
}
|
||||
|
||||
export const inout_print = function (_, generator) {
|
||||
var str = generator.valueToCode(this, 'VAR', generator.ORDER_ATOMIC) || '""';
|
||||
var code = "print(" + str + ")\n";
|
||||
return code;
|
||||
}
|
||||
|
||||
export const inout_print_inline = function (_, generator) {
|
||||
var str = generator.valueToCode(this, 'VAR', generator.ORDER_ATOMIC) || '""';
|
||||
var code = "print(" + str + ',end ="")\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const inout_print_end = function (_, generator) {
|
||||
var str = generator.valueToCode(this, 'VAR', generator.ORDER_ATOMIC) || '""';
|
||||
var end = generator.valueToCode(this, 'END', generator.ORDER_ATOMIC) || '""';
|
||||
var code = "print(" + str + ',end =' + end + ')\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const inout_type_input = function (_, generator) {
|
||||
var str = generator.valueToCode(this, 'VAR', generator.ORDER_ATOMIC) || '""';
|
||||
var type = this.getFieldValue('DIR');
|
||||
if (type == 'str') { var code = 'input(' + str + ')' }
|
||||
else if (type == 'int') { var code = 'int(input(' + str + '))' }
|
||||
else if (type == 'float') { var code = 'float(input(' + str + '))' }
|
||||
//var code=varname+"." + type + "(" + ')';
|
||||
return [code, generator.ORDER_ATOMIC];
|
||||
}
|
||||
|
||||
export const inout_print_many = function (_, generator) {
|
||||
var code = new Array(this.itemCount_);
|
||||
var default_value = '0';
|
||||
for (var n = 0; n < this.itemCount_; n++) {
|
||||
code[n] = generator.valueToCode(this, 'ADD' + n,
|
||||
generator.ORDER_NONE) || default_value;
|
||||
}
|
||||
var code = 'print(' + code.join(', ') + ')\n';
|
||||
return code;
|
||||
}
|
||||
114
boards/default_src/python_skulpt/generators/iot.js
Normal file
114
boards/default_src/python_skulpt/generators/iot.js
Normal file
@@ -0,0 +1,114 @@
|
||||
export const iot_mixio_connect = function (_, generator) {
|
||||
generator.definitions_['import_mixiot'] = "import mixiot";
|
||||
var server = generator.valueToCode(this, 'SERVER', generator.ORDER_ATOMIC);
|
||||
var username = generator.valueToCode(this, 'USERNAME', generator.ORDER_ATOMIC);
|
||||
var password = generator.valueToCode(this, 'PASSWORD', generator.ORDER_ATOMIC);
|
||||
var project = generator.valueToCode(this, 'PROJECT', generator.ORDER_ATOMIC);
|
||||
var timestamp = Math.round(new Date()).toString();
|
||||
//var subscribe = generator.valueToCode(this, 'SUB', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var a = "f'python-mqtt-" + username.replace("'", "").replace("'", "") + timestamp.replace("'", "").replace("'", "") + "'";
|
||||
var code = 'mqtt_client = mixiot.MixIO(' + server + ', 8084 ,' + username + ', ' + password + ', ' + project + ',' + a + ')\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const IOT_MIXIO_PUBLISH = function (_, generator) {
|
||||
var topic = generator.valueToCode(this, 'TOPIC', generator.ORDER_ATOMIC);
|
||||
var msg = generator.valueToCode(this, 'MSG', generator.ORDER_ATOMIC);
|
||||
generator.definitions_['import_mixiot'] = "import mixiot";
|
||||
var code = 'mqtt_client.publish(' + topic + ', ' + msg + ')\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const IOT_MIXIO_SUBSCRIBE = function (_, generator) {
|
||||
var topic = generator.valueToCode(this, 'TOPIC', generator.ORDER_ATOMIC);
|
||||
var method = generator.valueToCode(this, 'METHOD', generator.ORDER_ATOMIC);
|
||||
generator.definitions_['import_mixiot'] = "import mixiot";
|
||||
var code = 'mqtt_client.subscribe(' + topic + ',' + method + ')\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const IOT_MIXIO_UNSUBSCRIBE = function (_, generator) {
|
||||
var topic = generator.valueToCode(this, 'TOPIC', generator.ORDER_ATOMIC);
|
||||
generator.definitions_['import_mixiot'] = "import mixiot";
|
||||
var code = 'mqtt_client.unsubscribe(' + topic + ')\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const iot_mixio_disconnect = function (_, generator) {
|
||||
generator.definitions_['import_mixiot'] = "import mixiot";
|
||||
var code = 'mqtt_client.disconnect()\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const iot_mixio_connect_only = function (_, generator) {
|
||||
generator.definitions_['import_mixiot'] = "import mixiot";
|
||||
var code = 'mqtt_client.connect()\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const iot_mixio_check = function (_, generator) {
|
||||
generator.definitions_['import_mixiot'] = "import mixiot";
|
||||
var code = 'mqtt_client.check_msg()\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const iot_mixio_format_topic = function (_, generator) {
|
||||
var code = 'mqtt_client.decode("utf-8").split("/")[-1]';
|
||||
return [code, generator.ORDER_ATOMIC];
|
||||
}
|
||||
|
||||
export const iot_mixio_format_msg = function (_, generator) {
|
||||
var code = 'mqtt_client.decode("utf-8")';
|
||||
return [code, generator.ORDER_ATOMIC];
|
||||
}
|
||||
|
||||
export const IOT_FORMATTING = function (_, generator) {
|
||||
generator.definitions_['import_mixpy'] = "import mixpy";
|
||||
var v = generator.valueToCode(this, 'VAR', generator.ORDER_ATOMIC);
|
||||
var code = 'mixpy.format_content(' + v + ', mqtt_client.client_id)';
|
||||
return [code, generator.ORDER_ATOMIC];
|
||||
}
|
||||
|
||||
export const IOT_FORMAT_STRING = function (_, generator) {
|
||||
generator.definitions_['import_mixpy'] = "import mixpy";
|
||||
var v = generator.valueToCode(this, 'VAR', generator.ORDER_ATOMIC);
|
||||
var code = 'mixpy.format_str(' + v + ')';
|
||||
return [code, generator.ORDER_ATOMIC];
|
||||
}
|
||||
|
||||
export const IOT_EMQX_INIT_AND_CONNECT_BY_MIXLY_CODE = function (_, generator) {
|
||||
generator.definitions_['import_mixiot'] = "import mixiot";
|
||||
var server = generator.valueToCode(this, 'SERVER', generator.ORDER_ATOMIC);
|
||||
var share_code = generator.valueToCode(this, 'KEY', generator.ORDER_ATOMIC);
|
||||
var timestamp = Math.round(new Date()).toString();
|
||||
var a = "f'python-mqtt-" + share_code.replace("'", "").replace("'", "") + timestamp.replace("'", "").replace("'", "") + "'";
|
||||
var code = 'mqtt_client = mixiot.MixIO_init_by_mixly_key(' + server + ', 8084 ,' + share_code + ',' + a + ')\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const iot_mixly_key = function (_, generator) {
|
||||
var code = this.getFieldValue('VISITOR_ID');
|
||||
return [code, generator.ORDER_ATOMIC];
|
||||
}
|
||||
|
||||
export const IOT_EMQX_INIT_AND_CONNECT_BY_SHARE_CODE = function (_, generator) {
|
||||
generator.definitions_['import_mixiot'] = "import mixiot";
|
||||
generator.definitions_['import_time'] = 'import time';
|
||||
var server = generator.valueToCode(this, 'SERVER', generator.ORDER_ATOMIC);
|
||||
var mixly_code = generator.valueToCode(this, 'KEY', generator.ORDER_ATOMIC);
|
||||
var timestamp = Math.round(new Date()).toString();
|
||||
var a = "f'python-mqtt-" + mixly_code.replace("'", "").replace("'", "") + timestamp.replace("'", "").replace("'", "") + "'";
|
||||
var code = 'mqtt_client = mixiot.MixIO_init_by_share_key(' + server + ', 8084 ,' + mixly_code + ',' + a + ')\ntime.sleep(2)\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const IOT_EMQX_PING = function (_, generator) {
|
||||
generator.definitions_['import_mixiot'] = "import mixiot";
|
||||
var code = 'mqtt_client.pingSync()';
|
||||
return [code, generator.ORDER_ATOMIC];
|
||||
}
|
||||
|
||||
export const iot_mixly_key_py = function (_, generator) {
|
||||
var code = this.getFieldValue('VISITOR_ID');
|
||||
return ["'" + code + "'", generator.ORDER_ATOMIC];
|
||||
}
|
||||
22
boards/default_src/python_skulpt/generators/system.js
Normal file
22
boards/default_src/python_skulpt/generators/system.js
Normal file
@@ -0,0 +1,22 @@
|
||||
export const controls_millis = function (_, generator) {
|
||||
generator.definitions_.import_time = "import time";
|
||||
var code = 'time.time()';
|
||||
return [code, generator.ORDER_ATOMIC];
|
||||
}
|
||||
|
||||
export const controls_end_program = function () {
|
||||
return 'exit()\n';
|
||||
}
|
||||
|
||||
export const time_localtime = function (_, generator) {
|
||||
generator.definitions_.import_time = "import time";
|
||||
var op = this.getFieldValue('op');
|
||||
var code = "time.localtime()[" + op + "]";
|
||||
switch (op) {
|
||||
case "all":
|
||||
var code1 = "time.localtime()";
|
||||
return [code1, generator.ORDER_ASSIGNMENT];
|
||||
default:
|
||||
return [code, generator.ORDER_ASSIGNMENT];
|
||||
}
|
||||
}
|
||||
384
boards/default_src/python_skulpt/generators/turtle.js
Normal file
384
boards/default_src/python_skulpt/generators/turtle.js
Normal file
@@ -0,0 +1,384 @@
|
||||
import * as Blockly from 'blockly/core';
|
||||
|
||||
export const turtle_create = function (_, generator) {
|
||||
generator.definitions_.import_turtle = "import turtle";
|
||||
var varName = generator.variableDB_.getName(this.getFieldValue('VAR'),
|
||||
Blockly.Variables.NAME_TYPE);
|
||||
//var size=window.parseFloat(this.getFieldValue('SIZE'));
|
||||
//generator.definitions_['var_declare'+varName] = varName+'= '+ 'turtle.Turtle()\n';
|
||||
var code = varName + ' = ' + 'turtle.Turtle()\n';
|
||||
return code;
|
||||
// return '';
|
||||
}
|
||||
|
||||
export const turtle_done = function (_, generator) {
|
||||
generator.definitions_.import_turtle = "import turtle";
|
||||
var code = 'turtle.done()\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const turtle_exitonclick = function (_, generator) {
|
||||
generator.definitions_.import_turtle = "import turtle";
|
||||
var code = 'turtle.exitonclick()\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const turtle_move = function (_, generator) {
|
||||
generator.definitions_.import_turtle = "import turtle";
|
||||
var varName = generator.valueToCode(this, 'TUR', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var direction = this.getFieldValue('DIR');
|
||||
var num = generator.valueToCode(this, 'VAR', generator.ORDER_ATOMIC);
|
||||
var code = varName + "." + direction + "(" + num + ')\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const turtle_rotate = function (_, generator) {
|
||||
generator.definitions_.import_turtle = "import turtle";
|
||||
var varName = generator.valueToCode(this, 'TUR', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var direction = this.getFieldValue('DIR');
|
||||
var num = generator.valueToCode(this, 'VAR', generator.ORDER_ATOMIC);
|
||||
var code = varName + "." + direction + "(" + num + ')\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const turtle_setheading = function (_, generator) {
|
||||
generator.definitions_.import_turtle = "import turtle";
|
||||
var varName = generator.valueToCode(this, 'TUR', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var argument = generator.valueToCode(this, 'data', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var code = varName + '.setheading(' + argument + ')\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const turtle_screen_delay = function (_, generator) {
|
||||
generator.definitions_.import_turtle = "import turtle";
|
||||
var varName = generator.valueToCode(this, 'TUR', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var argument = generator.valueToCode(this, 'data', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var code = varName + '.screen.delay(' + argument + ')\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const turtle_goto = function (_, generator) {
|
||||
generator.definitions_.import_turtle = "import turtle";
|
||||
var varName = generator.valueToCode(this, 'TUR', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var xnum = generator.valueToCode(this, 'data', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var ynum = generator.valueToCode(this, 'val', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var code = varName + '.goto(' + xnum + ',' + ynum + ')\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const turtle_pos_shape = function (_, generator) {
|
||||
generator.definitions_.import_turtle = "import turtle";
|
||||
var varName = generator.valueToCode(this, 'TUR', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var get = this.getFieldValue('DIR');
|
||||
var code = varName + '.' + get + '()';
|
||||
return [code, generator.ORDER_ATOMIC];
|
||||
}
|
||||
|
||||
export const turtle_clear = function (_, generator) {
|
||||
generator.definitions_.import_turtle = "import turtle";
|
||||
var varName = generator.valueToCode(this, 'TUR', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var clear = this.getFieldValue('DIR');
|
||||
var code = varName + "." + clear + "(" + ')\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const turtle_penup = function (_, generator) {
|
||||
generator.definitions_.import_turtle = "import turtle";
|
||||
var varName = generator.valueToCode(this, 'TUR', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var penup = this.getFieldValue('DIR');
|
||||
var code = varName + "." + penup + "(" + ')\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const turtle_fill = function (_, generator) {
|
||||
generator.definitions_.import_turtle = "import turtle";
|
||||
var varName = generator.valueToCode(this, 'TUR', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var penup = this.getFieldValue('DIR');
|
||||
var code = varName + "." + penup + "_fill(" + ')\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const turtle_size_speed = function (_, generator) {
|
||||
generator.definitions_.import_turtle = "import turtle";
|
||||
var varName = this.getFieldValue('TUR');
|
||||
var size = this.getFieldValue('DIR');
|
||||
var num = generator.valueToCode(this, 'VAR', generator.ORDER_ATOMIC);
|
||||
var code = varName + "." + size + "(" + num + ')\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const turtle_size = function (_, generator) {
|
||||
generator.definitions_.import_turtle = "import turtle";
|
||||
var varName = generator.valueToCode(this, 'TUR', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var argument = generator.valueToCode(this, 'data', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var code = varName + '.pensize(' + argument + ')\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const turtle_speed = function (_, generator) {
|
||||
generator.definitions_.import_turtle = "import turtle";
|
||||
var varName = generator.valueToCode(this, 'TUR', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var argument = generator.valueToCode(this, 'data', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var code = varName + '.speed(' + argument + ')\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const turtle_circle = function (_, generator) {
|
||||
generator.definitions_.import_turtle = "import turtle";
|
||||
var varName = generator.valueToCode(this, 'TUR', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var circle = this.getFieldValue('DIR');
|
||||
var num = generator.valueToCode(this, 'VAR', generator.ORDER_ATOMIC);
|
||||
var code = varName + "." + circle + "(" + num + ')\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const turtle_setxy = function (_, generator) {
|
||||
generator.definitions_.import_turtle = "import turtle";
|
||||
var varName = generator.valueToCode(this, 'TUR', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var xy = this.getFieldValue('DIR');
|
||||
var num = generator.valueToCode(this, 'VAR', generator.ORDER_ATOMIC);
|
||||
var code = varName + ".set" + xy + "(" + num + ')\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const turtle_circle_advanced = function (_, generator) {
|
||||
generator.definitions_.import_turtle = "import turtle";
|
||||
var varName = generator.valueToCode(this, 'TUR', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var argument = generator.valueToCode(this, 'data', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var num = generator.valueToCode(this, 'VAR', generator.ORDER_ATOMIC);
|
||||
var code = varName + ".circle (" + num + ',' + argument + ')\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const turtle_visible = function (_, generator) {
|
||||
generator.definitions_.import_turtle = "import turtle";
|
||||
var varName = generator.valueToCode(this, 'TUR', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var visible = this.getFieldValue('DIR');
|
||||
var code = varName + "." + visible + "(" + ')\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const turtle_bgcolor = function (_, generator) {
|
||||
generator.definitions_.import_turtle = "import turtle";
|
||||
var color = this.getFieldValue('FIELDNAME');
|
||||
var code = "turtle." + 'bgcolor' + '("' + color + '")\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const turtle_pencolor = function (_, generator) {
|
||||
generator.definitions_.import_turtle = "import turtle";
|
||||
var varName = generator.valueToCode(this, 'TUR', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var color = this.getFieldValue('FIELDNAME');
|
||||
var code = varName + "." + 'pencolor' + '("' + color + '")\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const turtle_fillcolor = function (_, generator) {
|
||||
generator.definitions_.import_turtle = "import turtle";
|
||||
var varName = generator.valueToCode(this, 'TUR', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var color = this.getFieldValue('FIELDNAME');
|
||||
var code = varName + "." + 'fillcolor' + '("' + color + '")\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const turtle_clone = function (_, generator) {
|
||||
generator.definitions_.import_turtle = "import turtle";
|
||||
var varName = generator.valueToCode(this, 'TUR', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var code = varName + '.clone()';
|
||||
return [code, generator.ORDER_ATOMIC];
|
||||
}
|
||||
|
||||
export const turtle_bgcolor_hex = function (_, generator) {
|
||||
generator.definitions_.import_turtle = "import turtle";
|
||||
var color = generator.valueToCode(this, 'VAR', generator.ORDER_ATOMIC);
|
||||
var code = "turtle." + 'bgcolor' + '(' + color + ')\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const turtle_pencolor_hex = function (_, generator) {
|
||||
generator.definitions_.import_turtle = "import turtle";
|
||||
var varName = generator.valueToCode(this, 'TUR', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var color = generator.valueToCode(this, 'VAR', generator.ORDER_ATOMIC);
|
||||
//var color = generator.valueToCode(this, 'data', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var code = varName + "." + 'pencolor' + '(' + color + ')\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const turtle_fillcolor_hex = function (_, generator) {
|
||||
generator.definitions_.import_turtle = "import turtle";
|
||||
var varName = generator.valueToCode(this, 'TUR', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var color = generator.valueToCode(this, 'VAR', generator.ORDER_ATOMIC);
|
||||
var code = varName + "." + 'fillcolor' + '(' + color + ')\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const turtle_bgcolor_hex_new = function (_, generator) {
|
||||
generator.definitions_.import_turtle = "import turtle";
|
||||
var color = generator.valueToCode(this, 'VAR', generator.ORDER_ATOMIC);
|
||||
var code = "turtle." + 'bgcolor' + '(' + color + ')\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const turtle_pencolor_hex_new = function (_, generator) {
|
||||
generator.definitions_.import_turtle = "import turtle";
|
||||
var varName = generator.valueToCode(this, 'TUR', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var color = generator.valueToCode(this, 'VAR', generator.ORDER_ATOMIC);
|
||||
//var color = generator.valueToCode(this, 'data', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var code = varName + "." + 'pencolor' + '(' + color + ')\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const turtle_fillcolor_hex_new = function (_, generator) {
|
||||
generator.definitions_.import_turtle = "import turtle";
|
||||
var varName = generator.valueToCode(this, 'TUR', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var color = generator.valueToCode(this, 'VAR', generator.ORDER_ATOMIC);
|
||||
var code = varName + "." + 'fillcolor' + '(' + color + ')\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const turtle_color_hex = function (_, generator) {
|
||||
generator.definitions_.import_turtle = "import turtle";
|
||||
var varName = generator.valueToCode(this, 'TUR', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var color1 = generator.valueToCode(this, 'VAR1', generator.ORDER_ATOMIC);
|
||||
var color2 = generator.valueToCode(this, 'VAR2', generator.ORDER_ATOMIC);
|
||||
var code = varName + "." + 'color' + '(' + color1 + ',' + color2 + ')\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const turtle_color = function (_, generator) {
|
||||
generator.definitions_.import_turtle = "import turtle";
|
||||
var varName = generator.valueToCode(this, 'TUR', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var color1 = this.getFieldValue('FIELDNAME');
|
||||
var color2 = this.getFieldValue('FIELDNAME2');
|
||||
var code = varName + "." + 'color' + '("' + color1 + '","' + color2 + '")\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const turtle_shape = function (_, generator) {
|
||||
generator.definitions_.import_turtle = "import turtle";
|
||||
var varName = generator.valueToCode(this, 'TUR', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var direction = this.getFieldValue('DIR');
|
||||
|
||||
var code = varName + ".shape('" + direction + "')\n";
|
||||
return code;
|
||||
}
|
||||
|
||||
export const turtle_shapesize = function (_, generator) {
|
||||
generator.definitions_.import_turtle = "import turtle";
|
||||
var varName = generator.valueToCode(this, 'TUR', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var argument1 = generator.valueToCode(this, 'WID', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var argument2 = generator.valueToCode(this, 'LEN', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var argument3 = generator.valueToCode(this, 'OUTLINE', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var code = varName + ".shapesize(" + argument1 + ',' + argument2 + ',' + argument3 + ')\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const turtle_textinput = function (_, generator) {
|
||||
generator.definitions_.import_turtle = "import turtle";
|
||||
var title = generator.valueToCode(this, 'TITLE', generator.ORDER_ATOMIC);
|
||||
var prompt = generator.valueToCode(this, 'PROMPT', generator.ORDER_ATOMIC);
|
||||
var code = "turtle.textinput" + '(' + title + ',' + prompt + ')';
|
||||
return [code, generator.ORDER_ATOMIC];
|
||||
}
|
||||
|
||||
export const turtle_numinput = function (_, generator) {
|
||||
generator.definitions_.import_turtle = "import turtle";
|
||||
var title = generator.valueToCode(this, 'TITLE', generator.ORDER_ATOMIC);
|
||||
var prompt = generator.valueToCode(this, 'PROMPT', generator.ORDER_ATOMIC);
|
||||
var data = generator.valueToCode(this, 'DEFAULT', generator.ORDER_ATOMIC);
|
||||
var min = generator.valueToCode(this, 'MIN', generator.ORDER_ATOMIC);
|
||||
var max = generator.valueToCode(this, 'MAX', generator.ORDER_ATOMIC);
|
||||
var code = "turtle.numinput" + '(' + title + ',' + prompt + "," + data + ',minval = ' + min + ',maxval = ' + max + ')';
|
||||
return [code, generator.ORDER_ATOMIC];
|
||||
}
|
||||
|
||||
export const turtle_write = function (_, generator) {
|
||||
generator.definitions_.import_turtle = "import turtle";
|
||||
var varName = generator.valueToCode(this, 'TUR', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var write = generator.valueToCode(this, 'VAR', generator.ORDER_ATOMIC);
|
||||
//var color = generator.valueToCode(this, 'data', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var code = varName + "." + 'write' + '(' + write + ')\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const turtle_write_format = function (_, generator) {
|
||||
generator.definitions_.import_turtle = "import turtle";
|
||||
var move = this.getFieldValue('MOVE');
|
||||
var align = this.getFieldValue('ALIGN');
|
||||
var fontname = generator.valueToCode(this, 'FONTNAME', generator.ORDER_ATOMIC);
|
||||
var fontnum = generator.valueToCode(this, 'FONTNUM', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var fonttype = this.getFieldValue('FONTTYPE');
|
||||
var varName = generator.valueToCode(this, 'TUR', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var write = generator.valueToCode(this, 'VAR', generator.ORDER_ATOMIC);
|
||||
var code = varName + "." + 'write' + '(' + write + ',' + move + ',align="' + align + '",font=(' + fontname + ',' + fontnum + ',"' + fonttype + '"))\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const turtle_write_format_skulpt = function (_, generator) {
|
||||
generator.definitions_.import_turtle = "import turtle";
|
||||
var move = this.getFieldValue('MOVE');
|
||||
var align = this.getFieldValue('ALIGN');
|
||||
var fontname = generator.valueToCode(this, 'FONTNAME', generator.ORDER_ATOMIC);
|
||||
var fontnum = generator.valueToCode(this, 'FONTNUM', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var fonttype = this.getFieldValue('FONTTYPE');
|
||||
var varName = generator.valueToCode(this, 'TUR', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var write = generator.valueToCode(this, 'VAR', generator.ORDER_ATOMIC);
|
||||
var code = varName + "." + 'write' + '(' + write + ',' + move + ',align="' + align + '",font=(' + fontname + ',' + fontnum + ',"' + fonttype + '"))\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const turtle_color_seclet = function (_, generator) {
|
||||
var colour = this.getFieldValue('COLOR');
|
||||
var code = '"' + colour + '"'
|
||||
return [code, generator.ORDER_ATOMIC];
|
||||
}
|
||||
|
||||
export const turtle_getscreen = function (_, generator) {
|
||||
generator.definitions_.import_turtle = "import turtle";
|
||||
var turName = generator.valueToCode(this, 'TUR', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var varName = generator.variableDB_.getName(this.getFieldValue('VAR'),
|
||||
Blockly.Variables.NAME_TYPE);
|
||||
var code = varName + ' = ' + turName + '.getscreen()\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const turtle_onkey = function (_, generator) {
|
||||
generator.definitions_.import_turtle = "import turtle";
|
||||
var varName = generator.valueToCode(this, 'TUR', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var v = generator.valueToCode(this, "VAR", generator.ORDER_NONE) || "None";
|
||||
var callback = generator.valueToCode(this, "callback", generator.ORDER_NONE) || "None";
|
||||
var code = varName + ".onkey(" + callback + ", " + v + ")\n";
|
||||
return code;
|
||||
}
|
||||
|
||||
export const turtle_onclick = function (_, generator) {
|
||||
generator.definitions_.import_turtle = "import turtle";
|
||||
var varName = generator.valueToCode(this, 'TUR', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var callback = generator.valueToCode(this, "callback", generator.ORDER_NONE) || "None";
|
||||
var code = varName + ".onclick(" + callback + ")\n";
|
||||
return code;
|
||||
}
|
||||
|
||||
export const turtle_ontimer = function (_, generator) {
|
||||
generator.definitions_.import_turtle = "import turtle";
|
||||
var varName = generator.valueToCode(this, 'TUR', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var v = generator.valueToCode(this, "VAR", generator.ORDER_NONE) || "None";
|
||||
var callback = generator.valueToCode(this, "callback", generator.ORDER_NONE) || "None";
|
||||
var code = varName + ".ontimer(" + callback + ", " + v + ")\n";
|
||||
return code;
|
||||
}
|
||||
|
||||
export const turtle_listen = function (_, generator) {
|
||||
generator.definitions_.import_turtle = "import turtle";
|
||||
var varName = generator.valueToCode(this, 'TUR', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var code = varName + '.listen()\n';
|
||||
return code;
|
||||
}
|
||||
|
||||
export const turtle_screen_savefig = function (_, generator) {
|
||||
generator.definitions_.import_turtle = "import turtle";
|
||||
var varName = generator.valueToCode(this, 'TUR', generator.ORDER_ASSIGNMENT) || '0';
|
||||
var file = generator.valueToCode(this, 'FILE', generator.ORDER_ATOMIC);
|
||||
var code = varName + ".getcanvas().postscript(file=" + file + ")\n";
|
||||
return code;
|
||||
}
|
||||
111
boards/default_src/python_skulpt/index.js
Normal file
111
boards/default_src/python_skulpt/index.js
Normal file
@@ -0,0 +1,111 @@
|
||||
import * as Blockly from 'blockly/core';
|
||||
import { Profile } from 'mixly';
|
||||
|
||||
import Variables from '@mixly/python/others/variables';
|
||||
import Procedures from '@mixly/python/others/procedures';
|
||||
import { Python } from '@mixly/python/python_generator';
|
||||
|
||||
import * as PythonVariablesBlocks from '@mixly/python/blocks/variables';
|
||||
import * as PythonControlBlocks from '@mixly/python/blocks/control';
|
||||
import * as PythonMathBlocks from '@mixly/python/blocks/math';
|
||||
import * as PythonTextBlocks from '@mixly/python/blocks/text';
|
||||
import * as PythonListsBlocks from '@mixly/python/blocks/lists';
|
||||
import * as PythonDictsBlocks from '@mixly/python/blocks/dicts';
|
||||
import * as PythonLogicBlocks from '@mixly/python/blocks/logic';
|
||||
import * as PythonStorageBlocks from '@mixly/python/blocks/storage';
|
||||
import * as PythonProceduresBlocks from '@mixly/python/blocks/procedures';
|
||||
import * as PythonTupleBlocks from '@mixly/python/blocks/tuple';
|
||||
import * as PythonSetBlocks from '@mixly/python/blocks/set';
|
||||
import * as PythonHtmlBlocks from '@mixly/python/blocks/html';
|
||||
import * as PythonUtilityBlocks from '@mixly/python/blocks/utility';
|
||||
|
||||
import * as MixPyAlgorithmBlocks from '@mixly/python-mixpy/blocks/algorithm';
|
||||
import * as MixPyFactoryBlocks from '@mixly/python-mixpy/blocks/factory';
|
||||
|
||||
import * as DataBlocks from './blocks/data';
|
||||
import * as InoutBlocks from './blocks/inout';
|
||||
import * as IotBlocks from './blocks/iot';
|
||||
import * as SystemBlocks from './blocks/system';
|
||||
import * as TurtleBlocks from './blocks/turtle';
|
||||
|
||||
import * as PythonVariablesGenerators from '@mixly/python/generators/variables';
|
||||
import * as PythonControlGenerators from '@mixly/python/generators/control';
|
||||
import * as PythonMathGenerators from '@mixly/python/generators/math';
|
||||
import * as PythonTextGenerators from '@mixly/python/generators/text';
|
||||
import * as PythonListsGenerators from '@mixly/python/generators/lists';
|
||||
import * as PythonDictsGenerators from '@mixly/python/generators/dicts';
|
||||
import * as PythonLogicGenerators from '@mixly/python/generators/logic';
|
||||
import * as PythonStorageGenerators from '@mixly/python/generators/storage';
|
||||
import * as PythonProceduresGenerators from '@mixly/python/generators/procedures';
|
||||
import * as PythonTupleGenerators from '@mixly/python/generators/tuple';
|
||||
import * as PythonSetGenerators from '@mixly/python/generators/set';
|
||||
import * as PythonHtmlGenerators from '@mixly/python/generators/html';
|
||||
import * as PythonUtilityGenerators from '@mixly/python/generators/utility';
|
||||
|
||||
import * as MixPyAlgorithmGenerators from '@mixly/python-mixpy/generators/algorithm';
|
||||
import * as MixPyFactoryGenerators from '@mixly/python-mixpy/generators/factory';
|
||||
|
||||
import * as DataGenerators from './generators/data';
|
||||
import * as InoutGenerators from './generators/inout';
|
||||
import * as IotGenerators from './generators/iot';
|
||||
import * as SystemGenerators from './generators/system';
|
||||
import * as TurtleGenerators from './generators/turtle';
|
||||
|
||||
import './others/loader';
|
||||
|
||||
import './css/color_mixpy_python_skulpt.css';
|
||||
|
||||
Object.assign(Blockly.Variables, Variables);
|
||||
Object.assign(Blockly.Procedures, Procedures);
|
||||
Blockly.Python = Python;
|
||||
Blockly.generator = Python;
|
||||
|
||||
Profile.default = {};
|
||||
|
||||
Object.assign(
|
||||
Blockly.Blocks,
|
||||
PythonVariablesBlocks,
|
||||
PythonControlBlocks,
|
||||
PythonMathBlocks,
|
||||
PythonTextBlocks,
|
||||
PythonListsBlocks,
|
||||
PythonDictsBlocks,
|
||||
PythonLogicBlocks,
|
||||
PythonStorageBlocks,
|
||||
PythonProceduresBlocks,
|
||||
PythonTupleBlocks,
|
||||
PythonSetBlocks,
|
||||
PythonHtmlBlocks,
|
||||
PythonUtilityBlocks,
|
||||
MixPyAlgorithmBlocks,
|
||||
MixPyFactoryBlocks,
|
||||
DataBlocks,
|
||||
InoutBlocks,
|
||||
IotBlocks,
|
||||
SystemBlocks,
|
||||
TurtleBlocks
|
||||
);
|
||||
|
||||
Object.assign(
|
||||
Blockly.Python.forBlock,
|
||||
PythonVariablesGenerators,
|
||||
PythonControlGenerators,
|
||||
PythonMathGenerators,
|
||||
PythonTextGenerators,
|
||||
PythonListsGenerators,
|
||||
PythonDictsGenerators,
|
||||
PythonLogicGenerators,
|
||||
PythonStorageGenerators,
|
||||
PythonProceduresGenerators,
|
||||
PythonTupleGenerators,
|
||||
PythonSetGenerators,
|
||||
PythonHtmlGenerators,
|
||||
PythonUtilityGenerators,
|
||||
MixPyAlgorithmGenerators,
|
||||
MixPyFactoryGenerators,
|
||||
DataGenerators,
|
||||
InoutGenerators,
|
||||
IotGenerators,
|
||||
SystemGenerators,
|
||||
TurtleGenerators
|
||||
);
|
||||
13
boards/default_src/python_skulpt/origin/config.json
Normal file
13
boards/default_src/python_skulpt/origin/config.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"language": "Python",
|
||||
"nav": {
|
||||
"webrun": true,
|
||||
"webcancel": true,
|
||||
"save": {
|
||||
"py": true
|
||||
},
|
||||
"setting": {
|
||||
"pythonToBlockly": true
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<xml version="Mixly 2.0 rc4" board="Python 3 Lite@Python 3 Lite"><block type="turtle_create" id="=@#u4aYXP9.hp(aSHJO;" x="-1125" y="-607"><field name="VAR">tina</field><next><block type="turtle_move" id="kheNktzo1.$[X0D5u?Pb"><field name="DIR">forward</field><value name="TUR"><shadow type="variables_get" id="P5,i)O#t^Zr:/bll34g?"><field name="VAR">tina</field></shadow></value><value name="VAR"><shadow type="math_number" id="IK^z*mT}z3/HTf#M4)lj"><field name="NUM">20</field></shadow></value><next><block type="turtle_rotate" id="^kPxO/fTK^L.kez#U-1$"><field name="DIR">left</field><value name="TUR"><shadow type="variables_get" id="wV]N-MOK!~i@XdXGIEXO"><field name="VAR">tina</field></shadow></value><value name="VAR"><shadow type="math_number" id="n12x/S:;S9lOCu3#D;MU"><field name="NUM">90</field></shadow></value></block></next></block></next></block></xml><config>{}</config><code>aW1wb3J0IHR1cnRsZQoKCnRpbmEgPSB0dXJ0bGUuVHVydGxlKCkKdGluYS5mb3J3YXJkKDIwKQp0aW5hLmxlZnQoOTApCg==</code>
|
||||
@@ -0,0 +1 @@
|
||||
<xml version="Mixly 2.0 rc4" board="Python 3 Lite@Python 3 Lite"><block type="turtle_create" id="7G$V;q*l4L2X7cNi,~rY" x="-1349" y="-756"><field name="VAR">tina</field><next><block type="turtle_move" id="!LyfdvBw*,iXRt.Ju2Wx"><field name="DIR">forward</field><value name="TUR"><shadow type="variables_get" id="~s;XoGA^#~PKxwrk+{#D"><field name="VAR">tina</field></shadow></value><value name="VAR"><shadow type="math_number" id="W4RjNdGLsSnT(j=^lQ;J"><field name="NUM">100</field></shadow></value><next><block type="turtle_rotate" id="Mb}Qg1;yS{yk7}z9qUx-"><field name="DIR">left</field><value name="TUR"><shadow type="variables_get" id="cX]*bHg?UxXJLtP(uGPy"><field name="VAR">tina</field></shadow></value><value name="VAR"><shadow type="math_number" id="#V4V9HI$zJiA|EkR8]Pj"><field name="NUM">90</field></shadow></value><next><block type="turtle_move" id="UPJ.g/_vCmsZ9vwj*C7;"><field name="DIR">forward</field><value name="TUR"><shadow type="variables_get" id="_Z.5Zt#y52vdaTC9zGu,"><field name="VAR">tina</field></shadow></value><value name="VAR"><shadow type="math_number" id="fa$-l(G22BefW-|}t{u4"><field name="NUM">100</field></shadow></value><next><block type="turtle_rotate" id="f1~e@Gz_A*0M?hSVf_Au"><field name="DIR">left</field><value name="TUR"><shadow type="variables_get" id="~B23]GW0hDx,JnD0)_1z"><field name="VAR">tina</field></shadow></value><value name="VAR"><shadow type="math_number" id="t49BA^0Ah0dB=sa)qtV?"><field name="NUM">90</field></shadow></value><next><block type="turtle_move" id="f[h|t.1~*i|i|vxRN)iu"><field name="DIR">forward</field><value name="TUR"><shadow type="variables_get" id="MEO6SK~LI~-)3[==Fzb;"><field name="VAR">tina</field></shadow></value><value name="VAR"><shadow type="math_number" id="6*,{g/gms!$`_~j$3EVj"><field name="NUM">100</field></shadow></value><next><block type="turtle_rotate" id="*1Y@QW+{aSn2NCaOQ(D,"><field name="DIR">left</field><value name="TUR"><shadow type="variables_get" id="bfN1.)Xf+X4W*WEXRm1X"><field name="VAR">tina</field></shadow></value><value name="VAR"><shadow type="math_number" id="4ZEOiauOA4wh|j3sB;/7"><field name="NUM">90</field></shadow></value><next><block type="turtle_move" id="hv=Iwt=!U-~]qPEFN/NZ"><field name="DIR">forward</field><value name="TUR"><shadow type="variables_get" id="-m#GNhAwjyqI~5P]z[)p"><field name="VAR">tina</field></shadow></value><value name="VAR"><shadow type="math_number" id="^qV6#lc/S~#?9W-qbO@]"><field name="NUM">100</field></shadow></value></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></xml><config>{}</config><code>aW1wb3J0IHR1cnRsZQoKCnRpbmEgPSB0dXJ0bGUuVHVydGxlKCkKdGluYS5mb3J3YXJkKDEwMCkKdGluYS5sZWZ0KDkwKQp0aW5hLmZvcndhcmQoMTAwKQp0aW5hLmxlZnQoOTApCnRpbmEuZm9yd2FyZCgxMDApCnRpbmEubGVmdCg5MCkKdGluYS5mb3J3YXJkKDEwMCkK</code>
|
||||
@@ -0,0 +1 @@
|
||||
<xml version="Mixly 2.0 rc4" board="Python 3 Lite@Python 3 Lite"><block type="turtle_create" id="7G$V;q*l4L2X7cNi,~rY" x="-1390" y="-780"><field name="VAR">tina</field><next><block type="controls_repeat_ext" id="a~81+TwxRAL~n,~CP2l]"><value name="TIMES"><shadow type="math_number" id="-YAV~TkXp6#aW48hid;!"><field name="NUM">4</field></shadow></value><statement name="DO"><block type="turtle_rotate" id="*1Y@QW+{aSn2NCaOQ(D,"><field name="DIR">left</field><value name="TUR"><shadow type="variables_get" id="bfN1.)Xf+X4W*WEXRm1X"><field name="VAR">tina</field></shadow></value><value name="VAR"><shadow type="math_number" id="4ZEOiauOA4wh|j3sB;/7"><field name="NUM">90</field></shadow></value><next><block type="turtle_move" id="hv=Iwt=!U-~]qPEFN/NZ"><field name="DIR">forward</field><value name="TUR"><shadow type="variables_get" id="-m#GNhAwjyqI~5P]z[)p"><field name="VAR">tina</field></shadow></value><value name="VAR"><shadow type="math_number" id="^qV6#lc/S~#?9W-qbO@]"><field name="NUM">100</field></shadow></value></block></next></block></statement></block></next></block></xml><config>{}</config><code>aW1wb3J0IHR1cnRsZQoKCnRpbmEgPSB0dXJ0bGUuVHVydGxlKCkKZm9yIF9teV92YXJpYWJsZSBpbiByYW5nZSg0KToKICAgIHRpbmEubGVmdCg5MCkKICAgIHRpbmEuZm9yd2FyZCgxMDApCg==</code>
|
||||
@@ -0,0 +1 @@
|
||||
<xml version="Mixly 2.0 rc4" board="Python 3 Lite@Python 3 Lite"><block type="turtle_create" id="7G$V;q*l4L2X7cNi,~rY" x="-1390" y="-780"><field name="VAR">tina</field><next><block type="variables_set" id="7$yFOQiZD1hZ8p+r`(o)"><field name="VAR">n</field><value name="VALUE"><block type="math_number" id=",XMuie_Vj77[]$..+,:y"><field name="NUM">40</field></block></value><next><block type="controls_repeat_ext" id="a~81+TwxRAL~n,~CP2l]"><value name="TIMES"><shadow type="math_number" id="-YAV~TkXp6#aW48hid;!"><field name="NUM">4</field></shadow><block type="variables_get" id="JAf#XJ0:;`9n~9(_w`u0"><field name="VAR">n</field></block></value><statement name="DO"><block type="turtle_rotate" id="*1Y@QW+{aSn2NCaOQ(D,"><field name="DIR">left</field><value name="TUR"><shadow type="variables_get" id="bfN1.)Xf+X4W*WEXRm1X"><field name="VAR">tina</field></shadow></value><value name="VAR"><shadow type="math_number" id="4ZEOiauOA4wh|j3sB;/7"><field name="NUM">90</field></shadow><block type="math_arithmetic" id="uSTyrqq5PkfZyHQ9lusk"><field name="OP">DIVIDE</field><value name="A"><shadow type="math_number" id="I{I*0Kt.x8VDs85;4fX4"><field name="NUM">360</field></shadow></value><value name="B"><shadow type="math_number" id="bjq4Woz[YQv*:zr7gD,5"><field name="NUM">1</field></shadow><block type="variables_get" id="T{NNi9{sqgVUXS^Scf`j"><field name="VAR">n</field></block></value></block></value><next><block type="turtle_move" id="hv=Iwt=!U-~]qPEFN/NZ"><field name="DIR">forward</field><value name="TUR"><shadow type="variables_get" id="-m#GNhAwjyqI~5P]z[)p"><field name="VAR">tina</field></shadow></value><value name="VAR"><shadow type="math_number" id="^qV6#lc/S~#?9W-qbO@]"><field name="NUM">50</field></shadow><block type="math_arithmetic" id="`Dw8#mpj*2|n_xf-:C5]"><field name="OP">DIVIDE</field><value name="A"><shadow type="math_number" id="GJse|NNKvrMzxq|Tin(."><field name="NUM">400</field></shadow></value><value name="B"><shadow type="math_number" id="bjq4Woz[YQv*:zr7gD,5"><field name="NUM">1</field></shadow><block type="variables_get" id="u::zn@vviHACugMK1@i*"><field name="VAR">n</field></block></value></block></value></block></next></block></statement></block></next></block></next></block></xml><config>{}</config><code>aW1wb3J0IHR1cnRsZQoKCnRpbmEgPSB0dXJ0bGUuVHVydGxlKCkKbiA9IDQwCmZvciBfbXlfdmFyaWFibGUgaW4gcmFuZ2Uobik6CiAgICB0aW5hLmxlZnQoKDM2MCAvIG4pKQogICAgdGluYS5mb3J3YXJkKCg0MDAgLyBuKSkK</code>
|
||||
@@ -0,0 +1 @@
|
||||
<xml version="Mixly 2.0 rc4" board="Python 3 Lite@Python 3 Lite"><block type="turtle_create" id="7G$V;q*l4L2X7cNi,~rY" x="-1390" y="-780"><field name="VAR">tina</field><next><block type="variables_set" id="7$yFOQiZD1hZ8p+r`(o)"><field name="VAR">n</field><value name="VALUE"><block type="inout_type_input" id="NE.to-NY`WKnh#R,!b8N"><field name="DIR">int</field><value name="VAR"><shadow type="text" id="9S+5hQ(AM)V?KJWP(Xbc"><field name="TEXT">请输入边数:</field></shadow></value></block></value><next><block type="controls_repeat_ext" id="a~81+TwxRAL~n,~CP2l]"><value name="TIMES"><shadow type="math_number" id="-YAV~TkXp6#aW48hid;!"><field name="NUM">4</field></shadow><block type="variables_get" id="JAf#XJ0:;`9n~9(_w`u0"><field name="VAR">n</field></block></value><statement name="DO"><block type="turtle_rotate" id="*1Y@QW+{aSn2NCaOQ(D,"><field name="DIR">left</field><value name="TUR"><shadow type="variables_get" id="bfN1.)Xf+X4W*WEXRm1X"><field name="VAR">tina</field></shadow></value><value name="VAR"><shadow type="math_number" id="4ZEOiauOA4wh|j3sB;/7"><field name="NUM">90</field></shadow><block type="math_arithmetic" id="uSTyrqq5PkfZyHQ9lusk"><field name="OP">DIVIDE</field><value name="A"><shadow type="math_number" id="I{I*0Kt.x8VDs85;4fX4"><field name="NUM">360</field></shadow></value><value name="B"><shadow type="math_number" id="bjq4Woz[YQv*:zr7gD,5"><field name="NUM">1</field></shadow><block type="variables_get" id="T{NNi9{sqgVUXS^Scf`j"><field name="VAR">n</field></block></value></block></value><next><block type="turtle_move" id="hv=Iwt=!U-~]qPEFN/NZ"><field name="DIR">forward</field><value name="TUR"><shadow type="variables_get" id="-m#GNhAwjyqI~5P]z[)p"><field name="VAR">tina</field></shadow></value><value name="VAR"><shadow type="math_number" id="^qV6#lc/S~#?9W-qbO@]"><field name="NUM">50</field></shadow><block type="math_arithmetic" id="`Dw8#mpj*2|n_xf-:C5]"><field name="OP">DIVIDE</field><value name="A"><shadow type="math_number" id="GJse|NNKvrMzxq|Tin(."><field name="NUM">400</field></shadow></value><value name="B"><shadow type="math_number" id="bjq4Woz[YQv*:zr7gD,5"><field name="NUM">1</field></shadow><block type="variables_get" id="u::zn@vviHACugMK1@i*"><field name="VAR">n</field></block></value></block></value></block></next></block></statement></block></next></block></next></block></xml><config>{}</config><code>aW1wb3J0IHR1cnRsZQoKCnRpbmEgPSB0dXJ0bGUuVHVydGxlKCkKbiA9IGludChpbnB1dCgn6K+36L6T5YWl6L655pWw77yaJykpCmZvciBfbXlfdmFyaWFibGUgaW4gcmFuZ2Uobik6CiAgICB0aW5hLmxlZnQoKDM2MCAvIG4pKQogICAgdGluYS5mb3J3YXJkKCg0MDAgLyBuKSkK</code>
|
||||
@@ -0,0 +1 @@
|
||||
<xml version="Mixly 2.0 rc4" board="Python 3 Lite@Python 3 Lite"><block type="turtle_create" id="7G$V;q*l4L2X7cNi,~rY" x="-1459" y="-814"><field name="VAR">tina</field><next><block type="turtle_pencolor_hex_new" id="eRmf?!AyIXHb[uZphKUr"><value name="TUR"><shadow type="variables_get" id="f+,m(R8*9w{`K?K2bB.b"><field name="VAR">tina</field></shadow></value><value name="VAR"><shadow type="text" id=";uw+4^BRE2Ieda?z[bn_"><field name="TEXT">#FF0000</field></shadow><block type="turtle_color_seclet" id="YokoU#KBs*g|kGqO]SOz"><field name="COLOR">#ff0000</field></block></value><next><block type="turtle_size" id="joXG?0oK8REoEr*ng?pA"><value name="TUR"><shadow type="variables_get" id="/1X7(]3yHvP}-|8c=vga"><field name="VAR">tina</field></shadow></value><value name="data"><shadow type="math_number" id="$i2k5]t3G^/radVFsmui"><field name="NUM">5</field></shadow></value><next><block type="controls_repeat_ext" id="a~81+TwxRAL~n,~CP2l]"><value name="TIMES"><shadow type="math_number" id="-YAV~TkXp6#aW48hid;!"><field name="NUM">5</field></shadow></value><statement name="DO"><block type="turtle_move" id="hv=Iwt=!U-~]qPEFN/NZ"><field name="DIR">forward</field><value name="TUR"><shadow type="variables_get" id="-m#GNhAwjyqI~5P]z[)p"><field name="VAR">tina</field></shadow></value><value name="VAR"><shadow type="math_number" id="^qV6#lc/S~#?9W-qbO@]"><field name="NUM">100</field></shadow></value><next><block type="turtle_rotate" id="*1Y@QW+{aSn2NCaOQ(D,"><field name="DIR">right</field><value name="TUR"><shadow type="variables_get" id="bfN1.)Xf+X4W*WEXRm1X"><field name="VAR">tina</field></shadow></value><value name="VAR"><shadow type="math_number" id="4ZEOiauOA4wh|j3sB;/7"><field name="NUM">144</field></shadow></value></block></next></block></statement></block></next></block></next></block></next></block></xml><config>{}</config><code>aW1wb3J0IHR1cnRsZQoKCnRpbmEgPSB0dXJ0bGUuVHVydGxlKCkKdGluYS5wZW5jb2xvcigiI2ZmMDAwMCIpCnRpbmEucGVuc2l6ZSg1KQpmb3IgX215X3ZhcmlhYmxlIGluIHJhbmdlKDUpOgogICAgdGluYS5mb3J3YXJkKDEwMCkKICAgIHRpbmEucmlnaHQoMTQ0KQo=</code>
|
||||
@@ -0,0 +1 @@
|
||||
<xml version="Mixly 2.0 rc4" board="Python 3 Lite@Python 3 Lite"><block type="turtle_create" id="7G$V;q*l4L2X7cNi,~rY" x="-1459" y="-814"><field name="VAR">tina</field><next><block type="turtle_pencolor_hex_new" id="eRmf?!AyIXHb[uZphKUr"><value name="TUR"><shadow type="variables_get" id="f+,m(R8*9w{`K?K2bB.b"><field name="VAR">tina</field></shadow></value><value name="VAR"><shadow type="text" id=";uw+4^BRE2Ieda?z[bn_"><field name="TEXT">#FF0000</field></shadow><block type="turtle_color_seclet" id="YokoU#KBs*g|kGqO]SOz"><field name="COLOR">#ff0000</field></block></value><next><block type="turtle_fillcolor_hex_new" id="D!)L#PPo~Nz|^kz-qe2D"><value name="TUR"><shadow type="variables_get" id="67*o|,s1vhv7w;8HVgR$"><field name="VAR">tina</field></shadow></value><value name="VAR"><shadow type="text" id="cU`N^jH+RE$+2at1`Daj"><field name="TEXT">#FF0000</field></shadow><block type="turtle_color_seclet" id="wkzc/#ky2}HO8tCCY#$i"><field name="COLOR">#ff0000</field></block></value><next><block type="turtle_size" id="joXG?0oK8REoEr*ng?pA"><value name="TUR"><shadow type="variables_get" id="/1X7(]3yHvP}-|8c=vga"><field name="VAR">tina</field></shadow></value><value name="data"><shadow type="math_number" id="$i2k5]t3G^/radVFsmui"><field name="NUM">5</field></shadow></value><next><block type="turtle_fill" id=")F2ek~U/kK+dkKcCjT#b"><field name="DIR">begin</field><value name="TUR"><shadow type="variables_get" id="^82L{QYUFkmz]fD!g5wc"><field name="VAR">tina</field></shadow></value><next><block type="controls_repeat_ext" id="a~81+TwxRAL~n,~CP2l]"><value name="TIMES"><shadow type="math_number" id="-YAV~TkXp6#aW48hid;!"><field name="NUM">5</field></shadow></value><statement name="DO"><block type="turtle_move" id="hv=Iwt=!U-~]qPEFN/NZ"><field name="DIR">forward</field><value name="TUR"><shadow type="variables_get" id="-m#GNhAwjyqI~5P]z[)p"><field name="VAR">tina</field></shadow></value><value name="VAR"><shadow type="math_number" id="^qV6#lc/S~#?9W-qbO@]"><field name="NUM">100</field></shadow></value><next><block type="turtle_rotate" id="*1Y@QW+{aSn2NCaOQ(D,"><field name="DIR">right</field><value name="TUR"><shadow type="variables_get" id="bfN1.)Xf+X4W*WEXRm1X"><field name="VAR">tina</field></shadow></value><value name="VAR"><shadow type="math_number" id="4ZEOiauOA4wh|j3sB;/7"><field name="NUM">144</field></shadow></value></block></next></block></statement><next><block type="turtle_fill" id="H(nEbxtS.^94C_l}?|}0"><field name="DIR">end</field><value name="TUR"><shadow type="variables_get" id="?Cn7z)5e22v3*epbmC_l"><field name="VAR">tina</field></shadow></value></block></next></block></next></block></next></block></next></block></next></block></next></block></xml><config>{}</config><code>aW1wb3J0IHR1cnRsZQoKCnRpbmEgPSB0dXJ0bGUuVHVydGxlKCkKdGluYS5wZW5jb2xvcigiI2ZmMDAwMCIpCnRpbmEuZmlsbGNvbG9yKCIjZmYwMDAwIikKdGluYS5wZW5zaXplKDUpCnRpbmEuYmVnaW5fZmlsbCgpCmZvciBfbXlfdmFyaWFibGUgaW4gcmFuZ2UoNSk6CiAgICB0aW5hLmZvcndhcmQoMTAwKQogICAgdGluYS5yaWdodCgxNDQpCnRpbmEuZW5kX2ZpbGwoKQo=</code>
|
||||
@@ -0,0 +1 @@
|
||||
<xml version="Mixly 2.0 rc4" board="Python 3 Lite@Python 3 Lite"><block type="turtle_create" id="7G$V;q*l4L2X7cNi,~rY" x="-1499" y="-936"><field name="VAR">tina</field><next><block type="turtle_visible" id="d{7/!V(oYtnkS{{qi7Lw"><field name="DIR">hideturtle</field><value name="TUR"><shadow type="variables_get" id="!l,mc;1/s~-U_1_w;L;("><field name="VAR">tina</field></shadow></value><next><block type="turtle_pencolor_hex_new" id="eRmf?!AyIXHb[uZphKUr"><value name="TUR"><shadow type="variables_get" id="f+,m(R8*9w{`K?K2bB.b"><field name="VAR">tina</field></shadow></value><value name="VAR"><shadow type="text" id=";uw+4^BRE2Ieda?z[bn_"><field name="TEXT">#FF0000</field></shadow><block type="turtle_color_seclet" id="YokoU#KBs*g|kGqO]SOz"><field name="COLOR">#ff0000</field></block></value><next><block type="turtle_size" id="joXG?0oK8REoEr*ng?pA"><value name="TUR"><shadow type="variables_get" id="/1X7(]3yHvP}-|8c=vga"><field name="VAR">tina</field></shadow></value><value name="data"><shadow type="math_number" id="$i2k5]t3G^/radVFsmui"><field name="NUM">5</field></shadow></value><next><block type="turtle_setheading" id="8EBCyFgj^=;qHpPp}+`J"><value name="TUR"><shadow type="variables_get" id="Vm`YNJIef~|**315gJKX"><field name="VAR">tina</field></shadow></value><value name="data"><shadow type="math_number" id="MYe3QmB{@BWv1Gf2;m2w"><field name="NUM">135</field></shadow></value><next><block type="turtle_circle_advanced" id="7`,)T2d_71LSc6YR,^=O"><value name="TUR"><shadow type="variables_get" id="P8m=wcryQa)3.G#Y9cJp"><field name="VAR">tina</field></shadow></value><value name="VAR"><shadow type="math_number" id="8V0S;$Q7+zmz6I,5^khN"><field name="NUM">50</field></shadow></value><value name="data"><shadow type="math_number" id=".yDAWgxRTwZUm|ijSsrJ"><field name="NUM">180</field></shadow></value><next><block type="turtle_move" id="hv=Iwt=!U-~]qPEFN/NZ"><field name="DIR">forward</field><value name="TUR"><shadow type="variables_get" id="-m#GNhAwjyqI~5P]z[)p"><field name="VAR">tina</field></shadow></value><value name="VAR"><shadow type="math_number" id="^qV6#lc/S~#?9W-qbO@]"><field name="NUM">100</field></shadow></value><next><block type="turtle_setheading" id="6iDv/jZc77Ju/+HAho8w"><value name="TUR"><shadow type="variables_get" id="NUP9~qX8jLdZ]~DnY3t{"><field name="VAR">tina</field></shadow></value><value name="data"><shadow type="math_number" id="BPh,YY[ov#GP[,i{WX/y"><field name="NUM">45</field></shadow></value><next><block type="turtle_move" id="e,n2*KDD+CWVL56h2ZT@"><field name="DIR">forward</field><value name="TUR"><shadow type="variables_get" id="d8W*s^-m|!WjABjAQq=K"><field name="VAR">tina</field></shadow></value><value name="VAR"><shadow type="math_number" id="a=`O.$E=:2fN?Sl#1LlW"><field name="NUM">100</field></shadow></value><next><block type="turtle_circle_advanced" id="CqkZ[*|R8!N!_^^WxO6i"><value name="TUR"><shadow type="variables_get" id="7xj/R@xN;`m*NJ,rK+w|"><field name="VAR">tina</field></shadow></value><value name="VAR"><shadow type="math_number" id="_4ryR_WGnQ^OZ~l*uDv|"><field name="NUM">50</field></shadow></value><value name="data"><shadow type="math_number" id="*T1L,K|nY~|42FafC9)4"><field name="NUM">180</field></shadow></value></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></xml><config>{}</config><code>aW1wb3J0IHR1cnRsZQoKCnRpbmEgPSB0dXJ0bGUuVHVydGxlKCkKdGluYS5oaWRldHVydGxlKCkKdGluYS5wZW5jb2xvcigiI2ZmMDAwMCIpCnRpbmEucGVuc2l6ZSg1KQp0aW5hLnNldGhlYWRpbmcoMTM1KQp0aW5hLmNpcmNsZSAoNTAsMTgwKQp0aW5hLmZvcndhcmQoMTAwKQp0aW5hLnNldGhlYWRpbmcoNDUpCnRpbmEuZm9yd2FyZCgxMDApCnRpbmEuY2lyY2xlICg1MCwxODApCg==</code>
|
||||
@@ -0,0 +1 @@
|
||||
<xml version="Mixly 2.0 rc4" board="Python 3 Lite@Python 3 Lite"><block type="turtle_create" id="7G$V;q*l4L2X7cNi,~rY" x="-1499" y="-936"><field name="VAR">tina</field><next><block type="turtle_visible" id="d{7/!V(oYtnkS{{qi7Lw"><field name="DIR">hideturtle</field><value name="TUR"><shadow type="variables_get" id="!l,mc;1/s~-U_1_w;L;("><field name="VAR">tina</field></shadow></value><next><block type="turtle_pencolor_hex_new" id="eRmf?!AyIXHb[uZphKUr"><value name="TUR"><shadow type="variables_get" id="f+,m(R8*9w{`K?K2bB.b"><field name="VAR">tina</field></shadow></value><value name="VAR"><shadow type="text" id=";uw+4^BRE2Ieda?z[bn_"><field name="TEXT">#FF0000</field></shadow><block type="turtle_color_seclet" id="YokoU#KBs*g|kGqO]SOz"><field name="COLOR">#ff0000</field></block></value><next><block type="turtle_fillcolor_hex_new" id="tNQ^MXEZ4`2q@vn@ScSi"><value name="TUR"><shadow type="variables_get" id="OOXZU^fyhr,,mI$,+f}7"><field name="VAR">tina</field></shadow></value><value name="VAR"><shadow type="text" id="_f/TBI~xQm6@od!^;nz:"><field name="TEXT">#FF0000</field></shadow><block type="turtle_color_seclet" id=":R+ts[2{lj/m(,O0Rr9O"><field name="COLOR">#ff6666</field></block></value><next><block type="turtle_fill" id=").xDdIuZ(D2C~]cm1GD*"><field name="DIR">begin</field><value name="TUR"><shadow type="variables_get" id="Ncbm_j1.vP;gI+wQP0=Y"><field name="VAR">tina</field></shadow></value><next><block type="turtle_size" id="joXG?0oK8REoEr*ng?pA"><value name="TUR"><shadow type="variables_get" id="/1X7(]3yHvP}-|8c=vga"><field name="VAR">tina</field></shadow></value><value name="data"><shadow type="math_number" id="$i2k5]t3G^/radVFsmui"><field name="NUM">5</field></shadow></value><next><block type="turtle_setheading" id="8EBCyFgj^=;qHpPp}+`J"><value name="TUR"><shadow type="variables_get" id="Vm`YNJIef~|**315gJKX"><field name="VAR">tina</field></shadow></value><value name="data"><shadow type="math_number" id="MYe3QmB{@BWv1Gf2;m2w"><field name="NUM">135</field></shadow></value><next><block type="turtle_circle_advanced" id="7`,)T2d_71LSc6YR,^=O"><value name="TUR"><shadow type="variables_get" id="P8m=wcryQa)3.G#Y9cJp"><field name="VAR">tina</field></shadow></value><value name="VAR"><shadow type="math_number" id="8V0S;$Q7+zmz6I,5^khN"><field name="NUM">50</field></shadow></value><value name="data"><shadow type="math_number" id=".yDAWgxRTwZUm|ijSsrJ"><field name="NUM">180</field></shadow></value><next><block type="turtle_move" id="hv=Iwt=!U-~]qPEFN/NZ"><field name="DIR">forward</field><value name="TUR"><shadow type="variables_get" id="-m#GNhAwjyqI~5P]z[)p"><field name="VAR">tina</field></shadow></value><value name="VAR"><shadow type="math_number" id="^qV6#lc/S~#?9W-qbO@]"><field name="NUM">100</field></shadow></value><next><block type="turtle_setheading" id="6iDv/jZc77Ju/+HAho8w"><value name="TUR"><shadow type="variables_get" id="NUP9~qX8jLdZ]~DnY3t{"><field name="VAR">tina</field></shadow></value><value name="data"><shadow type="math_number" id="BPh,YY[ov#GP[,i{WX/y"><field name="NUM">45</field></shadow></value><next><block type="turtle_move" id="e,n2*KDD+CWVL56h2ZT@"><field name="DIR">forward</field><value name="TUR"><shadow type="variables_get" id="d8W*s^-m|!WjABjAQq=K"><field name="VAR">tina</field></shadow></value><value name="VAR"><shadow type="math_number" id="a=`O.$E=:2fN?Sl#1LlW"><field name="NUM">100</field></shadow></value><next><block type="turtle_circle_advanced" id="CqkZ[*|R8!N!_^^WxO6i"><value name="TUR"><shadow type="variables_get" id="7xj/R@xN;`m*NJ,rK+w|"><field name="VAR">tina</field></shadow></value><value name="VAR"><shadow type="math_number" id="_4ryR_WGnQ^OZ~l*uDv|"><field name="NUM">50</field></shadow></value><value name="data"><shadow type="math_number" id="*T1L,K|nY~|42FafC9)4"><field name="NUM">180</field></shadow></value><next><block type="turtle_fill" id="2rrFLb/#9:uaW+ckGK^G"><field name="DIR">end</field><value name="TUR"><shadow type="variables_get" id="=QX12.uE`.btwZY[v|I,"><field name="VAR">tina</field></shadow></value></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></xml><config>{}</config><code>aW1wb3J0IHR1cnRsZQoKCnRpbmEgPSB0dXJ0bGUuVHVydGxlKCkKdGluYS5oaWRldHVydGxlKCkKdGluYS5wZW5jb2xvcigiI2ZmMDAwMCIpCnRpbmEuZmlsbGNvbG9yKCIjZmY2NjY2IikKdGluYS5iZWdpbl9maWxsKCkKdGluYS5wZW5zaXplKDUpCnRpbmEuc2V0aGVhZGluZygxMzUpCnRpbmEuY2lyY2xlICg1MCwxODApCnRpbmEuZm9yd2FyZCgxMDApCnRpbmEuc2V0aGVhZGluZyg0NSkKdGluYS5mb3J3YXJkKDEwMCkKdGluYS5jaXJjbGUgKDUwLDE4MCkKdGluYS5lbmRfZmlsbCgpCg==</code>
|
||||
@@ -0,0 +1 @@
|
||||
<xml version="Mixly 2.0 rc4" board="Python 3 Lite@Python 3 Lite"><block type="turtle_create" id="7G$V;q*l4L2X7cNi,~rY" x="-1412" y="-825"><field name="VAR">tina</field><next><block type="controls_forEach" id="_$I:llo_l,5n4pf.pP/{"><value name="LIST"><shadow type="list_many_input" id="pQY$+/^3^+rnPDp3vFK3"><field name="CONTENT">0,1,2,3</field></shadow><block type="controls_range" id="W9Np02rPjO;MrdYGZjT8"><value name="FROM"><shadow type="math_number" id="TJ^?zN8|#jJT)DUDANE*"><field name="NUM">5</field></shadow></value><value name="TO"><shadow type="math_number" id="[on[P5k.jZ-N1~a_a3i{"><field name="NUM">150</field></shadow></value><value name="STEP"><shadow type="math_number" id="2H;eiQ1]Ju:_AMFc{G6I"><field name="NUM">5</field></shadow></value></block></value><value name="VAR"><shadow type="variables_get" id="ZvM_,1j*hwK~{_(@9^A]"><field name="VAR">i</field></shadow></value><statement name="DO"><block type="turtle_move" id="zY||bR$Hz*S:n]lN,c#b"><field name="DIR">forward</field><value name="TUR"><shadow type="variables_get" id="jxxhS8PlZbj!H~Dn[@Wx"><field name="VAR">tina</field></shadow></value><value name="VAR"><shadow type="math_number" id="o4[5yiS6e8CUk/w#f?8U"><field name="NUM">20</field></shadow><block type="variables_get" id="@zKKd;)BH8B)mHh{Q`BD"><field name="VAR">i</field></block></value><next><block type="turtle_rotate" id="p77_/D8tok]i7#]7N_.R"><field name="DIR">left</field><value name="TUR"><shadow type="variables_get" id="GG2}{#jzL-l15C@KOuOu"><field name="VAR">tina</field></shadow></value><value name="VAR"><shadow type="math_number" id="OTaF@T?^jragBCX=bHzW"><field name="NUM">90</field></shadow></value></block></next></block></statement></block></next></block></xml><config>{}</config><code>aW1wb3J0IHR1cnRsZQoKCnRpbmEgPSB0dXJ0bGUuVHVydGxlKCkKZm9yIGkgaW4gcmFuZ2UoNSwgMTUwLCA1KToKICAgIHRpbmEuZm9yd2FyZChpKQogICAgdGluYS5sZWZ0KDkwKQo=</code>
|
||||
@@ -0,0 +1 @@
|
||||
<xml version="Mixly 2.0 rc4" board="Python 3 Lite@Python 3 Lite"><block type="turtle_create" id="7G$V;q*l4L2X7cNi,~rY" x="-1412" y="-825"><field name="VAR">tina</field><next><block type="turtle_speed" id="Q3w4~Gfn@-ZX]c5ZVz|d"><value name="TUR"><shadow type="variables_get" id="30:kYcMj^,zMbp6JL(XB"><field name="VAR">tina</field></shadow></value><value name="data"><shadow type="math_number" id="9{@jMJ6zJyo(e(p)|^mA"><field name="NUM">0</field></shadow></value><next><block type="controls_forEach" id="_$I:llo_l,5n4pf.pP/{"><value name="LIST"><shadow type="list_many_input" id="pQY$+/^3^+rnPDp3vFK3"><field name="CONTENT">0,1,2,3</field></shadow><block type="controls_range" id="W9Np02rPjO;MrdYGZjT8"><value name="FROM"><shadow type="math_number" id="TJ^?zN8|#jJT)DUDANE*"><field name="NUM">5</field></shadow></value><value name="TO"><shadow type="math_number" id="[on[P5k.jZ-N1~a_a3i{"><field name="NUM">150</field></shadow></value><value name="STEP"><shadow type="math_number" id="2H;eiQ1]Ju:_AMFc{G6I"><field name="NUM">5</field></shadow></value></block></value><value name="VAR"><shadow type="variables_get" id="ZvM_,1j*hwK~{_(@9^A]"><field name="VAR">i</field></shadow></value><statement name="DO"><block type="turtle_circle_advanced" id="r8$`~,OHwhpVn^EBG)H1"><value name="TUR"><shadow type="variables_get" id="j/_xh#Ve(Rz)m=,]s){)"><field name="VAR">tina</field></shadow></value><value name="VAR"><shadow type="math_number" id="_Tm.CWB^ov*CVw0h{ejp"><field name="NUM">50</field></shadow><block type="variables_get" id="[N-5Z}1v()BBv#_ivlZ/"><field name="VAR">i</field></block></value><value name="data"><shadow type="math_number" id="h8r/^T#7!]#fzmP;C]te"><field name="NUM">180</field></shadow></value></block></statement></block></next></block></next></block></xml><config>{}</config><code>aW1wb3J0IHR1cnRsZQoKCnRpbmEgPSB0dXJ0bGUuVHVydGxlKCkKdGluYS5zcGVlZCgwKQpmb3IgaSBpbiByYW5nZSg1LCAxNTAsIDUpOgogICAgdGluYS5jaXJjbGUgKGksMTgwKQo=</code>
|
||||
@@ -0,0 +1 @@
|
||||
<xml version="Mixly 2.0 rc4" board="Python 3 Lite@Python 3 Lite"><block type="dicts_create_with" id="LnG}:auk1#(}kwsTQ+4x" inline="true" x="-1783" y="-993"><mutation items="4"></mutation><field name="VAR">color</field><field name="KEY0">0</field><field name="KEY1">1</field><field name="KEY2">2</field><field name="KEY3">3</field><value name="ADD0"><block type="turtle_color_seclet" id="PA7)X|dHs|fc:1nQ-1GM"><field name="COLOR">#ffcc33</field></block></value><value name="ADD1"><block type="turtle_color_seclet" id="@HL=bBHERH[J#}pl9(e?"><field name="COLOR">#ff0000</field></block></value><value name="ADD2"><block type="turtle_color_seclet" id=".it/c2oTw(*)J]htJL.Q"><field name="COLOR">#3333ff</field></block></value><value name="ADD3"><block type="turtle_color_seclet" id="pBdENf;dq#0SOB714_uh"><field name="COLOR">#000000</field></block></value><next><block type="turtle_create" id="bJHXF(:+KGc!s!c2uD=~"><field name="VAR">tina</field><next><block type="turtle_speed" id="!LL-I$n^Ke:]Vq!4,*-S"><value name="TUR"><shadow type="variables_get" id="KDuxX;U$28T^ds3wF8Z/"><field name="VAR">tina</field></shadow></value><value name="data"><shadow type="math_number" id="47`.?Uc27_{nf5V@qZtq"><field name="NUM">0</field></shadow></value><next><block type="turtle_size" id="@u}ze*gZKc-M~GNok/pO"><value name="TUR"><shadow type="variables_get" id="kr1K;j{SG6H/*xWQ,S(|"><field name="VAR">tina</field></shadow></value><value name="data"><shadow type="math_number" id=":fT#?oYhbEI@-72|AmZt"><field name="NUM">2</field></shadow></value><next><block type="controls_forEach" id="Q]Vd#yCX$o3W(=KB--Yo"><value name="LIST"><shadow type="list_many_input" id="2m)oDd523tkA|}iRWN~}"><field name="CONTENT">0,1,2,3</field></shadow><block type="controls_range" id="slI+v$!r+:qGETlYQfAj"><value name="FROM"><shadow type="math_number" id="Y:RN[ozi`/^b^GAbwR*m"><field name="NUM">0</field></shadow></value><value name="TO"><shadow type="math_number" id="zngjwAn@9r[!`wePYm{x"><field name="NUM">50</field></shadow></value><value name="STEP"><shadow type="math_number" id="lg/1#dzZ(qRv$fOEARiS"><field name="NUM">1</field></shadow></value></block></value><value name="VAR"><shadow type="variables_get" id="hn;m:ZVQYtWo@o1g{`Sh"><field name="VAR">i</field></shadow></value><statement name="DO"><block type="turtle_pencolor_hex_new" id="(-tS,TM.uFCNBq65z!mO"><value name="TUR"><shadow type="variables_get" id="[_8:xGy@*$I7`SQKVMQV"><field name="VAR">tina</field></shadow></value><value name="VAR"><shadow type="text" id=";9-s$$p*6Cl}u|D_^#Cc"><field name="TEXT">#FF0000</field></shadow><block type="dicts_get" id="~~P#jIWF*AYTAvCRKJf$"><value name="DICT"><shadow type="variables_get" id="vpKK_rhd_BxZz7SN,#YN"><field name="VAR">color</field></shadow></value><value name="KEY"><shadow type="text" id="^rpU8vpAhBV*p:Sagg3#"><field name="TEXT">key</field></shadow><block type="math_random" id="Lz70yFZ,]/Pn$)0Gnu-Z"><field name="TYPE">int</field><value name="FROM"><shadow type="math_number" id="?@|JPBe:1_b{?UY)9JK;"><field name="NUM">0</field></shadow></value><value name="TO"><shadow type="math_number" id="ivdA]([b|I}.6EtQ8bY_"><field name="NUM">3</field></shadow></value></block></value></block></value><next><block type="turtle_move" id="7R_^Y/eQzjm-FaUhx9qV"><field name="DIR">forward</field><value name="TUR"><shadow type="variables_get" id="57O.3*V+4vE0sP|5M[v="><field name="VAR">tina</field></shadow></value><value name="VAR"><shadow type="math_number" id="Cs|YJBGe];D=rlrKi]Q9"><field name="NUM">20</field></shadow><block type="math_arithmetic" id="tB#_Ur_qEla-eTvrf2vk"><field name="OP">MULTIPLY</field><value name="A"><shadow type="math_number" id="ym_H~wx52PLIN$I;1]U@"><field name="NUM">1</field></shadow><block type="variables_get" id="?sg9;|:|YiG5)@S6^i)1"><field name="VAR">i</field></block></value><value name="B"><shadow type="math_number" id=".;`D?/,XVJ5F@Ts?/;Qj"><field name="NUM">5</field></shadow></value></block></value><next><block type="turtle_rotate" id="*=?(R2.e,Z|t]b*3r3/z"><field name="DIR">left</field><value name="TUR"><shadow type="variables_get" id="*B9XwoSkxAblJ0nblgLv"><field name="VAR">tina</field></shadow></value><value name="VAR"><shadow type="math_number" id="F2qQn#7-^y9!Xsit~1vi"><field name="NUM">90</field></shadow></value></block></next></block></next></block></statement></block></next></block></next></block></next></block></next></block></xml><config>{}</config><code>aW1wb3J0IHR1cnRsZQppbXBvcnQgcmFuZG9tCgoKY29sb3I9IHswOiIjZmZjYzMzIiwgMToiI2ZmMDAwMCIsIDI6IiMzMzMzZmYiLCAzOiIjMDAwMDAwIn0KdGluYSA9IHR1cnRsZS5UdXJ0bGUoKQp0aW5hLnNwZWVkKDApCnRpbmEucGVuc2l6ZSgyKQpmb3IgaSBpbiByYW5nZSgwLCA1MCwgMSk6CiAgICB0aW5hLnBlbmNvbG9yKGNvbG9yW3JhbmRvbS5yYW5kaW50KDAsIDMpXSkKICAgIHRpbmEuZm9yd2FyZCgoaSAqIDUpKQogICAgdGluYS5sZWZ0KDkwKQo=</code>
|
||||
@@ -0,0 +1 @@
|
||||
<xml version="Mixly 2.0 rc4" board="Python 3 Lite@Python 3 Lite"><block type="lists_create_with" id="h+z}odWry9DT[~!:6^aB" inline="true" x="-1586" y="-916"><mutation items="4"></mutation><field name="VAR">color</field><value name="ADD0"><block type="turtle_color_seclet" id="vWQJyW.VOBdj}wC0g:z-"><field name="COLOR">#ffcccc</field></block></value><value name="ADD1"><block type="turtle_color_seclet" id="2tq2dkRDm.y`B:uvz`G("><field name="COLOR">#ff0000</field></block></value><value name="ADD2"><block type="turtle_color_seclet" id=".,BE.?qETf:~+dzZjf4z"><field name="COLOR">#990000</field></block></value><value name="ADD3"><block type="turtle_color_seclet" id="Z``x7~!B$|Qr!VK`:I-]"><field name="COLOR">#330000</field></block></value><next><block type="turtle_create" id="7G$V;q*l4L2X7cNi,~rY"><field name="VAR">tina</field><next><block type="turtle_speed" id="Q3w4~Gfn@-ZX]c5ZVz|d"><value name="TUR"><shadow type="variables_get" id="30:kYcMj^,zMbp6JL(XB"><field name="VAR">tina</field></shadow></value><value name="data"><shadow type="math_number" id="9{@jMJ6zJyo(e(p)|^mA"><field name="NUM">0</field></shadow></value><next><block type="turtle_size" id="WRE(aaj:+b3Hmbf~sv9:"><value name="TUR"><shadow type="variables_get" id="uLoQTVgPx2/f}}CX9kq$"><field name="VAR">tina</field></shadow></value><value name="data"><shadow type="math_number" id="BOiiO/vKs6a$V7wI.g`#"><field name="NUM">2</field></shadow></value><next><block type="controls_forEach" id="_$I:llo_l,5n4pf.pP/{"><value name="LIST"><shadow type="list_many_input" id="pQY$+/^3^+rnPDp3vFK3"><field name="CONTENT">0,1,2,3</field></shadow><block type="controls_range" id="W9Np02rPjO;MrdYGZjT8"><value name="FROM"><shadow type="math_number" id="TJ^?zN8|#jJT)DUDANE*"><field name="NUM">0</field></shadow></value><value name="TO"><shadow type="math_number" id="[on[P5k.jZ-N1~a_a3i{"><field name="NUM">50</field></shadow></value><value name="STEP"><shadow type="math_number" id="2H;eiQ1]Ju:_AMFc{G6I"><field name="NUM">1</field></shadow></value></block></value><value name="VAR"><shadow type="variables_get" id="ZvM_,1j*hwK~{_(@9^A]"><field name="VAR">i</field></shadow></value><statement name="DO"><block type="turtle_pencolor_hex_new" id="LFIhguxNWw2n}NqSjDO9"><value name="TUR"><shadow type="variables_get" id="/j38.{TW*grDO.D*YgNf"><field name="VAR">tina</field></shadow></value><value name="VAR"><shadow type="text" id="WK6Q$V0VcwIC|;@wLxky"><field name="TEXT">#FF0000</field></shadow><block type="lists_get_index" id="^#@?DwaD|2U;Dt7DZ-8$"><value name="LIST"><shadow type="variables_get" id="LM_?Cc[L,vE_2|M]pDq~"><field name="VAR">color</field></shadow></value><value name="AT"><shadow type="math_number" id="}gf=|fhb)6o;RW{92[sy"><field name="NUM">0</field></shadow><block type="math_arithmetic" id="0E#cSLT)@3x7tdOi*cUP"><field name="OP">QUYU</field><value name="A"><shadow type="math_number" id="4Ll|vG}BUNSY^t5XL3#2"><field name="NUM">1</field></shadow><block type="variables_get" id="@bHG_^Wp?jH7RJtX6guj"><field name="VAR">i</field></block></value><value name="B"><shadow type="math_number" id="Xc=jTe*5;hodgR;Qeujz"><field name="NUM">4</field></shadow></value></block></value></block></value><next><block type="turtle_move" id="X]qu]3gIVnjCh=kDG1w-"><field name="DIR">forward</field><value name="TUR"><shadow type="variables_get" id="JYVol)qk~joNQ5T}X^R{"><field name="VAR">tina</field></shadow></value><value name="VAR"><shadow type="math_number" id="PIMvZI,P)^?KJ_6Xege_"><field name="NUM">20</field></shadow><block type="math_arithmetic" id="x7,0+j=p2yp_oz8M6I$g"><field name="OP">MULTIPLY</field><value name="A"><shadow type="math_number" id="4Ll|vG}BUNSY^t5XL3#2"><field name="NUM">1</field></shadow><block type="variables_get" id="/+z*?mI^V~c?jrKeH^mI"><field name="VAR">i</field></block></value><value name="B"><shadow type="math_number" id="5T]nvfG*+deb)i00?nU-"><field name="NUM">5</field></shadow></value></block></value><next><block type="turtle_rotate" id="SlgP-svO5BMY5LPT[]r("><field name="DIR">left</field><value name="TUR"><shadow type="variables_get" id="Otr1gHGA-5n|!Ud-L]au"><field name="VAR">tina</field></shadow></value><value name="VAR"><shadow type="math_number" id="~tT-fCnVFPmNBK4(JNc+"><field name="NUM">90</field></shadow></value></block></next></block></next></block></statement></block></next></block></next></block></next></block></next></block></xml><config>{}</config><code>aW1wb3J0IHR1cnRsZQoKCmNvbG9yID0gWyIjZmZjY2NjIiwgIiNmZjAwMDAiLCAiIzk5MDAwMCIsICIjMzMwMDAwIl0KdGluYSA9IHR1cnRsZS5UdXJ0bGUoKQp0aW5hLnNwZWVkKDApCnRpbmEucGVuc2l6ZSgyKQpmb3IgaSBpbiByYW5nZSgwLCA1MCwgMSk6CiAgICB0aW5hLnBlbmNvbG9yKGNvbG9yW2kgJSA0XSkKICAgIHRpbmEuZm9yd2FyZCgoaSAqIDUpKQogICAgdGluYS5sZWZ0KDkwKQo=</code>
|
||||
@@ -0,0 +1 @@
|
||||
<xml version="Mixly 2.0 rc4" board="Python 3 Lite@Python 3 Lite"><block type="dicts_create_with" id="}`MNMK*5b5t^t}U$[@Ty" x="-430" y="-172"><mutation items="0"></mutation><field name="VAR">候选人</field><next><block type="variables_set" id="uC1#gS^uNhoIyDKe,@I)"><field name="VAR">投票人次</field><value name="VALUE"><block type="inout_type_input" id="#2tLsdBx)cFz@DRDeLF@"><field name="DIR">int</field><value name="VAR"><shadow type="text" id="9^g~n`R:*`i(+Td7Vo@c"><field name="TEXT">输入投票人次:</field></shadow></value></block></value><next><block type="controls_repeat_ext" id="M6+IRv=Ss@ruU#~|#uYY"><value name="TIMES"><shadow type="math_number" id="k(C32wHOjf9JXE(LV*7D"><field name="NUM">10</field></shadow><block type="variables_get" id="-xOw#i^Yfb/ZssBN@dvc"><field name="VAR">投票人次</field></block></value><statement name="DO"><block type="variables_set" id="{n+IK}ZNU_aSXgC-PlR."><field name="VAR">投票</field><value name="VALUE"><block type="inout_type_input" id="FzNKpp(AQ=(ixP]F:OGs"><field name="DIR">str</field><value name="VAR"><shadow type="text" id="IAw`Hl+RYvL*(b1BL`P@"><field name="TEXT">输入候选人姓名:</field></shadow></value></block></value><next><block type="dicts_add_or_change" id="D~B-O3.X1|4w_]d~ZcnA"><value name="DICT"><shadow type="variables_get" id="Gz[1=4hQ#1C1~taW9?`V"><field name="VAR">mydict</field></shadow><block type="variables_get" id="wsjg3V*,!szYBONWwRR("><field name="VAR">候选人</field></block></value><value name="KEY"><shadow type="text" id="Fo[GTdz@)(hah#NxKUMA"><field name="TEXT">key</field></shadow><block type="variables_get" id="cKl{OzX2^?+OL!j.BoC1"><field name="VAR">投票</field></block></value><value name="VAR"><shadow type="math_number" id="~SzjTE)zIh]|XoM7uat#"><field name="NUM">1</field></shadow><block type="math_arithmetic" id="|qu)jEKD_6jh?R0gCRj*"><field name="OP">ADD</field><value name="A"><shadow type="math_number" id="G|~/=Nz^4uBBC+.Gfzi@"><field name="NUM">1</field></shadow><block type="dicts_get_default" id="H}W8e|SW,3Q]$J~V7,4|"><value name="DICT"><shadow type="variables_get" id="szYg5a$?2v|c^#ZIG0[A"><field name="VAR">mydict</field></shadow><block type="variables_get" id="o{D+z*rS^;/Drw`lUw!6"><field name="VAR">候选人</field></block></value><value name="KEY"><shadow type="text" id="QR-^!~{1m^7=;-q`F*oj"><field name="TEXT">key</field></shadow><block type="variables_get" id="_7`U*:~Oftzeyq)Xanaj"><field name="VAR">投票</field></block></value><value name="VAR"><shadow type="math_number" id="7#BmACRk){!]Rai-H2xG"><field name="NUM">0</field></shadow></value></block></value><value name="B"><shadow type="math_number" id="G*/YE3[-K=e)m+iN}DFj"><field name="NUM">1</field></shadow></value></block></value></block></next></block></statement><next><block type="inout_print" id="HGw(L]|iSB,a(]e1Ucql"><value name="VAR"><shadow type="text" id="!Mu``G{:$}cNgu0?HmY7"><field name="TEXT">Hello</field></shadow><block type="variables_get" id="0xCY,i=REcL+PVn.n#]@"><field name="VAR">候选人</field></block></value></block></next></block></next></block></next></block></xml><config>{}</config><code>X0U1XzgwXzk5X0U5XzgwXzg5X0U0X0JBX0JBPSB7fQpfRTZfOEFfOTVfRTdfQTVfQThfRTRfQkFfQkFfRTZfQUNfQTEgPSBpbnQoaW5wdXQoJ+i+k+WFpeaKleelqOS6uuasoe+8micpKQpmb3IgX215X3ZhcmlhYmxlIGluIHJhbmdlKF9FNl84QV85NV9FN19BNV9BOF9FNF9CQV9CQV9FNl9BQ19BMSk6CiAgICBfRTZfOEFfOTVfRTdfQTVfQTggPSBpbnB1dCgn6L6T5YWl5YCZ6YCJ5Lq65aeT5ZCN77yaJykKICAgIF9FNV84MF85OV9FOV84MF84OV9FNF9CQV9CQVtfRTZfOEFfOTVfRTdfQTVfQThdID0gX0U1XzgwXzk5X0U5XzgwXzg5X0U0X0JBX0JBLmdldChfRTZfOEFfOTVfRTdfQTVfQTgsMCkgKyAxCnByaW50KF9FNV84MF85OV9FOV84MF84OV9FNF9CQV9CQSkK</code>
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1 @@
|
||||
<xml version="Mixly 2.0 rc4" board="Python 3 Lite@Python 3 Lite"><block type="variables_set" id="uLhmE_?]+LZ09A_OJrdI" x="-394" y="-238"><field name="VAR">密码本</field><value name="VALUE"><block type="text" id="A9})p,^.,X9}wVpr_;jI"><field name="TEXT">abcdef</field></block></value><next><block type="variables_set" id="{H.ZK/6kF)y_F-i+75{O"><field name="VAR">明文</field><value name="VALUE"><block type="inout_type_input" id="UT*Y$3[S@XADm==_?gwd"><field name="DIR">str</field><value name="VAR"><shadow type="text" id="7(85ED2LIL!a.+f+S3`6"><field name="TEXT">输入一个字符:</field></shadow></value></block></value><next><block type="variables_set" id="Pi+=UgUt?|GvjkO:{?d("><field name="VAR">位移</field><value name="VALUE"><block type="math_number" id=".GWtoBnPm.sl@i2[$PNb"><field name="NUM">2</field></block></value><next><block type="inout_print" id="2S@DvFZ]6JSnRyZ9K4v!"><value name="VAR"><shadow type="text" id="xT=KtJH{H=nCP6Sz{XF6"><field name="TEXT">Hello</field></shadow><block type="text_join" id="AvVYu82W5n6Z*BTRo8@1" inline="false"><value name="A"><shadow type="text" id="@ZY(_E.hK2@vYA`+X05!"><field name="TEXT">密码:</field></shadow></value><value name="B"><shadow type="text" id="j}0GK{Fr)UsC)dqO{aIg"><field name="TEXT">Mixly</field></shadow><block type="text_char_at" id="Q_iI7NXLq)RSlcIRC;IW" inline="false"><value name="VAR"><shadow type="text" id="7~QU]MS$U,+ez}RMB*`L"><field name="TEXT">Mixly</field></shadow><block type="variables_get" id="xr+RCUgpdjo:b*jx9zG?"><field name="VAR">密码本</field></block></value><value name="AT"><shadow type="math_number" id="T^lwqdEL]W,fdaYHdox^"><field name="NUM">0</field></shadow><block type="math_arithmetic" id="uGSH~:V#+`j/hC6V0Yd9"><field name="OP">QUYU</field><value name="A"><shadow type="math_number" id="g)v^Ku`_#p7yTKN*nedC"><field name="NUM">1</field></shadow><block type="math_arithmetic" id="46SRXysng^UzyBNnHHgk"><field name="OP">ADD</field><value name="A"><shadow type="math_number" id="+|+;a?235jqRtJ5n,Ve}"><field name="NUM">1</field></shadow><block type="text_find" id="0rzlM+3obASA:c3.FeBX"><value name="VAR"><shadow type="text" id="+#0bT4TZ4O1GK9~g{*]?"><field name="TEXT">Hello,mixly</field></shadow><block type="variables_get" id="Wi^[gp-d/Q]+/_;${NDr"><field name="VAR">密码本</field></block></value><value name="STR"><shadow type="text" id="?fdG:NuY8WW7!#3}IPVv"><field name="TEXT">l</field></shadow><block type="variables_get" id="lyg!k!eCp8#C4c:n8?1y"><field name="VAR">明文</field></block></value></block></value><value name="B"><shadow type="math_number" id="3UT(/+|#]?T=Zac+qw0:"><field name="NUM">8</field></shadow></value></block></value><value name="B"><shadow type="math_number" id="}uo|qNLTD~5iJi$[|ZQ}"><field name="NUM">6</field></shadow></value></block></value></block></value></block></value></block></next></block></next></block></next></block></xml><config>{}</config><code>X0U1X0FGXzg2X0U3X0EwXzgxX0U2XzlDX0FDID0gJ2FiY2RlZicKX0U2Xzk4XzhFX0U2Xzk2Xzg3ID0gaW5wdXQoJ+i+k+WFpeS4gOS4quWtl+espu+8micpCl9FNF9CRF84RF9FN19BN19CQiA9IDIKcHJpbnQoKCflr4bnoIHvvJonICsgX0U1X0FGXzg2X0U3X0EwXzgxX0U2XzlDX0FDWygoX0U1X0FGXzg2X0U3X0EwXzgxX0U2XzlDX0FDLmZpbmQoX0U2Xzk4XzhFX0U2Xzk2Xzg3KSArIDgpICUgNildKSkK</code>
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1 @@
|
||||
<xml version="Mixly 2.0 rc4" board="Python 3 Lite@Python 3 Lite"><block type="variables_set" id="Psy18EfE`yH$#4en4WNf" x="-1668" y="-448"><field name="VAR">数字-人</field><value name="VALUE"><block type="logic_null" id="qv1/fM0fvs}+mi;Tis7$"></block></value><next><block type="variables_set" id="@Eh7r}}}l.;O;b=~-^Ow"><field name="VAR">数字-人</field><value name="VALUE"><block type="inout_type_input" id="uJ5Eo(T_~WLg-@`?_)MT"><field name="DIR">int</field><value name="VAR"><shadow type="text" id="ZRXv-4dH]VWm86dy.{jE"><field name="TEXT">请输入0-20之间的整数:</field></shadow></value></block></value><next><block type="inout_print" id="uP,gFKH*=nx9COSgXj)S"><value name="VAR"><shadow type="text" id="6{KguyL$oEqrzqYswRUZ"><field name="TEXT">Hello</field></shadow><block type="text_join" id="LJv=F.]^D9vD`WL4}Z(S"><value name="A"><shadow type="text" id="lx`DTquhl)Z8_aAc*Mt="><field name="TEXT">人:</field></shadow></value><value name="B"><shadow type="text" id="HENKD;PLU`=o~ykm3_dv"><field name="TEXT">Mixly</field></shadow><block type="variables_change" id="x*mM8if)v^JW;B0}bVpZ"><field name="OP">str</field><value name="MYVALUE"><block type="variables_get" id="U^zC8WX-2#7Epeg+`vT:"><field name="VAR">数字-人</field></block></value></block></value></block></value><next><block type="controls_if" id="~8-dnjUHwvp=fi_jxCAQ"><value name="IF0"><block type="logic_compare_continous" id=".7b0YuopREOQM4XWAYus"><field name="OP1">LTE</field><field name="OP2">LTE</field><value name="A"><shadow type="math_number" id="fWn`lN@^tmBpiGLpl*ER"><field name="NUM">0</field></shadow></value><value name="B"><shadow type="variables_get" id="9]FhP;rC:`8+b6bVooKe"><field name="VAR">x</field></shadow><block type="variables_get" id="jLrUU?!7k^+Od#q[pA`3"><field name="VAR">数字-人</field></block></value><value name="C"><shadow type="math_number" id="|fq48HGZGgbK}/-e~cGm"><field name="NUM">20</field></shadow></value></block></value><statement name="DO0"><block type="variables_set" id="3B_5YNwdvCoWAm7t9J)R"><field name="VAR">数字-机</field><value name="VALUE"><block type="math_random" id="P~1PBe0:}iD(V3~uynFi"><field name="TYPE">int</field><value name="FROM"><shadow type="math_number" id="6.n7WLk+)[^_upghG8{."><field name="NUM">0</field></shadow></value><value name="TO"><shadow type="math_number" id="{*1Qsv(xlq)+ve^0Dp[|"><field name="NUM">20</field></shadow></value></block></value><next><block type="inout_print" id="W5LFiXi3J79RFec$,xi}"><value name="VAR"><shadow type="text" id="5x*0df}ECgThir|MXe=+"><field name="TEXT">Hello</field></shadow><block type="text_join" id="]1zubcPuP_LvxkR*kOy5"><value name="A"><shadow type="text" id=",hv/mwUCr~VqG(yOxqk|"><field name="TEXT">机:</field></shadow></value><value name="B"><shadow type="text" id="a`/yQP0d!rhcoRIl0YGl"><field name="TEXT">Mixly</field></shadow><block type="variables_change" id="!vGg*B*F,j{3z-@ewz-R"><field name="OP">str</field><value name="MYVALUE"><block type="variables_get" id="0Dw2XFr#`|z@wnkl1K;Z"><field name="VAR">数字-机</field></block></value></block></value></block></value></block></next></block></statement><next><block type="time_sleep" id="8~6BhC:S8X{STkXTObew"><value name="DELAY_TIME"><shadow type="math_number" id="ATDS?SQ;#F@g+YW.Ez{t"><field name="NUM">0.2</field></shadow></value></block></next></block></next></block></next></block></next></block></xml><config>{}</config><code>aW1wb3J0IHJhbmRvbQppbXBvcnQgdGltZQoKCl9FNl85NV9CMF9FNV9BRF85N19fRTRfQkFfQkEgPSBOb25lCl9FNl85NV9CMF9FNV9BRF85N19fRTRfQkFfQkEgPSBpbnQoaW5wdXQoJ+ivt+i+k+WFpTAtMjDkuYvpl7TnmoTmlbTmlbDvvJonKSkKcHJpbnQoKCfkurrvvJonICsgc3RyKF9FNl85NV9CMF9FNV9BRF85N19fRTRfQkFfQkEpKSkKaWYgMCA8PSBfRTZfOTVfQjBfRTVfQURfOTdfX0U0X0JBX0JBIDw9IDIwOgogICAgX0U2Xzk1X0IwX0U1X0FEXzk3X19FNl85Q19CQSA9IHJhbmRvbS5yYW5kaW50KDAsIDIwKQogICAgcHJpbnQoKCfmnLrvvJonICsgc3RyKF9FNl85NV9CMF9FNV9BRF85N19fRTZfOUNfQkEpKSkKdGltZS5zbGVlcCgwLjIpCg==</code>
|
||||
@@ -0,0 +1 @@
|
||||
<xml version="Mixly 2.0 rc4" board="Python 3 Lite@Python 3 Lite"><block type="variables_set" id="U0HY~f^K=p~$M!^mMD.~" x="-1541" y="-307"><field name="VAR">数字-机</field><value name="VALUE"><block type="math_random" id="]5=w}kEfi(D1(87H|!8/"><field name="TYPE">int</field><value name="FROM"><shadow type="math_number" id=";3+O:bKq!+Vuvh3jt{U_"><field name="NUM">1</field></shadow></value><value name="TO"><shadow type="math_number" id="kNJxt!`@@5s[*hAuR!qF"><field name="NUM">100</field></shadow></value></block></value><next><block type="variables_set" id="/O5Rlxt,gFgkgnl0L`*9"><field name="VAR">数字-人</field><value name="VALUE"><block type="logic_null" id="Y(Gf0(oOU;|FM_i~QjO!"></block></value><next><block type="controls_whileUntil" id="rIe[]c27wG`P85XYy^Qa"><field name="MODE">WHILE</field><value name="BOOL"><shadow type="logic_boolean" id="o@d6g4e1J^Mvy#6T,pZ4"><field name="BOOL">TRUE</field></shadow><block type="logic_compare" id="ey.kzJrgg2{2Ik]_iO;Z"><field name="OP">NEQ</field><value name="A"><block type="variables_get" id="wKZImlN:B_;X!k{=(WSi"><field name="VAR">数字-人</field></block></value><value name="B"><block type="variables_get" id="2+`s97!n^)=U*fiGP-@l"><field name="VAR">数字-机</field></block></value></block></value><statement name="DO"><block type="variables_set" id="h2zruKWtG6DOhH:EhZg."><field name="VAR">数字-人</field><value name="VALUE"><block type="inout_type_input" id="reA30j0s1+3EzkLbSi85"><field name="DIR">int</field><value name="VAR"><shadow type="text" id="4~MncC:sTY(os98efhs["><field name="TEXT">输入数字:</field></shadow></value></block></value><next><block type="controls_if" id="}^(l`HF,T5arRiy6PP28"><mutation elseif="1" else="1"></mutation><value name="IF0"><block type="logic_compare" id="wOe2j,Ly$/^SoFV^Ry`@"><field name="OP">GT</field><value name="A"><block type="variables_get" id="y_15?MhC=Q7`+C2OU*l_"><field name="VAR">数字-人</field></block></value><value name="B"><block type="variables_get" id="`xTl,/]Z]fm5fuUFE6x}"><field name="VAR">数字-机</field></block></value></block></value><statement name="DO0"><block type="inout_print" id=".0]1@R_Brf-,Pcyc49w)"><value name="VAR"><shadow type="text" id=";jjZ{-`~r#|~]ml7-9SK"><field name="TEXT">猜大了!</field></shadow></value></block></statement><value name="IF1"><block type="logic_compare" id="S+Bp[Wb$v1g[R28{7-/r"><field name="OP">LT</field><value name="A"><block type="variables_get" id="-SAiN)M#b7xtZ8UrYvzd"><field name="VAR">数字-人</field></block></value><value name="B"><block type="variables_get" id="2M(h$DjbYM?Gs|Oy~~jV"><field name="VAR">数字-机</field></block></value></block></value><statement name="DO1"><block type="inout_print" id="Sn?n|!gtllX,tiTr!la7"><value name="VAR"><shadow type="text" id="cts4zr=fKG,nk8$iY?pk"><field name="TEXT">猜小了!</field></shadow></value></block></statement><statement name="ELSE"><block type="inout_print" id="SfJb*1?#(DU7DJ@,MKn~"><value name="VAR"><shadow type="text" id="t}$,y$Seg^Prh0YYLE)I"><field name="TEXT">猜对了!</field></shadow></value></block></statement></block></next></block></statement></block></next></block></next></block></xml><config>{}</config><code>aW1wb3J0IHJhbmRvbQoKCl9FNl85NV9CMF9FNV9BRF85N19fRTZfOUNfQkEgPSByYW5kb20ucmFuZGludCgxLCAxMDApCl9FNl85NV9CMF9FNV9BRF85N19fRTRfQkFfQkEgPSBOb25lCndoaWxlIF9FNl85NV9CMF9FNV9BRF85N19fRTRfQkFfQkEgIT0gX0U2Xzk1X0IwX0U1X0FEXzk3X19FNl85Q19CQToKICAgIF9FNl85NV9CMF9FNV9BRF85N19fRTRfQkFfQkEgPSBpbnQoaW5wdXQoJ+i+k+WFpeaVsOWtl++8micpKQogICAgaWYgX0U2Xzk1X0IwX0U1X0FEXzk3X19FNF9CQV9CQSA+IF9FNl85NV9CMF9FNV9BRF85N19fRTZfOUNfQkE6CiAgICAgICAgcHJpbnQoJ+eMnOWkp+S6hu+8gScpCiAgICBlbGlmIF9FNl85NV9CMF9FNV9BRF85N19fRTRfQkFfQkEgPCBfRTZfOTVfQjBfRTVfQURfOTdfX0U2XzlDX0JBOgogICAgICAgIHByaW50KCfnjJzlsI/kuobvvIEnKQogICAgZWxzZToKICAgICAgICBwcmludCgn54yc5a+55LqG77yBJykK</code>
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1 @@
|
||||
<xml version="Mixly 2.0 rc4" board="Python 3 Lite@Python 3 Lite"><block type="algorithm_all_books" id="|J-;tcC79QKLe1YpDLqA" x="-943" y="-125"><next><block type="controls_whileUntil" id="#U*aD0/SBu;gPSs?]JcC"><field name="MODE">WHILE</field><value name="BOOL"><shadow type="logic_boolean" id="kg^2w@CwKX$GAZ;(3poe"><field name="BOOL">TRUE</field></shadow><block type="algorithm_two_left" id="M.!+?#+}4b*z|}FOWO98"></block></value><statement name="DO"><block type="algorithm_divide_books" id="Cx$P*dB-ON2P]L]EV7W1"><next><block type="algorithm_get_half_books" id="4nvOGpCQ;:^!xvU;z,kJ"><next><block type="controls_if" id="Wl42{xbq+mSHZmOXqF49"><value name="IF0"><block type="algorithm_yes_ring2" id="7~wnA(BYH0ExIKRP*|QG"></block></value><statement name="DO0"><block type="algorithm_delete_book" id=".J-XOF.`7A6X#:Y+FRQ5"></block></statement></block></next></block></next></block></statement><next><block type="algorithm_print_book2" id="=O,QtV!s7d][T^#g/Eaj"></block></next></block></next></block></xml><config>{}</config><code>aW1wb3J0IHRpbWUKaW1wb3J0IHNwcml0ZQoKCmlmICdtb2RlJyBub3QgaW4gZ2xvYmFscygpIG9yIG1vZGUgPT0gMDoKICAgIHNwcml0ZS5jbGVhckFsbFNwcml0ZXMoKQogICAgcmluZz1bMCwwLDAsMCwwLDAsMCwwLDAsMF0KICAgIG1vZGU9MgogICAgbj01CiAgICBuYW1lPVsn5bCP546L5a2QJywn5rW35bqV5Lik5LiH6YeMJywn6I236Iqx6ZWH55qE5pep5biCJywn5a2U5a2Q55qE5pWF5LqLJywn5aSP5rSb55qE572RJywn6I2J5oi/5a2QJywn5pyI5LiL55yL54yr5aS06bmwJywn5Lya5ZSx5q2M55qE5ZKW5ZWh56OoJywn54i25LiO5a2QJywn5Z+O5Y2X5pen5LqLJ10KICAgIEJvb2tzID0gW10KICAgIGZvciBpIGluIHJhbmdlKDEsIDExLCAxKToKICAgICAgICBCb29rcy5hcHBlbmQoc3ByaXRlLlNwcml0ZSgnYm9va3MvYm9vaycrc3RyKGkpLCAoMTMwKmktNjUwKSBpZiBpPjUgZWxzZSAxMzAqaSwgMzIwIGlmIGk+NSBlbHNlIDEyMCkpCmVsc2U6CiAgICBtb2RlPTIKICAgIG49bGVuKHJpbmcpLTEKcmluZ1tuXT1uCmxpc3Q9cmluZwp0ZW1wPUJvb2tzCnRpbWUuc2xlZXAoMSkKd2hpbGUgbGVuKGxpc3QpPj0yOgogICAgbWlkID0gaW50KGxlbihsaXN0KS8yKQogICAgcWlhbiA9IGxpc3RbMDptaWRdCiAgICBob3UgPSBsaXN0W21pZDpdCiAgICBxaWFudGVtcCA9IHRlbXBbMDptaWRdCiAgICBob3V0ZW1wID0gdGVtcFttaWQ6XQogICAgcXVjaHUgPSBxaWFuCiAgICBsaXN0ID0gaG91CiAgICBxdWNodXRlbXAgPSBxaWFudGVtcAogICAgdGVtcCA9IGhvdXRlbXAKICAgIGZvciBpIGluIHFpYW50ZW1wOgogICAgICAgIGkuZmlsdGVyQnJpZ2h0ZXIoKQogICAgdGltZS5zbGVlcCgwLjUpCiAgICBmb3IgaSBpbiBxaWFudGVtcDoKICAgICAgICBpLmZpbHRlckdyYXkoKQogICAgdGltZS5zbGVlcCgwLjUpCiAgICBpZiAoKCdtb2RlJyBpbiBnbG9iYWxzKCkpYW5kKChtb2RlPT0xIGFuZCBmbGFnIT0wKW9yKG1vZGU9PTIgYW5kIGFueSh2YWx1ZSA+IDAgZm9yIHZhbHVlIGluIHFpYW4pKSkpOgogICAgICAgIGxpc3QgPSBxdWNodQogICAgICAgIHRlbXAgPSBxdWNodXRlbXAKICAgICAgICBmb3IgaSBpbiBxaWFudGVtcDoKICAgICAgICAgICAgaS5maWx0ZXJCcmlnaHRlcigpCiAgICAgICAgdGltZS5zbGVlcCgwLjUpCiAgICAgICAgZm9yIGkgaW4gcWlhbnRlbXA6CiAgICAgICAgICAgIGkuZmlsdGVyT3JpZ2luKCkKICAgICAgICBmb3IgaSBpbiBob3V0ZW1wOgogICAgICAgIAlpLmZpbHRlckJyaWdodGVyKCkKICAgICAgICB0aW1lLnNsZWVwKDAuNSkKICAgICAgICBmb3IgaSBpbiBob3V0ZW1wOgogICAgICAgICAgICBpLmZpbHRlckdyYXkoKQogICAgICAgIHRpbWUuc2xlZXAoMC41KQppZiAnbGlzdCcgaW4gZ2xvYmFscygpOgogICAgcmVzID0gbGlzdFswXQpCb29rc1tyZXNdLmZpbHRlckJyaWdodGVyKCkKcHJpbnQoJ+acqua2iOejgeeahOS5puexjeaYr+esrCcrc3RyKHJlcysxKSsn5pys44CKJytuYW1lW3JlcyUxMF0rJ+OAi+OAgicpCmlmIHJlcyE9bjoKICAgIHByaW50KCfnrZTmoYjplJnor6/vvIHor7fmo4Dmn6XnqIvluo/vvIEnKQptb2RlPTAK</code>
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1 @@
|
||||
<xml version="Mixly 2.0 rc4" board="Python 3 Lite@Python 3 Lite"><block type="algorithm_prepare" id="pUS7)Gd/X5z0N?j38_yv" x="-906" y="-79"><next><block type="algorithm_add_school" id="y*J@~N0u]XbHpFx^NH]]"><next><block type="controls_whileUntil" id="D7FSFINrhT:$2uZLOu2W"><field name="MODE">UNTIL</field><value name="BOOL"><shadow type="logic_boolean" id="qetj2]s~Z8O`*ai`~gt."><field name="BOOL">TRUE</field></shadow><block type="algorithm_no_left" id="ZVQgLMRIUO*7[Dt=4*a."></block></value><statement name="DO"><block type="algorithm_find_path" id="NFw_685O$is4#_;#u2+9"><next><block type="controls_if" id="]eCp3~FUJE13;M@!7Ag}"><mutation else="1"></mutation><value name="IF0"><block type="algorithm_new_path" id="25A70o2xeBBX#vkU_i_O"></block></value><statement name="DO0"><block type="algorithm_set_path" id="r?HG~0tU}r$GT@p.J2OI"><next><block type="algorithm_add_path" id="XQP`{FdKf(mWK?xk?xC8"></block></next></block></statement><statement name="ELSE"><block type="algorithm_del_path" id="~-dhDT6OSrr6cCF5E{HY"><next><block type="algorithm_return_path" id="feZ/(:@vNpv;DmbJ@}@W"></block></next></block></statement></block></next></block></statement></block></next></block></next></block></xml><config>{}</config><code>aW1wb3J0IHNwcml0ZQppbXBvcnQgcmFuZG9tCmltcG9ydCB0aW1lCgoKZyA9IFtbMCwwLDAsMCwwLDAsMCwwLDAsMF0sIFswLDAsMCwxLDAsMCwwLDAsMCwwXSwgWzAsMCwwLDEsMCwwLDEsMCwwLDBdLCBbMCwxLDEsMCwxLDEsMCwwLDAsMF0sIFswLDAsMCwxLDAsMCwwLDEsMCwwXSwgWzAsMCwwLDEsMCwwLDEsMSwwLDBdLCBbMCwwLDEsMCwwLDEsMCwxLDAsMF0sIFswLDAsMCwwLDEsMSwxLDAsMCwwXV0KbWFyayA9IFtbMCwwLDAsMCwwLDAsMCwwLDAsMF0sIFswLDAsMCwwLDAsMCwwLDAsMCwwXSwgWzAsMCwwLDAsMCwwLDAsMCwwLDBdLCBbMCwwLDAsMCwwLDAsMCwwLDAsMF0sIFswLDAsMCwwLDAsMCwwLDAsMCwwXSwgWzAsMCwwLDAsMCwwLDAsMCwwLDBdLCBbMCwwLDAsMCwwLDAsMCwwLDAsMF0sIFswLDAsMCwwLDAsMCwwLDAsMCwwXV0KdmlzID0gWzAsMSwwLDAsMCwwLDAsMCwwXQpwb3NpdGlvbiA9IFtbMCwgMF0sIFsyMDAsIDIwMF0sIFsyNTAsIDYwXSwgWzMyMCwgMjAwXSwgWzI4MCwgMzgwXSwgWzQ3MCwgMjUwXSwgWzY3MCwgOTBdLCBbNjUwLCAzNDBdXQpzcHJpdGUuY2xlYXJBbGxTcHJpdGVzKCkKc3ByaXRlLmNyZWF0ZUJhY2tncm91bmQoJ21hcF94dWV4aWFvJykKCmhvdXNlID0gWyBzcHJpdGUuU3ByaXRlKCdtYXJrJywgMTUwLCAzODApLAogICAgc3ByaXRlLlNwcml0ZSgnU2Nob29sJywgMTE1LCAxOTUpLAogICAgc3ByaXRlLlNwcml0ZSgnSG91c2UyNScsIDI2NCwgNjcpLAogICAgc3ByaXRlLlNwcml0ZSgnSG91c2UzNicsIDMyMCwgMjAwKSwKICAgIHNwcml0ZS5TcHJpdGUoJ0hvdXNlNDcnLCAyOTAsIDM3MSksCiAgICBzcHJpdGUuU3ByaXRlKCdIb3VzZTI1JywgNDc5LCAyMzMpLAogICAgc3ByaXRlLlNwcml0ZSgnSG91c2UzNicsIDY3NCwgOTYpLAogICAgc3ByaXRlLlNwcml0ZSgnSG91c2U0NycsIDY0MiwgMzE4KQpdCmZvciBpIGluIGhvdXNlOgogICAgaS5oaWRlKCkKcGF0aCA9IFsxXQpjYXIgPSBzcHJpdGUuU3ByaXRlKCdjYXInLCBwb3NpdGlvblsxXVswXSwgcG9zaXRpb25bMV1bMV0pCmhvdXNlWzFdLnNob3coKQpjYXIubm93UG9zID0gMQpkZWYgZHJpdmUobik6CiAgICBpZiBnW2Nhci5ub3dQb3NdW25dPT0xOgogICAgICAgIGNhci5zbGlkZVRvKHBvc2l0aW9uW25dWzBdLCBwb3NpdGlvbltuXVsxXSwgMSkKICAgICAgICBjYXIubm93UG9zID0gbgogICAgZWxzZToKICAgICAgICBwcmludCgn56e75Yqo5aSx6LSl77yB56iL5bqP5pyJ6K+v77yBJykKICAgICAgICBleGl0KCkKd2hpbGUgbm90IGxlbihwYXRoKSA9PSA3OgogICAgZiA9IHBhdGhbKGxlbihwYXRoKSAtIDEpXQogICAgZmxhZyA9IDAKICAgIGZvciBfbXlfdmFyaWFibGUgaW4gWzYsNSw0LDMsMiwxLDBdOgogICAgICAgIGlmIHZpc1tfbXlfdmFyaWFibGUrMV0gPT0gMCBhbmQgZ1tmXVtfbXlfdmFyaWFibGUrMV0gPT0gMToKICAgICAgICAgICAgaWYgbWFya1tmXVtfbXlfdmFyaWFibGUrMV0gPT0gMDoKICAgICAgICAgICAgICAgIGZsYWcgPSAxCiAgICAgICAgICAgICAgICBicmVhawogICAgaWYgZmxhZyA9PSAxOgogICAgICAgIG1hcmtbZl1bX215X3ZhcmlhYmxlKzFdID0gMQogICAgICAgIHZpc1tfbXlfdmFyaWFibGUrMV0gPSAxCiAgICAgICAgcGF0aC5hcHBlbmQoX215X3ZhcmlhYmxlKzEpCiAgICAgICAgZHJpdmUocGF0aFtsZW4ocGF0aCkgLSAxXSkKICAgICAgICBob3VzZVtfbXlfdmFyaWFibGUrMV0uc2hvdygpCiAgICBlbHNlOgogICAgICAgIGRlbCBwYXRoW2xlbihwYXRoKSAtIDFdCiAgICAgICAgaG91c2VbMF0uc2hvdygpCiAgICAgICAgdGltZS5zbGVlcCgwLjUpCiAgICAgICAgaG91c2VbMF0uaGlkZSgpCiAgICAgICAgaG91c2VbZl0uaGlkZSgpCiAgICAgICAgZHJpdmUocGF0aFtsZW4ocGF0aCkgLSAxXSkKICAgICAgICBmb3IgaSBpbiByYW5nZSg3KToKICAgICAgICAgICAgbWFya1tmXVtpKzFdID0gMAogICAgICAgICAgICB2aXNbZl0gPSAwCg==</code>
|
||||
@@ -0,0 +1 @@
|
||||
<xml version="Mixly 2.0 rc4" board="Python 3 Lite@Python 3 Lite"><block type="algorithm_prepare_2_1" id="zdQXXEM$g@nwJMy4A^g_" x="-910" y="71"><next><block type="controls_whileUntil" id="Z~::;?|vNDl1o,.aIqz~"><field name="MODE">WHILE</field><value name="BOOL"><shadow type="logic_boolean" id="lHgNCr2v:neec+jPzcnh"><field name="BOOL">TRUE</field></shadow><block type="algorithm_not_home" id="b,#Y#gCUWJe+}gWz*]lO"></block></value><statement name="DO"><block type="algorithm_move_recent" id="iO:25_U1;+UYE4(U?pj8"></block></statement><next><block type="algorithm_print_path2" id="4y5Gz[_k3D:.4kCd|yF|"></block></next></block></next></block></xml><config>{}</config><code>aW1wb3J0IHRpbWUKaW1wb3J0IHNwcml0ZQoKCmcgPSBbWzEwMDAwLDEwMDAwLDEwMDAwLDEwMDAwLDEwMDAwLDEwMDAwLDEwMDAwLDEwMDAwLDEwMDAwLDEwMDAwLDEwMDAwXSxbMTAwMDAsMTAwMDAsNTAwLDMwMCwxMDAwMCwxMDAwMCwxMDAwMCwxMDAwMCwxMDAwMCwxMDAwMCwxMDAwMF0sWzEwMDAwLDUwMCwxMDAwMCwxMDAwMCwxMDAsMTAwMDAsMTAwMDAsMTAwMDAsMTAwMDAsMTAwMDAsMTAwMDBdLFsxMDAwMCwzMDAsMTAwMDAsMTAwMDAsNDAwLDMwMCwxMDAwMCwxMDAwMCwxMDAwMCwxMDAwMCwxMDAwMF0sWzEwMDAwLDEwMDAwLDEwMCw0MDAsMTAwMDAsMTAwMDAsMjAwLDEwMDAwLDEwMDAwLDEwMDAwLDEwMDAwXSxbMTAwMDAsMTAwMDAsMTAwMDAsMzAwLDEwMDAwLDEwMDAwLDEwMCwyMDAsMTAwMDAsMTAwMDAsMTAwMDBdLFsxMDAwMCwxMDAwMCwxMDAwMCwxMDAwMCwyMDAsMTAwLDEwMDAwLDEwMDAwLDEwMCwxMDAwMCwxMDAwMF0sWzEwMDAwLDEwMDAwLDEwMDAwLDEwMDAwLDEwMDAwLDIwMCwxMDAwMCwxMDAwMCwxMDAsMTAwMDAsMTAwMDBdLFsxMDAwMCwxMDAwMCwxMDAwMCwxMDAwMCwxMDAwMCwxMDAwMCwxMDAsMTAwLDEwMDAwLDEwMDAwLDEwMDAwXV0Kbm93PTEKbGFzdD0xCnBhdGg9W10KcGF0aC5hcHBlbmQoMSkKbmFtZSA9IFsiIiwi5bCP5oCd5a62Iiwi6ZO26KGMIiwi6YKu5bGAIiwi6aSQ5Y6FIiwi5Lmm5bqXIiwi5Yy76ZmiIiwi6LaF5biCIiwi5bCP56eR5a62Il0KcG9zaXRpb24gPSBbWzAsIDBdLCBbNjAsIDMyMF0sIFs1MTAsIDM5MF0sIFsyNDAsIDIwMF0sIFs3NTAsIDMzMF0sIFs0MTAsIDkwXSwgWzU0MCwgMTkwXSwgWzU1MCwgMzBdLCBbNzIwLCAxMjBdXQpzcHJpdGUuY2xlYXJBbGxTcHJpdGVzKCkKc3ByaXRlLmNyZWF0ZUJhY2tncm91bmQoJ21hcF9zaV9rZScpCnN0dSA9IHNwcml0ZS5TcHJpdGUoJ2dpcmwnLCA2MCwgMzIwKQpzdHUuZW5sYXJnZVRvKDEwMCkKdGltZS5zbGVlcCgxKQoKd2hpbGUgbmFtZVtub3ddICE9ICflsI/np5HlrrYnOgogICAgdG1wPTEwMDAwCiAgICBmb3IgaSBpbiByYW5nZSgwLCBsZW4oZyksIDEpOgogICAgICAgIGlmIGdbbm93XVtpXTx0bXAgYW5kIGkhPWxhc3Q6CiAgICAgICAgICAgIG5leHQ9aQogICAgICAgICAgICB0bXA9Z1tub3ddW2ldCiAgICBzdHUuc2xpZGVUbyhwb3NpdGlvbltuZXh0XVswXSwgcG9zaXRpb25bbmV4dF1bMV0sIDEpCiAgICB0aW1lLnNsZWVwKDAuNSkKICAgIHBhdGguYXBwZW5kKG5leHQpCiAgICBsYXN0PW5vdwogICAgbm93PW5leHQKICAgIGlmIGxlbihwYXRoKT42OgogICAgICAgIHByaW50KCLot6/nur/plJnkubHvvIHnqIvluo/mnInor6/vvIEiKQogICAgICAgIGV4aXQoKQpyZXMgPSAiIgpmb3IgaSBpbiBwYXRoOgogICAgcmVzID0gcmVzICsgbmFtZVtpXSArICLihpIiCnByaW50KHJlc1s6LTFdKQo=</code>
|
||||
File diff suppressed because one or more lines are too long
146
boards/default_src/python_skulpt/origin/examples/map.json
Normal file
146
boards/default_src/python_skulpt/origin/examples/map.json
Normal file
@@ -0,0 +1,146 @@
|
||||
{
|
||||
"01-1 海归画图初体验.mix": {
|
||||
"__file__": true,
|
||||
"__name__": "01-1 海归画图初体验.mix"
|
||||
},
|
||||
"01-2 绘制四边形.mix": {
|
||||
"__file__": true,
|
||||
"__name__": "01-2 绘制四边形.mix"
|
||||
},
|
||||
"01-2-2 绘制四边形.mix": {
|
||||
"__file__": true,
|
||||
"__name__": "01-2-2 绘制四边形.mix"
|
||||
},
|
||||
"01-3 绘制多边形.mix": {
|
||||
"__file__": true,
|
||||
"__name__": "01-3 绘制多边形.mix"
|
||||
},
|
||||
"01-3-2 绘制多边形.mix": {
|
||||
"__file__": true,
|
||||
"__name__": "01-3-2 绘制多边形.mix"
|
||||
},
|
||||
"02-1 一笔画五角形.mix": {
|
||||
"__file__": true,
|
||||
"__name__": "02-1 一笔画五角形.mix"
|
||||
},
|
||||
"02-1-2 一笔画五角形.mix": {
|
||||
"__file__": true,
|
||||
"__name__": "02-1-2 一笔画五角形.mix"
|
||||
},
|
||||
"02-2 绘制红心.mix": {
|
||||
"__file__": true,
|
||||
"__name__": "02-2 绘制红心.mix"
|
||||
},
|
||||
"02-2-2 绘制红心.mix": {
|
||||
"__file__": true,
|
||||
"__name__": "02-2-2 绘制红心.mix"
|
||||
},
|
||||
"03-1 绘制螺旋线.mix": {
|
||||
"__file__": true,
|
||||
"__name__": "03-1 绘制螺旋线.mix"
|
||||
},
|
||||
"03-1-2 绘制螺旋线.mix": {
|
||||
"__file__": true,
|
||||
"__name__": "03-1-2 绘制螺旋线.mix"
|
||||
},
|
||||
"03-2 绘制螺旋线-字典.mix": {
|
||||
"__file__": true,
|
||||
"__name__": "03-2 绘制螺旋线-字典.mix"
|
||||
},
|
||||
"03-2 绘制螺旋线.mix": {
|
||||
"__file__": true,
|
||||
"__name__": "03-2 绘制螺旋线.mix"
|
||||
},
|
||||
"04-0 投票选举.mix": {
|
||||
"__file__": true,
|
||||
"__name__": "04-0 投票选举.mix"
|
||||
},
|
||||
"04-1 投票选举.mix": {
|
||||
"__file__": true,
|
||||
"__name__": "04-1 投票选举.mix"
|
||||
},
|
||||
"05-1 凯撒加密(一位密码).mix": {
|
||||
"__file__": true,
|
||||
"__name__": "05-1 凯撒加密(一位密码).mix"
|
||||
},
|
||||
"05-2 凯撒加密(ASCII码补充解密验证).mix": {
|
||||
"__file__": true,
|
||||
"__name__": "05-2 凯撒加密(ASCII码补充解密验证).mix"
|
||||
},
|
||||
"05-2 凯撒加密(ASCII码).mix": {
|
||||
"__file__": true,
|
||||
"__name__": "05-2 凯撒加密(ASCII码).mix"
|
||||
},
|
||||
"05-2 凯撒加密(多位密码).mix": {
|
||||
"__file__": true,
|
||||
"__name__": "05-2 凯撒加密(多位密码).mix"
|
||||
},
|
||||
"06-1 人机出数字比大小.mix": {
|
||||
"__file__": true,
|
||||
"__name__": "06-1 人机出数字比大小.mix"
|
||||
},
|
||||
"06-1 猜数字游戏.mix": {
|
||||
"__file__": true,
|
||||
"__name__": "06-1 猜数字游戏.mix"
|
||||
},
|
||||
"06-1-2 人机出数字比大小.mix": {
|
||||
"__file__": true,
|
||||
"__name__": "06-1-2 人机出数字比大小.mix"
|
||||
},
|
||||
"06-2-2 猜数字限定次数.mix": {
|
||||
"__file__": true,
|
||||
"__name__": "06-2-2 猜数字限定次数.mix"
|
||||
},
|
||||
"06-2-3 二分法.mix": {
|
||||
"__file__": true,
|
||||
"__name__": "06-2-3 二分法.mix"
|
||||
},
|
||||
"07-1 鸡兔同笼.mix": {
|
||||
"__file__": true,
|
||||
"__name__": "07-1 鸡兔同笼.mix"
|
||||
},
|
||||
"07-2 韩信点兵.mix": {
|
||||
"__file__": true,
|
||||
"__name__": "07-2 韩信点兵.mix"
|
||||
},
|
||||
"08-1 冒泡排序.mix": {
|
||||
"__file__": true,
|
||||
"__name__": "08-1 冒泡排序.mix"
|
||||
},
|
||||
"08-2 选择排序.mix": {
|
||||
"__file__": true,
|
||||
"__name__": "08-2 选择排序.mix"
|
||||
},
|
||||
"08-3 插入排序.mix": {
|
||||
"__file__": true,
|
||||
"__name__": "08-3 插入排序.mix"
|
||||
},
|
||||
"08-4 快速排序.mix": {
|
||||
"__file__": true,
|
||||
"__name__": "08-4 快速排序.mix"
|
||||
},
|
||||
"09-1 2层汉诺塔算法.mix": {
|
||||
"__file__": true,
|
||||
"__name__": "09-1 2层汉诺塔算法.mix"
|
||||
},
|
||||
"09-2 3层汉诺塔算法.mix": {
|
||||
"__file__": true,
|
||||
"__name__": "09-2 3层汉诺塔算法.mix"
|
||||
},
|
||||
"09-2 多层汉诺塔算法.mix": {
|
||||
"__file__": true,
|
||||
"__name__": "09-2 多层汉诺塔算法.mix"
|
||||
},
|
||||
"10-1 回溯算法.mix": {
|
||||
"__file__": true,
|
||||
"__name__": "10-1 回溯算法.mix"
|
||||
},
|
||||
"11-1 贪心算法.mix": {
|
||||
"__file__": true,
|
||||
"__name__": "11-1 贪心算法.mix"
|
||||
},
|
||||
"2-2-3凯撒加密(ASCII码补充解密验证).mix": {
|
||||
"__file__": true,
|
||||
"__name__": "2-2-3凯撒加密(ASCII码补充解密验证).mix"
|
||||
}
|
||||
}
|
||||
BIN
boards/default_src/python_skulpt/origin/media/webpy.png
Normal file
BIN
boards/default_src/python_skulpt/origin/media/webpy.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 52 KiB |
BIN
boards/default_src/python_skulpt/origin/media/webpy0.png
Normal file
BIN
boards/default_src/python_skulpt/origin/media/webpy0.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 31 KiB |
3
boards/default_src/python_skulpt/others/loader.js
Normal file
3
boards/default_src/python_skulpt/others/loader.js
Normal file
@@ -0,0 +1,3 @@
|
||||
import NavExt from './nav-ext';
|
||||
|
||||
NavExt.init();
|
||||
97
boards/default_src/python_skulpt/others/mixpy-project.js
Normal file
97
boards/default_src/python_skulpt/others/mixpy-project.js
Normal file
@@ -0,0 +1,97 @@
|
||||
export default class MixpyProject {
|
||||
constructor() {
|
||||
this.initProject();
|
||||
}
|
||||
|
||||
initProject() {
|
||||
this.fileD = {};
|
||||
this.MAINF = 'main.py';
|
||||
this.fileD[this.MAINF] = ["", true, 1];
|
||||
this.selectFile = this.MAINF;
|
||||
}
|
||||
|
||||
add(file, filecontent, filetype) {
|
||||
if (this.exist(file)) {
|
||||
console.log("Warning:file already in project");
|
||||
return;
|
||||
}
|
||||
this.fileD[file] = [filecontent, false, filetype];
|
||||
}
|
||||
|
||||
delete(file) {
|
||||
delete this.fileD[file];
|
||||
this.selectFile = undefined;
|
||||
}
|
||||
|
||||
getProject() {
|
||||
return Object.keys(this.fileD);
|
||||
}
|
||||
|
||||
getUploadFileList() {
|
||||
var fileNameList = Object.keys(this.fileD);
|
||||
var ret = [];
|
||||
for (var i in fileNameList) {
|
||||
if (this.fileD[fileNameList[i]][2] === 2)
|
||||
ret.push(fileNameList[i]);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
getNewFileList() {
|
||||
var fileNameList = Object.keys(this.fileD);
|
||||
var ret = [];
|
||||
for (var i in fileNameList) {
|
||||
if (this.fileD[fileNameList[i]][2] === 1)
|
||||
ret.push(fileNameList[i]);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
isSelect(f) {
|
||||
return this.fileD[f][1];
|
||||
}
|
||||
|
||||
select(f) {
|
||||
// if (this.selectFile !== undefined) {
|
||||
// this.modify(this.selectFile, mixlyjs.getCodeContent());
|
||||
// this.fileD[this.selectFile][1] = false;
|
||||
// }
|
||||
this.fileD[f][1] = true;
|
||||
// this.selectFile = f;
|
||||
// var suffix = mixlyjs.getFileSuffix(f);
|
||||
// var textFileSuffix = ["py", "txt", "csv", "xml"];
|
||||
// if (textFileSuffix.indexOf(suffix) !== -1) {
|
||||
// tabClick('arduino');
|
||||
// mixlyjs.renderIno(this.fileD[f][0]);
|
||||
// } else {
|
||||
// var base64str = 'data:image/' + suffix + ';base64,' + this.fileD[f][0];
|
||||
// $('#mixpy_show_image').attr('src', base64str);
|
||||
// mixlyjs.renderIno(this.fileD[f][0]);
|
||||
// tabClick('image');
|
||||
// var $imageA = $('#mixpy_link_image');
|
||||
// $imageA.attr('href', base64str);
|
||||
// $imageA.attr('download', f);
|
||||
// }
|
||||
}
|
||||
|
||||
getFileNum() {
|
||||
var files = Object.keys(this.fileD);
|
||||
return files.length;
|
||||
}
|
||||
|
||||
getFileContent(f) {
|
||||
return this.fileD[f][0];
|
||||
}
|
||||
|
||||
getFileType(f) {
|
||||
return this.fileD[f][2];
|
||||
}
|
||||
|
||||
modify(f, content) {
|
||||
this.fileD[f][0] = content;
|
||||
}
|
||||
|
||||
exist(f) {
|
||||
return f in this.fileD;
|
||||
}
|
||||
}
|
||||
42
boards/default_src/python_skulpt/others/nav-ext.js
Normal file
42
boards/default_src/python_skulpt/others/nav-ext.js
Normal file
@@ -0,0 +1,42 @@
|
||||
import { app, Nav, Debug } from 'mixly';
|
||||
import * as Blockly from 'blockly/core';
|
||||
import PythonShell from './python-shell';
|
||||
|
||||
const NavExt = {};
|
||||
|
||||
NavExt.init = function () {
|
||||
PythonShell.init();
|
||||
const nav = app.getNav();
|
||||
|
||||
nav.register({
|
||||
icon: 'icon-play-circled',
|
||||
title: '',
|
||||
id: 'python-run-btn',
|
||||
displayText: Blockly.Msg.MSG['run'],
|
||||
preconditionFn: () => {
|
||||
return true;
|
||||
},
|
||||
callback: () => {
|
||||
PythonShell.run().catch(Debug.error);
|
||||
},
|
||||
scopeType: Nav.Scope.LEFT,
|
||||
weight: 4
|
||||
});
|
||||
|
||||
nav.register({
|
||||
icon: 'icon-cancel',
|
||||
title: '',
|
||||
id: 'python-stop-btn',
|
||||
displayText: Blockly.Msg.MSG['stop'],
|
||||
preconditionFn: () => {
|
||||
return true;
|
||||
},
|
||||
callback: () => {
|
||||
PythonShell.stop().catch(Debug.error);
|
||||
},
|
||||
scopeType: Nav.Scope.LEFT,
|
||||
weight: 5
|
||||
});
|
||||
}
|
||||
|
||||
export default NavExt;
|
||||
806
boards/default_src/python_skulpt/others/py-engine.js
Normal file
806
boards/default_src/python_skulpt/others/py-engine.js
Normal file
@@ -0,0 +1,806 @@
|
||||
/* eslint-disable new-cap */
|
||||
import Sk from './skulpt/skulpt';
|
||||
import {
|
||||
Events,
|
||||
Debug
|
||||
} from 'mixly';
|
||||
import MIXPY_TEMPLATE from '../templates/python/mixpy.py';
|
||||
|
||||
const externalLibs = {//外部引入的第三方库
|
||||
"./numpy/__init__.js": "../common/js/skulpt_libs/numpy/__init__.js",
|
||||
"./pygal/__init__.js": "../common/js/skulpt_libs/pygal/__init__.js",
|
||||
// "./numpy/random/__init__.js" : 'https://cdn.jsdelivr.net/gh/ebertmi/skulpt_numpy@master/numpy/random/__init__.js',
|
||||
"./matplotlib/__init__.js": '../common/js/skulpt_libs/matplotlib/__init__.js',
|
||||
"./matplotlib/pyplot/__init__.js": "../common/js/skulpt_libs/pyplot/__init__.js",
|
||||
'./pgzhelper/__init__.js': "../common/js/skulpt_libs/pgzhelper/pgzhelper.js",
|
||||
"./sprite/__init__.js": "../common/js/skulpt_libs/sprite/basic.js"
|
||||
};
|
||||
|
||||
var GLOBAL_VALUE;
|
||||
|
||||
function prettyPrintError(error) {
|
||||
if (typeof error === "string") {
|
||||
return error;
|
||||
}
|
||||
// A weird skulpt thing?
|
||||
if (error.tp$str !== undefined) {
|
||||
return error.tp$str().v;
|
||||
}
|
||||
return "" + error.name + ": " + error.message;
|
||||
}
|
||||
|
||||
export default class PyEngine {
|
||||
#events_ = new Events(['input', 'output', 'display', 'finished', 'error']);
|
||||
|
||||
constructor(programStatus, mixpyProject) {
|
||||
this.programStatus = programStatus;
|
||||
this.mixpyProject = mixpyProject;
|
||||
/**
|
||||
* Definable function to be run when execution has fully ended,
|
||||
* whether it succeeds or fails.
|
||||
*
|
||||
*/
|
||||
this.onExecutionEnd = null;
|
||||
}
|
||||
|
||||
getEvents() {
|
||||
return this.#events_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function that will attempt to call the defined onExecutionEnd,
|
||||
* but will do nothing if there is no function defined.
|
||||
*/
|
||||
executionEnd_() {
|
||||
if (this.onExecutionEnd !== null) {
|
||||
this.onExecutionEnd();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the Python Execution engine and the Printer (console).
|
||||
*/
|
||||
loadEngine(container) {
|
||||
Sk.__future__ = Sk.python3;
|
||||
// No connected services
|
||||
Sk.connectedServices = {};
|
||||
// No time limit
|
||||
//Sk.execLimit = null;
|
||||
// Ensure version 3, so we get proper print handling
|
||||
// Sk.python3 = true;
|
||||
//输出海龟画图图片
|
||||
//如果需要输出pygame_zero场景,需要重新设置
|
||||
Sk.TurtleGraphics = {
|
||||
target: container,
|
||||
width: 500,
|
||||
height: 500
|
||||
};
|
||||
|
||||
//数据分析显示图片
|
||||
Sk.MatPlotLibGraphics = {
|
||||
target: container,
|
||||
width: 500,
|
||||
height: 500
|
||||
};
|
||||
// TODO
|
||||
//Sk.console = printer.getConfiguration();
|
||||
// Definitely use a prompt
|
||||
Sk.inputfunTakesPrompt = true;
|
||||
|
||||
// Keeps track of the tracing while the program is executing; destroyed afterwards.
|
||||
this.executionBuffer = {};
|
||||
|
||||
Sk.domOutput = (html) => {
|
||||
const dom = this.#events_.on('display', html)[0];
|
||||
return dom;
|
||||
};
|
||||
|
||||
Sk.configure({
|
||||
//设置文本输出
|
||||
output: (lineText) => {
|
||||
this.#events_.run('output', {
|
||||
content: lineText
|
||||
});
|
||||
},
|
||||
// Function to handle loading in new files
|
||||
read: this.readFile.bind(this),
|
||||
inputfun: this.skInput.bind(this),
|
||||
inputfunTakesPrompt: true,
|
||||
execLimit: Number.POSITIVE_INFINITY,
|
||||
fileread: this.fileread.bind(this),
|
||||
filewrite: this.filewrite.bind(this),
|
||||
__future__: Sk.python3, //python3已成默认值,要使用python2需要单独设置
|
||||
});
|
||||
|
||||
Sk.builtins.value = new Sk.builtin.func(function () {
|
||||
return Sk.ffi.remapToPy(GLOBAL_VALUE === undefined ? 5 : GLOBAL_VALUE);
|
||||
});
|
||||
Sk.builtins.set_value = new Sk.builtin.func(function (v) {
|
||||
GLOBAL_VALUE = v.v;
|
||||
});
|
||||
|
||||
Sk.builtinFiles.files['./mixpy.py'] = MIXPY_TEMPLATE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to access Skulpt built-ins. This is pretty generic, taken
|
||||
* almost directly from the Skulpt docs.
|
||||
*
|
||||
* @param {String} filename - The python filename (e.g., "os" or "pprint") that will be loaded.
|
||||
* @returns {String} The JavaScript source code of the file (weird, right?)
|
||||
* @throws Will throw an error if the file isn't found.
|
||||
*/
|
||||
readFile(file) {
|
||||
// console.log("Attempting file: " + Sk.ffi.remapToJs(file));
|
||||
// 加载模块
|
||||
// if (PyGameZero.matchModelName(file)) {
|
||||
// return PyGameZero.load(file);
|
||||
// }
|
||||
if (externalLibs[file] !== undefined) {
|
||||
return Sk.misceval.promiseToSuspension(fetch(externalLibs[file]).then((resp) => resp.text()));
|
||||
}
|
||||
if (Sk.builtinFiles === undefined || Sk.builtinFiles.files[file] === undefined) {
|
||||
throw "File not found: '" + file + "'";
|
||||
}
|
||||
return Sk.builtinFiles.files[file];
|
||||
}
|
||||
|
||||
fileread(filename, mode) {
|
||||
if (this.mixpyProject.exist(filename)) {
|
||||
return this.mixpyProject.getFileContent(filename);
|
||||
}
|
||||
if (mode.indexOf('w') !== -1) {
|
||||
this.mixpyProject.add(filename, '', 1);
|
||||
return '';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
filewrite(fileItem, str) {
|
||||
var filename = fileItem.name;
|
||||
this.mixpyProject.modify(filename, str);
|
||||
this.mixpyProject.select(filename);
|
||||
}
|
||||
|
||||
skInput(prompt) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.#events_.run('input', {
|
||||
content: {
|
||||
prompt
|
||||
},
|
||||
resolve, reject
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the state of the execution engine, including reinitailizing
|
||||
* the execution buffer (trace, step, etc.), reseting the printer, and
|
||||
* hiding the trace button.
|
||||
*
|
||||
*/
|
||||
reset() {
|
||||
Sk.execLimit = Number.POSITIVE_INFINITY;
|
||||
Sk.TurtleGraphics.reset && Sk.TurtleGraphics.reset();
|
||||
}
|
||||
|
||||
kill() {
|
||||
// 新增了sprite相关内容
|
||||
// SPRITE.kill();
|
||||
//点击取消按钮发送数据
|
||||
Sk.execLimit = 0;
|
||||
this.executionEnd_();
|
||||
}
|
||||
|
||||
/**
|
||||
* "Steps" the execution of the code, meant to be used as a callback to the Skulpt
|
||||
* environment.
|
||||
*
|
||||
* @param {Object} variables - Hash that maps the names of variables (Strings) to their Skulpt representation.
|
||||
* @param {Number} lineNumber - The corresponding line number in the source code that is being executed.
|
||||
* @param {Number} columnNumber - The corresponding column number in the source code that is being executed. Think of it as the "X" position to the lineNumber's "Y" position.
|
||||
* @param {String} filename - The name of the python file being executed (e.g., "__main__.py").
|
||||
* @param {String} astType - Unused? TODO: What is this?
|
||||
* @param {String} ast - String-encoded JSON representation of the AST node associated with this element.
|
||||
*/
|
||||
step(variables, lineNumber,
|
||||
columnNumber, filename) {
|
||||
if (filename == '<stdin>.py') {
|
||||
var currentStep = this.executionBuffer.step;
|
||||
var globals = this.parseGlobals(variables);
|
||||
this.executionBuffer.trace.push(
|
||||
{
|
||||
'step': currentStep,
|
||||
'filename': filename,
|
||||
//'block': highlightMap[lineNumber-1],
|
||||
'line': lineNumber,
|
||||
'column': columnNumber,
|
||||
'properties': globals.properties,
|
||||
'modules': globals.modules
|
||||
}
|
||||
);
|
||||
this.executionBuffer.step = currentStep + 1;
|
||||
this.executionBuffer.last_step = currentStep + 1;
|
||||
this.executionBuffer.line_number = lineNumber;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the AbstractInterpreter to get some static information about the code,
|
||||
* in particular the variables' types. This is needed for type checking.
|
||||
*
|
||||
* @returns {Object<String, AIType>} Maps variable names (as Strings) to types as constructed by the AbstractIntepreter.
|
||||
*/
|
||||
analyzeVariables() {
|
||||
// Get the code
|
||||
var code = this.main.model.programs['__main__']();
|
||||
if (code.trim() == "") {
|
||||
return {};
|
||||
}
|
||||
|
||||
// var analyzer = new AbstractInterpreter(code);
|
||||
// report = analyzer.report;
|
||||
// return analyzer.variableTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the AbstractInterpreter to get some static information about the code,
|
||||
* including potential semantic errors. It then parses that information to give
|
||||
* feedback.
|
||||
*
|
||||
* @returns {Boolean} Whether the code was successfully analyzed.
|
||||
*/
|
||||
analyze() {
|
||||
this.main.model.execution.status("analyzing");
|
||||
|
||||
// var feedback = this.main.components.feedback;
|
||||
|
||||
// Get the code
|
||||
var code = this.main.model.programs['__main__']();
|
||||
if (code.trim() == "") {
|
||||
this.main.components.feedback.emptyProgram("You haven't written any code yet!");
|
||||
//this.main.model.feedback.status("semantic");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the given python code, resetting the console and Trace Table.
|
||||
*/
|
||||
run(code) {
|
||||
// Reset everything
|
||||
this.reset();
|
||||
this.programStatus['running'] = true;
|
||||
Sk.misceval.asyncToPromise(() => Sk.importMainWithBody("<stdin>", false, code, true))
|
||||
.then(() => {
|
||||
this.programStatus['running'] = false;
|
||||
this.#events_.run('finished');
|
||||
})
|
||||
.catch((error) => {
|
||||
Debug.error(error);
|
||||
this.programStatus['running'] = false;
|
||||
this.#events_.run('error', error);
|
||||
var original = prettyPrintError(error);
|
||||
this.#events_.run('finished');
|
||||
//hack for kill program with time limiterror
|
||||
if (original.indexOf("TimeLimitError") !== -1) {
|
||||
return;
|
||||
}
|
||||
this.executionEnd_();
|
||||
});
|
||||
}
|
||||
|
||||
setupEnvironment(student_code, traceTable, output, ast, final_values) {
|
||||
var model = this.main.model;
|
||||
this._backup_execution = Sk.afterSingleExecution;
|
||||
Sk.afterSingleExecution = undefined;
|
||||
Sk.builtins.get_output = new Sk.builtin.func(function () {
|
||||
Sk.builtin.pyCheckArgs("get_output", arguments, 0, 0);
|
||||
return Sk.ffi.remapToPy(model.execution.output());
|
||||
});
|
||||
Sk.builtins.reset_output = new Sk.builtin.func(function () {
|
||||
Sk.builtin.pyCheckArgs("reset_output", arguments, 0, 0);
|
||||
model.execution.output.removeAll();
|
||||
});
|
||||
Sk.builtins.log = new Sk.builtin.func(function (data) {
|
||||
Sk.builtin.pyCheckArgs("log", arguments, 1, 1);
|
||||
console.log(data);
|
||||
});
|
||||
//Sk.builtins.trace = Sk.ffi.remapToPy(traceTable);
|
||||
Sk.builtins._trace = traceTable;
|
||||
Sk.builtins._final_values = final_values;
|
||||
Sk.builtins.code = Sk.ffi.remapToPy(student_code);
|
||||
Sk.builtins.set_success = this.instructor_module.set_success;
|
||||
Sk.builtins.set_feedback = this.instructor_module.set_feedback;
|
||||
Sk.builtins.set_finished = this.instructor_module.set_finished;
|
||||
Sk.builtins.count_components = this.instructor_module.count_components;
|
||||
Sk.builtins.no_nonlist_nums = this.instructor_module.no_nonlist_nums;
|
||||
Sk.builtins.only_printing_properties = this.instructor_module.only_printing_properties;
|
||||
Sk.builtins.calls_function = this.instructor_module.calls_function;
|
||||
Sk.builtins.get_property = this.instructor_module.get_property;
|
||||
Sk.builtins.get_value_by_name = this.instructor_module.get_value_by_name;
|
||||
Sk.builtins.get_value_by_type = this.instructor_module.get_value_by_type;
|
||||
Sk.builtins.parse_json = this.instructor_module.parse_json;
|
||||
Sk.skip_drawing = true;
|
||||
model.settings.mute_printer(true);
|
||||
}
|
||||
|
||||
disposeEnvironment() {
|
||||
Sk.afterSingleExecution = this._backup_execution;
|
||||
Sk.builtins.get_output = undefined;
|
||||
Sk.builtins.reset_output = undefined;
|
||||
Sk.builtins.log = undefined;
|
||||
Sk.builtins._trace = undefined;
|
||||
Sk.builtins.trace = undefined;
|
||||
Sk.builtins.code = undefined;
|
||||
Sk.builtins.set_success = undefined;
|
||||
Sk.builtins.set_feedback = undefined;
|
||||
Sk.builtins.set_finished = undefined;
|
||||
Sk.builtins.count_components = undefined;
|
||||
Sk.builtins.calls_function = undefined;
|
||||
Sk.builtins.get_property = undefined;
|
||||
Sk.builtins.get_value_by_name = undefined;
|
||||
Sk.builtins.get_value_by_type = undefined;
|
||||
Sk.builtins.no_nonlist_nums = undefined;
|
||||
Sk.builtins.only_printing_properties = undefined;
|
||||
Sk.builtins.parse_json = undefined;
|
||||
Sk.skip_drawing = false;
|
||||
GLOBAL_VALUE = undefined;
|
||||
this.main.model.settings.mute_printer(false);
|
||||
}
|
||||
|
||||
parseGlobals(variables) {
|
||||
var result = Array();
|
||||
var modules = Array();
|
||||
for (var property in variables) {
|
||||
var value = variables[property];
|
||||
if (property !== "__name__" && property !== "__doc__") {
|
||||
property = property.replace('_$rw$', '')
|
||||
.replace('_$rn$', '');
|
||||
var parsed = this.parseValue(property, value);
|
||||
if (parsed !== null) {
|
||||
result.push(parsed);
|
||||
} else if (value.constructor == Sk.builtin.module) {
|
||||
modules.push(value.$d.__name__.v);
|
||||
}
|
||||
}
|
||||
}
|
||||
return { "properties": result, "modules": modules };
|
||||
}
|
||||
|
||||
parseValue(property, value) {
|
||||
if (value == undefined) {
|
||||
return {
|
||||
'name': property,
|
||||
'type': 'Unknown',
|
||||
"value": 'Undefined'
|
||||
};
|
||||
}
|
||||
switch (value.constructor) {
|
||||
case Sk.builtin.func:
|
||||
return {
|
||||
'name': property,
|
||||
'type': "Function",
|
||||
"value": (value.func_code.co_varnames !== undefined ?
|
||||
" Arguments: " + value.func_code.co_varnames.join(", ") :
|
||||
' No arguments')
|
||||
};
|
||||
case Sk.builtin.module: return null;
|
||||
case Sk.builtin.str:
|
||||
return {
|
||||
'name': property,
|
||||
'type': "String",
|
||||
"value": value.$r().v
|
||||
};
|
||||
case Sk.builtin.none:
|
||||
return {
|
||||
'name': property,
|
||||
'type': "None",
|
||||
"value": "None"
|
||||
};
|
||||
case Sk.builtin.bool:
|
||||
return {
|
||||
'name': property,
|
||||
'type': "Boolean",
|
||||
"value": value.$r().v
|
||||
};
|
||||
case Sk.builtin.nmber:
|
||||
return {
|
||||
'name': property,
|
||||
'type': "int" == value.skType ? "Integer" : "Float",
|
||||
"value": value.$r().v
|
||||
};
|
||||
case Sk.builtin.int_:
|
||||
return {
|
||||
'name': property,
|
||||
'type': "Integer",
|
||||
"value": value.$r().v
|
||||
};
|
||||
case Sk.builtin.float_:
|
||||
return {
|
||||
'name': property,
|
||||
'type': "Float",
|
||||
"value": value.$r().v
|
||||
};
|
||||
case Sk.builtin.tuple:
|
||||
return {
|
||||
'name': property,
|
||||
'type': "Tuple",
|
||||
"value": value.$r().v
|
||||
};
|
||||
case Sk.builtin.list:
|
||||
if (value.v.length <= 20) {
|
||||
return {
|
||||
'name': property,
|
||||
'type': "List",
|
||||
"value": value.$r().v,
|
||||
'exact_value': value
|
||||
};
|
||||
}
|
||||
return {
|
||||
'name': property,
|
||||
'type': "List",
|
||||
"value": "[... " + value.v.length + " elements ...]",
|
||||
"exact_value": value
|
||||
};
|
||||
|
||||
case Sk.builtin.dict:
|
||||
return {
|
||||
'name': property,
|
||||
'type': "Dictionary",
|
||||
"value": value.$r().v
|
||||
};
|
||||
case Number:
|
||||
return {
|
||||
'name': property,
|
||||
'type': value % 1 === 0 ? "Integer" : "Float",
|
||||
"value": value
|
||||
};
|
||||
case String:
|
||||
return {
|
||||
'name': property,
|
||||
'type': "String",
|
||||
"value": value
|
||||
};
|
||||
case Boolean:
|
||||
return {
|
||||
'name': property,
|
||||
'type': "Boolean",
|
||||
"value": (value ? "True" : "False")
|
||||
};
|
||||
default:
|
||||
return {
|
||||
'name': property,
|
||||
'type': value.tp$name == undefined ? value : value.tp$name,
|
||||
"value": value.$r == undefined ? value : value.$r().v
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Skulpt Module for holding the Instructor API.
|
||||
*
|
||||
* This module is a little hackish. We need to sit down and reevaluate the best way to
|
||||
* organize it and whether this particular structure is ideal. I suspect it should be
|
||||
* it's own proper JS file.
|
||||
*
|
||||
* @param {String} name - The name of the module (should always be 'instructor')
|
||||
*
|
||||
*/
|
||||
// var instructor_module = function (name) {
|
||||
// // Main module object that gets returned at the end.
|
||||
// var mod = {};
|
||||
|
||||
// /**
|
||||
// * Skulpt Exception that represents a Feedback object, to be rendered to the user
|
||||
// * when the feedback system finds a problem.
|
||||
// *
|
||||
// * @param {Array} args - A list of optional arguments to pass to the Exception.
|
||||
// * Usually this will include a message for the user.
|
||||
// */
|
||||
// Sk.builtin.Feedback = function (args) {
|
||||
// var o;
|
||||
// if (!(this instanceof Sk.builtin.Feedback)) {
|
||||
// o = Object.create(Sk.builtin.Feedback.prototype);
|
||||
// o.constructor.apply(o, arguments);
|
||||
// return o;
|
||||
// }
|
||||
// Sk.builtin.Exception.apply(this, arguments);
|
||||
// };
|
||||
// Sk.abstr.setUpInheritance("Feedback", Sk.builtin.Feedback, Sk.builtin.Exception);
|
||||
|
||||
// /**
|
||||
// * Skulpt Exception that represents a Success object, to be thrown when the user
|
||||
// * completes their program successfully.
|
||||
// *
|
||||
// ** @param {Array} args - A list of optional arguments to pass to the Exception.
|
||||
// * Usually this will be empty.
|
||||
// */
|
||||
// Sk.builtin.Success = function (args) {
|
||||
// var o;
|
||||
// if (!(this instanceof Sk.builtin.Success)) {
|
||||
// o = Object.create(Sk.builtin.Success.prototype);
|
||||
// o.constructor.apply(o, arguments);
|
||||
// return o;
|
||||
// }
|
||||
// Sk.builtin.Exception.apply(this, arguments);
|
||||
// };
|
||||
// Sk.abstr.setUpInheritance("Success", Sk.builtin.Success, Sk.builtin.Exception);
|
||||
|
||||
// /**
|
||||
// * Skulpt Exception that represents a Finished object, to be thrown when the user
|
||||
// * completes their program successfully, but isn't in a problem with a "solution".
|
||||
// * This is useful for open-ended canvases where we still want to capture the students'
|
||||
// * code in Canvas.
|
||||
// *
|
||||
// ** @param {Array} args - A list of optional arguments to pass to the Exception.
|
||||
// * Usually this will be empty.
|
||||
// */
|
||||
// Sk.builtin.Finished = function (args) {
|
||||
// var o;
|
||||
// if (!(this instanceof Sk.builtin.Finished)) {
|
||||
// o = Object.create(Sk.builtin.Finished.prototype);
|
||||
// o.constructor.apply(o, arguments);
|
||||
// return o;
|
||||
// }
|
||||
// Sk.builtin.Exception.apply(this, arguments);
|
||||
// };
|
||||
// Sk.abstr.setUpInheritance("Finished", Sk.builtin.Finished, Sk.builtin.Exception);
|
||||
|
||||
// /**
|
||||
// * A Skulpt function that throws a Feedback exception, allowing us to give feedback
|
||||
// * to the user through the Feedback panel. This function call is done for aesthetic
|
||||
// * reasons, so that we are calling a function instead of raising an error. Still,
|
||||
// * exceptions allow us to break out of the control flow immediately, like a
|
||||
// * return, so they are a good mechanism to use under the hood.
|
||||
// *
|
||||
// * @param {String} message - The message to display to the user.
|
||||
// */
|
||||
// mod.set_feedback = new Sk.builtin.func(function (message) {
|
||||
// Sk.builtin.pyCheckArgs("set_feedback", arguments, 1, 1);
|
||||
// Sk.builtin.pyCheckType("message", "string", Sk.builtin.checkString(message));
|
||||
// throw new Sk.builtin.Feedback(message.v);
|
||||
// });
|
||||
|
||||
// /**
|
||||
// * A Skulpt function that throws a Success exception. This will terminate the
|
||||
// * feedback analysis, but reports that the students' code was successful.
|
||||
// * This function call is done for aesthetic reasons, so that we are calling a
|
||||
// * function instead of raising an error. Still, exceptions allow us to break
|
||||
// * out of the control flow immediately, like a return would, so they are a
|
||||
// * good mechanism to use under the hood.
|
||||
// */
|
||||
// mod.set_success = new Sk.builtin.func(function () {
|
||||
// Sk.builtin.pyCheckArgs("set_success", arguments, 0, 0);
|
||||
// throw new Sk.builtin.Success();
|
||||
// });
|
||||
|
||||
// /**
|
||||
// * A Skulpt function that throws a Finished exception. This will terminate the
|
||||
// * feedback analysis, but reports that the students' code was successful.
|
||||
// * This function call is done for aesthetic reasons, so that we are calling a
|
||||
// * function instead of raising an error. Still, exceptions allow us to break
|
||||
// * out of the control flow immediately, like a return would, so they are a
|
||||
// * good mechanism to use under the hood.
|
||||
// */
|
||||
// mod.set_finished = new Sk.builtin.func(function () {
|
||||
// Sk.builtin.pyCheckArgs("set_finished", arguments, 0, 0);
|
||||
// throw new Sk.builtin.Finished();
|
||||
// });
|
||||
|
||||
// // Memoization of previous parses - some mild redundancy to save time
|
||||
// // TODO: There's no evidence this is good, and could be a memory hog on big
|
||||
// // programs. Someone should investigate this. The assumption is that multiple
|
||||
// // helper functions might be using parses. But shouldn't we trim old parses?
|
||||
// // Perhaps a timed cache would work better.
|
||||
// var parses = {};
|
||||
|
||||
// /**
|
||||
// * Given source code as a string, return a flat list of all of the AST elements
|
||||
// * in the parsed source code.
|
||||
// *
|
||||
// * TODO: There's redundancy here, since the source code was previously parsed
|
||||
// * to run the file and to execute it. We should probably be able to do this just
|
||||
// * once and shave off time.
|
||||
// *
|
||||
// * @param {String} source - Python source code.
|
||||
// * @returns {Array.<Object>}
|
||||
// */
|
||||
// function getParseList(source) {
|
||||
// if (!(source in parses)) {
|
||||
// var parse = Sk.parse("__main__", source);
|
||||
// parses[source] = Sk.astFromParse(parse.cst, "__main__", parse.flags);
|
||||
// }
|
||||
// var ast = parses[source];
|
||||
// return (new NodeVisitor()).recursive_walk(ast);
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Given source code as a string, return a list of all of the AST elements
|
||||
// * that are Num (aka numeric literals) but that are not inside List elements.
|
||||
// *
|
||||
// * @param {String} source - Python source code.
|
||||
// * @returns {Array.number} The list of JavaScript numeric literals that were found.
|
||||
// */
|
||||
// function getNonListNums(source) {
|
||||
// if (!(source in parses)) {
|
||||
// var parse = Sk.parse("__main__", source);
|
||||
// parses[source] = Sk.astFromParse(parse.cst, "__main__", parse.flags);
|
||||
// }
|
||||
// var ast = parses[source];
|
||||
// var visitor = new NodeVisitor();
|
||||
// var insideList = false;
|
||||
// var nums = [];
|
||||
// visitor.visit_List = function (node) {
|
||||
// insideList = true;
|
||||
// this.generic_visit(node);
|
||||
// insideList = false;
|
||||
// }
|
||||
// visitor.visit_Num = function (node) {
|
||||
// if (!insideList) {
|
||||
// nums.push(node.n);
|
||||
// }
|
||||
// this.generic_visit(node);
|
||||
// }
|
||||
// visitor.visit(ast);
|
||||
// return nums;
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Given source code as a string, return a list of all of the AST elements
|
||||
// * that are being printed (using the print function) but are not variables.
|
||||
// *
|
||||
// * @param {String} source - Python source code.
|
||||
// * @returns {Array.<Object>} The list of AST elements that were found.
|
||||
// */
|
||||
// function getPrintedNonProperties(source) {
|
||||
// if (!(source in parses)) {
|
||||
// var parse = Sk.parse("__main__", source);
|
||||
// parses[source] = Sk.astFromParse(parse.cst, "__main__", parse.flags);
|
||||
// }
|
||||
// var ast = parses[source];
|
||||
// var visitor = new NodeVisitor();
|
||||
// var nonVariables = [];
|
||||
// visitor.visit_Call = function (node) {
|
||||
// var func = node.func;
|
||||
// var args = node.args;
|
||||
// if (func._astname == 'Name' && func.id.v == 'print') {
|
||||
// for (var i = 0; i < args.length; i += 1) {
|
||||
// if (args[i]._astname != "Name") {
|
||||
// nonVariables.push(args[i]);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// this.generic_visit(node);
|
||||
// }
|
||||
// visitor.visit(ast);
|
||||
// return nonVariables;
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Skulpt function to iterate through the final state of
|
||||
// * all the variables in the program, and check to see if they have
|
||||
// * a given value.
|
||||
// */
|
||||
// mod.get_value_by_name = new Sk.builtin.func(function (name) {
|
||||
// Sk.builtin.pyCheckArgs("get_value_by_name", arguments, 1, 1);
|
||||
// Sk.builtin.pyCheckType("name", "string", Sk.builtin.checkString(name));
|
||||
// name = name.v;
|
||||
// var final_values = Sk.builtins._final_values;
|
||||
// if (name in final_values) {
|
||||
// return final_values[name];
|
||||
// }
|
||||
// return Sk.builtin.none.none$;
|
||||
|
||||
// });
|
||||
// mod.get_value_by_type = new Sk.builtin.func(function (type) {
|
||||
// Sk.builtin.pyCheckArgs("get_value_by_type", arguments, 1, 1);
|
||||
|
||||
// var final_values = Sk.builtins._final_values;
|
||||
// var result = [];
|
||||
// for (var property in final_values) {
|
||||
// if (final_values[property].tp$name == type.tp$name) {
|
||||
// result.push(final_values[property]);
|
||||
// }
|
||||
// }
|
||||
// return Sk.builtin.list(result);
|
||||
// });
|
||||
|
||||
// mod.parse_json = new Sk.builtin.func(function (blob) {
|
||||
// Sk.builtin.pyCheckArgs("parse_json", arguments, 1, 1);
|
||||
// Sk.builtin.pyCheckType("blob", "string", Sk.builtin.checkString(blob));
|
||||
// blob = blob.v;
|
||||
// return Sk.ffi.remapToPy(JSON.parse(blob));
|
||||
// });
|
||||
// mod.get_property = new Sk.builtin.func(function (name) {
|
||||
// Sk.builtin.pyCheckArgs("get_property", arguments, 1, 1);
|
||||
// Sk.builtin.pyCheckType("name", "string", Sk.builtin.checkString(name));
|
||||
// name = name.v;
|
||||
// var trace = Sk.builtins._trace;
|
||||
// if (trace.length <= 0) {
|
||||
// return Sk.builtin.none.none$;
|
||||
// }
|
||||
// var properties = trace[trace.length - 1]["properties"];
|
||||
// for (var i = 0, len = properties.length; i < len; i += 1) {
|
||||
// if (properties[i]['name'] == name) {
|
||||
// return Sk.ffi.remapToPy(properties[i])
|
||||
// }
|
||||
// }
|
||||
// return Sk.builtin.none.none$;
|
||||
// });
|
||||
|
||||
// mod.calls_function = new Sk.builtin.func(function (source, name) {
|
||||
// Sk.builtin.pyCheckArgs("calls_function", arguments, 2, 2);
|
||||
// Sk.builtin.pyCheckType("source", "string", Sk.builtin.checkString(source));
|
||||
// Sk.builtin.pyCheckType("name", "string", Sk.builtin.checkString(name));
|
||||
|
||||
// source = source.v;
|
||||
// name = name.v;
|
||||
|
||||
// var ast_list = getParseList(source);
|
||||
|
||||
// var count = 0;
|
||||
// for (var i = 0, len = ast_list.length; i < len; i = i + 1) {
|
||||
// if (ast_list[i]._astname == 'Call') {
|
||||
// if (ast_list[i].func._astname == 'Attribute') {
|
||||
// count += Sk.ffi.remapToJs(ast_list[i].func.attr) == name | 0;
|
||||
// } else if (ast_list[i].func._astname == 'Name') {
|
||||
// count += Sk.ffi.remapToJs(ast_list[i].func.id) == name | 0;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// return Sk.ffi.remapToPy(count > 0);
|
||||
// });
|
||||
|
||||
// mod.count_components = new Sk.builtin.func(function (source, component) {
|
||||
// Sk.builtin.pyCheckArgs("count_components", arguments, 2, 2);
|
||||
// Sk.builtin.pyCheckType("source", "string", Sk.builtin.checkString(source));
|
||||
// Sk.builtin.pyCheckType("component", "string", Sk.builtin.checkString(component));
|
||||
|
||||
// source = source.v;
|
||||
// component = component.v;
|
||||
|
||||
// var ast_list = getParseList(source);
|
||||
|
||||
// var count = 0;
|
||||
// for (var i = 0, len = ast_list.length; i < len; i = i + 1) {
|
||||
// if (ast_list[i]._astname == component) {
|
||||
// count = count + 1;
|
||||
// }
|
||||
// }
|
||||
|
||||
// return Sk.ffi.remapToPy(count);
|
||||
// });
|
||||
|
||||
// mod.no_nonlist_nums = new Sk.builtin.func(function (source) {
|
||||
// Sk.builtin.pyCheckArgs("no_nonlist_nums", arguments, 1, 1);
|
||||
// Sk.builtin.pyCheckType("source", "string", Sk.builtin.checkString(source));
|
||||
|
||||
// source = source.v;
|
||||
|
||||
// var num_list = getNonListNums(source);
|
||||
|
||||
// var count = 0;
|
||||
// for (var i = 0, len = num_list.length; i < len; i = i + 1) {
|
||||
// if (num_list[i].v != 0 && num_list[i].v != 1) {
|
||||
// return Sk.ffi.remapToPy(true);
|
||||
// }
|
||||
// }
|
||||
// return Sk.ffi.remapToPy(false);
|
||||
// });
|
||||
// mod.only_printing_properties = new Sk.builtin.func(function (source) {
|
||||
// Sk.builtin.pyCheckArgs("only_printing_properties", arguments, 1, 1);
|
||||
// Sk.builtin.pyCheckType("source", "string", Sk.builtin.checkString(source));
|
||||
|
||||
// source = source.v;
|
||||
|
||||
// var non_var_list = getPrintedNonProperties(source);
|
||||
// return Sk.ffi.remapToPy(non_var_list.length == 0);
|
||||
// });
|
||||
|
||||
// return mod;
|
||||
// }
|
||||
194
boards/default_src/python_skulpt/others/python-shell.js
Normal file
194
boards/default_src/python_skulpt/others/python-shell.js
Normal file
@@ -0,0 +1,194 @@
|
||||
import MixpyProject from './mixpy-project';
|
||||
import PyEngine from './py-engine';
|
||||
import { Workspace, Msg } from 'mixly';
|
||||
import StatusBarImage from './statusbar-image';
|
||||
|
||||
class PythonShell {
|
||||
static {
|
||||
this.pythonShell = null;
|
||||
|
||||
this.init = async function () {
|
||||
StatusBarImage.init();
|
||||
this.pythonShell = new PythonShell();
|
||||
}
|
||||
|
||||
this.run = function () {
|
||||
const mainWorkspace = Workspace.getMain();
|
||||
const editor = mainWorkspace.getEditorsManager().getActive();
|
||||
const code = editor.getCode();
|
||||
return this.pythonShell.run(code);
|
||||
}
|
||||
|
||||
this.stop = function () {
|
||||
return this.pythonShell.stop();
|
||||
}
|
||||
}
|
||||
|
||||
#statusBarTerminal_ = null;
|
||||
#statusBarImage_ = null;
|
||||
#statusBarsManager_ = null;
|
||||
#cursor_ = {
|
||||
row: 0,
|
||||
column: 0
|
||||
};
|
||||
#prompt_ = '';
|
||||
#inputResolve_ = null;
|
||||
#inputReject_ = null;
|
||||
#waittingForInput_ = false;
|
||||
#running_ = false;
|
||||
#pyEngine_ = null;
|
||||
#onCursorChangeEvent_ = () => this.#onCursorChange_();
|
||||
#commands_ = [
|
||||
{
|
||||
name: 'REPL-Enter',
|
||||
bindKey: 'Enter',
|
||||
exec: (editor) => {
|
||||
const session = editor.getSession();
|
||||
const cursor = session.selection.getCursor();
|
||||
if (cursor.row === this.#cursor_.row) {
|
||||
const newPos = this.#statusBarTerminal_.getEndPos();
|
||||
let str = this.#statusBarTerminal_.getValueRange(this.#cursor_, newPos);
|
||||
str = str.replace(this.#prompt_, '');
|
||||
this.#inputResolve_?.(str);
|
||||
this.#inputResolve_ = null;
|
||||
this.#inputReject_ = null;
|
||||
this.#statusBarTerminal_.addValue('\n');
|
||||
this.#exitInput_();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}, {
|
||||
name: 'REPL-ChangeEditor',
|
||||
bindKey: 'Delete|Ctrl-X|Backspace',
|
||||
exec: (editor) => {
|
||||
const session = editor.getSession();
|
||||
const cursor = session.selection.getCursor();
|
||||
if (cursor.row < this.#cursor_.row || cursor.column <= this.#cursor_.column) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
];
|
||||
constructor() {
|
||||
const mainWorkspace = Workspace.getMain();
|
||||
this.#statusBarsManager_ = mainWorkspace.getStatusBarsManager();
|
||||
this.#statusBarTerminal_ = this.#statusBarsManager_.getStatusBarById('output');
|
||||
this.#statusBarImage_ = this.#statusBarsManager_.getStatusBarById('images');
|
||||
this.#pyEngine_ = new PyEngine({}, new MixpyProject());
|
||||
this.#pyEngine_.loadEngine(this.#statusBarImage_.getContent().children()[0]);
|
||||
this.#addEventsListener_();
|
||||
}
|
||||
|
||||
#addEventsListener_() {
|
||||
const events = this.#pyEngine_.getEvents();
|
||||
events.bind('finished', () => {
|
||||
this.#running_ = false;
|
||||
this.#statusBarTerminal_.addValue(`\n==${Msg.Lang['shell.finish']}==`);
|
||||
});
|
||||
|
||||
events.bind('output', (data) => {
|
||||
this.#statusBarTerminal_.addValue(data.content);
|
||||
});
|
||||
|
||||
events.bind('error', (data) => {
|
||||
this.#running_ = false;
|
||||
this.#statusBarTerminal_.addValue(`\n${data.toString()}\n`);
|
||||
});
|
||||
|
||||
events.bind('input', (data) => {
|
||||
const prompt = String(data?.content?.prompt);
|
||||
this.#statusBarTerminal_.addValue(`>>> ${prompt}`);
|
||||
this.#prompt_ = prompt;
|
||||
this.#inputResolve_ = data.resolve;
|
||||
this.#inputReject_ = data.reject;
|
||||
this.#enterInput_();
|
||||
});
|
||||
|
||||
events.bind('display', (data) => {
|
||||
this.#statusBarsManager_.changeTo('images');
|
||||
this.#statusBarImage_.display(data);
|
||||
});
|
||||
}
|
||||
|
||||
#onCursorChange_() {
|
||||
const editor = this.#statusBarTerminal_.getEditor();
|
||||
const session = editor.getSession();
|
||||
const cursor = session.selection.getCursor();
|
||||
editor.setReadOnly(
|
||||
cursor.row < this.#cursor_.row || cursor.column < this.#cursor_.column
|
||||
);
|
||||
}
|
||||
|
||||
#enterInput_() {
|
||||
if (!this.#running_) {
|
||||
return;
|
||||
}
|
||||
this.#waittingForInput_ = true;
|
||||
this.#cursor_ = this.#statusBarTerminal_.getEndPos();
|
||||
const editor = this.#statusBarTerminal_.getEditor();
|
||||
editor.setReadOnly(false);
|
||||
editor.focus();
|
||||
const session = editor.getSession();
|
||||
session.selection.on('changeCursor', this.#onCursorChangeEvent_);
|
||||
editor.commands.addCommands(this.#commands_);
|
||||
}
|
||||
|
||||
#exitInput_() {
|
||||
this.#waittingForInput_ = false;
|
||||
const editor = this.#statusBarTerminal_.getEditor();
|
||||
const session = editor.getSession();
|
||||
session.selection.off('changeCursor', this.#onCursorChangeEvent_);
|
||||
editor.commands.removeCommands(this.#commands_);
|
||||
this.#prompt_ = '';
|
||||
this.#inputResolve_?.('');
|
||||
// this.#inputReject_?.({});
|
||||
this.cursor_ = { row: 0, column: 0 };
|
||||
editor.setReadOnly(true);
|
||||
}
|
||||
|
||||
addPrompt(prompt, resolve, reject) {
|
||||
this.#statusBarTerminal_.addValue(prompt);
|
||||
this.#prompt_ = prompt;
|
||||
this.#inputResolve_ = resolve;
|
||||
this.#inputReject_ = reject;
|
||||
this.#enterInput_();
|
||||
}
|
||||
|
||||
async run(code) {
|
||||
await this.stop();
|
||||
this.#statusBarsManager_.changeTo('output');
|
||||
this.#statusBarsManager_.show();
|
||||
this.#statusBarTerminal_.setValue(`${Msg.Lang['shell.running']}...\n`);
|
||||
this.#running_ = true;
|
||||
if (code.indexOf('import turtle') !== -1
|
||||
|| code.indexOf('from turtle import') !== -1
|
||||
|| code.indexOf('import matplotlib') !== -1
|
||||
|| code.indexOf('from matplotlib import') !== -1
|
||||
|| code.indexOf('import pgzrun') !== -1
|
||||
|| code.indexOf('from pgzrun import') !== -1
|
||||
|| code.indexOf('import sprite') !== -1
|
||||
|| code.indexOf('from sprite import') !== -1) {
|
||||
this.#statusBarsManager_.changeTo('images');
|
||||
}
|
||||
this.#pyEngine_.run(code);
|
||||
}
|
||||
|
||||
async stop() {
|
||||
if (this.#waittingForInput_) {
|
||||
this.#exitInput_();
|
||||
}
|
||||
if (this.#running_) {
|
||||
this.#pyEngine_.kill();
|
||||
await this.sleep(500);
|
||||
this.#running_ = false;
|
||||
}
|
||||
}
|
||||
|
||||
sleep(ms) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
}
|
||||
|
||||
export default PythonShell;
|
||||
312
boards/default_src/python_skulpt/others/skulpt/debugger.js
Normal file
312
boards/default_src/python_skulpt/others/skulpt/debugger.js
Normal file
@@ -0,0 +1,312 @@
|
||||
/**
|
||||
* Debugger support for skulpt module
|
||||
*/
|
||||
|
||||
var Sk = Sk || {}; //jshint ignore:line
|
||||
|
||||
function hasOwnProperty(obj, prop) {
|
||||
var proto = obj.constructor.prototype;
|
||||
return (prop in obj) &&
|
||||
(!(prop in proto) || proto[prop] !== obj[prop]);
|
||||
}
|
||||
|
||||
Sk.Breakpoint = function(filename, lineno, colno) {
|
||||
this.filename = filename;
|
||||
this.lineno = lineno;
|
||||
this.colno = colno;
|
||||
this.enabled = true;
|
||||
this.ignore_count = 0;
|
||||
};
|
||||
|
||||
Sk.Debugger = function(filename, output_callback) {
|
||||
this.dbg_breakpoints = {};
|
||||
this.tmp_breakpoints = {};
|
||||
this.suspension_stack = [];
|
||||
this.current_suspension = -1;
|
||||
this.eval_callback = null;
|
||||
this.suspension = null;
|
||||
this.output_callback = output_callback;
|
||||
this.step_mode = false;
|
||||
this.filename = filename;
|
||||
};
|
||||
|
||||
Sk.Debugger.prototype.print = function(txt) {
|
||||
if (this.output_callback != null) {
|
||||
this.output_callback.print(txt);
|
||||
}
|
||||
};
|
||||
|
||||
Sk.Debugger.prototype.get_source_line = function(lineno) {
|
||||
if (this.output_callback != null) {
|
||||
return this.output_callback.get_source_line(lineno);
|
||||
}
|
||||
|
||||
return "";
|
||||
};
|
||||
|
||||
Sk.Debugger.prototype.move_up_the_stack = function() {
|
||||
this.current_suspension = Math.min(this.current_suspension + 1, this.suspension_stack.length - 1);
|
||||
};
|
||||
|
||||
Sk.Debugger.prototype.move_down_the_stack = function() {
|
||||
this.current_suspension = Math.max(this.current_suspension - 1, 0);
|
||||
};
|
||||
|
||||
Sk.Debugger.prototype.enable_step_mode = function() {
|
||||
this.step_mode = true;
|
||||
};
|
||||
|
||||
Sk.Debugger.prototype.disable_step_mode = function() {
|
||||
this.step_mode = false;
|
||||
};
|
||||
|
||||
Sk.Debugger.prototype.get_suspension_stack = function() {
|
||||
return this.suspension_stack;
|
||||
};
|
||||
|
||||
Sk.Debugger.prototype.get_active_suspension = function() {
|
||||
if (this.suspension_stack.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.suspension_stack[this.current_suspension];
|
||||
};
|
||||
|
||||
Sk.Debugger.prototype.generate_breakpoint_key = function(filename, lineno, colno) {
|
||||
var key = filename + "-" + lineno;
|
||||
return key;
|
||||
};
|
||||
|
||||
Sk.Debugger.prototype.check_breakpoints = function(filename, lineno, colno, globals, locals) {
|
||||
// If Step mode is enabled then ignore breakpoints since we will just break
|
||||
// at every line.
|
||||
if (this.step_mode === true) {
|
||||
return true;
|
||||
}
|
||||
|
||||
var key = this.generate_breakpoint_key(filename, lineno, colno);
|
||||
if (hasOwnProperty(this.dbg_breakpoints, key) &&
|
||||
this.dbg_breakpoints[key].enabled === true) {
|
||||
var bp = null;
|
||||
if (hasOwnProperty(this.tmp_breakpoints, key)) {
|
||||
delete this.dbg_breakpoints[key];
|
||||
delete this.tmp_breakpoints[key];
|
||||
return true;
|
||||
}
|
||||
|
||||
this.dbg_breakpoints[key].ignore_count -= 1;
|
||||
this.dbg_breakpoints[key].ignore_count = Math.max(0, this.dbg_breakpoints[key].ignore_count);
|
||||
|
||||
bp = this.dbg_breakpoints[key];
|
||||
if (bp.ignore_count === 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
Sk.Debugger.prototype.get_breakpoints_list = function() {
|
||||
return this.dbg_breakpoints;
|
||||
};
|
||||
|
||||
Sk.Debugger.prototype.disable_breakpoint = function(filename, lineno, colno) {
|
||||
var key = this.generate_breakpoint_key(filename, lineno, colno);
|
||||
|
||||
if (hasOwnProperty(this.dbg_breakpoints, key)) {
|
||||
this.dbg_breakpoints[key].enabled = false;
|
||||
}
|
||||
};
|
||||
|
||||
Sk.Debugger.prototype.enable_breakpoint = function(filename, lineno, colno) {
|
||||
var key = this.generate_breakpoint_key(filename, lineno, colno);
|
||||
|
||||
if (hasOwnProperty(this.dbg_breakpoints, key)) {
|
||||
this.dbg_breakpoints[key].enabled = true;
|
||||
}
|
||||
};
|
||||
|
||||
Sk.Debugger.prototype.clear_breakpoint = function(filename, lineno, colno) {
|
||||
var key = this.generate_breakpoint_key(filename, lineno, colno);
|
||||
if (hasOwnProperty(this.dbg_breakpoints, key)) {
|
||||
delete this.dbg_breakpoints[key];
|
||||
return null;
|
||||
} else {
|
||||
return "Invalid breakpoint specified: " + filename + " line: " + lineno;
|
||||
}
|
||||
};
|
||||
|
||||
Sk.Debugger.prototype.clear_all_breakpoints = function() {
|
||||
this.dbg_breakpoints = {};
|
||||
this.tmp_breakpoints = {};
|
||||
};
|
||||
|
||||
Sk.Debugger.prototype.set_ignore_count = function(filename, lineno, colno, count) {
|
||||
var key = this.generate_breakpoint_key(filename, lineno, colno);
|
||||
if (hasOwnProperty(this.dbg_breakpoints, key)) {
|
||||
var bp = this.dbg_breakpoints[key];
|
||||
bp.ignore_count = count;
|
||||
}
|
||||
};
|
||||
|
||||
Sk.Debugger.prototype.set_condition = function(filename, lineno, colno, lhs, cond, rhs) {
|
||||
var key = this.generate_breakpoint_key(filename, lineno, colno);
|
||||
var bp;
|
||||
if (hasOwnProperty(this.dbg_breakpoints, key)) {
|
||||
// Set a new condition
|
||||
bp = this.dbg_breakpoints[key];
|
||||
} else {
|
||||
bp = new Sk.Breakpoint(filename, lineno, colno);
|
||||
}
|
||||
|
||||
bp.condition = new Sk.Condition(lhs, cond, rhs);
|
||||
this.dbg_breakpoints[key] = bp;
|
||||
};
|
||||
|
||||
Sk.Debugger.prototype.print_suspension_info = function(suspension) {
|
||||
var filename = suspension.filename;
|
||||
var lineno = suspension.lineno;
|
||||
var colno = suspension.colno;
|
||||
this.print("Hit Breakpoint at <" + filename + "> at line: " + lineno + " column: " + colno + "\n");
|
||||
this.print("----------------------------------------------------------------------------------\n");
|
||||
this.print(" ==> " + this.get_source_line(lineno - 1) + "\n");
|
||||
this.print("----------------------------------------------------------------------------------\n");
|
||||
};
|
||||
|
||||
Sk.Debugger.prototype.set_suspension = function(suspension) {
|
||||
var parent = null;
|
||||
if (!hasOwnProperty(suspension, "filename") && suspension.child instanceof Sk.misceval.Suspension) {
|
||||
suspension = suspension.child;
|
||||
}
|
||||
|
||||
// Pop the last suspension of the stack if there is more than 0
|
||||
if (this.suspension_stack.length > 0) {
|
||||
this.suspension_stack.pop();
|
||||
this.current_suspension -= 1;
|
||||
}
|
||||
|
||||
// Unroll the stack to get each suspension.
|
||||
while (suspension instanceof Sk.misceval.Suspension) {
|
||||
parent = suspension;
|
||||
this.suspension_stack.push(parent);
|
||||
this.current_suspension += 1;
|
||||
suspension = suspension.child;
|
||||
}
|
||||
|
||||
suspension = parent;
|
||||
|
||||
this.print_suspension_info(suspension);
|
||||
};
|
||||
|
||||
Sk.Debugger.prototype.add_breakpoint = function(filename, lineno, colno, temporary) {
|
||||
var key = this.generate_breakpoint_key(filename, lineno, colno);
|
||||
this.dbg_breakpoints[key] = new Sk.Breakpoint(filename, lineno, colno);
|
||||
if (temporary) {
|
||||
this.tmp_breakpoints[key] = true;
|
||||
}
|
||||
};
|
||||
|
||||
Sk.Debugger.prototype.suspension_handler = function(susp) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
try {
|
||||
resolve(susp.resume());
|
||||
} catch(e) {
|
||||
reject(e);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Sk.Debugger.prototype.resume = function() {
|
||||
// Reset the suspension stack to the topmost
|
||||
this.current_suspension = this.suspension_stack.length - 1;
|
||||
|
||||
if (this.suspension_stack.length === 0) {
|
||||
this.print("No running program");
|
||||
} else {
|
||||
var promise = this.suspension_handler(this.get_active_suspension());
|
||||
promise.then(this.success.bind(this), this.error.bind(this));
|
||||
}
|
||||
};
|
||||
|
||||
Sk.Debugger.prototype.pop_suspension_stack = function() {
|
||||
this.suspension_stack.pop();
|
||||
this.current_suspension -= 1;
|
||||
};
|
||||
|
||||
Sk.Debugger.prototype.success = function(r) {
|
||||
if (r instanceof Sk.misceval.Suspension) {
|
||||
this.set_suspension(r);
|
||||
} else {
|
||||
if (this.suspension_stack.length > 0) {
|
||||
// Current suspension needs to be popped of the stack
|
||||
this.pop_suspension_stack();
|
||||
|
||||
if (this.suspension_stack.length === 0) {
|
||||
this.print("Program execution complete");
|
||||
return;
|
||||
}
|
||||
|
||||
var parent_suspension = this.get_active_suspension();
|
||||
// The child has completed the execution. So override the child's resume
|
||||
// so we can continue the execution.
|
||||
parent_suspension.child.resume = function() {
|
||||
return r;
|
||||
};
|
||||
this.resume();
|
||||
} else {
|
||||
this.print("Program execution complete");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Sk.Debugger.prototype.error = function(e) {
|
||||
this.print("Traceback (most recent call last):");
|
||||
for (var idx = 0; idx < e.traceback.length; ++idx) {
|
||||
this.print(" File \"" + e.traceback[idx].filename + "\", line " + e.traceback[idx].lineno + ", in <module>");
|
||||
var code = this.get_source_line(e.traceback[idx].lineno - 1);
|
||||
code = code.trim();
|
||||
code = " " + code;
|
||||
this.print(code);
|
||||
}
|
||||
|
||||
var err_ty = e.constructor.tp$name;
|
||||
for (idx = 0; idx < e.args.v.length; ++idx) {
|
||||
this.print(err_ty + ": " + e.args.v[idx].v);
|
||||
}
|
||||
};
|
||||
|
||||
Sk.Debugger.prototype.asyncToPromise = function(suspendablefn, suspHandlers, debugger_obj) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
try {
|
||||
var r = suspendablefn();
|
||||
|
||||
(function handleResponse (r) {
|
||||
try {
|
||||
while (r instanceof Sk.misceval.Suspension) {
|
||||
debugger_obj.set_suspension(r);
|
||||
return;
|
||||
}
|
||||
|
||||
resolve(r);
|
||||
} catch(e) {
|
||||
reject(e);
|
||||
}
|
||||
})(r);
|
||||
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Sk.Debugger.prototype.execute = function(suspendablefn, suspHandlers) {
|
||||
var r = suspendablefn();
|
||||
|
||||
if (r instanceof Sk.misceval.Suspension) {
|
||||
this.suspensions.concat(r);
|
||||
this.eval_callback(r);
|
||||
}
|
||||
};
|
||||
|
||||
goog.exportSymbol("Sk.Debugger", Sk.Debugger);
|
||||
File diff suppressed because one or more lines are too long
4
boards/default_src/python_skulpt/others/skulpt/skulpt.js
Normal file
4
boards/default_src/python_skulpt/others/skulpt/skulpt.js
Normal file
@@ -0,0 +1,4 @@
|
||||
import './skulpt.min.js';
|
||||
import './skulpt-stdlib.js';
|
||||
|
||||
export default window.Sk;
|
||||
1133
boards/default_src/python_skulpt/others/skulpt/skulpt.min.js
vendored
Normal file
1133
boards/default_src/python_skulpt/others/skulpt/skulpt.min.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
166
boards/default_src/python_skulpt/others/statusbar-image.js
Normal file
166
boards/default_src/python_skulpt/others/statusbar-image.js
Normal file
@@ -0,0 +1,166 @@
|
||||
import STATUS_BAR_IMAGE_TEMPLATE from '../templates/html/statusbar-image.html';
|
||||
import {
|
||||
PageBase,
|
||||
HTMLTemplate,
|
||||
StatusBarsManager,
|
||||
Workspace
|
||||
} from 'mixly';
|
||||
import $ from 'jquery';
|
||||
|
||||
class StatusBarImage extends PageBase {
|
||||
static {
|
||||
HTMLTemplate.add(
|
||||
'html/statusbar/statusbar-image.html',
|
||||
new HTMLTemplate(STATUS_BAR_IMAGE_TEMPLATE)
|
||||
);
|
||||
|
||||
this.init = function () {
|
||||
StatusBarsManager.typesRegistry.register(['images'], StatusBarImage);
|
||||
const mainWorkspace = Workspace.getMain();
|
||||
const statusBarsManager = mainWorkspace.getStatusBarsManager();
|
||||
statusBarsManager.add('images', 'images', '图像');
|
||||
statusBarsManager.changeTo('output');
|
||||
}
|
||||
}
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
const $content = $(HTMLTemplate.get('html/statusbar/statusbar-image.html').render());
|
||||
this.setContent($content);
|
||||
}
|
||||
|
||||
init() {
|
||||
super.init();
|
||||
this.hideCloseBtn();
|
||||
}
|
||||
|
||||
clean() {
|
||||
this.getContent().empty();
|
||||
}
|
||||
|
||||
display(data) {
|
||||
const $content = this.getContent();
|
||||
const autoFit = function (node) {
|
||||
node.style.width = 'auto';
|
||||
node.style.height = 'auto';
|
||||
node.style.maxWidth = '100%';
|
||||
node.style.maxHeight = '100%';
|
||||
};
|
||||
this.clean();
|
||||
let root = data.content;
|
||||
let canvas = null;
|
||||
let iframe = null;
|
||||
switch (data.display_type) {
|
||||
case 'p5':
|
||||
root.style.width = '100%';
|
||||
root.style.height = '100%';
|
||||
root.style.display = 'flex';
|
||||
root.style.justifyContent = 'center';
|
||||
root.style.alignItems = 'center';
|
||||
|
||||
// some canvas nodes can be added later so we observe...
|
||||
new MutationObserver(function (mutationsList) {
|
||||
mutationsList.forEach((mutation) =>
|
||||
mutation.addedNodes.forEach((node) => {
|
||||
const elem = node;
|
||||
if (
|
||||
elem.tagName != null &&
|
||||
['canvas', 'video'].includes(elem.tagName.toLowerCase())
|
||||
)
|
||||
autoFit(elem);
|
||||
})
|
||||
);
|
||||
}).observe(root, { childList: true });
|
||||
|
||||
root.querySelectorAll('canvas,video').forEach(autoFit);
|
||||
$content.append(root);
|
||||
break;
|
||||
case 'matplotlib':
|
||||
canvas = root.querySelector('canvas');
|
||||
if (canvas) root = canvas;
|
||||
root.style.width = '';
|
||||
root.style.height = '';
|
||||
root.style.maxWidth = '100%';
|
||||
root.style.maxHeight = '100%';
|
||||
$content.append(root);
|
||||
break;
|
||||
case 'ocaml-canvas':
|
||||
root.style.width = '';
|
||||
root.style.height = '';
|
||||
root.style.maxWidth = '100%';
|
||||
root.style.maxHeight = '100%';
|
||||
$content.append(root);
|
||||
break;
|
||||
case 'turtle':
|
||||
// Turtle result
|
||||
root.setAttribute('width', '100%');
|
||||
root.setAttribute('height', '100%');
|
||||
$content.append(root.outerHTML);
|
||||
break;
|
||||
case 'sympy':
|
||||
$content.append(data.content);
|
||||
if (typeof window.MathJax === 'undefined') {
|
||||
// dynamically loading MathJax
|
||||
console.log('Loading MathJax (Sympy expression needs it).');
|
||||
(function () {
|
||||
let script = document.createElement('script');
|
||||
script.type = 'text/javascript';
|
||||
script.src =
|
||||
'https://cdn.jsdelivr.net/npm/mathjax@3.0.5/es5/tex-mml-chtml.js';
|
||||
document.getElementsByTagName('head')[0].appendChild(script);
|
||||
})();
|
||||
} else {
|
||||
// otherwise, render it
|
||||
window.MathJax.typeset();
|
||||
}
|
||||
break;
|
||||
case 'multiple':
|
||||
/* typically dispached by display() */
|
||||
for (let mime of [
|
||||
'image/svg+xml',
|
||||
'image/png',
|
||||
'text/html',
|
||||
'text/plain',
|
||||
]) {
|
||||
if (mime in data.content) {
|
||||
let content = data.content[mime];
|
||||
if (mime === 'image/png') {
|
||||
content =
|
||||
'<img src="data:image/png;base64,' +
|
||||
content +
|
||||
'" style="max-width: 100%; max-height: 100%;">';
|
||||
}
|
||||
$content.append(content);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'tutor':
|
||||
// hacky but iframe.document.body.style require to wait for
|
||||
// iframe loading
|
||||
$content.append($(data.content.replace('overflow-y%3A%20hidden%3B', '')));
|
||||
iframe = this.getContent()[0].getElementsByTagName('iframe')[0];
|
||||
if (iframe == null) return;
|
||||
// trick to avoid taking height update into account
|
||||
iframe.style.maxHeight = iframe.style.minHeight = '100%';
|
||||
|
||||
// force rendering when visible,
|
||||
// otherwise, strange things happends
|
||||
// since PythonTutor check for visibility at some point
|
||||
new IntersectionObserver((entries, observer) => {
|
||||
const entry = entries[0];
|
||||
if (entry && !entry.isIntersecting) return;
|
||||
iframe.contentWindow?.postMessage({ type: 'redraw' }, '*');
|
||||
observer.disconnect();
|
||||
}).observe(iframe);
|
||||
|
||||
break;
|
||||
default:
|
||||
console.error(
|
||||
`Not supported node type '${data.display_type}' in eval.display result processing.`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default StatusBarImage;
|
||||
32
boards/default_src/python_skulpt/package.json
Normal file
32
boards/default_src/python_skulpt/package.json
Normal file
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"name": "@mixly/python-skulpt",
|
||||
"version": "1.0.0",
|
||||
"description": "适用于mixly的python skulpt模块",
|
||||
"scripts": {
|
||||
"build:dev": "webpack --config=webpack.dev.js",
|
||||
"build:prod": "webpack --config=webpack.prod.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@mixly/python": "1.0.0"
|
||||
},
|
||||
"main": "./export.js",
|
||||
"author": "Mixly Team",
|
||||
"keywords": [
|
||||
"mixly",
|
||||
"mixly-plugin",
|
||||
"python-skulpt"
|
||||
],
|
||||
"homepage": "https://gitee.com/mixly2/mixly2.0_src/tree/develop/boards/default_src/python_skulpt",
|
||||
"bugs": {
|
||||
"url": "https://gitee.com/mixly2/mixly2.0_src/issues"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://gitee.com/mixly2/mixly2.0_src.git",
|
||||
"directory": "default_src/python_skulpt"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"license": "Apache 2.0"
|
||||
}
|
||||
2646
boards/default_src/python_skulpt/template.xml
Normal file
2646
boards/default_src/python_skulpt/template.xml
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,26 @@
|
||||
<style>
|
||||
div[m-id="{{d.mId}}"] {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
html[data-bs-theme=light] div[m-id="{{d.mId}}"] {
|
||||
background-color: #ffffff;
|
||||
}
|
||||
|
||||
html[data-bs-theme=dark] div[m-id="{{d.mId}}"] {
|
||||
background-color: #1e1e1e;
|
||||
}
|
||||
|
||||
div[m-id="{{d.mId}}"] > #output-img {
|
||||
width: 500px;
|
||||
height: 500px;
|
||||
position: relative;
|
||||
}
|
||||
</style>
|
||||
<div m-id="{{d.mId}}" class="page-item mixly-scrollbar">
|
||||
<div id="output-img"></div>
|
||||
</div>
|
||||
59
boards/default_src/python_skulpt/templates/python/mixpy.py
Normal file
59
boards/default_src/python_skulpt/templates/python/mixpy.py
Normal file
@@ -0,0 +1,59 @@
|
||||
import math
|
||||
|
||||
def math_map(v, al, ah, bl, bh):
|
||||
return bl + (bh - bl) * (v - al) / (ah - al)
|
||||
|
||||
def math_mean(myList):
|
||||
localList = [e for e in myList if type(e) == int or type(e) == float]
|
||||
if not localList: return
|
||||
return float(sum(localList)) / len(localList)
|
||||
|
||||
def math_median(myList):
|
||||
localList = sorted([e for e in myList if type(e) == int or type(e) == float])
|
||||
if not localList: return
|
||||
if len(localList) % 2 == 0:
|
||||
return (localList[len(localList) // 2 - 1] + localList[len(localList) // 2]) / 2.0
|
||||
else:
|
||||
return localList[(len(localList) - 1) // 2]
|
||||
|
||||
def math_modes(some_list):
|
||||
modes = []
|
||||
# Using a lists of [item, count] to keep count rather than dict
|
||||
# to avoid "unhashable" errors when the counted item is itself a list or dict.
|
||||
counts = []
|
||||
maxCount = 1
|
||||
for item in some_list:
|
||||
found = False
|
||||
for count in counts:
|
||||
if count[0] == item:
|
||||
count[1] += 1
|
||||
maxCount = max(maxCount, count[1])
|
||||
found = True
|
||||
if not found:
|
||||
counts.append([item, 1])
|
||||
for counted_item, item_count in counts:
|
||||
if item_count == maxCount:
|
||||
modes.append(counted_item)
|
||||
return modes
|
||||
|
||||
def math_standard_deviation(numbers):
|
||||
n = len(numbers)
|
||||
if n == 0: return
|
||||
mean = float(sum(numbers)) / n
|
||||
variance = sum((x - mean) ** 2 for x in numbers) / n
|
||||
return math.sqrt(variance)
|
||||
|
||||
def lists_sort(my_list, type, reverse):
|
||||
def try_float(s):
|
||||
try:
|
||||
return float(s)
|
||||
except:
|
||||
return 0
|
||||
key_funcs = {
|
||||
"NUMERIC": try_float,
|
||||
"TEXT": str,
|
||||
"IGNORE_CASE": lambda s: str(s).lower()
|
||||
}
|
||||
key_func = key_funcs[type]
|
||||
list_cpy = list(my_list)
|
||||
return sorted(list_cpy, key=key_func, reverse=reverse)
|
||||
23
boards/default_src/python_skulpt/webpack.common.js
Normal file
23
boards/default_src/python_skulpt/webpack.common.js
Normal file
@@ -0,0 +1,23 @@
|
||||
const path = require("path");
|
||||
const common = require("../../../webpack.common");
|
||||
const { merge } = require("webpack-merge");
|
||||
|
||||
module.exports = merge(common, {
|
||||
resolve: {
|
||||
alias: {
|
||||
'@mixly/python': path.resolve(__dirname, '../python'),
|
||||
'@mixly/python-mixpy': path.resolve(__dirname, '../python_mixpy')
|
||||
}
|
||||
},
|
||||
externals: {
|
||||
'sk': 'Sk'
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.py$/,
|
||||
type: "asset/source",
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
21
boards/default_src/python_skulpt/webpack.dev.js
Normal file
21
boards/default_src/python_skulpt/webpack.dev.js
Normal file
@@ -0,0 +1,21 @@
|
||||
const path = require("path");
|
||||
const common = require("./webpack.common");
|
||||
const { merge } = require("webpack-merge");
|
||||
const HtmlWebpackPlugin = require("html-webpack-plugin");
|
||||
const ESLintPlugin = require('eslint-webpack-plugin');
|
||||
|
||||
module.exports = merge(common, {
|
||||
mode: "development",
|
||||
devtool: 'source-map',
|
||||
plugins: [
|
||||
new ESLintPlugin({
|
||||
context: process.cwd(),
|
||||
}),
|
||||
new HtmlWebpackPlugin({
|
||||
inject: false,
|
||||
template: path.resolve(process.cwd(), 'template.xml'),
|
||||
filename: 'index.xml',
|
||||
minify: false
|
||||
}),
|
||||
]
|
||||
});
|
||||
27
boards/default_src/python_skulpt/webpack.prod.js
Normal file
27
boards/default_src/python_skulpt/webpack.prod.js
Normal file
@@ -0,0 +1,27 @@
|
||||
const path = require("path");
|
||||
const common = require("./webpack.common");
|
||||
const { merge } = require("webpack-merge");
|
||||
const TerserPlugin = require("terser-webpack-plugin");
|
||||
var HtmlWebpackPlugin = require("html-webpack-plugin");
|
||||
|
||||
module.exports = merge(common, {
|
||||
mode: "production",
|
||||
optimization: {
|
||||
minimize: true,
|
||||
minimizer: [
|
||||
new TerserPlugin({
|
||||
extractComments: false,
|
||||
}),
|
||||
new HtmlWebpackPlugin({
|
||||
inject: false,
|
||||
template: path.resolve(process.cwd(), 'template.xml'),
|
||||
filename: 'index.xml',
|
||||
minify: {
|
||||
removeAttributeQuotes: true,
|
||||
collapseWhitespace: true,
|
||||
removeComments: true,
|
||||
}
|
||||
})
|
||||
]
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user