GithubHelp home page GithubHelp logo

a1ip / turtle-canvas Goto Github PK

View Code? Open in Web Editor NEW

This project forked from theoperatore/turtle-canvas

0.0 2.0 0.0 120 KB

A turtle for making turtle graphics that uses the <canvas>

JavaScript 82.11% HTML 17.89%

turtle-canvas's Introduction

Turtle Canvas

A simple package to help you create wonderful Turtle Graphics.

Installation

Install via npm for browserify:

npm install turtle-canvas --save

Install via clone and include in script tag

<script src="path/to/clone/turtle-graphics/browser/turtle-canvas.min.js"></script>

Usage

via node:

var Turtle = require('turtle-canvas');
var turtle = new Turtle("canvasID");

// move turtle forward 10 pixels and draw line
turtle.forward(10);
turtle.stroke();

via <script>:

var turtle = new TURTLE("canvasID");

// move turtle forward 10 pixels and draw line
turtle.forward(10);
turtle.stroke();

Documentation

Each function returns the turtle instance to allow for chaining of commands.

Turtle(canvas)

Constructor; canvas can either be a string of the ID of the canvas, or a canvas DOMElement itself.

Turtle.penup()

Sets the turtle to not stroke when using turtle.forward() or turtle.back()

Turtle.pendown()

Sets the turtle to stroke when using turtle.forward() or turtle.back()

Turtle.moveTo(x, y)

Move (not stroke) the turtle to coordinates (x,y).

Turtle.forward(amount)

Move the turtle forward by amount pixels. If the turtle pen is down, the turtle will stroke the distance.

Turtle.back(amount)

Move the turtle backward by amount pixels. If the turtle pen is down, the turtle will stroke the distance.

Turtle.left(amount)

Turn the turtle counter-clockwise by amount degrees.

Turtle.right(amount)

Turn the turtle clockwise by amount degrees.

Turtle.save()

Save the current state of the turtle; saves penup/pendown, orientation, position.

Turtle.restore()

Restores the most recently saved state of the turtle; restores penup/pendown, orientation, position.

Turtle.fill()

Fill all shapes from last turtle.fill().

Turtle.stroke()

Stroke all shapes from last turtle.stroke().

Lisense

MIT

turtle-canvas's People

Contributors

theoperatore avatar

Watchers

 avatar  avatar

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.