forked from hacketyhack/hacketyhack
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathturtle-graphics
99 lines (69 loc) · 2.08 KB
/
turtle-graphics
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
Turtle Graphics support (http://en.wikipedia.org/wiki/Turtle_graphics)
Turtle code can be run from the HacketyHack editor, two modes are available:
1. interactive mode, allowing step by step execution
Turtle.start do
# turtle code here
end
2. drawing mode that execute the whole code at once
Turtle.draw do
# turtle code here
end
== Available Commands ==
penup
after this command gets called the pen is up and nothing is drawn
pendown
after this command the pen is dawn and lines are drawn as the turtle moves
pendown?
returns true if the pen is down, (default is true)
pensize x
set the width of the line drawn by the turtle to x
pencolor c
set the color of the line drawn by the turtle to c, use the shoes color system
background c
set the background color to c, use the shoes color system
forward x
moves the turtle forward by x pixels
when no options are given a default argument of 50 pixels is used
backward x
moves the turtle forward by x pixels, equivalent to forward -x
when no options are given a default argument of 50 pixels is used
turnleft a
turns the turtle heading a degrees to the left, default heading is 0 degrees
when no options are given a default argument of 90 degrees is used
turnright a
turns the turtle heading a degrees to the right, equivalent to turnleft -a
when no options are given a default argument of 90 degrees is used
setheading a
sets the current heading to a
getheading
retuns the current heading in degrees
setx x
moves the turtle horizontally to (current_y, x)
doesn't draw anything
sety y
moves the turtle vertically to (y, current_x)
doesn't draw anything
goto x, y
moves the turtle to (x, y)
doesn't draw anything
getposition
retuns [x, y] (as an array)
clear
removes all content (but does not change the turtle attributes)
reset
removes all content and resets all attributes (including turtle position)
== Example ==
Turtle.start do
background blue
pensize 2
pencolor yellow
30.times do
goto rand(width), rand(height)
setheading rand(360)
len = 5 + rand(30)
5.times do
forward len
turnleft 180-360/10
end
end
end