def right_triangle(height,width,direction): # takes direction to mean which side of the triangle will have the hypoteneuse # using pythagorean theorem: hyp is the sqrt of height^2 + width^2 hypotenuse=sqrt((height**2)+(width**2)) # using radians for sin functions turtle.radians() if direction == 'right': turtle.forward(width) #90 degrees in radians turtle.setheading(1.57079633) turtle.forward(height) #pi is 180 degrees in radians, arcsin of side over hypotenuse equals angle turtle.setheading(pi+asin(height/hypotenuse)) turtle.forward(hypotenuse) if direction =='left': turtle.setheading(pi) turtle.forward(width) #90 degrees in radians turtle.setheading(1.57079633) turtle.forward(height) #arcsin of side over hypotenuse equals angle, subtracted turtle.setheading(-asin(height/hypotenuse)) turtle.forward(hypotenuse)
def tGraph(word='F', theta=0, alpha=0, step=10, x0=0, y0=0): #Run, turtle, RUN!!! #tr.clear() tr.radians() tr.speed(0) tr.pu() tr.setx(x0) tr.sety(y0) tr.seth(alpha) tr.pd() st = [] for c in word: if c == 'F': tr.fd(step) if c == 'b': tr.pu() tr.bk(step) tr.pd() if c == '[': st.append({'x': tr.xcor(), 'y': tr.ycor(), 'ang': tr.heading()}) if c == ']': pos = st.pop() tr.pu() tr.setx(pos['x']) tr.sety(pos['y']) tr.seth(pos['ang']) tr.pd() if c == '+': tr.lt(theta) if c == '-': tr.rt(theta)
def draw(self, limit = None): if limit == None: limit = Vector(*turtle.screensize()).magnitude() turtle.goto(self.start) turtle.dot(4) turtle.pendown() turtle.radians() turtle.setheading(self.direc.to_theta()) turtle.fd(limit)
def drawLine(p1, p2): # Compute the distance between p1 and p2 d = distance(p1[0], p1[1], p2[0], p2[1]) if p1[0] <= p2[0]: # p2 is on the right of p1 angle = math.asin((p2[1] - p1[1]) / d) else: angle = -math.asin((p2[1] - p1[1]) / d) + math.pi turtle.radians() turtle.setheading(angle) turtle.penup() turtle.goto(p1[0], p1[1]) turtle.pendown() turtle.forward(d) turtle.setheading(0)
def drawLine(p1, p2): # Compute the distance between p1 and p2 d = distance(p1[0], p1[1], p2[0], p2[1]) if (p1[0] <= p2[0]): # p2 is on the right of p1 angle = math.asin((p2[1] - p1[1]) / d) else: angle = -math.asin((p2[1] - p1[1]) / d) + math.pi turtle.radians() turtle.setheading(angle) turtle.penup() turtle.goto(p1[0], p1[1]) turtle.pendown() turtle.forward(d) turtle.setheading(0)
def to_turtle(self, lines=None, filter_fxn=None, scale=1): lines = lines or self.lines import turtle from tqdm import tqdm turtle.speed(0) turtle.radians() turtle.home() turtle.clear() if filter_fxn is not None: lines = it.takewhile(filter_fxn, lines) for move in tqdm(list(lines)): if 'E' in move: turtle.pencolor('black') else: turtle.pencolor('yellow') turtle.setheading(math.atan2(move['Y'], move['X'])) turtle.forward(scale * (move['Y']**2 + move['X']**2)**0.5) input()
import turtle import math n = int(input("How many sides should the shape have?\n")) radius = float(input("What should the radius be?\n")) turtle.radians() turtle.pu() turtle.goto(0, radius) turtle.right(math.pi / n) turtle.pd() for i in range(n): turtle.forward(math.sin(math.pi / n) * radius * 2) turtle.right(math.pi / n * 2)
def __init__(self, n=1): turtle.radians() self.n = n self.count = -1
def hpy_d7a8d793d799d790d7a0d799d79d(): """שנה את יחידות הזוית לרדיאנים""" turtle.radians()
def _setheading(self, heading): self.__ensure_init_hook() turtle.radians() turtle.setheading(heading)
elif road[0] == 2: turtle.right(math.pi / 2 + road[1]) turtle.forward(road[2]) turtle.left(math.pi / 2 + road[1]) else: turtle.right(road[1]) turtle.forward(road[2]) turtle.left( road[1]) def equation(xequation, yequation, step): i = 0 while True: tmpx = xequation.replace('@', str (i)) tmpy = yequation.replace('@', str (i)) x, y = eval (tmpx), eval (tmpy) i += step tmpx, tmpy = xequation.replace('@', str (i)), yequation.replace('@', str (i)) newx, newy = eval (tmpx), eval (tmpy) completestep(buildroad([x,y], [newx, newy])) turtle.radians() equation("100 * math.cos(@ * math.pi / 180)","100 * math.sin(@ * math.pi / 180)", 1)
if self.len > 4: colour(count) line(x, y, 0, 0, 0, self.len, self.ang + (pi / 4)) count += 1 branch(self.len, self.ang + (pi / 4), count) count -= 1 tur.pu() tur.goto(x, y) colour(count) line(x, y, 0, 0, 0, self.len, self.ang - (pi / 4)) count += 1 branch(self.len, self.ang - (pi / 4), count) count -= 1 pi = math.pi tur.radians() tur.speed(0) tur.pensize(2) tur.ht() tur.bgcolor("black") while True: tur.color("white") tur.pu() tur.goto(0, -400) tur.pd() tur.goto(0, -200) branch(300, 0, 0) time.sleep(10) tur.clear()