File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed
Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change 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>"
You can’t perform that action at this time.
0 commit comments