import turtle bob = turtle.Turtle() for i in range(1,5): bob.fd(100) bob.lt(90) turtle.mainloop ()
import turtle import math DEF Circle (T, R & lt, A): # incoming interfaces arc, the arc in the most complete computing arc (t, r, a) DEF ARC (T, R & lt, A): # calculating the length of the edge, while setting the number of edges length = 2 * R & lt Math.PI * * ABS (A) / 360 n- = int (length /. 4) +. 3 step_length length = / n- step_angle = a / n polygon(t, step_length, n) DEF Polygon (T, length, n-): # Draw graphics for I in Range (n-): t.fd(length) t.lt(360/n) bob = turtle.Turtle() radius = 50 angle = 360 circle(bob, radius, angle) turtle.mainloop ()
import turtle def draw_spiral(t, n, length=3, a=0.1, b=0.0002): #Draws an Archimedian spiral starting at the origin theta = 0.0 for i in range(n): t.fd(length) dtheta = 1 / (a + b * theta) t.lt(dtheta) theta += dtheta #create the world and bob bob = turtle.Turtle() draw_spiral(bob, n=1000) turtle.mainloop ()
import turtle def draw_diamond(turt): for i in range(1,3): turt.forward(100) turt.right(45) turt.forward(100) turt.right(135) def draw_art(): window = turtle.Screen () # Windows window.bgcolor ( " Black " ) # the background color brad = turtle.Turtle () # create a "turtle" Object brad.shape ( " Turtle " ) # set brush picture turtle brad .color ( " red " ) # set brush color is red brad.speed ( " fAST " ) # drawing speed is fast for I in Range (. 1, 37 [): # call function diamond 36, i.e., 36 petals Videos draw_diamond (brad) brad.right(10) brad.right ( 90) # Draw branches brad.forward (1000 ) window.exitonclick() draw_art()
import math import turtle def polyline(t, n, length, angle): #Draws n line segments for i in range(n): t.fd(length) t.lt(angle) def arc(t, r, angle): #Draws an arc with given radius and angle arc_length = 2 * math.pi * r * abs(angle) / 360 n = int(arc_length / 4) + 3 step_length = arc_length / n step_angle = float(angle) / n t.lt(step_angle/2) polyline(t, n, step_length, step_angle) t.rt(step_angle/2) def petal(t, r, angle): #Draws a petal using two arcs. for i in range(2): arc(t, r, angle) t.lt(180 - angle) def flower(t, n, r, angle): #Draws a flower with n petals for i in range(n): petal(t, r, angle) t.lt(360.0/n) def move(t, length): #Move turtle(t) forwoard (length) units without leaving a trail # t.pu() t.fd(length) t.pd() bob = turtle.Turtle() #draw a sequence of three flowers move(bob, -100) flower(bob, 7, 60.0, 60.0) move(bob, 100) flower(bob, 10, 40.0, 80.0) move(bob, 100) flower(bob, 20, 140.0, 20.0) bob.hideturtle() turtle.mainloop ()
import turtle t = turtle.Pen() turtle.bgcolor ( " Black " ) # Sides = the eval (STR (INPUT ( "Enter the number of sides to be drawn, enter 2-6Dev number!"))) Sides. 6 = Colors = [ " Red " , " Yellow " , " Green " , " Blue " , " Orange " , " Purple " ] for X in Range (360 ): t.pencolor (Colors [X % Sides]) # random color t.speed ( " FAST " ) t.forward (X *. 3 / X + Sides) # hexagonal successively increasing length t.left (360 / + Sides. 1) # rotational angle sequentially changes t.width (Sides * X / 180 [ ) t.left(91) Print ( " End " )
import turtle from datetime import * # Lift the brush, some distance down the forward movement DEF Skip (the STEP): turtle.penup() turtle.forward(step) turtle.pendown() DEF mkHand (name, length): # registered Turtle shape, build hands Turtle turtle.reset () Skip ( -length is 0.1 * ) # start recording vertices of the polygon. Turtle current position of the first vertex of the polygon. turtle.begin_poly () turtle.forward (length * 1.1 ) # stop recording the vertices of the polygon. The current position of the turtle is the last vertex of the polygon. Connected to the first vertex. turtle.end_poly () # last recorded polygon. = handForm turtle.get_poly () turtle.register_shape(name, handForm) DEF the Init (): , Ltd. Free Join secHand, minHand, hurHand, Printer # reset Turtle pointing north turtle.mode ( " logo " ) # establish three hands Turtle and initialize mkHand ( " secHand " , 135 ) mkHand("minHand", 125) mkHand("hurHand", 90) secHand = turtle.Turtle() secHand.shape("secHand") minHand = turtle.Turtle() minHand.shape("minHand") hurHand = turtle.Turtle() hurHand.shape("hurHand") for hand in secHand, minHand, hurHand: hand.shapesize(1, 1, 3) hand.speed(0) # Create output text Turtle Printer = turtle.Turtle () # hidden brush turtle shape printer.hideturtle () printer.penup () DEF SetupClock (the RADIUS): # establish a table frame turtle.reset () turtle.pensize(7) for i in range(60): Skip(radius) if i % 5 == 0: turtle.forward(20) Skip(-radius - 20) Skip(radius + 20) if i == 0: turtle.write(int(12), align="center", font=("Courier", 14, "bold")) elif i == 30: Skip(25) turtle.write(int(i/5), align="center", font=("Courier", 14, "bold")) Skip(-25) elif (i == 25 or i == 35): Skip(20) turtle.write(int(i/5), align="center", font=("Courier", 14, "bold")) Skip(-20) else: turtle.write(int(i/5), align="center", font=("Courier", 14, "bold")) Skip(-radius - 20) else: turtle.dot(5) Skip(-radius) turtle.right(6) def Week(t): Week = [ " Monday " , " Tuesday " , " Wednesday " , " Thursday " , " Friday " , " Saturday " , " Sunday " ] return Week [t.weekday ()] def Date(t): y = t.year m = t.month D = t.day return " % S% d% d month on Day " % (Y, m, D) DEF the Tick (): # dynamic drawing display hands T = datetime.today () second = t.second + t.microsecond * 0.000001 minute = t.minute + second / 60.0 hour = t.hour + minute / 60.0 secHand.setheading(6 * second) minHand.setheading(6 * minute) hurHand.setheading(30 * hour) turtle.tracer(False) printer.forward(65) printer.write(Week(t), align="center", font=("Courier", 14, "bold")) printer.back(130) printer.write(Date(t), align="center", font=("Courier", 14, "bold")) printer.home() turtle.tracer(True) # After 100ms continue to call tick turtle.ontimer (Tick, 100 ) DEF main (): # Open / Close turtle animation, and drawings updated delay settings. turtle.tracer (False) Init() SetupClock(160) turtle.tracer(True) Tick() turtle.mainloop () if __name__ == "__main__": main()