nadesiko3 3.3.49 → 3.3.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +143 -143
- package/batch/.DS_Store +0 -0
- package/batch/browsers.template.md +3 -3
- package/batch/build_browsers.nako3 +72 -72
- package/batch/build_command.nako3 +44 -44
- package/batch/build_nako_version.nako3 +42 -42
- package/batch/calc_hash.nako3 +29 -29
- package/batch/cmd_txt2json.nako3 +74 -74
- package/batch/command.txt +79 -0
- package/batch/command_nakopad.txt +69 -0
- package/batch/download-extlib.nako3 +43 -43
- package/batch/gen_command_nakopad.nako3 +57 -57
- package/batch/jsplugin2text.nako3 +285 -285
- package/batch/pickup_command.nako3 +110 -110
- package/batch/pickup_reserved_words.nako3 +11 -11
- package/batch/publish_version.nako3 +46 -46
- package/batch/show_agents.js +14 -14
- package/batch/turtle2js.nako3 +21 -21
- package/bin/cnako3 +10 -10
- package/core/LICENSE +21 -21
- package/core/README.md +66 -66
- package/core/batch/build_nako_version.nako3 +42 -42
- package/core/command/snako.mjs +105 -105
- package/core/command/snako.mts +116 -116
- package/core/index.mjs +21 -21
- package/core/package.json +47 -47
- package/core/sample/hello.nako3 +7 -7
- package/core/sample/hoge.mjs +4 -4
- package/core/sample/hoge.mts +6 -6
- package/core/src/nako3.mjs +864 -858
- package/core/src/nako3.mts +976 -967
- package/core/src/nako_colors.mjs +78 -78
- package/core/src/nako_colors.mts +86 -86
- package/core/src/nako_core_version.mjs +8 -8
- package/core/src/nako_core_version.mts +19 -19
- package/core/src/nako_csv.mjs +185 -185
- package/core/src/nako_csv.mts +188 -188
- package/core/src/nako_errors.mjs +173 -173
- package/core/src/nako_errors.mts +197 -197
- package/core/src/nako_from_dncl.mjs +255 -255
- package/core/src/nako_from_dncl.mts +250 -250
- package/core/src/nako_gen.mjs +1647 -1648
- package/core/src/nako_gen.mts +1718 -1719
- package/core/src/nako_gen_async.mjs +1659 -1659
- package/core/src/nako_gen_async.mts +1732 -1732
- package/core/src/nako_global.mjs +107 -107
- package/core/src/nako_global.mts +138 -138
- package/core/src/nako_indent.mjs +445 -445
- package/core/src/nako_indent.mts +492 -492
- package/core/src/nako_josi_list.mjs +38 -38
- package/core/src/nako_josi_list.mts +45 -45
- package/core/src/nako_lex_rules.mjs +253 -253
- package/core/src/nako_lex_rules.mts +260 -260
- package/core/src/nako_lexer.mjs +609 -609
- package/core/src/nako_lexer.mts +612 -612
- package/core/src/nako_logger.mjs +199 -199
- package/core/src/nako_logger.mts +232 -232
- package/core/src/nako_parser3.mjs +2439 -2439
- package/core/src/nako_parser3.mts +2195 -2195
- package/core/src/nako_parser_base.mjs +370 -370
- package/core/src/nako_parser_base.mts +370 -370
- package/core/src/nako_parser_const.mjs +37 -37
- package/core/src/nako_parser_const.mts +37 -37
- package/core/src/nako_prepare.mjs +304 -304
- package/core/src/nako_prepare.mts +315 -315
- package/core/src/nako_reserved_words.mjs +38 -38
- package/core/src/nako_reserved_words.mts +38 -38
- package/core/src/nako_source_mapping.mjs +207 -207
- package/core/src/nako_source_mapping.mts +262 -262
- package/core/src/nako_test.mjs +37 -37
- package/core/src/nako_types.mjs +25 -25
- package/core/src/nako_types.mts +151 -151
- package/core/src/plugin_csv.mjs +49 -49
- package/core/src/plugin_csv.mts +50 -50
- package/core/src/plugin_math.mjs +328 -328
- package/core/src/plugin_math.mts +326 -326
- package/core/src/plugin_promise.mjs +91 -91
- package/core/src/plugin_promise.mts +91 -91
- package/core/src/plugin_system.mjs +2832 -2832
- package/core/src/plugin_system.mts +2690 -2690
- package/core/src/plugin_test.mjs +34 -34
- package/core/src/plugin_test.mts +34 -34
- package/demo/.DS_Store +0 -0
- package/demo/ace_editor.html +89 -89
- package/demo/ace_editor_tabs.html +161 -161
- package/demo/basic.html +71 -71
- package/demo/browsers.html +10 -9
- package/demo/css/basic.css +3 -3
- package/demo/css/common.css +157 -157
- package/demo/css/editor.css +8 -8
- package/demo/css/flow.css +3 -3
- package/demo/css/index.css +3 -3
- package/demo/extlib/.DS_Store +0 -0
- package/demo/flow.html +98 -98
- package/demo/graph.html +53 -53
- package/demo/image/nakopad-icon256.png +0 -0
- package/demo/index.html +133 -133
- package/demo/js/common.js +17 -17
- package/demo/js/turtle3d_test.js +44 -44
- package/demo/js/turtle_test.js +45 -45
- package/demo/nako3/calc.nako3 +4 -4
- package/demo/runscript.html +47 -47
- package/demo/runscript2.html +33 -33
- package/demo/runscript3.html +35 -35
- package/demo/runscript4.html +33 -33
- package/demo/turtle.html +58 -58
- package/demo/turtle2.html +141 -141
- package/demo/turtle3.html +279 -279
- package/demo/turtle3d.html +58 -58
- package/demo/turtle3d2.html +107 -107
- package/demo/version.html +24 -24
- package/doc/SETUP.md +157 -157
- package/doc/about.md +17 -17
- package/doc/browsers.md +26 -26
- package/doc/docgen.md +21 -21
- package/doc/editor.md +44 -44
- package/doc/files.md +39 -39
- package/doc/plugins.md +234 -234
- package/doc/release.md +79 -79
- package/doc/textlint.md +43 -43
- package/doc/win32.md +57 -57
- package/package.json +195 -195
- package/release/_hash.txt +28 -28
- package/release/_script-tags.txt +14 -14
- package/release/command.json +1 -1
- package/release/command.json.js +1 -1
- package/release/command_cnako3.json +1 -1
- package/release/command_list.json +1 -1
- package/release/editor.js +1 -1
- package/release/nako_gen_async.js +1 -1
- package/release/nako_gen_async.js.LICENSE.txt +35 -0
- package/release/plugin_caniuse.js.LICENSE.txt +11 -0
- package/release/plugin_csv.js +1 -1
- package/release/plugin_csv.js.LICENSE.txt +15 -0
- package/release/plugin_datetime.js.LICENSE.txt +15 -0
- package/release/plugin_kansuji.js.LICENSE.txt +3 -0
- package/release/plugin_markup.js.LICENSE.txt +11 -0
- package/release/plugin_turtle.js.LICENSE.txt +15 -0
- package/release/plugin_webworker.js.LICENSE.txt +3 -0
- package/release/plugin_weykturtle3d.js.LICENSE.txt +3 -0
- package/release/stats.json +1 -1
- package/release/version.js +1 -1
- package/release/wnako3.js +1 -1
- package/release/wnako3webworker.js +1 -1
- package/release/wnako3webworker.js.LICENSE.txt +131 -0
- package/src/.DS_Store +0 -0
- package/src/browsers.txt +12 -11
- package/src/browsers_agents.json +2 -2
- package/src/browsers_agents.mjs +1 -1
- package/src/cnako3.mjs +17 -17
- package/src/cnako3.mts +18 -18
- package/src/cnako3mod.mjs +707 -707
- package/src/cnako3mod.mts +712 -712
- package/src/commander_ja.mjs +164 -164
- package/src/commander_ja.mts +161 -161
- package/src/enako3.mjs +68 -68
- package/src/era.mjs +22 -22
- package/src/image_turtle-elephant.mjs +2 -2
- package/src/image_turtle-panda.mjs +2 -2
- package/src/image_turtle64.mjs +2 -2
- package/src/index.mjs +9 -9
- package/src/index.mts +10 -10
- package/src/nako3editorfix.sfd +106 -106
- package/src/nako_version.mjs +8 -8
- package/src/nako_version.mts +2 -2
- package/src/plugin_browser.mjs +213 -213
- package/src/plugin_browser.mts +206 -206
- package/src/plugin_browser_ajax.mjs +399 -399
- package/src/plugin_browser_audio.mjs +109 -109
- package/src/plugin_browser_canvas.mjs +449 -449
- package/src/plugin_browser_chart.mjs +294 -294
- package/src/plugin_browser_color.mjs +49 -49
- package/src/plugin_browser_crypto.mjs +26 -26
- package/src/plugin_browser_dialog.mjs +53 -53
- package/src/plugin_browser_dom_basic.mjs +336 -336
- package/src/plugin_browser_dom_event.mjs +193 -193
- package/src/plugin_browser_dom_parts.mjs +396 -396
- package/src/plugin_browser_geolocation.mjs +51 -51
- package/src/plugin_browser_hotkey.mjs +25 -25
- package/src/plugin_browser_html.mjs +59 -59
- package/src/plugin_browser_in_worker.mjs +45 -45
- package/src/plugin_browser_location.mjs +21 -21
- package/src/plugin_browser_speech.mjs +111 -111
- package/src/plugin_browser_storage.mjs +121 -121
- package/src/plugin_browser_system.mjs +31 -31
- package/src/plugin_browser_websocket.mjs +73 -73
- package/src/plugin_caniuse.mjs +29 -29
- package/src/plugin_datetime.mjs +394 -394
- package/src/plugin_httpserver.mjs +277 -277
- package/src/plugin_httpserver.mts +286 -286
- package/src/plugin_kansuji.mjs +224 -224
- package/src/plugin_keigo.mjs +55 -55
- package/src/plugin_markup.mjs +32 -32
- package/src/plugin_node.mjs +1047 -1047
- package/src/plugin_node.mts +980 -980
- package/src/plugin_turtle.mjs +647 -647
- package/src/plugin_webworker.mjs +334 -334
- package/src/plugin_weykturtle3d.mjs +1214 -1214
- package/src/plugin_worker.mjs +95 -95
- package/src/repl.nako3 +63 -63
- package/src/wnako3.mjs +12 -12
- package/src/wnako3.mts +11 -11
- package/src/wnako3_editor.css +215 -215
- package/src/wnako3_editor.mjs +1542 -1542
- package/src/wnako3_editor.mts +1658 -1657
- package/src/wnako3mod.mjs +213 -213
- package/src/wnako3mod.mts +214 -214
- package/src/wnako3webworker.mjs +69 -69
- package/test/.DS_Store +0 -0
- package/test/ace_editor/karma.config.js +94 -94
- package/test/ace_editor/test/.babelrc.json +3 -3
- package/test/ace_editor/test/ace_editor_test.js +178 -178
- package/test/ace_editor/test/html/custom_context.html +139 -139
- package/test/async/async_basic_test.mjs +122 -122
- package/test/browser/.DS_Store +0 -0
- package/test/browser/karma.config.js +221 -221
- package/test/browser/test/.babelrc.json +3 -3
- package/test/browser/test/compare_util.js +50 -50
- package/test/browser/test/html/div_basic.html +2 -2
- package/test/browser/test/html/event_dom_form.html +4 -4
- package/test/browser/test/html/event_dom_scrolldiv.html +5 -5
- package/test/browser/test/import_plugin_checker.js +24 -24
- package/test/browser/test/plugin_browser_test.js +51 -51
- package/test/browser/test/plugin_browser_test_ajax.js +123 -123
- package/test/browser/test/plugin_browser_test_color.js +18 -18
- package/test/browser/test/plugin_browser_test_dialog.js +72 -72
- package/test/browser/test/plugin_browser_test_dom_event.js +598 -598
- package/test/browser/test/plugin_browser_test_dom_parts.js +125 -125
- package/test/browser/test/plugin_browser_test_system.js +9 -9
- package/test/browser/test/plugin_turtle_test.js +817 -817
- package/test/browser/test/plugin_webworker_test.js +86 -86
- package/test/browser/test/require_test.js +68 -68
- package/test/bundled/.DS_Store +0 -0
- package/test/bundled/karma.config.base.js +117 -117
- package/test/bundled/karma.config.js +86 -86
- package/test/bundled/test/.babelrc.json +3 -3
- package/test/bundled/test/bundled_test.js +69 -69
- package/test/bundled/test/html/custom_context.html +65 -65
- package/test/bundled/test/html/custom_debug.html +66 -66
- package/test/bundled/test4b.cmd +52 -52
- package/test/bundled/test_base/.DS_Store +0 -0
- package/test/bundled/test_base/.babelrc.json +3 -3
- package/test/bundled/test_base/_checktool_test.js +25 -25
- package/test/bundled/test_base/basic_ajax_test.js +56 -56
- package/test/bundled/test_base/basic_async_test.js +18 -18
- package/test/bundled/test_base/basic_test.js +153 -153
- package/test/bundled/test_base/calc_test.js +132 -132
- package/test/bundled/test_base/css/browsers_box.css +114 -114
- package/test/bundled/test_base/html/custom_context.html +69 -69
- package/test/bundled/test_base/html/custom_debug.html +71 -71
- package/test/bundled/test_base/js/browsers_box.js +72 -72
- package/test/bundled/test_base/plugin_csv_test.js +37 -37
- package/test/bundled/test_base/plugin_datetime_test.js +115 -115
- package/test/bundled/test_base/plugin_kansuji_test.js +49 -49
- package/test/bundled/test_base/plugin_system_test.js +410 -410
- package/test/bundled/test_base/plugin_webworker_test.js +53 -53
- package/test/bundled/test_base/test_utils.js +191 -191
- package/test/common/.DS_Store +0 -0
- package/test/common/plugin_browser_test.mjs +22 -22
- package/test/common/plugin_browser_ut_audio_test.mjs +108 -108
- package/test/common/plugin_browser_ut_color_test.mjs +21 -21
- package/test/common/plugin_browser_ut_dialog_test.mjs +100 -100
- package/test/common/plugin_browser_ut_html_test.mjs +13 -13
- package/test/common/plugin_browser_ut_system_test.mjs +10 -10
- package/test/common/plugin_markup_test.mjs +23 -23
- package/test/jsconfig.json +19 -19
- package/test/karma.config.js +91 -91
- package/test/node/.DS_Store +0 -0
- package/test/node/async_test.mjs +96 -96
- package/test/node/commander_ja_test.mjs +89 -89
- package/test/node/error_message_test.mjs +243 -243
- package/test/node/kai_test.nako3 +6 -6
- package/test/node/node_test.mjs +60 -60
- package/test/node/plugin_broken.js.txt +3 -3
- package/test/node/plugin_browser_ut_ajax_test.mjs.todo +357 -357
- package/test/node/plugin_browser_ut_location_test.mjs +42 -42
- package/test/node/plugin_markup_test.mjs +47 -47
- package/test/node/plugin_math_test.mjs +45 -45
- package/test/node/plugin_node_test.mjs +98 -98
- package/test/node/plugin_test.mjs +44 -44
- package/test/node/relative_import_test_1.nako3 +1 -1
- package/test/node/relative_import_test_2.nako3 +2 -2
- package/test/node/require_nako3_test.mjs +67 -67
- package/test/node/requiretest.nako3 +4 -4
- package/test/node/requiretest_indirect.nako3 +1 -1
- package/test/node/requiretest_name.nako3 +5 -5
- package/test/node/runtime_error.nako3 +2 -2
- package/test/node/scope1.nako3 +10 -10
- package/test/node/scope2.nako3 +12 -12
- package/test/node/side_effects_test.mjs +39 -39
- package/test/node/sjis.txt +5 -5
- package/test/node/syntax_error.nako3 +1 -1
- package/test/node/wnako3_editor_test.mjs +384 -384
- package/tools/.DS_Store +0 -0
- package/tools/README.md +12 -12
- package/tools/check_new_version.nako3 +25 -25
- package/tools/nako3edit/.DS_Store +0 -0
- package/tools/nako3edit/a.sqlite3 +0 -0
- package/tools/nako3edit/html/.DS_Store +0 -0
- package/tools/nako3edit/html/daisyui/LICENSE +22 -22
- package/tools/nako3edit/html/daisyui/version_2.14.1 +1 -1
- package/tools/nako3edit/html/edit.html +170 -170
- package/tools/nako3edit/html/edit_plugin.js +6 -6
- package/tools/nako3edit/html/files.html +125 -125
- package/tools/nako3edit/html/nako3edit.css +65 -65
- package/tools/nako3edit/index.mjs +248 -248
- package/tools/nako3server/index.html +10 -10
- package/tools/nako3server/index.mjs +116 -116
- package/tools/nako3server/index.nako3 +34 -34
- package/core/.editorconfig +0 -6
- package/core/.eslintrc.cjs +0 -33
- package/core/.github/dependabot.yml +0 -7
- package/core/.github/workflows/nodejs.yml +0 -37
- package/core/.github/workflows/super-linter.yml +0 -61
- package/core/.github/workflows/textlint.yml +0 -199
- package/core/index.mts +0 -21
- package/core/test/array_test.mjs +0 -34
- package/core/test/basic_test.mjs +0 -344
- package/core/test/calc_test.mjs +0 -140
- package/core/test/core_module_test.mjs +0 -23
- package/core/test/debug_test.mjs +0 -16
- package/core/test/dncl_test.mjs +0 -94
- package/core/test/error_message_test.mjs +0 -210
- package/core/test/error_test.mjs +0 -16
- package/core/test/flow_test.mjs +0 -373
- package/core/test/func_call.mjs +0 -160
- package/core/test/func_test.mjs +0 -149
- package/core/test/indent_test.mjs +0 -364
- package/core/test/lex_test.mjs +0 -168
- package/core/test/literal_test.mjs +0 -73
- package/core/test/nako_lexer_test.mjs +0 -35
- package/core/test/nako_logger_test.mjs +0 -76
- package/core/test/nako_logger_test.mts +0 -78
- package/core/test/plugin_csv_test.mjs +0 -38
- package/core/test/plugin_promise_test.mjs +0 -18
- package/core/test/plugin_system_test.mjs +0 -630
- package/core/test/prepare_test.mjs +0 -96
- package/core/test/re_test.mjs +0 -22
- package/core/test/side_effects_test.mjs +0 -92
- package/core/test/variable_scope_test.mjs +0 -149
- package/core/tsconfig.json +0 -101
package/src/plugin_turtle.mjs
CHANGED
|
@@ -1,647 +1,647 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
/**
|
|
3
|
-
* Turtle Graphics for Web browser (nadesiko3)
|
|
4
|
-
* plugin_turtle.js
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import turtleImage from './image_turtle64.mjs'
|
|
8
|
-
import elephantImage from './image_turtle-elephant.mjs'
|
|
9
|
-
import pandaImage from './image_turtle-panda.mjs'
|
|
10
|
-
|
|
11
|
-
const PluginTurtle = {
|
|
12
|
-
'初期化': {
|
|
13
|
-
type: 'func',
|
|
14
|
-
josi: [],
|
|
15
|
-
pure: true,
|
|
16
|
-
fn: function (sys) {
|
|
17
|
-
/* istanbul ignore if */
|
|
18
|
-
if (sys._turtle) { return }
|
|
19
|
-
sys._turtle = {
|
|
20
|
-
list: [],
|
|
21
|
-
target: -1,
|
|
22
|
-
ctx: null,
|
|
23
|
-
canvas: null,
|
|
24
|
-
canvas_r: { left: 0, top: 0, width: 640, height: 400 },
|
|
25
|
-
clearAll: function () {
|
|
26
|
-
const me = this
|
|
27
|
-
console.log('[TURTLE] clearAll')
|
|
28
|
-
for (let i = 0; i < me.list.length; i++) {
|
|
29
|
-
const tt = me.list[i]
|
|
30
|
-
tt.mlist = [] // ジョブをクリア
|
|
31
|
-
document.body.removeChild(tt.canvas)
|
|
32
|
-
}
|
|
33
|
-
me.list = []
|
|
34
|
-
if (me.canvas !== null) {
|
|
35
|
-
me.ctx.clearRect(0, 0,
|
|
36
|
-
me.canvas.width,
|
|
37
|
-
me.canvas.height)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
me.target = -1
|
|
41
|
-
me.flagSetTimer = false
|
|
42
|
-
},
|
|
43
|
-
drawTurtle: function (id) {
|
|
44
|
-
const tt = this.list[id]
|
|
45
|
-
if (!tt) { return }
|
|
46
|
-
const cr = this.canvas_r
|
|
47
|
-
// カメの位置を移動
|
|
48
|
-
tt.canvas.style.left = (cr.left + tt.x - tt.cx) + 'px'
|
|
49
|
-
tt.canvas.style.top = (cr.top + tt.y - tt.cx) + 'px'
|
|
50
|
-
if (!tt.f_update) { return }
|
|
51
|
-
/* istanbul ignore if */
|
|
52
|
-
if (!tt.flagLoaded) { return }
|
|
53
|
-
tt.f_update = false
|
|
54
|
-
tt.ctx.clearRect(0, 0,
|
|
55
|
-
tt.canvas.width,
|
|
56
|
-
tt.canvas.height)
|
|
57
|
-
if (!tt.f_visible) { return }
|
|
58
|
-
if (tt.dir !== 270) {
|
|
59
|
-
const rad = (tt.dir + 90) * 0.017453292519943295
|
|
60
|
-
tt.ctx.save()
|
|
61
|
-
tt.ctx.translate(tt.cx, tt.cy)
|
|
62
|
-
tt.ctx.rotate(rad)
|
|
63
|
-
tt.ctx.translate(-tt.cx, -tt.cy)
|
|
64
|
-
tt.ctx.drawImage(tt.img, 0, 0)
|
|
65
|
-
tt.ctx.restore()
|
|
66
|
-
} else { tt.ctx.drawImage(tt.img, 0, 0) }
|
|
67
|
-
},
|
|
68
|
-
getCur: function () {
|
|
69
|
-
if (this.list.length === 0) { throw Error('最初に『カメ作成』命令を呼び出してください。') }
|
|
70
|
-
|
|
71
|
-
return this.list[this.target]
|
|
72
|
-
},
|
|
73
|
-
flagSetTimer: false,
|
|
74
|
-
setTimer: function () {
|
|
75
|
-
if (this.flagSetTimer) { return }
|
|
76
|
-
this.flagSetTimer = true
|
|
77
|
-
console.log('[TURTLE] standby ...')
|
|
78
|
-
setTimeout(() => {
|
|
79
|
-
console.log('[TURTLE] Let\'s go!')
|
|
80
|
-
sys._turtle.play()
|
|
81
|
-
}, 1)
|
|
82
|
-
},
|
|
83
|
-
line: function (tt, x1, y1, x2, y2) {
|
|
84
|
-
/* istanbul ignore else */
|
|
85
|
-
if (tt) { if (!tt.flagDown) { return } }
|
|
86
|
-
|
|
87
|
-
const ctx = this.ctx
|
|
88
|
-
if (tt.flagBegeinPath) {
|
|
89
|
-
ctx.lineTo(x2, y2)
|
|
90
|
-
} else {
|
|
91
|
-
ctx.beginPath()
|
|
92
|
-
ctx.lineWidth = tt.lineWidth
|
|
93
|
-
ctx.strokeStyle = tt.color
|
|
94
|
-
ctx.moveTo(x1, y1)
|
|
95
|
-
ctx.lineTo(x2, y2)
|
|
96
|
-
ctx.stroke()
|
|
97
|
-
}
|
|
98
|
-
},
|
|
99
|
-
doMacro: function (tt, wait) {
|
|
100
|
-
const me = this
|
|
101
|
-
if (!tt.flagLoaded && wait > 0) {
|
|
102
|
-
// console.log('[TURTLE] waiting ...')
|
|
103
|
-
return true
|
|
104
|
-
}
|
|
105
|
-
const m = tt.mlist.shift()
|
|
106
|
-
const cmd = (m !== undefined) ? m[0] : ''
|
|
107
|
-
switch (cmd) {
|
|
108
|
-
case 'xy':
|
|
109
|
-
// 起点を移動する
|
|
110
|
-
tt.x = m[1]
|
|
111
|
-
tt.y = m[2]
|
|
112
|
-
break
|
|
113
|
-
case 'begin':
|
|
114
|
-
// 描画を明示的に開始する
|
|
115
|
-
this.ctx.beginPath()
|
|
116
|
-
this.ctx.moveTo(tt.x, tt.y)
|
|
117
|
-
tt.flagBegeinPath = true
|
|
118
|
-
break
|
|
119
|
-
case 'close':
|
|
120
|
-
// パスを閉じる
|
|
121
|
-
this.ctx.closePath()
|
|
122
|
-
tt.flagBegeinPath = false
|
|
123
|
-
break
|
|
124
|
-
case 'fill':
|
|
125
|
-
if (tt.flagBegeinPath) {
|
|
126
|
-
this.ctx.closePath()
|
|
127
|
-
tt.flagBegeinPath = false
|
|
128
|
-
}
|
|
129
|
-
this.ctx.fill()
|
|
130
|
-
break
|
|
131
|
-
case 'stroke':
|
|
132
|
-
if (tt.flagBegeinPath) {
|
|
133
|
-
this.ctx.closePath()
|
|
134
|
-
tt.flagBegeinPath = false
|
|
135
|
-
}
|
|
136
|
-
this.ctx.stroke()
|
|
137
|
-
break
|
|
138
|
-
case 'text':
|
|
139
|
-
this.ctx.fillText(m[1], tt.x, tt.y)
|
|
140
|
-
break
|
|
141
|
-
case 'textset':
|
|
142
|
-
this.ctx.font = m[1]
|
|
143
|
-
break
|
|
144
|
-
case 'fillStyle':
|
|
145
|
-
this.ctx.fillStyle = m[1]
|
|
146
|
-
break
|
|
147
|
-
case 'mv': {
|
|
148
|
-
// 線を引く
|
|
149
|
-
me.line(tt, tt.x, tt.y, m[1], m[2])
|
|
150
|
-
// カメの角度を変更
|
|
151
|
-
const mvRad = Math.atan2(m[2] - tt.y, m[1] - tt.x)
|
|
152
|
-
tt.dir = mvRad * 57.29577951308232
|
|
153
|
-
tt.f_update = true
|
|
154
|
-
// 実際に位置を移動
|
|
155
|
-
tt.x = m[1]
|
|
156
|
-
tt.y = m[2]
|
|
157
|
-
break
|
|
158
|
-
}
|
|
159
|
-
case 'fd': {
|
|
160
|
-
const fdv = m[1] * m[2]
|
|
161
|
-
const rad = tt.dir * 0.017453292519943295
|
|
162
|
-
const x2 = tt.x + Math.cos(rad) * fdv
|
|
163
|
-
const y2 = tt.y + Math.sin(rad) * fdv
|
|
164
|
-
me.line(tt, tt.x, tt.y, x2, y2)
|
|
165
|
-
tt.x = x2
|
|
166
|
-
tt.y = y2
|
|
167
|
-
break
|
|
168
|
-
}
|
|
169
|
-
case 'angle': {
|
|
170
|
-
const angle = m[1]
|
|
171
|
-
tt.dir = ((angle - 90 + 360) % 360)
|
|
172
|
-
tt.f_update = true
|
|
173
|
-
break
|
|
174
|
-
}
|
|
175
|
-
case 'rotr': {
|
|
176
|
-
const rv = m[1]
|
|
177
|
-
tt.dir = (tt.dir + rv) % 360
|
|
178
|
-
tt.f_update = true
|
|
179
|
-
break
|
|
180
|
-
}
|
|
181
|
-
case 'rotl': {
|
|
182
|
-
const lv = m[1]
|
|
183
|
-
tt.dir = (tt.dir - lv + 360) % 360
|
|
184
|
-
tt.f_update = true
|
|
185
|
-
break
|
|
186
|
-
}
|
|
187
|
-
case 'color':
|
|
188
|
-
tt.color = m[1]
|
|
189
|
-
this.ctx.strokeStyle = tt.color
|
|
190
|
-
break
|
|
191
|
-
case 'size':
|
|
192
|
-
this.ctx.lineWidth = tt.lineWidth
|
|
193
|
-
tt.lineWidth = m[1]
|
|
194
|
-
break
|
|
195
|
-
case 'penOn':
|
|
196
|
-
tt.flagDown = m[1]
|
|
197
|
-
break
|
|
198
|
-
case 'visible':
|
|
199
|
-
tt.f_visible = m[1]
|
|
200
|
-
tt.f_update = true
|
|
201
|
-
break
|
|
202
|
-
case 'changeImage':
|
|
203
|
-
tt.flagLoaded = false
|
|
204
|
-
tt.img.src = m[1]
|
|
205
|
-
break
|
|
206
|
-
}
|
|
207
|
-
if (tt.flagLoaded) { sys._turtle.drawTurtle(tt.id) }
|
|
208
|
-
return (tt.mlist.length > 0)
|
|
209
|
-
},
|
|
210
|
-
doMacroAll: function (wait) {
|
|
211
|
-
let hasNext = false
|
|
212
|
-
for (let i = 0; i < sys._turtle.list.length; i++) {
|
|
213
|
-
const tt = sys._turtle.list[i]
|
|
214
|
-
if (this.doMacro(tt, wait)) { hasNext = true }
|
|
215
|
-
}
|
|
216
|
-
return hasNext
|
|
217
|
-
},
|
|
218
|
-
play: function () {
|
|
219
|
-
const me = this
|
|
220
|
-
const wait = sys.__v0['カメ速度']
|
|
221
|
-
let hasNext = this.doMacroAll(wait)
|
|
222
|
-
if (wait <= 0) {
|
|
223
|
-
while (hasNext) { hasNext = this.doMacroAll(wait) }
|
|
224
|
-
} else if (hasNext) {
|
|
225
|
-
setTimeout(() => me.play(), wait)
|
|
226
|
-
return
|
|
227
|
-
}
|
|
228
|
-
console.log('[TURTLE] finished.')
|
|
229
|
-
me.flagSetTimer = false
|
|
230
|
-
},
|
|
231
|
-
setupCanvas: function (sys) {
|
|
232
|
-
// 描画先をセットする
|
|
233
|
-
let canvasId = sys.__v0['カメ描画先']
|
|
234
|
-
if (typeof canvasId === 'string') {
|
|
235
|
-
canvasId = document.getElementById(canvasId) || document.querySelector(canvasId)
|
|
236
|
-
sys.__v0['カメ描画先'] = canvasId
|
|
237
|
-
}
|
|
238
|
-
console.log('カメ描画先=', canvasId)
|
|
239
|
-
const cv = sys._turtle.canvas = canvasId
|
|
240
|
-
if (!cv) {
|
|
241
|
-
console.log('[ERROR] カメ描画先が見当たりません。' + canvasId)
|
|
242
|
-
throw Error('カメ描画先が見当たりません。')
|
|
243
|
-
}
|
|
244
|
-
const ctx = sys._turtle.ctx = sys._turtle.canvas.getContext('2d')
|
|
245
|
-
ctx.lineWidth = 4
|
|
246
|
-
ctx.strokeStyle = 'black'
|
|
247
|
-
ctx.lineCap = 'round'
|
|
248
|
-
sys._turtle.resizeCanvas(sys)
|
|
249
|
-
},
|
|
250
|
-
resizeCanvas: function (sys) {
|
|
251
|
-
const cv = sys._turtle.canvas
|
|
252
|
-
const rect = cv.getBoundingClientRect()
|
|
253
|
-
const rx = rect.left + window.pageXOffset
|
|
254
|
-
const ry = rect.top + window.pageYOffset
|
|
255
|
-
sys._turtle.canvas_r = {
|
|
256
|
-
'left': rx,
|
|
257
|
-
'top': ry,
|
|
258
|
-
width: rect.width,
|
|
259
|
-
height: rect.height
|
|
260
|
-
}
|
|
261
|
-
},
|
|
262
|
-
createTurtle: function (imageUrl, sys) {
|
|
263
|
-
// キャンバス情報は毎回参照する (#734)
|
|
264
|
-
sys._turtle.setupCanvas(sys)
|
|
265
|
-
// const cv = sys._turtle.canvas
|
|
266
|
-
// カメの情報を sys._turtle リストに追加
|
|
267
|
-
const id = sys._turtle.list.length
|
|
268
|
-
const tt = {
|
|
269
|
-
id: id,
|
|
270
|
-
img: null,
|
|
271
|
-
canvas: null,
|
|
272
|
-
ctx: null,
|
|
273
|
-
dir: 270, // 上向き
|
|
274
|
-
cx: 32,
|
|
275
|
-
cy: 32,
|
|
276
|
-
x: 0,
|
|
277
|
-
y: 0,
|
|
278
|
-
color: 'black',
|
|
279
|
-
lineWidth: 4,
|
|
280
|
-
flagDown: true,
|
|
281
|
-
flagBegeinPath: false,
|
|
282
|
-
f_update: true,
|
|
283
|
-
flagLoaded: false,
|
|
284
|
-
f_visible: true,
|
|
285
|
-
mlist: []
|
|
286
|
-
}
|
|
287
|
-
sys._turtle.list.push(tt)
|
|
288
|
-
sys._turtle.target = id
|
|
289
|
-
// 画像を読み込む
|
|
290
|
-
tt.img = document.createElement('img')
|
|
291
|
-
tt.canvas = document.createElement('canvas')
|
|
292
|
-
tt.ctx = tt.canvas.getContext('2d')
|
|
293
|
-
tt.canvas.id = id
|
|
294
|
-
tt.img.onload = () => {
|
|
295
|
-
tt.cx = tt.img.width / 2
|
|
296
|
-
tt.cy = tt.img.height / 2
|
|
297
|
-
tt.canvas.width = tt.img.width
|
|
298
|
-
tt.canvas.height = tt.img.height
|
|
299
|
-
tt.flagLoaded = true
|
|
300
|
-
tt.f_update = true
|
|
301
|
-
sys._turtle.drawTurtle(tt.id)
|
|
302
|
-
console.log('turtle.onload')
|
|
303
|
-
}
|
|
304
|
-
tt.img.onerror = () => {
|
|
305
|
-
console.log('カメの読み込みに失敗')
|
|
306
|
-
tt.flagLoaded = true
|
|
307
|
-
tt.f_visible = false
|
|
308
|
-
tt.f_update = true
|
|
309
|
-
sys._turtle.drawTurtle(tt.id)
|
|
310
|
-
}
|
|
311
|
-
tt.img.src = imageUrl
|
|
312
|
-
tt.canvas.style.position = 'absolute'
|
|
313
|
-
document.body.appendChild(tt.canvas)
|
|
314
|
-
// デフォルト位置の設定
|
|
315
|
-
tt.x = sys._turtle.canvas_r.width / 2
|
|
316
|
-
tt.y = sys._turtle.canvas_r.height / 2
|
|
317
|
-
return id
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
},
|
|
322
|
-
|
|
323
|
-
'!クリア': {
|
|
324
|
-
type: 'func',
|
|
325
|
-
josi: [],
|
|
326
|
-
pure: true,
|
|
327
|
-
fn: function (sys) {
|
|
328
|
-
sys._turtle.clearAll()
|
|
329
|
-
}
|
|
330
|
-
},
|
|
331
|
-
|
|
332
|
-
// @タートルグラフィックス・カメ描画
|
|
333
|
-
'カメ作成': { // @タートルグラフィックスを開始してカメのIDを返す // @かめさくせい
|
|
334
|
-
type: 'func',
|
|
335
|
-
josi: [],
|
|
336
|
-
pure: true,
|
|
337
|
-
fn: function (sys) {
|
|
338
|
-
const imageUrl = sys.__v0['カメ画像URL']
|
|
339
|
-
return sys._turtle.createTurtle(imageUrl, sys)
|
|
340
|
-
}
|
|
341
|
-
},
|
|
342
|
-
'ゾウ作成': { // @ゾウの画像でタートルグラフィックスを開始してIDを返す // @ぞうさくせい
|
|
343
|
-
type: 'func',
|
|
344
|
-
josi: [],
|
|
345
|
-
pure: true,
|
|
346
|
-
fn: function (sys) {
|
|
347
|
-
const imageUrl = elephantImage
|
|
348
|
-
return sys._turtle.createTurtle(imageUrl, sys)
|
|
349
|
-
}
|
|
350
|
-
},
|
|
351
|
-
'パンダ作成': { // @パンダの画像でタートルグラフィックスを開始してIDを返す // @ぱんださくせい
|
|
352
|
-
type: 'func',
|
|
353
|
-
josi: [],
|
|
354
|
-
pure: true,
|
|
355
|
-
fn: function (sys) {
|
|
356
|
-
const imageUrl = pandaImage
|
|
357
|
-
return sys._turtle.createTurtle(imageUrl, sys)
|
|
358
|
-
}
|
|
359
|
-
},
|
|
360
|
-
'カメ操作対象設定': { // @IDを指定して操作対象となるカメを変更する // @かめそうさたいしょうせってい
|
|
361
|
-
type: 'func',
|
|
362
|
-
josi: [['に', 'へ', 'の']],
|
|
363
|
-
pure: true,
|
|
364
|
-
fn: function (id, sys) {
|
|
365
|
-
sys._turtle.target = id
|
|
366
|
-
},
|
|
367
|
-
return_none: true
|
|
368
|
-
},
|
|
369
|
-
'カメ描画先': { type: 'var', value: 'turtle_cv' }, // @かめびょうがさき
|
|
370
|
-
'カメ画像URL': { type: 'var', value: turtleImage }, // @かめがぞうURL
|
|
371
|
-
'カメ画像変更': { // @カメの画像をURLに変更する // @かめがぞうへんこう
|
|
372
|
-
type: 'func',
|
|
373
|
-
josi: [['に', 'へ']],
|
|
374
|
-
pure: true,
|
|
375
|
-
fn: function (url, sys) {
|
|
376
|
-
const tt = sys._turtle.getCur()
|
|
377
|
-
tt.mlist.push(['changeImage', url])
|
|
378
|
-
sys._turtle.setTimer()
|
|
379
|
-
},
|
|
380
|
-
return_none: true
|
|
381
|
-
},
|
|
382
|
-
'カメ速度': { type: 'const', value: 100 }, // @かめそくど
|
|
383
|
-
'カメ速度設定': { // @カメの動作速度vに設定(大きいほど遅い) // @かめそくどせってい
|
|
384
|
-
type: 'func',
|
|
385
|
-
josi: [['に', 'へ']],
|
|
386
|
-
pure: true,
|
|
387
|
-
fn: function (v, sys) {
|
|
388
|
-
sys.__varslist[0]['カメ速度'] = v
|
|
389
|
-
}
|
|
390
|
-
},
|
|
391
|
-
'カメ移動': { // @カメの位置を[x,y]へ移動する // @かめいどう
|
|
392
|
-
type: 'func',
|
|
393
|
-
josi: [['に', 'へ']],
|
|
394
|
-
pure: true,
|
|
395
|
-
fn: function (xy, sys) {
|
|
396
|
-
const tt = sys._turtle.getCur()
|
|
397
|
-
tt.mlist.push(['mv', xy[0], xy[1]])
|
|
398
|
-
sys._turtle.setTimer()
|
|
399
|
-
},
|
|
400
|
-
return_none: true
|
|
401
|
-
},
|
|
402
|
-
'カメ起点移動': { // @カメの描画起点位置を[x,y]へ移動する // @かめきてんいどう
|
|
403
|
-
type: 'func',
|
|
404
|
-
josi: [['に', 'へ']],
|
|
405
|
-
pure: true,
|
|
406
|
-
fn: function (xy, sys) {
|
|
407
|
-
const tt = sys._turtle.getCur()
|
|
408
|
-
tt.mlist.push(['xy', xy[0], xy[1]])
|
|
409
|
-
sys._turtle.setTimer()
|
|
410
|
-
},
|
|
411
|
-
return_none: true
|
|
412
|
-
},
|
|
413
|
-
'カメ進': { // @カメの位置をVだけ進める // @かめすすむ
|
|
414
|
-
type: 'func',
|
|
415
|
-
josi: [['だけ']],
|
|
416
|
-
pure: true,
|
|
417
|
-
fn: function (v, sys) {
|
|
418
|
-
const tt = sys._turtle.getCur()
|
|
419
|
-
tt.mlist.push(['fd', v, 1])
|
|
420
|
-
sys._turtle.setTimer()
|
|
421
|
-
},
|
|
422
|
-
return_none: true
|
|
423
|
-
},
|
|
424
|
-
'カメ戻': { // @カメの位置をVだけ戻す // @かめもどる
|
|
425
|
-
type: 'func',
|
|
426
|
-
josi: [['だけ']],
|
|
427
|
-
pure: true,
|
|
428
|
-
fn: function (v, sys) {
|
|
429
|
-
const tt = sys._turtle.getCur()
|
|
430
|
-
tt.mlist.push(['fd', v, -1])
|
|
431
|
-
sys._turtle.setTimer()
|
|
432
|
-
},
|
|
433
|
-
return_none: true
|
|
434
|
-
},
|
|
435
|
-
'カメ角度設定': { // @カメの向きをDEGに設定する // @かめかくどせってい
|
|
436
|
-
type: 'func',
|
|
437
|
-
josi: [['に', 'へ', 'の']],
|
|
438
|
-
pure: true,
|
|
439
|
-
fn: function (v, sys) {
|
|
440
|
-
const tt = sys._turtle.getCur()
|
|
441
|
-
tt.mlist.push(['angle', parseFloat(v)])
|
|
442
|
-
sys._turtle.setTimer()
|
|
443
|
-
},
|
|
444
|
-
return_none: true
|
|
445
|
-
},
|
|
446
|
-
'カメ右回転': { // @カメの向きをDEGだけ右に向ける // @かめみぎかいてん
|
|
447
|
-
type: 'func',
|
|
448
|
-
josi: [['だけ']],
|
|
449
|
-
pure: true,
|
|
450
|
-
fn: function (v, sys) {
|
|
451
|
-
const tt = sys._turtle.getCur()
|
|
452
|
-
tt.mlist.push(['rotr', v])
|
|
453
|
-
sys._turtle.setTimer()
|
|
454
|
-
},
|
|
455
|
-
return_none: true
|
|
456
|
-
},
|
|
457
|
-
'カメ左回転': { // @カメの向きをDEGだけ左に向ける // @かめひだりかいてん
|
|
458
|
-
type: 'func',
|
|
459
|
-
josi: [['だけ']],
|
|
460
|
-
pure: true,
|
|
461
|
-
fn: function (v, sys) {
|
|
462
|
-
const tt = sys._turtle.getCur()
|
|
463
|
-
tt.mlist.push(['rotl', v])
|
|
464
|
-
sys._turtle.setTimer()
|
|
465
|
-
},
|
|
466
|
-
return_none: true
|
|
467
|
-
},
|
|
468
|
-
'カメペン色設定': { // @カメのペン描画色をCに設定する // @かめぺんいろせってい
|
|
469
|
-
type: 'func',
|
|
470
|
-
josi: [['に', 'へ']],
|
|
471
|
-
pure: true,
|
|
472
|
-
fn: function (c, sys) {
|
|
473
|
-
const tt = sys._turtle.getCur()
|
|
474
|
-
tt.mlist.push(['color', c])
|
|
475
|
-
sys._turtle.setTimer()
|
|
476
|
-
},
|
|
477
|
-
return_none: true
|
|
478
|
-
},
|
|
479
|
-
'カメペンサイズ設定': { // @カメペンのサイズをWに設定する // @かめぺんさいずせってい
|
|
480
|
-
type: 'func',
|
|
481
|
-
josi: [['に', 'へ']],
|
|
482
|
-
pure: true,
|
|
483
|
-
fn: function (w, sys) {
|
|
484
|
-
const tt = sys._turtle.getCur()
|
|
485
|
-
tt.mlist.push(['size', w])
|
|
486
|
-
sys._turtle.setTimer()
|
|
487
|
-
}
|
|
488
|
-
},
|
|
489
|
-
'カメペン設定': { // @カメペンを使うかどうかをV(オン/オフ)に設定する // @かめぺんせってい
|
|
490
|
-
type: 'func',
|
|
491
|
-
josi: [['に', 'へ']],
|
|
492
|
-
pure: true,
|
|
493
|
-
fn: function (w, sys) {
|
|
494
|
-
const tt = sys._turtle.getCur()
|
|
495
|
-
tt.mlist.push(['penOn', w])
|
|
496
|
-
sys._turtle.setTimer()
|
|
497
|
-
}
|
|
498
|
-
},
|
|
499
|
-
'カメパス開始': { // @カメで明示的にパスの描画を開始する // @かめぱすかいし
|
|
500
|
-
type: 'func',
|
|
501
|
-
josi: [],
|
|
502
|
-
pure: true,
|
|
503
|
-
fn: function (sys) {
|
|
504
|
-
const tt = sys._turtle.getCur()
|
|
505
|
-
tt.mlist.push(['begin'])
|
|
506
|
-
sys._turtle.setTimer()
|
|
507
|
-
}
|
|
508
|
-
},
|
|
509
|
-
'カメパス閉': { // @カメでパスを明示的に閉じる(省略可能) // @かめぱすとじる
|
|
510
|
-
type: 'func',
|
|
511
|
-
josi: [],
|
|
512
|
-
pure: true,
|
|
513
|
-
fn: function (sys) {
|
|
514
|
-
const tt = sys._turtle.getCur()
|
|
515
|
-
tt.mlist.push(['close'])
|
|
516
|
-
sys._turtle.setTimer()
|
|
517
|
-
}
|
|
518
|
-
},
|
|
519
|
-
'カメパス線引': { // @カメでパスを閉じて、カメペン色設定で指定した色で枠線を引く // @かめぱすせんひく
|
|
520
|
-
type: 'func',
|
|
521
|
-
josi: [],
|
|
522
|
-
pure: true,
|
|
523
|
-
fn: function (sys) {
|
|
524
|
-
const tt = sys._turtle.getCur()
|
|
525
|
-
tt.mlist.push(['stroke'])
|
|
526
|
-
sys._turtle.setTimer()
|
|
527
|
-
}
|
|
528
|
-
},
|
|
529
|
-
'カメパス塗': { // @カメでパスを閉じて、カメ塗り色設定で指定した色で塗りつぶす // @かめぱすぬる
|
|
530
|
-
type: 'func',
|
|
531
|
-
josi: [],
|
|
532
|
-
pure: true,
|
|
533
|
-
fn: function (sys) {
|
|
534
|
-
const tt = sys._turtle.getCur()
|
|
535
|
-
tt.mlist.push(['fill'])
|
|
536
|
-
sys._turtle.setTimer()
|
|
537
|
-
}
|
|
538
|
-
},
|
|
539
|
-
'カメ文字描画': { // @カメの位置に文字Sを描画 // @かめもじびょうが
|
|
540
|
-
type: 'func',
|
|
541
|
-
josi: [['を', 'と', 'の']],
|
|
542
|
-
pure: true,
|
|
543
|
-
fn: function (s, sys) {
|
|
544
|
-
const tt = sys._turtle.getCur()
|
|
545
|
-
tt.mlist.push(['text', s])
|
|
546
|
-
sys._turtle.setTimer()
|
|
547
|
-
}
|
|
548
|
-
},
|
|
549
|
-
'カメ文字設定': { // @カメ文字描画で描画するテキストサイズやフォント(48px serif)などを設定 // @かめもじせってい
|
|
550
|
-
type: 'func',
|
|
551
|
-
josi: [['に', 'へ', 'で']],
|
|
552
|
-
pure: true,
|
|
553
|
-
fn: function (s, sys) {
|
|
554
|
-
s = '' + s // 文字列に
|
|
555
|
-
if (s.match(/^\d+$/)) {
|
|
556
|
-
s = s + 'px serif'
|
|
557
|
-
} else if (s.match(/^\d+(px|em)$/)) {
|
|
558
|
-
s = s + ' serif'
|
|
559
|
-
}
|
|
560
|
-
const tt = sys._turtle.getCur()
|
|
561
|
-
tt.mlist.push(['textset', s])
|
|
562
|
-
sys._turtle.setTimer()
|
|
563
|
-
}
|
|
564
|
-
},
|
|
565
|
-
'カメ塗色設定': { // @カメパスの塗り色をCに設定する // @かめぬりいろせってい
|
|
566
|
-
type: 'func',
|
|
567
|
-
josi: [['に', 'へ']],
|
|
568
|
-
pure: true,
|
|
569
|
-
fn: function (c, sys) {
|
|
570
|
-
const tt = sys._turtle.getCur()
|
|
571
|
-
tt.mlist.push(['fillStyle', c])
|
|
572
|
-
sys._turtle.setTimer()
|
|
573
|
-
},
|
|
574
|
-
return_none: true
|
|
575
|
-
},
|
|
576
|
-
'カメ全消去': { // @表示しているカメと描画内容を全部消去する // @かめぜんしょうきょ
|
|
577
|
-
type: 'func',
|
|
578
|
-
josi: [],
|
|
579
|
-
pure: true,
|
|
580
|
-
fn: function (sys) {
|
|
581
|
-
sys._turtle.clearAll()
|
|
582
|
-
},
|
|
583
|
-
return_none: true
|
|
584
|
-
},
|
|
585
|
-
'カメコマンド実行': { // @カメにコマンドSを実行する。コマンドは改行か「;」で区切る。コマンドと引数は「=」で区切り引数はかカンマで区切る // @かめこまんどじっこう
|
|
586
|
-
type: 'func',
|
|
587
|
-
josi: [['の', 'を']],
|
|
588
|
-
pure: true,
|
|
589
|
-
fn: function (cmd, sys) {
|
|
590
|
-
const tt = sys._turtle.getCur()
|
|
591
|
-
const a = cmd.split(/(\n|;)/)
|
|
592
|
-
for (let i = 0; i < a.length; i++) {
|
|
593
|
-
let c = a[i]
|
|
594
|
-
c = c.replace(/^([a-zA-Z_]+)\s*(\d+)/, '$1,$2')
|
|
595
|
-
c = c.replace(/^([a-zA-Z_]+)\s*=/, '$1,')
|
|
596
|
-
const ca = c.split(/\s*,\s*/)
|
|
597
|
-
tt.mlist.push(ca)
|
|
598
|
-
}
|
|
599
|
-
sys._turtle.setTimer()
|
|
600
|
-
},
|
|
601
|
-
return_none: true
|
|
602
|
-
},
|
|
603
|
-
'カメ非表示': { // @カメの画像を非表示にする。描画に影響しない。 // @かめひひょうじ
|
|
604
|
-
type: 'func',
|
|
605
|
-
josi: [],
|
|
606
|
-
pure: true,
|
|
607
|
-
fn: function (sys) {
|
|
608
|
-
const tt = sys._turtle.getCur()
|
|
609
|
-
tt.mlist.push(['visible', false])
|
|
610
|
-
sys._turtle.setTimer()
|
|
611
|
-
},
|
|
612
|
-
return_none: true
|
|
613
|
-
},
|
|
614
|
-
'カメ表示': { // @非表示にしたカメを表示する。 // @かめひょうじ
|
|
615
|
-
type: 'func',
|
|
616
|
-
josi: [],
|
|
617
|
-
pure: true,
|
|
618
|
-
fn: function (sys) {
|
|
619
|
-
const tt = sys._turtle.getCur()
|
|
620
|
-
tt.mlist.push(['visible', true])
|
|
621
|
-
sys._turtle.setTimer()
|
|
622
|
-
},
|
|
623
|
-
return_none: true
|
|
624
|
-
},
|
|
625
|
-
'カメクリック時': { // @ 操作対象のカメをクリックした時のイベントを設定する // @かめくりっくしたとき
|
|
626
|
-
type: 'func',
|
|
627
|
-
josi: [['を']],
|
|
628
|
-
pure: false,
|
|
629
|
-
fn: function (func, sys) {
|
|
630
|
-
func = sys.__findVar(func, null) // 文字列指定なら関数に変換
|
|
631
|
-
const tid = sys._turtle.target
|
|
632
|
-
const tt = sys._turtle.list[tid]
|
|
633
|
-
tt.canvas.onclick = (e) => {
|
|
634
|
-
sys.__v0['対象'] = e.target
|
|
635
|
-
return func(e, sys)
|
|
636
|
-
}
|
|
637
|
-
},
|
|
638
|
-
return_none: true
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
|
-
|
|
642
|
-
// module.exports = PluginTurtle
|
|
643
|
-
export default PluginTurtle
|
|
644
|
-
|
|
645
|
-
// scriptタグで取り込んだ時、自動で登録する
|
|
646
|
-
/* istanbul ignore else */
|
|
647
|
-
if (typeof (navigator) === 'object' && typeof (navigator.nako3)) { navigator.nako3.addPluginObject('PluginTurtle', PluginTurtle) }
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* Turtle Graphics for Web browser (nadesiko3)
|
|
4
|
+
* plugin_turtle.js
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import turtleImage from './image_turtle64.mjs'
|
|
8
|
+
import elephantImage from './image_turtle-elephant.mjs'
|
|
9
|
+
import pandaImage from './image_turtle-panda.mjs'
|
|
10
|
+
|
|
11
|
+
const PluginTurtle = {
|
|
12
|
+
'初期化': {
|
|
13
|
+
type: 'func',
|
|
14
|
+
josi: [],
|
|
15
|
+
pure: true,
|
|
16
|
+
fn: function (sys) {
|
|
17
|
+
/* istanbul ignore if */
|
|
18
|
+
if (sys._turtle) { return }
|
|
19
|
+
sys._turtle = {
|
|
20
|
+
list: [],
|
|
21
|
+
target: -1,
|
|
22
|
+
ctx: null,
|
|
23
|
+
canvas: null,
|
|
24
|
+
canvas_r: { left: 0, top: 0, width: 640, height: 400 },
|
|
25
|
+
clearAll: function () {
|
|
26
|
+
const me = this
|
|
27
|
+
console.log('[TURTLE] clearAll')
|
|
28
|
+
for (let i = 0; i < me.list.length; i++) {
|
|
29
|
+
const tt = me.list[i]
|
|
30
|
+
tt.mlist = [] // ジョブをクリア
|
|
31
|
+
document.body.removeChild(tt.canvas)
|
|
32
|
+
}
|
|
33
|
+
me.list = []
|
|
34
|
+
if (me.canvas !== null) {
|
|
35
|
+
me.ctx.clearRect(0, 0,
|
|
36
|
+
me.canvas.width,
|
|
37
|
+
me.canvas.height)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
me.target = -1
|
|
41
|
+
me.flagSetTimer = false
|
|
42
|
+
},
|
|
43
|
+
drawTurtle: function (id) {
|
|
44
|
+
const tt = this.list[id]
|
|
45
|
+
if (!tt) { return }
|
|
46
|
+
const cr = this.canvas_r
|
|
47
|
+
// カメの位置を移動
|
|
48
|
+
tt.canvas.style.left = (cr.left + tt.x - tt.cx) + 'px'
|
|
49
|
+
tt.canvas.style.top = (cr.top + tt.y - tt.cx) + 'px'
|
|
50
|
+
if (!tt.f_update) { return }
|
|
51
|
+
/* istanbul ignore if */
|
|
52
|
+
if (!tt.flagLoaded) { return }
|
|
53
|
+
tt.f_update = false
|
|
54
|
+
tt.ctx.clearRect(0, 0,
|
|
55
|
+
tt.canvas.width,
|
|
56
|
+
tt.canvas.height)
|
|
57
|
+
if (!tt.f_visible) { return }
|
|
58
|
+
if (tt.dir !== 270) {
|
|
59
|
+
const rad = (tt.dir + 90) * 0.017453292519943295
|
|
60
|
+
tt.ctx.save()
|
|
61
|
+
tt.ctx.translate(tt.cx, tt.cy)
|
|
62
|
+
tt.ctx.rotate(rad)
|
|
63
|
+
tt.ctx.translate(-tt.cx, -tt.cy)
|
|
64
|
+
tt.ctx.drawImage(tt.img, 0, 0)
|
|
65
|
+
tt.ctx.restore()
|
|
66
|
+
} else { tt.ctx.drawImage(tt.img, 0, 0) }
|
|
67
|
+
},
|
|
68
|
+
getCur: function () {
|
|
69
|
+
if (this.list.length === 0) { throw Error('最初に『カメ作成』命令を呼び出してください。') }
|
|
70
|
+
|
|
71
|
+
return this.list[this.target]
|
|
72
|
+
},
|
|
73
|
+
flagSetTimer: false,
|
|
74
|
+
setTimer: function () {
|
|
75
|
+
if (this.flagSetTimer) { return }
|
|
76
|
+
this.flagSetTimer = true
|
|
77
|
+
console.log('[TURTLE] standby ...')
|
|
78
|
+
setTimeout(() => {
|
|
79
|
+
console.log('[TURTLE] Let\'s go!')
|
|
80
|
+
sys._turtle.play()
|
|
81
|
+
}, 1)
|
|
82
|
+
},
|
|
83
|
+
line: function (tt, x1, y1, x2, y2) {
|
|
84
|
+
/* istanbul ignore else */
|
|
85
|
+
if (tt) { if (!tt.flagDown) { return } }
|
|
86
|
+
|
|
87
|
+
const ctx = this.ctx
|
|
88
|
+
if (tt.flagBegeinPath) {
|
|
89
|
+
ctx.lineTo(x2, y2)
|
|
90
|
+
} else {
|
|
91
|
+
ctx.beginPath()
|
|
92
|
+
ctx.lineWidth = tt.lineWidth
|
|
93
|
+
ctx.strokeStyle = tt.color
|
|
94
|
+
ctx.moveTo(x1, y1)
|
|
95
|
+
ctx.lineTo(x2, y2)
|
|
96
|
+
ctx.stroke()
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
doMacro: function (tt, wait) {
|
|
100
|
+
const me = this
|
|
101
|
+
if (!tt.flagLoaded && wait > 0) {
|
|
102
|
+
// console.log('[TURTLE] waiting ...')
|
|
103
|
+
return true
|
|
104
|
+
}
|
|
105
|
+
const m = tt.mlist.shift()
|
|
106
|
+
const cmd = (m !== undefined) ? m[0] : ''
|
|
107
|
+
switch (cmd) {
|
|
108
|
+
case 'xy':
|
|
109
|
+
// 起点を移動する
|
|
110
|
+
tt.x = m[1]
|
|
111
|
+
tt.y = m[2]
|
|
112
|
+
break
|
|
113
|
+
case 'begin':
|
|
114
|
+
// 描画を明示的に開始する
|
|
115
|
+
this.ctx.beginPath()
|
|
116
|
+
this.ctx.moveTo(tt.x, tt.y)
|
|
117
|
+
tt.flagBegeinPath = true
|
|
118
|
+
break
|
|
119
|
+
case 'close':
|
|
120
|
+
// パスを閉じる
|
|
121
|
+
this.ctx.closePath()
|
|
122
|
+
tt.flagBegeinPath = false
|
|
123
|
+
break
|
|
124
|
+
case 'fill':
|
|
125
|
+
if (tt.flagBegeinPath) {
|
|
126
|
+
this.ctx.closePath()
|
|
127
|
+
tt.flagBegeinPath = false
|
|
128
|
+
}
|
|
129
|
+
this.ctx.fill()
|
|
130
|
+
break
|
|
131
|
+
case 'stroke':
|
|
132
|
+
if (tt.flagBegeinPath) {
|
|
133
|
+
this.ctx.closePath()
|
|
134
|
+
tt.flagBegeinPath = false
|
|
135
|
+
}
|
|
136
|
+
this.ctx.stroke()
|
|
137
|
+
break
|
|
138
|
+
case 'text':
|
|
139
|
+
this.ctx.fillText(m[1], tt.x, tt.y)
|
|
140
|
+
break
|
|
141
|
+
case 'textset':
|
|
142
|
+
this.ctx.font = m[1]
|
|
143
|
+
break
|
|
144
|
+
case 'fillStyle':
|
|
145
|
+
this.ctx.fillStyle = m[1]
|
|
146
|
+
break
|
|
147
|
+
case 'mv': {
|
|
148
|
+
// 線を引く
|
|
149
|
+
me.line(tt, tt.x, tt.y, m[1], m[2])
|
|
150
|
+
// カメの角度を変更
|
|
151
|
+
const mvRad = Math.atan2(m[2] - tt.y, m[1] - tt.x)
|
|
152
|
+
tt.dir = mvRad * 57.29577951308232
|
|
153
|
+
tt.f_update = true
|
|
154
|
+
// 実際に位置を移動
|
|
155
|
+
tt.x = m[1]
|
|
156
|
+
tt.y = m[2]
|
|
157
|
+
break
|
|
158
|
+
}
|
|
159
|
+
case 'fd': {
|
|
160
|
+
const fdv = m[1] * m[2]
|
|
161
|
+
const rad = tt.dir * 0.017453292519943295
|
|
162
|
+
const x2 = tt.x + Math.cos(rad) * fdv
|
|
163
|
+
const y2 = tt.y + Math.sin(rad) * fdv
|
|
164
|
+
me.line(tt, tt.x, tt.y, x2, y2)
|
|
165
|
+
tt.x = x2
|
|
166
|
+
tt.y = y2
|
|
167
|
+
break
|
|
168
|
+
}
|
|
169
|
+
case 'angle': {
|
|
170
|
+
const angle = m[1]
|
|
171
|
+
tt.dir = ((angle - 90 + 360) % 360)
|
|
172
|
+
tt.f_update = true
|
|
173
|
+
break
|
|
174
|
+
}
|
|
175
|
+
case 'rotr': {
|
|
176
|
+
const rv = m[1]
|
|
177
|
+
tt.dir = (tt.dir + rv) % 360
|
|
178
|
+
tt.f_update = true
|
|
179
|
+
break
|
|
180
|
+
}
|
|
181
|
+
case 'rotl': {
|
|
182
|
+
const lv = m[1]
|
|
183
|
+
tt.dir = (tt.dir - lv + 360) % 360
|
|
184
|
+
tt.f_update = true
|
|
185
|
+
break
|
|
186
|
+
}
|
|
187
|
+
case 'color':
|
|
188
|
+
tt.color = m[1]
|
|
189
|
+
this.ctx.strokeStyle = tt.color
|
|
190
|
+
break
|
|
191
|
+
case 'size':
|
|
192
|
+
this.ctx.lineWidth = tt.lineWidth
|
|
193
|
+
tt.lineWidth = m[1]
|
|
194
|
+
break
|
|
195
|
+
case 'penOn':
|
|
196
|
+
tt.flagDown = m[1]
|
|
197
|
+
break
|
|
198
|
+
case 'visible':
|
|
199
|
+
tt.f_visible = m[1]
|
|
200
|
+
tt.f_update = true
|
|
201
|
+
break
|
|
202
|
+
case 'changeImage':
|
|
203
|
+
tt.flagLoaded = false
|
|
204
|
+
tt.img.src = m[1]
|
|
205
|
+
break
|
|
206
|
+
}
|
|
207
|
+
if (tt.flagLoaded) { sys._turtle.drawTurtle(tt.id) }
|
|
208
|
+
return (tt.mlist.length > 0)
|
|
209
|
+
},
|
|
210
|
+
doMacroAll: function (wait) {
|
|
211
|
+
let hasNext = false
|
|
212
|
+
for (let i = 0; i < sys._turtle.list.length; i++) {
|
|
213
|
+
const tt = sys._turtle.list[i]
|
|
214
|
+
if (this.doMacro(tt, wait)) { hasNext = true }
|
|
215
|
+
}
|
|
216
|
+
return hasNext
|
|
217
|
+
},
|
|
218
|
+
play: function () {
|
|
219
|
+
const me = this
|
|
220
|
+
const wait = sys.__v0['カメ速度']
|
|
221
|
+
let hasNext = this.doMacroAll(wait)
|
|
222
|
+
if (wait <= 0) {
|
|
223
|
+
while (hasNext) { hasNext = this.doMacroAll(wait) }
|
|
224
|
+
} else if (hasNext) {
|
|
225
|
+
setTimeout(() => me.play(), wait)
|
|
226
|
+
return
|
|
227
|
+
}
|
|
228
|
+
console.log('[TURTLE] finished.')
|
|
229
|
+
me.flagSetTimer = false
|
|
230
|
+
},
|
|
231
|
+
setupCanvas: function (sys) {
|
|
232
|
+
// 描画先をセットする
|
|
233
|
+
let canvasId = sys.__v0['カメ描画先']
|
|
234
|
+
if (typeof canvasId === 'string') {
|
|
235
|
+
canvasId = document.getElementById(canvasId) || document.querySelector(canvasId)
|
|
236
|
+
sys.__v0['カメ描画先'] = canvasId
|
|
237
|
+
}
|
|
238
|
+
console.log('カメ描画先=', canvasId)
|
|
239
|
+
const cv = sys._turtle.canvas = canvasId
|
|
240
|
+
if (!cv) {
|
|
241
|
+
console.log('[ERROR] カメ描画先が見当たりません。' + canvasId)
|
|
242
|
+
throw Error('カメ描画先が見当たりません。')
|
|
243
|
+
}
|
|
244
|
+
const ctx = sys._turtle.ctx = sys._turtle.canvas.getContext('2d')
|
|
245
|
+
ctx.lineWidth = 4
|
|
246
|
+
ctx.strokeStyle = 'black'
|
|
247
|
+
ctx.lineCap = 'round'
|
|
248
|
+
sys._turtle.resizeCanvas(sys)
|
|
249
|
+
},
|
|
250
|
+
resizeCanvas: function (sys) {
|
|
251
|
+
const cv = sys._turtle.canvas
|
|
252
|
+
const rect = cv.getBoundingClientRect()
|
|
253
|
+
const rx = rect.left + window.pageXOffset
|
|
254
|
+
const ry = rect.top + window.pageYOffset
|
|
255
|
+
sys._turtle.canvas_r = {
|
|
256
|
+
'left': rx,
|
|
257
|
+
'top': ry,
|
|
258
|
+
width: rect.width,
|
|
259
|
+
height: rect.height
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
createTurtle: function (imageUrl, sys) {
|
|
263
|
+
// キャンバス情報は毎回参照する (#734)
|
|
264
|
+
sys._turtle.setupCanvas(sys)
|
|
265
|
+
// const cv = sys._turtle.canvas
|
|
266
|
+
// カメの情報を sys._turtle リストに追加
|
|
267
|
+
const id = sys._turtle.list.length
|
|
268
|
+
const tt = {
|
|
269
|
+
id: id,
|
|
270
|
+
img: null,
|
|
271
|
+
canvas: null,
|
|
272
|
+
ctx: null,
|
|
273
|
+
dir: 270, // 上向き
|
|
274
|
+
cx: 32,
|
|
275
|
+
cy: 32,
|
|
276
|
+
x: 0,
|
|
277
|
+
y: 0,
|
|
278
|
+
color: 'black',
|
|
279
|
+
lineWidth: 4,
|
|
280
|
+
flagDown: true,
|
|
281
|
+
flagBegeinPath: false,
|
|
282
|
+
f_update: true,
|
|
283
|
+
flagLoaded: false,
|
|
284
|
+
f_visible: true,
|
|
285
|
+
mlist: []
|
|
286
|
+
}
|
|
287
|
+
sys._turtle.list.push(tt)
|
|
288
|
+
sys._turtle.target = id
|
|
289
|
+
// 画像を読み込む
|
|
290
|
+
tt.img = document.createElement('img')
|
|
291
|
+
tt.canvas = document.createElement('canvas')
|
|
292
|
+
tt.ctx = tt.canvas.getContext('2d')
|
|
293
|
+
tt.canvas.id = id
|
|
294
|
+
tt.img.onload = () => {
|
|
295
|
+
tt.cx = tt.img.width / 2
|
|
296
|
+
tt.cy = tt.img.height / 2
|
|
297
|
+
tt.canvas.width = tt.img.width
|
|
298
|
+
tt.canvas.height = tt.img.height
|
|
299
|
+
tt.flagLoaded = true
|
|
300
|
+
tt.f_update = true
|
|
301
|
+
sys._turtle.drawTurtle(tt.id)
|
|
302
|
+
console.log('turtle.onload')
|
|
303
|
+
}
|
|
304
|
+
tt.img.onerror = () => {
|
|
305
|
+
console.log('カメの読み込みに失敗')
|
|
306
|
+
tt.flagLoaded = true
|
|
307
|
+
tt.f_visible = false
|
|
308
|
+
tt.f_update = true
|
|
309
|
+
sys._turtle.drawTurtle(tt.id)
|
|
310
|
+
}
|
|
311
|
+
tt.img.src = imageUrl
|
|
312
|
+
tt.canvas.style.position = 'absolute'
|
|
313
|
+
document.body.appendChild(tt.canvas)
|
|
314
|
+
// デフォルト位置の設定
|
|
315
|
+
tt.x = sys._turtle.canvas_r.width / 2
|
|
316
|
+
tt.y = sys._turtle.canvas_r.height / 2
|
|
317
|
+
return id
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
},
|
|
322
|
+
|
|
323
|
+
'!クリア': {
|
|
324
|
+
type: 'func',
|
|
325
|
+
josi: [],
|
|
326
|
+
pure: true,
|
|
327
|
+
fn: function (sys) {
|
|
328
|
+
sys._turtle.clearAll()
|
|
329
|
+
}
|
|
330
|
+
},
|
|
331
|
+
|
|
332
|
+
// @タートルグラフィックス・カメ描画
|
|
333
|
+
'カメ作成': { // @タートルグラフィックスを開始してカメのIDを返す // @かめさくせい
|
|
334
|
+
type: 'func',
|
|
335
|
+
josi: [],
|
|
336
|
+
pure: true,
|
|
337
|
+
fn: function (sys) {
|
|
338
|
+
const imageUrl = sys.__v0['カメ画像URL']
|
|
339
|
+
return sys._turtle.createTurtle(imageUrl, sys)
|
|
340
|
+
}
|
|
341
|
+
},
|
|
342
|
+
'ゾウ作成': { // @ゾウの画像でタートルグラフィックスを開始してIDを返す // @ぞうさくせい
|
|
343
|
+
type: 'func',
|
|
344
|
+
josi: [],
|
|
345
|
+
pure: true,
|
|
346
|
+
fn: function (sys) {
|
|
347
|
+
const imageUrl = elephantImage
|
|
348
|
+
return sys._turtle.createTurtle(imageUrl, sys)
|
|
349
|
+
}
|
|
350
|
+
},
|
|
351
|
+
'パンダ作成': { // @パンダの画像でタートルグラフィックスを開始してIDを返す // @ぱんださくせい
|
|
352
|
+
type: 'func',
|
|
353
|
+
josi: [],
|
|
354
|
+
pure: true,
|
|
355
|
+
fn: function (sys) {
|
|
356
|
+
const imageUrl = pandaImage
|
|
357
|
+
return sys._turtle.createTurtle(imageUrl, sys)
|
|
358
|
+
}
|
|
359
|
+
},
|
|
360
|
+
'カメ操作対象設定': { // @IDを指定して操作対象となるカメを変更する // @かめそうさたいしょうせってい
|
|
361
|
+
type: 'func',
|
|
362
|
+
josi: [['に', 'へ', 'の']],
|
|
363
|
+
pure: true,
|
|
364
|
+
fn: function (id, sys) {
|
|
365
|
+
sys._turtle.target = id
|
|
366
|
+
},
|
|
367
|
+
return_none: true
|
|
368
|
+
},
|
|
369
|
+
'カメ描画先': { type: 'var', value: 'turtle_cv' }, // @かめびょうがさき
|
|
370
|
+
'カメ画像URL': { type: 'var', value: turtleImage }, // @かめがぞうURL
|
|
371
|
+
'カメ画像変更': { // @カメの画像をURLに変更する // @かめがぞうへんこう
|
|
372
|
+
type: 'func',
|
|
373
|
+
josi: [['に', 'へ']],
|
|
374
|
+
pure: true,
|
|
375
|
+
fn: function (url, sys) {
|
|
376
|
+
const tt = sys._turtle.getCur()
|
|
377
|
+
tt.mlist.push(['changeImage', url])
|
|
378
|
+
sys._turtle.setTimer()
|
|
379
|
+
},
|
|
380
|
+
return_none: true
|
|
381
|
+
},
|
|
382
|
+
'カメ速度': { type: 'const', value: 100 }, // @かめそくど
|
|
383
|
+
'カメ速度設定': { // @カメの動作速度vに設定(大きいほど遅い) // @かめそくどせってい
|
|
384
|
+
type: 'func',
|
|
385
|
+
josi: [['に', 'へ']],
|
|
386
|
+
pure: true,
|
|
387
|
+
fn: function (v, sys) {
|
|
388
|
+
sys.__varslist[0]['カメ速度'] = v
|
|
389
|
+
}
|
|
390
|
+
},
|
|
391
|
+
'カメ移動': { // @カメの位置を[x,y]へ移動する // @かめいどう
|
|
392
|
+
type: 'func',
|
|
393
|
+
josi: [['に', 'へ']],
|
|
394
|
+
pure: true,
|
|
395
|
+
fn: function (xy, sys) {
|
|
396
|
+
const tt = sys._turtle.getCur()
|
|
397
|
+
tt.mlist.push(['mv', xy[0], xy[1]])
|
|
398
|
+
sys._turtle.setTimer()
|
|
399
|
+
},
|
|
400
|
+
return_none: true
|
|
401
|
+
},
|
|
402
|
+
'カメ起点移動': { // @カメの描画起点位置を[x,y]へ移動する // @かめきてんいどう
|
|
403
|
+
type: 'func',
|
|
404
|
+
josi: [['に', 'へ']],
|
|
405
|
+
pure: true,
|
|
406
|
+
fn: function (xy, sys) {
|
|
407
|
+
const tt = sys._turtle.getCur()
|
|
408
|
+
tt.mlist.push(['xy', xy[0], xy[1]])
|
|
409
|
+
sys._turtle.setTimer()
|
|
410
|
+
},
|
|
411
|
+
return_none: true
|
|
412
|
+
},
|
|
413
|
+
'カメ進': { // @カメの位置をVだけ進める // @かめすすむ
|
|
414
|
+
type: 'func',
|
|
415
|
+
josi: [['だけ']],
|
|
416
|
+
pure: true,
|
|
417
|
+
fn: function (v, sys) {
|
|
418
|
+
const tt = sys._turtle.getCur()
|
|
419
|
+
tt.mlist.push(['fd', v, 1])
|
|
420
|
+
sys._turtle.setTimer()
|
|
421
|
+
},
|
|
422
|
+
return_none: true
|
|
423
|
+
},
|
|
424
|
+
'カメ戻': { // @カメの位置をVだけ戻す // @かめもどる
|
|
425
|
+
type: 'func',
|
|
426
|
+
josi: [['だけ']],
|
|
427
|
+
pure: true,
|
|
428
|
+
fn: function (v, sys) {
|
|
429
|
+
const tt = sys._turtle.getCur()
|
|
430
|
+
tt.mlist.push(['fd', v, -1])
|
|
431
|
+
sys._turtle.setTimer()
|
|
432
|
+
},
|
|
433
|
+
return_none: true
|
|
434
|
+
},
|
|
435
|
+
'カメ角度設定': { // @カメの向きをDEGに設定する // @かめかくどせってい
|
|
436
|
+
type: 'func',
|
|
437
|
+
josi: [['に', 'へ', 'の']],
|
|
438
|
+
pure: true,
|
|
439
|
+
fn: function (v, sys) {
|
|
440
|
+
const tt = sys._turtle.getCur()
|
|
441
|
+
tt.mlist.push(['angle', parseFloat(v)])
|
|
442
|
+
sys._turtle.setTimer()
|
|
443
|
+
},
|
|
444
|
+
return_none: true
|
|
445
|
+
},
|
|
446
|
+
'カメ右回転': { // @カメの向きをDEGだけ右に向ける // @かめみぎかいてん
|
|
447
|
+
type: 'func',
|
|
448
|
+
josi: [['だけ']],
|
|
449
|
+
pure: true,
|
|
450
|
+
fn: function (v, sys) {
|
|
451
|
+
const tt = sys._turtle.getCur()
|
|
452
|
+
tt.mlist.push(['rotr', v])
|
|
453
|
+
sys._turtle.setTimer()
|
|
454
|
+
},
|
|
455
|
+
return_none: true
|
|
456
|
+
},
|
|
457
|
+
'カメ左回転': { // @カメの向きをDEGだけ左に向ける // @かめひだりかいてん
|
|
458
|
+
type: 'func',
|
|
459
|
+
josi: [['だけ']],
|
|
460
|
+
pure: true,
|
|
461
|
+
fn: function (v, sys) {
|
|
462
|
+
const tt = sys._turtle.getCur()
|
|
463
|
+
tt.mlist.push(['rotl', v])
|
|
464
|
+
sys._turtle.setTimer()
|
|
465
|
+
},
|
|
466
|
+
return_none: true
|
|
467
|
+
},
|
|
468
|
+
'カメペン色設定': { // @カメのペン描画色をCに設定する // @かめぺんいろせってい
|
|
469
|
+
type: 'func',
|
|
470
|
+
josi: [['に', 'へ']],
|
|
471
|
+
pure: true,
|
|
472
|
+
fn: function (c, sys) {
|
|
473
|
+
const tt = sys._turtle.getCur()
|
|
474
|
+
tt.mlist.push(['color', c])
|
|
475
|
+
sys._turtle.setTimer()
|
|
476
|
+
},
|
|
477
|
+
return_none: true
|
|
478
|
+
},
|
|
479
|
+
'カメペンサイズ設定': { // @カメペンのサイズをWに設定する // @かめぺんさいずせってい
|
|
480
|
+
type: 'func',
|
|
481
|
+
josi: [['に', 'へ']],
|
|
482
|
+
pure: true,
|
|
483
|
+
fn: function (w, sys) {
|
|
484
|
+
const tt = sys._turtle.getCur()
|
|
485
|
+
tt.mlist.push(['size', w])
|
|
486
|
+
sys._turtle.setTimer()
|
|
487
|
+
}
|
|
488
|
+
},
|
|
489
|
+
'カメペン設定': { // @カメペンを使うかどうかをV(オン/オフ)に設定する // @かめぺんせってい
|
|
490
|
+
type: 'func',
|
|
491
|
+
josi: [['に', 'へ']],
|
|
492
|
+
pure: true,
|
|
493
|
+
fn: function (w, sys) {
|
|
494
|
+
const tt = sys._turtle.getCur()
|
|
495
|
+
tt.mlist.push(['penOn', w])
|
|
496
|
+
sys._turtle.setTimer()
|
|
497
|
+
}
|
|
498
|
+
},
|
|
499
|
+
'カメパス開始': { // @カメで明示的にパスの描画を開始する // @かめぱすかいし
|
|
500
|
+
type: 'func',
|
|
501
|
+
josi: [],
|
|
502
|
+
pure: true,
|
|
503
|
+
fn: function (sys) {
|
|
504
|
+
const tt = sys._turtle.getCur()
|
|
505
|
+
tt.mlist.push(['begin'])
|
|
506
|
+
sys._turtle.setTimer()
|
|
507
|
+
}
|
|
508
|
+
},
|
|
509
|
+
'カメパス閉': { // @カメでパスを明示的に閉じる(省略可能) // @かめぱすとじる
|
|
510
|
+
type: 'func',
|
|
511
|
+
josi: [],
|
|
512
|
+
pure: true,
|
|
513
|
+
fn: function (sys) {
|
|
514
|
+
const tt = sys._turtle.getCur()
|
|
515
|
+
tt.mlist.push(['close'])
|
|
516
|
+
sys._turtle.setTimer()
|
|
517
|
+
}
|
|
518
|
+
},
|
|
519
|
+
'カメパス線引': { // @カメでパスを閉じて、カメペン色設定で指定した色で枠線を引く // @かめぱすせんひく
|
|
520
|
+
type: 'func',
|
|
521
|
+
josi: [],
|
|
522
|
+
pure: true,
|
|
523
|
+
fn: function (sys) {
|
|
524
|
+
const tt = sys._turtle.getCur()
|
|
525
|
+
tt.mlist.push(['stroke'])
|
|
526
|
+
sys._turtle.setTimer()
|
|
527
|
+
}
|
|
528
|
+
},
|
|
529
|
+
'カメパス塗': { // @カメでパスを閉じて、カメ塗り色設定で指定した色で塗りつぶす // @かめぱすぬる
|
|
530
|
+
type: 'func',
|
|
531
|
+
josi: [],
|
|
532
|
+
pure: true,
|
|
533
|
+
fn: function (sys) {
|
|
534
|
+
const tt = sys._turtle.getCur()
|
|
535
|
+
tt.mlist.push(['fill'])
|
|
536
|
+
sys._turtle.setTimer()
|
|
537
|
+
}
|
|
538
|
+
},
|
|
539
|
+
'カメ文字描画': { // @カメの位置に文字Sを描画 // @かめもじびょうが
|
|
540
|
+
type: 'func',
|
|
541
|
+
josi: [['を', 'と', 'の']],
|
|
542
|
+
pure: true,
|
|
543
|
+
fn: function (s, sys) {
|
|
544
|
+
const tt = sys._turtle.getCur()
|
|
545
|
+
tt.mlist.push(['text', s])
|
|
546
|
+
sys._turtle.setTimer()
|
|
547
|
+
}
|
|
548
|
+
},
|
|
549
|
+
'カメ文字設定': { // @カメ文字描画で描画するテキストサイズやフォント(48px serif)などを設定 // @かめもじせってい
|
|
550
|
+
type: 'func',
|
|
551
|
+
josi: [['に', 'へ', 'で']],
|
|
552
|
+
pure: true,
|
|
553
|
+
fn: function (s, sys) {
|
|
554
|
+
s = '' + s // 文字列に
|
|
555
|
+
if (s.match(/^\d+$/)) {
|
|
556
|
+
s = s + 'px serif'
|
|
557
|
+
} else if (s.match(/^\d+(px|em)$/)) {
|
|
558
|
+
s = s + ' serif'
|
|
559
|
+
}
|
|
560
|
+
const tt = sys._turtle.getCur()
|
|
561
|
+
tt.mlist.push(['textset', s])
|
|
562
|
+
sys._turtle.setTimer()
|
|
563
|
+
}
|
|
564
|
+
},
|
|
565
|
+
'カメ塗色設定': { // @カメパスの塗り色をCに設定する // @かめぬりいろせってい
|
|
566
|
+
type: 'func',
|
|
567
|
+
josi: [['に', 'へ']],
|
|
568
|
+
pure: true,
|
|
569
|
+
fn: function (c, sys) {
|
|
570
|
+
const tt = sys._turtle.getCur()
|
|
571
|
+
tt.mlist.push(['fillStyle', c])
|
|
572
|
+
sys._turtle.setTimer()
|
|
573
|
+
},
|
|
574
|
+
return_none: true
|
|
575
|
+
},
|
|
576
|
+
'カメ全消去': { // @表示しているカメと描画内容を全部消去する // @かめぜんしょうきょ
|
|
577
|
+
type: 'func',
|
|
578
|
+
josi: [],
|
|
579
|
+
pure: true,
|
|
580
|
+
fn: function (sys) {
|
|
581
|
+
sys._turtle.clearAll()
|
|
582
|
+
},
|
|
583
|
+
return_none: true
|
|
584
|
+
},
|
|
585
|
+
'カメコマンド実行': { // @カメにコマンドSを実行する。コマンドは改行か「;」で区切る。コマンドと引数は「=」で区切り引数はかカンマで区切る // @かめこまんどじっこう
|
|
586
|
+
type: 'func',
|
|
587
|
+
josi: [['の', 'を']],
|
|
588
|
+
pure: true,
|
|
589
|
+
fn: function (cmd, sys) {
|
|
590
|
+
const tt = sys._turtle.getCur()
|
|
591
|
+
const a = cmd.split(/(\n|;)/)
|
|
592
|
+
for (let i = 0; i < a.length; i++) {
|
|
593
|
+
let c = a[i]
|
|
594
|
+
c = c.replace(/^([a-zA-Z_]+)\s*(\d+)/, '$1,$2')
|
|
595
|
+
c = c.replace(/^([a-zA-Z_]+)\s*=/, '$1,')
|
|
596
|
+
const ca = c.split(/\s*,\s*/)
|
|
597
|
+
tt.mlist.push(ca)
|
|
598
|
+
}
|
|
599
|
+
sys._turtle.setTimer()
|
|
600
|
+
},
|
|
601
|
+
return_none: true
|
|
602
|
+
},
|
|
603
|
+
'カメ非表示': { // @カメの画像を非表示にする。描画に影響しない。 // @かめひひょうじ
|
|
604
|
+
type: 'func',
|
|
605
|
+
josi: [],
|
|
606
|
+
pure: true,
|
|
607
|
+
fn: function (sys) {
|
|
608
|
+
const tt = sys._turtle.getCur()
|
|
609
|
+
tt.mlist.push(['visible', false])
|
|
610
|
+
sys._turtle.setTimer()
|
|
611
|
+
},
|
|
612
|
+
return_none: true
|
|
613
|
+
},
|
|
614
|
+
'カメ表示': { // @非表示にしたカメを表示する。 // @かめひょうじ
|
|
615
|
+
type: 'func',
|
|
616
|
+
josi: [],
|
|
617
|
+
pure: true,
|
|
618
|
+
fn: function (sys) {
|
|
619
|
+
const tt = sys._turtle.getCur()
|
|
620
|
+
tt.mlist.push(['visible', true])
|
|
621
|
+
sys._turtle.setTimer()
|
|
622
|
+
},
|
|
623
|
+
return_none: true
|
|
624
|
+
},
|
|
625
|
+
'カメクリック時': { // @ 操作対象のカメをクリックした時のイベントを設定する // @かめくりっくしたとき
|
|
626
|
+
type: 'func',
|
|
627
|
+
josi: [['を']],
|
|
628
|
+
pure: false,
|
|
629
|
+
fn: function (func, sys) {
|
|
630
|
+
func = sys.__findVar(func, null) // 文字列指定なら関数に変換
|
|
631
|
+
const tid = sys._turtle.target
|
|
632
|
+
const tt = sys._turtle.list[tid]
|
|
633
|
+
tt.canvas.onclick = (e) => {
|
|
634
|
+
sys.__v0['対象'] = e.target
|
|
635
|
+
return func(e, sys)
|
|
636
|
+
}
|
|
637
|
+
},
|
|
638
|
+
return_none: true
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
// module.exports = PluginTurtle
|
|
643
|
+
export default PluginTurtle
|
|
644
|
+
|
|
645
|
+
// scriptタグで取り込んだ時、自動で登録する
|
|
646
|
+
/* istanbul ignore else */
|
|
647
|
+
if (typeof (navigator) === 'object' && typeof (navigator.nako3)) { navigator.nako3.addPluginObject('PluginTurtle', PluginTurtle) }
|