Skip to content

Commit fde657c

Browse files
committed
[turtle] Output LOGO code too
1 parent cc6561b commit fde657c

File tree

2 files changed

+44
-11
lines changed

2 files changed

+44
-11
lines changed

demos/turtle/index.html

+18-3
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,18 @@ <h1><img id="turtle_image" src='data:image/svg+xml,<svg xmlns="http://www.w3.org
2929

3030
<div class="mv-bar" mv-bar="with import export clear"></div>
3131
<details>
32-
<summary class="button mv-code-js">Code (JS)</summary>
32+
<summary class="button code-js">Code (JS)</summary>
3333
<div>
3434
<textarea>[code_before][code]</textarea>
3535
</div>
3636
</details>
37+
<details>
38+
<summary class="button code-logo">Code (LOGO)</summary>
39+
<div>
40+
<textarea>[logo_code]</textarea>
41+
</div>
42+
</details>
43+
3744

3845
<section>
3946
<input type="number" property="width" value="1000" /> &times;
@@ -63,6 +70,7 @@ <h1><img id="turtle_image" src='data:image/svg+xml,<svg xmlns="http://www.w3.org
6370
<option value="1">clockwise</option>
6471
<option value="-1">anti-clockwise</option>
6572
</select>
73+
<meta property="logo" content="[if(direction = 1, 'right', 'left')] [angle]" />
6674
<meta property="js" content='ctx.rotate((Math.PI / 180) * [direction] * [angle]);
6775
'>
6876
</label>
@@ -74,7 +82,7 @@ <h1><img id="turtle_image" src='data:image/svg+xml,<svg xmlns="http://www.w3.org
7482
</select>
7583
<input type="number" property="steps" value="100" />
7684
steps
77-
85+
<meta property="logo" content="[if(direction = 1, 'forward', 'backward')] [steps]" />
7886
<meta property="js" content='
7987
ctx.moveTo(0, 0);
8088
ctx.lineTo([direction] * [steps], 0);
@@ -87,19 +95,25 @@ <h1><img id="turtle_image" src='data:image/svg+xml,<svg xmlns="http://www.w3.org
8795
to
8896
<!-- color.$previous should have worked here -->
8997
<input type="color" property="color" mv-default="[first(condense(color.$all).slice(0, -1)) or '#ff0066']" />
90-
<meta property="js" content='var color = ctx.strokeStyle = "[color]";
98+
<meta property="logo" content="setpc [color]" />
99+
<meta property="js" content='ctx.strokeStyle = "[color]";
91100
if (brushDown) ctx.closePath(); ctx.beginPath();'>
92101
</label>
93102

94103
<div mv-if="type = 'up'">
104+
<meta property="logo" mv-mode="read" content="penup" />
95105
<meta property="js" content='ctx.closePath(); brushDown = false;' mv-mode="read">
96106
</div>
97107
<div mv-if="type = 'down'">
108+
<meta property="logo" mv-mode="read" content="pendown" />
98109
<meta property="js" content='ctx.beginPath(); brushDown = true;' mv-mode="read">
99110
</div>
100111
<label mv-if="type = 'repeat'">
101112
<input type="number" property="times" />
102113
times:
114+
<meta property="logo" content='repeat [times] ["\\u005B"]
115+
[ replace(join(instruction.logo, "\\n"), "\\n", "\\n\\t") ]
116+
["\\u005D"] ' />
103117
<meta property="js" content='for (let i=0; i<[times]; i++) {
104118
[ replace(join(instruction.js, "\\n"), "\\n", "\\n\\t") ]
105119
}'>
@@ -112,6 +126,7 @@ <h1><img id="turtle_image" src='data:image/svg+xml,<svg xmlns="http://www.w3.org
112126
</li>
113127
</ol>
114128
<meta property="code" content="[join(js, '\\n')]" />
129+
<meta property="logo_code" content="[join(logo, '\\n')]" />
115130

116131
<footer>
117132
Concept & design heavily inspired <br> from Nicky Case’s awesome <a href="http://ncase.me/joy-demo/turtle/" target="_blank">Joy of Turtle</a>

demos/turtle/style.css

+26-8
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,20 @@ body > header {
5353
}
5454
}
5555

56+
.code-js {
57+
&::before {
58+
content: "⚙️ ";
59+
}
60+
}
61+
62+
.code-logo {
63+
&::before {
64+
content: "🐢 ";
65+
display: inline-block;
66+
translate: 0 -.15em;
67+
}
68+
}
69+
5670
h1 {
5771
margin: 0;
5872
font-size: 130%;
@@ -109,18 +123,19 @@ body > header {
109123

110124
& > div {
111125
position: absolute;
112-
left: -.5em;
126+
left: 0;
127+
top: 100%;
113128
z-index: 2;
114-
margin-top: .5em;
115-
background: white;
129+
margin-top: .3em;
130+
background: hsl(220 10% 96%);
116131
border: 1px solid rgb(0 0 0 / .2);
117-
box-shadow: 0 .2em 1em rgb(0 0 0 / .2);
132+
box-shadow: 0 .2em 1.5em -.5em rgb(0 0 0 / .2);
118133
border-radius: .3rem;
119134

120135
&::before {
121136
content: "";
122137
position: absolute;
123-
top: -.5em * .6;
138+
top: calc(-.5em * .6);
124139
left: 1em;
125140
background: inherit;
126141
border: inherit;
@@ -132,18 +147,21 @@ body > header {
132147
}
133148
}
134149

135-
/* JS */
150+
/* Code */
136151
textarea {
137152
display: block;
138-
width: 40rem;
153+
field-sizing: content;
154+
min-width: 12rem;
139155
max-width: 90vw;
140-
height: 20rem;
156+
background: transparent;
157+
tab-size: 4;
141158
max-height: 90vh;
142159
padding: 1rem;
143160
box-sizing: border-box;
144161
border: 0;
145162
font: 60%/1.5 Consolas, Monaco, monospace;
146163
border-radius: inherit;
164+
white-space: pre;
147165
}
148166
}
149167

0 commit comments

Comments
 (0)