; MousedQuadrants.jlogo - Identify Mouse Click Location (Lesson 12 - Predicates) ;---------------------- ;Symbolic Constants ;------------------ ; SETPENCOLOR inputs to black output 0 end to grey output 15 end ; SETHEADING inputs to north output 0 end to east output 90 end to south output 180 end to west output 270 end ; Label stuff (SETLABELHEIGHT and SETLABELFONT inputs) to quadrantLabelHeight output 24 end to sansSerifBold output 5 end ; Axes Stuff ; ---------- ; draw a tick mark at the turtle's current location ; the tick mark is drawn perpendicular to its heading ; input :len is length the tick mark extends outward to tickMark :len right 90 forward :len back :len left 180 forward :len back :len right 90 end ; draw a line segment at the turtle's current location ; the line segment runs along the turtle's current heading ; tick marks are drawn along the line every 20 turtle steps ; input :segLen is the length of the line segment ; input :ticLen is the distance a tick mark extends outward to drawLineSegment :segLen :ticLen setpencolor black setpensize 2 pendown forward :segLen back :segLen setpensize 1 setpencolor grey repeat quotient :segLen 20 [penup forward 20 pendown tickMark :ticLen] end ; draw north, east, south, west line segments ; with little tick marks, to form X and Y axes to drawAxes setheading north drawLineSegment (quotient canvasheight 2) 5 penup home setheading east drawLineSegment (quotient canvaswidth 2) 5 penup home setheading south drawLineSegment (quotient canvasheight 2) 5 penup home setheading west drawLineSegment (quotient canvaswidth 2) 5 end ; draw labels in the four quadrants I, II, III, IV to labelQuadrants setlabelheight quadrantLabelHeight setlabelfont sansSerifBold setpencolor grey penup setxy 50 80 label [Quadrant I] setxy -270 80 label [Quadrant II] setxy -270 -100 label [Quadrant III] setxy 50 -100 label [Quadrant IV] end ; User Interface Stuff ; -------------------- ; when user clicks the mouse in the graphics canvas, ; print which quadrant in the Cartesian coordinate ; system the click occured in to mouseClicked ... end ; MAIN ; ---- to main hideturtle home clean drawAxes labelQuadrants end main