Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kongnet/turtle
Simulate Turtle Geometry
https://github.com/kongnet/turtle
animation fractal js logo turtle
Last synced: 2 months ago
JSON representation
Simulate Turtle Geometry
- Host: GitHub
- URL: https://github.com/kongnet/turtle
- Owner: kongnet
- License: mit
- Created: 2023-07-29T03:40:07.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-07-07T13:36:24.000Z (7 months ago)
- Last Synced: 2024-07-07T14:52:24.177Z (7 months ago)
- Topics: animation, fractal, js, logo, turtle
- Language: HTML
- Homepage:
- Size: 915 KB
- Stars: 11
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Turtle
> I enjoy the turtle geometry, so I implemented a simplified version using vanilla JavaScript.
> Simulate Turtle Geometry
- fd() forward
- bk() backward
- rt() right
- lt() left
- pu() penup
- pd() pendown
- repeat()
- setxy() put the turtle at coordinate(x, y)
- home() bring the turtle at the center
- cs() clearscreen> run() vs go(), go() can clear atction queue, run() not
```javascript
const t = new Turtle({ debug: false })
t.fd(10).rt(90).repeat(4).go() // draw a square
``````javascript
/*
combine t0, t1
t0,t1 can play solo, use t.to('t0').run()
*/
const t = new Turtle({ debug: false })t.to('t0').fd(0.1).rt(2).repeat(90)
t.to('t1').fd(0.1).lt(2).repeat(90)
t.to().add('t0').add('t1').rt(90).repeat(4).rt(36).repeat(10).go()console.log(t.list) // ['_mainproc', 't0', 't1']
```- demo1 regular polygon
- demo2 regular star polygon
- demo3 constant velocity helix + golden spiral
- demo4 variable speed helix
- demo5 Koch curve
- demo6 Fractal Tree
- demo7 Sierpinski triangle
- demo8 Leaf![screenshot](https://github.com/kongnet/turtle/blob/main/screenshot/s1.png)
## Animation
```javascript
let t = new Turtle({ debug: false, animate: 2 }) // draw speed
t.to('t0').fd(0.1).rt(2).repeat(90) // combine
t.to('t1').fd(0.1).lt(2).repeat(90)
t.to().add('t0').add('t1').rt(90).repeat(4).rt(36).repeat(10).go()
```![Animation](https://github.com/kongnet/turtle/blob/main/screenshot/s3.gif)
## turtle-maze.html
![Maze](https://github.com/kongnet/turtle/blob/main/screenshot/s2.jpg)