-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
430 additions
and
683 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,306 +1,4 @@ | ||
# Docs of [turtle.js](https://github.com/Siyu1017/turtle.js) | ||
# Docs of turtle.js | ||
|
||
## Table of contents | ||
|
||
### Methods specific to Turtle.js | ||
- [setlinecap()](#turtlesetlinecaptype) | ||
- [setlinejoin()](#turtlesetlinejointype) | ||
- [seteasing()](#turtleseteasingeasing) | ||
- [setduration()](#turtlesetdurationduration) | ||
|
||
### Turtle methods | ||
- Turtle motion | ||
- Move and draw | ||
- [forward()](#turtleforwarddistance) \| [fd()](#turtleforwarddistance) | ||
- [backward()](#turtlebackwarddistance) \| [bk()](#turtlebackwarddistance) \| [back()](#turtlebackwarddistance) | ||
- [right()](#turtlerightangle) \| [rt()](#turtlerightangle) | ||
- [left()](#turtleleftangle) \| [lt()](#turtleleftangle) | ||
- [goto()](#turtlegotox-y) \| [setpos()](#turtlegotox-y) \| [setposition()](#turtlegotox-y) | ||
- [teleport()](#turtleteleportx-y) | ||
- [setx()](#turtlesetxx) | ||
- [sety()](#turtlesetyy) | ||
- [setheading()](#turtlesetheadingangle) \| [seth()](#turtlesetheadingangle) | ||
- [home()](#turtlehome) | ||
- [circle()](#turtlecircleradius-startangle0-endangle360) | ||
- [dot()](#turtledotsize-color) | ||
- stamp() | ||
- clearstamp() | ||
- clearstamps() | ||
- undo() | ||
- speed() | ||
- Tell Turtle’s state | ||
- [position()](#turtleposition) \| [pos()](#turtleposition) | ||
- towards() | ||
- [xcor()](#turtlexcor) | ||
- [ycor()](#turtleycor) | ||
- [heading()](#turtleheading) | ||
- distance() | ||
- Setting and measurement | ||
- degrees() | ||
- radians() | ||
- Pen control | ||
- Drawing state | ||
- [pendown()](#turtlependown) \| [pd()](#turtlependown) \| [down()](#turtlependown) | ||
- [penup()](#turtlepenup) \| [pu()](#turtlepenup) \| [up()](#turtlepenup) | ||
- [pensize()](#turtlepensizewidthnone) \| [width()](#turtlepensizewidthnone) | ||
- pen() | ||
- [isdown()](#turtleisdown) | ||
- Color control | ||
- [pencolor()](#turtlepencolorcolor) | ||
- [fillcolor()](#turtlefillcolorcolor) | ||
- [color()](#turtlecolorcolor) | ||
- Filling | ||
- [filling()](#turtlefilling) | ||
- [begin_fill()](#turtlebegin_fill) | ||
- [end_fill()](#turtleend_fill) | ||
- More drawing control | ||
- [reset()](#turtlereset) | ||
- clear() | ||
- [write()](#turtlewritearg-movefalse-alignleft-font) | ||
- Turtle state | ||
- Visibility | ||
- [showturtle()](#turtleshowturtle) \| [st()](#turtleshowturtle) | ||
- [hideturtle()](#turtlehideturtle) \| [ht()](#turtlehideturtle) | ||
- [isvisible()](#turtleisvisible) | ||
- Appearance | ||
- [shape()](#turtleshapenamenone) | ||
- resizemode() | ||
- shapesize() \| turtlesize() | ||
- shearfactor() | ||
- settiltangle() | ||
- tiltangle() | ||
- tilt() | ||
- shapetransform() | ||
- get_shapepoly() | ||
- Using events | ||
- onclick() | ||
- onrelease() | ||
- ondrag() | ||
- Special Turtle methods | ||
- begin_poly() | ||
- end_poly() | ||
- get_poly() | ||
- clone() | ||
- getturtle() \| getpen() | ||
- getscreen() | ||
- setundobuffer() | ||
- undobufferentries() | ||
### Methods of TurtleScreen/Screen | ||
- Window control | ||
- bgcolor() | ||
- bgpic() | ||
- clearscreen() | ||
- resetscreen() | ||
- screensize() | ||
- setworldcoordinates() | ||
- Animation control | ||
- delay() | ||
- tracer() | ||
- update() | ||
- Using screen events | ||
- listen() | ||
- onkey() \| onkeyrelease() | ||
- onkeypress() | ||
- onclick() \| onscreenclick() | ||
- ontimer() | ||
- mainloop() \| done() | ||
- Settings and special methods | ||
- mode() | ||
- colormode() | ||
- getcanvas() | ||
- getshapes() | ||
- register_shape() \| addshape() | ||
- turtles() | ||
- window_height() | ||
- window_width() | ||
- Input methods | ||
- textinput() | ||
- numinput() | ||
|
||
## Methods of RawTurtle/Turtle and corresponding functions | ||
|
||
Most of the examples in this section refer to a Turtle instance called `turtle`. | ||
|
||
> [!WARNING] | ||
> Functions with ~~Strikethrough~~ indicate that the function exists in [Python Turtle](https://docs.python.org/3/library/turtle.html), but is not supported by the current version of [turtle.js](https://github.com/Siyu1017/turtle.js). | ||
### Methods specific to Turtle.js | ||
|
||
#### turtle.setlinecap(_type_) | ||
- `Parameters:` **type** - `round` ( Default ), `butt` or `square` | ||
- Sets how line segment ends are drawn | ||
|
||
#### turtle.setlinejoin(_type_) | ||
- `Parameters:` **type** - `round` ( Default ), `bevel` or `miter` | ||
- Set how connected parts of line segments are connected together | ||
|
||
#### turtle.seteasing(_easing_) | ||
- `Parameters:` **easing** - `ease`, `ease-in`, `ease-out`, `ease-in-out`, `tep-start`, `tep-end`, `linear`, `easeInQuad`, `easeOutQuad`, `easeInOutQuad`, `easeInCubic`, `easeOutCubic`, `easeInOutCubic`, `easeInQuart`, `easeOutQuart`, `easeInOutQuart`, `easeInQuint`, `easeOutQuint`, `easeInOutQuint`, `easeInSine`, `easeOutSine`, `easeInOutSine`, `easeInExpo`, `easeOutExpo`, `easeInOutExpo`, `easeInCirc`, `easeOutCirc`, `easeInOutCirc` ( Default ), `easeInBack`, `easeOutBack`, `easeInOutBack`, `easeInElastic`, `easeOutElastic`, `easeInOutElastic`, `easeInBounce`, `easeOutBounce`, `easeInOutBounce` | ||
- Set the easing function of turtle motion transition | ||
|
||
#### turtle.setduration(_duration_) | ||
- `Parameters:` **duration** - a positive number | ||
- Set the duration of turtle motion transition | ||
|
||
### Turtle motion | ||
|
||
#### turtle.forward(_distance_) | ||
- `Parameters:` **distance** – a number (integer or float) | ||
- Short functions : **turtle.fd(_distance_)** | ||
- Move the turtle forward by the specified `distance`, in the direction the turtle is headed. | ||
|
||
#### turtle.backward(_distance_) | ||
- `Parameters:` **distance** – a number | ||
- Short functions : **turtle.bk(_distance_)**, **turtle.back(_distance_)** | ||
- Move the turtle backward by `distance`, opposite to the direction the turtle is headed. Do not change the turtle’s heading. | ||
|
||
#### turtle.right(_angle_) | ||
- `Parameters:` **angle** – a number (integer or float) | ||
- Short functions : **turtle.rt(_angle_)** | ||
- Turn turtle right by `angle` units. (Units are by default degrees, but can be set via the ~~degrees()~~ and ~~radians()~~ functions.) Angle orientation depends on the turtle mode, see ~~mode()~~. | ||
|
||
#### turtle.left(_angle_) | ||
- `Parameters:` **angle** – a number (integer or float) | ||
- Short functions : **turtle.lt(_angle_)** | ||
- Turn turtle left by `angle` units. (Units are by default degrees, but can be set via the ~~degrees()~~ and ~~radians()~~ functions.) Angle orientation depends on the turtle mode, see ~~mode()~~. | ||
|
||
#### turtle.goto(_x_, _y_) | ||
- `Parameters:` | ||
- **x** – a number | ||
- **y** – a number | ||
- Short functions : **turtle.setpos(_x_, _y_)**, **turtle.setposition(_x_, _y_)** | ||
- Move turtle to an absolute position. If the pen is down, draw line. Do not change the turtle’s orientation. | ||
|
||
#### turtle.teleport(_x_, _y_) | ||
- `Parameters:` | ||
- **x** – a number | ||
- **y** – a number | ||
- Move turtle to an absolute position. Unlike [goto(x, y)](#turtlegotox-y), a line will not be drawn. The turtle’s orientation does not change. | ||
|
||
#### turtle.setx(_x_) | ||
- `Parameters:` **x** – a number (integer or float) | ||
- Set the turtle’s first coordinate to `x`, leave second coordinate unchanged. | ||
|
||
#### turtle.sety(_y_) | ||
- `Parameters:` **y** – a number (integer or float) | ||
- Set the turtle’s second coordinate to `y`, leave first coordinate unchanged. | ||
|
||
#### turtle.setheading(_angle_) | ||
- `Parameters:` **angle** – a number (integer or float) | ||
- Short functions : **turtle.seth(_angle_)** | ||
- Set the orientation of the turtle to `angle`. Here are some common directions in degrees: | ||
| Directions | East | South | West | North | | ||
| :--------: | :--: | :---: | :--: | :---: | | ||
| Degrees | 0 | 90 | 180 | 270 | | ||
|
||
#### turtle.home() | ||
- Move turtle to the origin – coordinates (0,0) – and set its heading to its start-orientation (which depends on the mode, see ~~mode()~~). | ||
|
||
#### turtle.circle(_radius_, _startAngle=0_, _endAngle=360_) | ||
- `Parameters:` | ||
- **radius** – a number | ||
- **startAngle** – a number | ||
- **endAngle** – a number | ||
- Draws a circle with `radius` specified. The center of the circle is at the position of the turtle; the difference between `startAngle` and `endAngle` is an angle, which is used to determine the part of the circle to be drawn. If `startAngle` and `endAngle` are not specified, the entire circle is drawn. | ||
|
||
#### turtle.dot(_size_, _color_) | ||
- `Parameters:` | ||
- **size** – a positive number | ||
- **color** – a colorstring or a color code | ||
- Draw a circular dot with diameter `size`, using `color`. If `size` is not given, the maximum of penSize+4 and penSize*2 is used. | ||
|
||
### Tell Turtle’s state | ||
|
||
#### turtle.position() | ||
- Short functions : **pos()** | ||
- Return the turtle’s current location (x,y) (as an object). | ||
|
||
#### turtle.xcor() | ||
- Return the turtle’s x coordinate. | ||
|
||
#### turtle.ycor() | ||
- Return the turtle’s y coordinate. | ||
|
||
#### turtle.heading() | ||
- Return the turtle’s current heading (value depends on the turtle mode, see ~~mode()~~). | ||
|
||
### Pen control | ||
Drawing state | ||
|
||
#### turtle.pendown() | ||
- Short functions : **pd()**, **down()** | ||
- Pull the pen down – drawing when moving. | ||
|
||
#### turtle.penup() | ||
- Short functions : **pu()**, **up()** | ||
- Pull the pen up – no drawing when moving. | ||
|
||
#### turtle.pensize(_width=None_) | ||
- `Parameters:` **width** – a positive number | ||
- Short functions : **width()** | ||
- Set the line thickness to `width` or return it. If no argument is given, the current penSize is returned. | ||
|
||
#### turtle.isdown() | ||
- Return True if pen is down, False if it’s up. | ||
|
||
Color control | ||
|
||
#### turtle.pencolor(_color_) | ||
- `Parameters:` **color** – a colorstring or a numeric color code | ||
- Return or set the pencolor. | ||
|
||
#### turtle.fillcolor(_color_) | ||
- `Parameters:` **color** – a colorstring or a numeric color code | ||
- Return or set the fillcolor. | ||
|
||
#### turtle.color(_color_) | ||
- `Parameters:` | ||
- **color** – a colorstring or a numeric color code | ||
- Set pencolor and fillcolor to `color` or return them. If no argument is given, the current pencolor and fillcolor are returned. | ||
|
||
Filling | ||
|
||
> [!NOTE] | ||
> The fill methods ( [turtle.filling()](#turtlefilling)、[turtle.begin_fill()](#turtlebegin_fill)、[turtle.end_fill()](#turtleend_fill) ) are not yet unavailable | ||
#### turtle.filling() | ||
- Return fillstate (True if filling, False else). | ||
|
||
#### turtle.begin_fill() | ||
- To be called just before drawing a shape to be filled. | ||
|
||
#### turtle.end_fill() | ||
- Fill the shape drawn after the last call to [begin_fill()](#turtlebegin_fill). | ||
|
||
More drawing control | ||
|
||
#### turtle.reset() | ||
- Delete the turtle’s drawings from the screen, re-center the turtle and set variables to the default values. | ||
|
||
#### turtle.write(arg, move=false, align='left', font) | ||
- `Parameters:` | ||
- arg – object to be written to the TurtleScreen | ||
- ~~move~~ – True/False ( unavailable ) | ||
- align – one of the strings `left`, `center` or `right` | ||
- font – a string using the same syntax as the CSS font property | ||
|
||
### Turtle state | ||
|
||
Visibility | ||
|
||
#### turtle.showturtle() | ||
- Short functions : **st()** | ||
- Make the turtle visible. | ||
|
||
#### turtle.hideturtle() | ||
- Short functions : **ht()** | ||
- Make the turtle invisible. It’s a good idea to do this while you’re in the middle of doing some complex drawing, because hiding the turtle speeds up the drawing observably. | ||
|
||
#### turtle.isvisible() | ||
- Return `True` if the Turtle is shown, `False` if it’s hidden. | ||
|
||
Appearance | ||
|
||
#### turtle.shape(_name=None_) | ||
- `Parameters:` **name** – a string which is a valid shapename | ||
- Set turtle shape to shape with given `name` or, if name is not given, return name of current shape. Shape with `name` must exist in the TurtleScreen’s shape dictionary. Initially there are the following polygon shapes: `arrow`, `turtle`, `circle`, `square`, `triangle`, `classic`. | ||
> [!IMPORTANT] | ||
> Documentation has been moved to https://turtlejs.vercel.app/docs |
Oops, something went wrong.