Pencil Code Reference Sheet
Pencil Code Reference Sheet
net
Movement Drawing
fd 50 forward 50 pixels pen blue draw in blue
bk 10 backward 10 pixels pen red, 9 9 pixel wide red pen
rt 90 turn right 90 degrees pen null use no color
lt 120 turn left 120 degrees pen off pause use of the pen
rt 90, 50 do a 90° arc of radius 50 pen on use the pen again
home() go to the page center label 'X' draw the letter X
slide x, y slide right x and forward y dot green draw a green dot
moveto x, y go to x, y relative to home dot gold, 30 30 pixel gold circle
turnto 45 set direction to 45 (NE) pen path trace an invisible path
turnto obj point toward obj fill cyan fill traced path in cyan
speed 30 do 30 moves per second cg() clear graphics
Appearance Properties
ht() hide the turtle turtle name of the main turtle
st() show the turtle getxy() [x, y] position relative to home
scale 8 do everything 8x bigger direction() direction of turtle
wear yellow wear a yellow shell hidden() if the turtle is hidden
fadeOut() fade and hide the turtle touches(obj) if the turtle touches obj
remove() totally remove the turtle inside(window) if enclosed in the window
Output Objects
see obj debug the value of obj t = new Turtle make a new turtle
write 'hello' writes a line of HTML p = new Piano 88 make a new 88-key piano
p = write 'hm' saves an HTML element g = $('img') select all <img> as a set
p.html 'done' changes old text
append 'ok' text without a new line Other Functions
button 'go', adds a button with tick 5, -> fd 10 go 5 times per second
-> fd 10 an action click -> fd 10 go when clicked
read (n) -> adds a text input with random [3,5,7] return 3, 5, or 7
write n*n an action random 100 random [0..99]
t = table 3,5 adds a 3x5 <table> play 'ceg' play musical notes
t.cell(0, 0). selects the first cell of the $(window) the visible window
text 'aloha' table and sets its text $('p').eq(0) the first <p> element
ct() clear text $('#zed') the element with id="zed"
Colors
white gainsboro silver darkgray gray dimgray black