def create_snake(self): for num in pos: turtle = t("square") turtle.pu() turtle.color('white') turtle.goto(x=num, y=0) self.segments.append(turtle)
def circle(turtle, r): turtle = t() p = 3.14159265758939 n = 360 length = (2 * p * r) / n for i in range(n): turtle.fd(length) turtle.rt(360 / n)
def create_car(self): chance = r.randint(1, 6) if chance == 6: car = t("square") car.pu() car.shapesize(stretch_wid=1, stretch_len=2) car.color(r.choice(COLORS)) y = r.randint(-250, 240) car.goto(300, y) self.all_cars.append(car)
def flower(turtle, n, length): turtle = t() angle_1 = 50 for i in range(n): turtle.fd(length) turtle.lt(angle_1) turtle.fd(length) turtle.lt(180 - angle_1) turtle.fd(length) turtle.lt(angle_1) turtle.fd(length) turtle.rt(angle_1) slp(10) turtle.mainloop()
#This will a mini etch and sketch project #Importing the classes needed for this from turtle import Turtle as t from turtle import Screen as s #Creating objects for the turtle on the screen and the screen itself tim = t() screen = s() def move_forward(): tim.forward(10) def move_back(): tim.backward(10) def turn_left(): new_heading = tim.heading() + 10 tim.setheading(new_heading) def turn_right(): new_heading = tim.heading() - 10 tim.setheading(new_heading) def clear(): tim.clear()
def add_segment(self, pos): turtle = t("square") turtle.pu() turtle.color('white') turtle.goto(pos) self.segments.append(turtle)
from turtle import Turtle as t, Screen import random as r # Return a random integer N such that a <= N <= b. Alias for randrange(a, b+1). # from turtle import Turtle as t, Screen wn = Screen() wn.bgcolor('black') wn.screensize(2000, 2000) point = 0 pt = t() draw = t() # -280, 250 부터 def drawwall(): draw.pencolor("white") draw.penup() draw.goto(-280, 250) draw.pendown() draw.goto(280, 250) draw.goto(280, -250) draw.goto(-280, -250) draw.goto(-280, 250) draw.speed(2) def L(): # 재시작하는 함수 global playing
def square(turtle, length): turtle = t() for i in range(4): turtle.fd(length) turtle.rt(90)
def polyline(turtle, n, length, ang): turtle = t() for i in range(n): turtle.fd(length) turtle.lt(ang)
def polygon(turtle, length, n): turtle = t() for i in range(n): turtle.fd(length) turtle.rt(360 / n)