def main(): windows = turtle.Screen() windows.bgcolor('pink') turtle.shape('square') turtle.shapesize(stretch_wid=2, stretch_len=4, outline=6) bran = turtle.Turtle() bran.shape('turtle') bran.color('yellow', 'red') bran.speed(1) for i in range(1, 20): bran.forward(10) bran.left(20) bran.forward(20) turtle.reset() turtle.shape("circle") turtle.shapesize(2, 2) turtle.tilt(30) turtle.fd(50) turtle.tilt(90) turtle.fd(50) turtle.mainloop() def turn(x, y): left(180) onclick(turn) # Now clicking into the turtle w>>> def turn(x, y):
def roll_dice(): turtle.shape('square') turtle.shapesize(5,5) turtle.speed(1) for i in range(2): turtle.tilt(45) sleep(.3)
def screenLeftClick(x, y): global r, g, b r = random.random() g = random.random() b = random.random() turtle.color((r, g, b)) tSize = random.randrange(1, 10) turtle.shapesize(tSize) tTilt = random.randrange(10, 350) turtle.tilt(tTilt) turtle.stamp() turtle.goto(x, y)
screen = turtle.Screen() screen.colormode(255) turtle.speed(9) # Générateur de dessins for _ in range(25): turtle.pencolor(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) turtle.left(random.randint(0, 360)) turtle.forward(random.randint(0, 25)) turtle.right(random.randint(0, 360)) turtle.pencolor(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) turtle.forward(random.randint(0, 100)) turtle.pensize(random.randint(0, 6)) turtle.tilt(random.randint(0, 360)) turtle.right(random.randint(0, 360)) turtle.pencolor(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) turtle.circle(random.randint(0, 100), random.randint(0, 360)) turtle.pencolor(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) turtle.forward(random.randint(0, 100)) turtle.pensize(random.randint(0, 6)) turtle.goto(random.randint(-200, 200), random.randint(-200, 200)) turtle.done() ts = turtle.getscreen() #ts.getcanvas().postscript(file=str(uuid.uuid4())) ts.getcanvas().postscript(file="file.eps")
import turtle turtle = turtle.Turtle() # turtle. tilt(angle) # Parameters: angle – a number # Rotate the turtleshape by angle from its current tilt-angle, but do not change the turtle’s heading (direction of movement). turtle.speed(1) turtle.shape("circle") turtle.shapesize(5, 2) turtle.tilt(30) turtle.fd(50) turtle.tilt(30) turtle.fd(50)
def drawmonsterdetails(mirror, scale, generikmon, startoftoes): detailsbit = generikmon['detail0'] turtle.penup() turtle.goto(startoftoes) turtle.pendown() ### draw the toes webs and claws numofToes = generikmon['numofToes'] fullwidth = turtle.xcor() tailwidth = fullwidth * generikmon['tailbodyratio'] #talibodywidthratio, pawswidth = fullwidth - tailwidth frontpawwidth = pawswidth * generikmon['frontbackratio'] #fronttobackratio toewidth = frontpawwidth / (numofToes) for i in range(numofToes): turtle.setheading(270) turtle.forward(scale * generikmon['toelengthD']) #toelengthD turtle.right(mirror * 90) turtle.forward( mirror * toewidth * 0.1) #mirror required here since xcord is negative on second hlaf # start claw layout calcs xclawstart = turtle.xcor() xclawtip = xclawstart - toewidth * 0.4 xclawend = xclawtip - toewidth * 0.4 yclawstart = turtle.ycor() yclawtip = yclawstart - scale * detailsbit['clawlength'] yclawend = yclawstart #draw claw (it's already at the start) turtle.goto(xclawtip, yclawtip) turtle.goto(xclawend, yclawend) turtle.forward( mirror * toewidth * 0.1) #mirror required here since xcord is negative on second hlaf turtle.right(mirror * 90) turtle.forward(scale * generikmon['toelengthD']) #toelegnth - going back up #into the rear toes. # all lengths scaled by generikmon[16] = frontotbackratio toewidth = (pawswidth - frontpawwidth) / numofToes #redefines toe width for backpaws. for i in range(numofToes): turtle.setheading(270) turtle.forward(scale * generikmon['frontbackratio'] * generikmon['toelengthD']) #toelengthD turtle.right(mirror * 90) turtle.forward( mirror * toewidth * 0.1) #mirror required here since xcord is negative on second hlaf # start claw layout calcs xclawstart = turtle.xcor() xclawtip = xclawstart - toewidth * 0.4 xclawend = xclawtip - toewidth * 0.4 yclawstart = turtle.ycor() yclawtip = yclawstart - scale * detailsbit['clawlength'] * generikmon[ 'frontbackratio'] yclawend = yclawstart #draw claw (it's already at the start) turtle.goto(xclawtip, yclawtip) turtle.goto(xclawend, yclawend) turtle.forward( mirror * toewidth * 0.1) #mirror required here since xcord is negative on second hlaf turtle.right(mirror * 90) turtle.forward(scale * generikmon['frontbackratio'] * generikmon['toelengthD']) #toelegnth - going back up ### draw the ears turtle.penup() turtle.home() turtle.setheading(90) turtle.right(mirror * 90) #requires turtle to be facing upwards turtle.forward(scale * generikmon['crownD']) #crownD follow crown line exactly turtle.left(mirror * generikmon['ear1A']) #ear1A turtle.right(mirror * 90) #turns back into shape. turtle.forward(scale * (generikmon['ear2D'] * 0.1 + 0.01)) startoftheear = turtle.pos() turtle.pendown() # start actually drawing turtle.setheading(90) turtle.right(mirror * 90) turtle.left(mirror * generikmon['ear1A']) #ear1A turtle.forward(scale * generikmon['ear2D'] * 0.8) #ear2D turtle.right(mirror * generikmon['ear3A']) #ear3A turtle.forward(scale * generikmon['ear2D'] * 0.8) #ear2D turtle.right(mirror * generikmon['ear4A']) #ear4A turtle.forward(scale * generikmon['ear6D'] * 0.7) #ear6D turtle.right(mirror * generikmon['ear5A']) #ear5A turtle.forward(scale * generikmon['ear6D'] * 0.7) #ear5D turtle.goto(startoftheear) #finishs the ear off. ### draw the eyes (stamped over ears if needed) turtle.penup() turtle.home() # print(turtle.xcor(),turtle.ycor()) turtle.setheading(90) turtle.right(mirror * 90) #requires turtle to be facing upwards turtle.forward(scale * generikmon['crownD'] * detailsbit['eyeratio']) #crownD, #eyeratio turtle.setheading(270) turtle.forward(scale * generikmon['cheekD'] * (1 - detailsbit['eyeratio'])) #cheekD, #eyeratio turtle.shape("circle") turtle.resizemode("user") turtle.shapesize(detailsbit['eyesize'], detailsbit['eyesize'] * detailsbit['eyeratio'] * 4, 1) # print(turtle.shapesize()) turtle.tilt(mirror * detailsbit['frownA']) turtle.stamp() turtle.tilt(-1 * mirror * detailsbit['frownA'] ) #takes the tilt off the turtle to avoid later confusion turtle.shapesize(1, 1, 1) #takes off the eye size, i think. ### draw the nose turtle.penup() turtle.home() turtle.setheading(270) turtle.forward(scale * generikmon['cheekD']) #cheekD turtle.shape("triangle") turtle.shapesize(detailsbit['nosesize'], detailsbit['nosesize'], 1) turtle.stamp() #and from the nose, the mouth turtle.pendown() turtle.forward(scale * generikmon['shoulderD'] * detailsbit['nosesize'] + detailsbit['nosesize']) #shouldD below the nose turtle.left(mirror * 90) turtle.forward(scale * generikmon['crownD'] * detailsbit['mouthsize']) #crownD #width of mouth turtle.penup() turtle.home() return ()
from turtle import shape, shapesize, tilt, fillcolor, pencolor, left, right, forward, stamp, penup, goto, circle, exitonclick penup() # no drawing goto(2, 14) # move to new position shape("circle") # drawing yellow shape circle shapesize(7, 7) fillcolor("yellow") pencolor("darkRed") stamp() penup() # no drawing goto(0, -100) # move to new position shape("circle") # drawing red ellipse shapesize(5, 1, 2) fillcolor("red") pencolor("darkRed") # for loop for ellipse for x in range(72): forward(10) left(5) tilt(10) stamp() exitonclick()
def drawmonsterdetails(mirror, scale, generikmon,startoftoes): detailsbit = generikmon['detail0'] turtle.penup() turtle.goto(startoftoes) turtle.pendown() ### draw the toes webs and claws numofToes = generikmon['numofToes'] fullwidth= turtle.xcor() tailwidth= fullwidth*generikmon['tailbodyratio'] #talibodywidthratio, pawswidth= fullwidth-tailwidth frontpawwidth=pawswidth*generikmon['frontbackratio'] #fronttobackratio toewidth=frontpawwidth/(numofToes) for i in range(numofToes): turtle.setheading(270) turtle.forward(scale*generikmon['toelengthD'])#toelengthD turtle.right(mirror*90) turtle.forward(mirror*toewidth*0.1) #mirror required here since xcord is negative on second hlaf # start claw layout calcs xclawstart = turtle.xcor() xclawtip = xclawstart - toewidth*0.4 xclawend = xclawtip - toewidth*0.4 yclawstart = turtle.ycor() yclawtip = yclawstart-scale*detailsbit['clawlength'] yclawend = yclawstart #draw claw (it's already at the start) turtle.goto(xclawtip, yclawtip) turtle.goto(xclawend, yclawend) turtle.forward(mirror*toewidth*0.1) #mirror required here since xcord is negative on second hlaf turtle.right(mirror*90) turtle.forward(scale*generikmon['toelengthD']) #toelegnth - going back up #into the rear toes. # all lengths scaled by generikmon[16] = frontotbackratio toewidth=(pawswidth-frontpawwidth)/numofToes #redefines toe width for backpaws. for i in range(numofToes): turtle.setheading(270) turtle.forward(scale*generikmon['frontbackratio']*generikmon['toelengthD'])#toelengthD turtle.right(mirror*90) turtle.forward(mirror*toewidth*0.1) #mirror required here since xcord is negative on second hlaf # start claw layout calcs xclawstart = turtle.xcor() xclawtip = xclawstart - toewidth*0.4 xclawend = xclawtip - toewidth*0.4 yclawstart = turtle.ycor() yclawtip = yclawstart-scale*detailsbit['clawlength']*generikmon['frontbackratio'] yclawend = yclawstart #draw claw (it's already at the start) turtle.goto(xclawtip, yclawtip) turtle.goto(xclawend, yclawend) turtle.forward(mirror*toewidth*0.1) #mirror required here since xcord is negative on second hlaf turtle.right(mirror*90) turtle.forward(scale*generikmon['frontbackratio']*generikmon['toelengthD']) #toelegnth - going back up ### draw the ears turtle.penup() turtle.home() turtle.setheading(90) turtle.right(mirror*90) #requires turtle to be facing upwards turtle.forward(scale*generikmon['crownD']) #crownD follow crown line exactly turtle.left(mirror*generikmon['ear1A']) #ear1A turtle.right(mirror*90) #turns back into shape. turtle.forward(scale*(generikmon['ear2D']*0.1+0.01)) startoftheear = turtle.pos() turtle.pendown() # start actually drawing turtle.setheading(90) turtle.right(mirror*90) turtle.left(mirror*generikmon['ear1A']) #ear1A turtle.forward(scale*generikmon['ear2D']*0.8) #ear2D turtle.right(mirror*generikmon['ear3A']) #ear3A turtle.forward(scale*generikmon['ear2D']*0.8) #ear2D turtle.right(mirror*generikmon['ear4A']) #ear4A turtle.forward(scale*generikmon['ear6D']*0.7) #ear6D turtle.right(mirror*generikmon['ear5A']) #ear5A turtle.forward(scale*generikmon['ear6D']*0.7) #ear5D turtle.goto(startoftheear) #finishs the ear off. ### draw the eyes (stamped over ears if needed) turtle.penup() turtle.home() # print(turtle.xcor(),turtle.ycor()) turtle.setheading(90) turtle.right(mirror*90) #requires turtle to be facing upwards turtle.forward(scale*generikmon['crownD']*detailsbit['eyeratio']) #crownD, #eyeratio turtle.setheading(270) turtle.forward(scale*generikmon['cheekD']*(1-detailsbit['eyeratio'])) #cheekD, #eyeratio turtle.shape("circle") turtle.resizemode("user") turtle.shapesize(detailsbit['eyesize'],detailsbit['eyesize']*detailsbit['eyeratio']*4,1) # print(turtle.shapesize()) turtle.tilt(mirror*detailsbit['frownA']) turtle.stamp() turtle.tilt(-1*mirror*detailsbit['frownA']) #takes the tilt off the turtle to avoid later confusion turtle.shapesize(1,1,1) #takes off the eye size, i think. ### draw the nose turtle.penup() turtle.home() turtle.setheading(270) turtle.forward(scale*generikmon['cheekD']) #cheekD turtle.shape("triangle") turtle.shapesize(detailsbit['nosesize'],detailsbit['nosesize'],1) turtle.stamp() #and from the nose, the mouth turtle.pendown() turtle.forward(scale*generikmon['shoulderD']*detailsbit['nosesize']+detailsbit['nosesize']) #shouldD below the nose turtle.left(mirror*90) turtle.forward(scale*generikmon['crownD']*detailsbit['mouthsize']) #crownD #width of mouth turtle.penup() turtle.home() return()
def shape(): turtle.shape("circle") turtle.shapesize(5, 2) turtle.tilt(30) turtle.fd(50) turtle.tilt(30) turtle.fd(50) turtle.tilt(30) turtle.left(90) turtle.tilt(30) turtle.fd(50) turtle.tilt(30) turtle.fd(50) turtle.tilt(30) turtle.left(90) turtle.tilt(30) turtle.fd(50) turtle.tilt(30) turtle.fd(50) turtle.tilt(30) turtle.fd(50) turtle.tilt(30) turtle.fd(50) turtle.tilt(30) turtle.fd(50) turtle.left(90) turtle.tilt(30) turtle.fd(50) turtle.tilt(30) turtle.fd(50)
import turtle turtle.bgcolor("blue") turtle.pensize(10) turtle.color("green", "yellow") turtle.begin_fill() turtle.speed(1) turtle.shape("turtle") turtle.fd(50) turtle.circle(70) turtle.shapesize(5, 1) turtle.settiltangle(90) turtle.fd(100) turtle.end_fill() turtle.shape("square") turtle.shaptransform(4, -1, 0, 2) turtle.get_shapepoly() turtle.end_fill() turtle.reset() turtle.resizemode("auto") turtle.speed(6) turtle.shape("triangle") turtle.tilt(90) turtle.shaptransform() turtle.end_fill()