turtle coffeescript websitehttp://dabbler.org/home/yourname/, then select turtle.html as a template. | |||
turtle basic motionfd 50 moves forward 50 pixelsbk 30 moves backward 30 pixels rt 90 turns right 90 degrees lt 60 turns left 60 degrees turtle drawingpen red starts drawing a red linepen null stops drawing a line dot green, 30 draws 30 pixel green dot do cs clears the screen turtle visibilitydo ht hides the turtledo st shows the turtle hidden() true if is hidden shown() true if is visible turtle absolute motionmoveto 10, 20 10 right, 20 down from topleftmoveto s moves to the location of s moveto s, 5 moves 5 pixels towards s turnto 45 turns to 45 degrees right of north turnto s turns towards the object s turnto s, 3 turns 3 degrees towards s turtle locationcenter() returns {pageX:, pageY:} from topleftdirection() returns degrees from north turtle collisionsif touches(s) ... true if turtle touches sif encloses(s) ... if surrounds s window motionmoveto window centers in window$(window).moveto(s) scrolls window center to s printing outputsee x + y |
timer eventstick 3, -> fd 10 moves 3 times per secmouse eventsmoveto lastclickmoveto lastmousemove mousemove -> run when mouse is over keyboard eventsif keydown.which is 37 ... left arrowif keydown.which is 38 ... up arrow if keydown.which is 39 ... right arrow if keydown.which is 40 ... down arrow if keydown.which is 65 ... A key if keydown.which is 87 ... W key if keydown.which is 83 ... S key if keydown.which is 68 ... D key if keydown.which is 32 ... space key if keydown.which is 16 ... shift key jQuery selectors$('#x') selects the element with <... id="x">$('img') selects all <img> elements $('.c') selects all with <... class="c"> $('a b') selects all <b> inside <a>...</a> text inside elementss.text() returns the text inside ss.text 'hello' sets text inside s |