Draw ellipse on top of turtle picture RRS feed

  • Question

  • Basically used the turtle to draw a polygon.  (i.e. Christmas tree) After its complete the user is supposed to click on an area in the graphics window and have it draw an ellipse at the location clicked(i.e. ornament) .  This all works perfectly fine. Only problem is that the ellipse is drawn behind the polygon. 

    also tried to use shape instead of draw but you cannot set the location of the shape to the XY of the mouse click

    Shouldn't the order of the drawing determine the layer of the graphic?

    • Edited by McManbus Sunday, November 27, 2011 11:33 PM
    Sunday, November 27, 2011 11:33 PM


  • For some reason I am not sure why, but the turtle draws shape object lines that lie on top of the background layer.  So you do need shape ellipses to draw on top of the turtle path.  Each shape will appear on top of the last - it is also possible to alter the layer (Z indez) of shapes using extensions, but in your case drawing the ornaments after the turtle has drawn its shape will work ok.

    The GraphicsWindow.Draw.. and GraphicsWindow.Fill... commands draw fixed objects on the background layer below any movable shapes created using the Shapes or Controls methods.

    In order to position a shape ellipse you need to use Shapes.Move, this positions the named shape (returned when the shape is created) setting the top left corner of the shape bounding box, therefore the centre is at (left+width/2,top+height/2).

    Here is a simple example positioning shapes (Circles of radius 20) on mouse clicks.


    GraphicsWindow.MouseDown = OnMouseDown
    Sub OnMouseDown
      xM = GraphicsWindow.MouseX
      yM = GraphicsWindow.MouseY
      GraphicsWindow.PenWidth = 0
      GraphicsWindow.BrushColor = "Red"
      shape = Shapes.AddEllipse(20,20)
    Monday, November 28, 2011 6:31 PM