Pen control



Python Turtle Graphics Quick GuideTo use turtle graphics:import turtleTo create a turtle:t = turtle.Turtle()To create a window for the turtle:win = turtle.Screen()To wait for the user to click the mouse before closing the window:win.exitonclick()turtle.done()t.bye()Pen controlt.up(), t.down()t.isup(), t.isdown()Raise/lower the pen.Return True/False if the pen is up or down.Color Controlt.color(r,g,b)Sets the color to the given r, g, b values.t.color(p, f)Sets the pen color to the given name p (a string like "blue") and the fill color to the color f (also a string)t.pensize(n)Set the pen's width to n pixelst.begin_fill()t.end_fill()Must use before and after drawing to get fill to work.Turtle Visibilityt.hideturtle()t.showturtle()t.isvisible()Hide turtle.Show turtle.Return true/false.t.xcor(), t.ycor()Return x/y coordinate of the turtle t.t.setx(x)t.sety(y)t.setheading(degrees)Set the x and y coordinates of the turtle tSet the direction of the turtle t.t.home()Move the turtle to the 0,0 location.t.speed(n)Set speed to a number from 1 (slow) to 10 (fast).t.bye() Close the turtle drawing window.Turtle movementt.right(degrees)t.rt(degrees)Turn right the given number of degreest.left(degrees) t.lt(degrees)Turn left the given number of degrees.t.forward(distance) t.fd(distance)Move forward the given distance.t.backward(distance) t.bk(distance)Move backward the given distance.t.setheading(angle)Point the turtle in the given direction. 0=east, 90=north, 180=west, 270=southt.goto(x,y)Move the turtle to the given location.t.circle(radius)Draw a circle with the given radius.Screen methodst.screen.bgcolor("white")t.screen.bgpic("gif file")t.screen.clear()t.screen.reset()t.screen.screensize()t.screen.setworldcoordinates()Set background color.Set background picture.Clear screen.Reset screen.Set screen size.Set "world" coordinatesMore turtle graphics commandsTurtle motioncircle()dot()stamp()clearstamp()clearstamps()undo()Tell Turtle’s statex, y = t.position()// returns x and ytowards()x = t.xcor()y = t.ycor()direction = heading()distance()Setting and measurementt.degrees()// use degreest.radians()// use radiansPen controlDrawing statepen()isdown()//returns true/falseColor controlcolor()pencolor()fillcolor()Fillingfilling()begin_fill()end_fill()More drawing controlreset()clear()write()Turtle stateAppearanceshape("turtle")// sets to one of: resizemode()shapesize() | turtlesize()shearfactor()settiltangle()tiltangle()tilt()shapetransform()get_shapepoly()Using eventsonclick()onrelease()ondrag()Special Turtle methodsbegin_poly()end_poly()get_poly()clone()getturtle() | getpen()getscreen()setundobuffer()undobufferentries()24.1.2.2. Methods of TurtleScreen/ScreenWindow controlAnimation controldelay()tracer()update()Using screen eventslisten()onkey() | onkeyrelease()onkeypress()onclick() | onscreenclick()ontimer()mainloop() | done() ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download