Skip to content

Commit 315e483

Browse files
author
James Brundage
committed
feat: Turtle.js.ToHtml() ( Fixes #321 )
1 parent f41a210 commit 315e483

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

Types/Turtle.js/ToHTML.ps1

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<#
2+
.SYNOPSIS
3+
A Tiny Turtle
4+
.DESCRIPTION
5+
A minimal implementation of Turtle graphics in PowerShell and JavaScript, with and a speed test.
6+
.EXAMPLE
7+
./TinyTurtle.html.ps1 > ./TinyTurtle.html
8+
#>
9+
"<div>"
10+
"<turtle>"
11+
"<svg width='100%' height='100%' id='stage'>"
12+
"<path id='turtle-path' fill='transparent' stroke='currentColor' stroke-width='1%' stroke-linecap='round'></path>"
13+
"<text id='counter' font-size='12px' x='50%' y='50%' text-anchor='middle' dominant-baseline='middle'></text>"
14+
"</svg>"
15+
"</turtle>"
16+
"<script>"
17+
18+
@"
19+
let counter = 0;
20+
let time = new Date()
21+
function draw() {
22+
requestAnimationFrame(draw)
23+
24+
let turtle = $this
25+
26+
turtle.rotate(Math.random() * 360).polygon(100, 8)
27+
let turtleElement = document.querySelector('turtle')
28+
let svg = turtleElement.querySelector('#stage')
29+
svg.setAttribute('viewBox', ``0 0 `${turtle.width} `${turtle.height}``)
30+
let path = turtleElement.querySelector('#turtle-path')
31+
path.setAttribute('d', turtle.pathData())
32+
counter++
33+
34+
document.getElementById('counter').textContent =
35+
```${Math.round(counter/((new Date() - time)/1000)*100)/100} fps``
36+
}
37+
draw()
38+
"@
39+
"</script>"
40+
"</div>"

0 commit comments

Comments
 (0)