These are the values given for particular keys:
|
If you are uncertain about the value returned by a key, you can type:
pr readchar. The interpreter will then wait for you to type on a key before giving you the corresponding
value.
to vintage read [What is your age?] "age make "age :age if :age<18 [pr [you are a minor]] if or :age=18 :age>18 [pr [you are an adult]] if :age>99 [pr [Respect is due!!]] end to rallye if key? [ make "car readchar if :car=-37 [lt 90] if :car=-39 [rt 90] if :car=-38 [fd 10] if :car=-40 [bk 10] if :car=27 [stop] ] rallye end # You can control the turtle with the keyboard, and stop with Esc |
The button 1 is the left button , the button 2 is the next on the right ...
to example # when the mouse moves, go to the next position if readmouse=0 [setpos mousepos] example end |
In this second procedure, it’s the same but you must click with the left button of the mouse if you want the turtle to move.
to example2 if readmouse=1 [setpos mousepos] example2 end |
In this third example, we create two pink buttons. If we left-click on the left button, we draw a square with a side of 40. if we left-click on the right button, we draw a little circle. Last, if we right-click on the right button, it stops the program.
to button #create a pink rectangular button (height 50 - width 100) repeat 2[fd 50 rt 90 fd 100 rt 90] rt 45 pu fd 10 pd setpc [255 153 153] fill bk 10 lt 45 pd setpc 0 end to lance cs button pu setpos [150 0] pd button pu setpos [30 20] pd label "Square pu setpos [180 20] pd label "Circle pu setpos [0 -100] pd mouse end to mouse # we put the value of readmouse in the variable ev make "ev readmouse # we put the first coordinate of the mouse in variable x make "x item 1 mousepos # we put the second coordinate of the mouse in variable y make "y item 2 mousepos # When we click on the left button if :ev=1 & :x>0 & :x<100 & :y>0 & :y<50 [square] # When we click on the right button if :x>150 & :x<250 & :y>0 & :y<50 [ if :ev=1 [circle] if :ev=3 [stop] ] mouse end to circle repeat 90 [fd 1 lt 4] lt 90 pu fd 40 rt 90 pd end to square repeat 4 [fd 40 rt 90] rt 90 fd 40 lt 90 end |
guiposition "b [20 100] |
If you don’t specify a location for the component, it will be placed by default on the upper left corner of the
drawing area.
guiremove "b |
# the turtle forwards of 100 if we click on the button "b guiaction "b [fd 100 ] # For the combo menu, each item has its own action guiaction "m [[print "item1] [print "item2] [print "item3]] |
guidraw "b |