Coder Social home page Coder Social logo

turtle's Introduction

Turtle

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

const t = new Turtle({ debug: false })
t.fd(10).rt(90).repeat(4).go() // draw a square
/*
  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

Animation

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

turtle-maze.html

Maze

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.