Example #1
0
def __drawMouth():
    __startFunction()

    #draw the lower lips of the mouth
    turtle.color("black", "black")
    turtle.begin_poly()
    turtle.begin_fill()
    turtle.pensize(10)
    turtle.circle(300, 60)
    turtle.end_fill()
    turtle.end_poly()
    lowerlips = turtle.get_poly()
    screen.addshape("LowerLips", lowerlips)

    #draw the upper lips of the mouth
    turtle.color("cyan", "cyan")
    turtle.pensize(10)
    turtle.begin_poly()
    turtle.begin_fill()
    turtle.circle(160, 60)
    turtle.end_fill()
    turtle.end_poly()
    upperlips = turtle.get_poly()

    screen.addshape("UpperLips", upperlips)
    __drawEndFunction()
Example #2
0
def drawfus():  # spaceship!
    global basesize
    B = basesize
    turtle.begin_poly()
    turtle.fd(B)
    turtle.rt(90)
    turtle.fd(B)
    turtle.rt(90)
    turtle.fd(B)
    turtle.rt(90)
    turtle.fd(B)
    turtle.fd(2.25 * B)
    turtle.rt(90)
    turtle.fd(B)
    turtle.rt(90)
    turtle.fd(B)
    turtle.rt(90)
    turtle.fd(B)
    turtle.fd(3 * B)
    turtle.rt(-90)
    turtle.fd(1.25 * B)

    turtle.end_poly()
    poly = turtle.get_poly()  # c'est le poly... yveslemaire.poly
    turtle.register_shape('fusee', poly)
def draw_rectangle(x,y,width,height):
    """
    Draws a rectangle with the upper left hand corner starting at point (x,y).
    The said rectangle has the dimensions width x height.
    :param x:
    :param y:
    :param width:
    :param height:
    :return: None
    """
    turtle.penup()
    turtle.setx(x)
    turtle.sety(y)
    turtle.pendown()
    turtle.setheading(0)  # Set heading in x+ direction
    turtle.begin_fill()
    turtle.begin_poly()
    turtle.fd(width)
    turtle.right(90)
    turtle.fd(height)
    turtle.right(90)
    turtle.fd(width)
    turtle.right(90)
    turtle.fd(height)
    turtle.end_poly()
    turtle.end_fill()
    return None
Example #4
0
    def __init__ (self, size, color):
        Turtle.__init__(self)

        turtle.home()
        turtle.begin_poly()
        i = 6
        turtle.pu()
Example #5
0
def drawfus(): # spaceship!
	global basesize
	B = basesize
	turtle.begin_poly()
	turtle.fd(B)
	turtle.rt(90)
	turtle.fd(B)
	turtle.rt(90)
	turtle.fd(B)
	turtle.rt(90)
	turtle.fd(B)
	turtle.fd(2.25 * B)
	turtle.rt(90)
	turtle.fd(B)
	turtle.rt(90)
	turtle.fd(B)
	turtle.rt(90)
	turtle.fd(B)
	turtle.fd(3 * B)
	turtle.rt(-90)
	turtle.fd(1.25 * B)
	
	turtle.end_poly()
	poly = turtle.get_poly() # c'est le poly... yveslemaire.poly
	turtle.register_shape('fusee', poly)
Example #6
0
def make_circle(point, radius):
    turtle.seth(90)
    turtle.setpos(point[0] + radius, point[1])
    turtle.begin_poly()
    turtle.circle(radius)
    turtle.end_poly()
    return turtle.get_poly()
Example #7
0
def makeshape():
    B = 25  # base unit size
    turtle.begin_poly()
    turtle.fd(B)  # roof
    turtle.rt(45)
    turtle.fd(B * 3 / 4)  # windshield
    turtle.lt(45)
    turtle.fd(B)  # hood
    turtle.rt(90)
    turtle.fd(B * 3 / 4)  # front
    turtle.rt(90)
    turtle.fd(B * 1 / 7)
    turtle.lt(90)
    turtle.circle(-B / 2, 180)  # front tire
    turtle.lt(90)
    turtle.fd(B)
    turtle.lt(90)
    turtle.circle(-B / 2, 180)  # back tire
    turtle.lt(90)
    turtle.fd(B * 1 / 7)
    turtle.rt(90)
    turtle.fd(B * 5 / 6)  # back
    turtle.end_poly()
    poly = turtle.get_poly()
    turtle.register_shape('car', poly)
Example #8
0
def makegunshape(alpha):
	turtle.home()			# return to known location & orientation
	turtle.lt(90)			# shapes use initial upward orientation

	# apparent gun length due to alpha
	alpharad = math.radians(alpha)
	appgunlen = math.sin(alpharad) * GUNLEN

	thetarad = math.atan2(GUNLEN / 6, appgunlen)
	theta = math.degrees(thetarad)
	hyp = GUNLEN/6 / math.sin(thetarad)

	turtle.begin_poly()
	turtle.lt(180)
	turtle.fd(GUNLEN/6)
	turtle.rt(90 + theta)
	turtle.fd(hyp)
	turtle.rt(180 - 2*theta)
	turtle.fd(hyp)
	turtle.rt(90 + theta)
	turtle.fd(GUNLEN/6)
	turtle.end_poly()
	poly = turtle.get_poly()
	name = 'gun%d' % alpha
	turtle.register_shape(name, poly)
	return name
Example #9
0
def makeshape():
	B = 25				# base unit size
	turtle.begin_poly()
	turtle.fd(B)			# roof
	turtle.rt(45)
	turtle.fd(B * 3/4)		# windshield
	turtle.lt(45)
	turtle.fd(B)			# hood
	turtle.rt(90)
	turtle.fd(B * 3/4)		# front
	turtle.rt(90)
	turtle.fd(B * 1/7)
	turtle.lt(90)
	turtle.circle(-B/2, 180)	# front tire
	turtle.lt(90)
	turtle.fd(B)
	turtle.lt(90)
	turtle.circle(-B/2, 180)	# back tire
	turtle.lt(90)
	turtle.fd(B * 1/7)
	turtle.rt(90)
	turtle.fd(B * 5/6)		# back
	turtle.end_poly()
	poly = turtle.get_poly()
	turtle.register_shape('car', poly)
Example #10
0
    def __init__(self, size, color, speed):
        Turtle.__init__(self)
        self.size = size

        turtle.begin_poly()
        turtle.fillcolor(color)
        turtle.speed(speed)
        turtle.penup()
        turtle.backward(50)
        turtle.fd(50)
        turtle.right(50)
        turtle.fd(50)
        turtle.rt(50)
        turtle.fd(50)
        turtle.rt(50)
        turtle.fd(50)
        turtle.rt(50)
        turtle.fd(50)
        turtle.rt(50)
        turtle.fd(50)
        turtle.rt(50)
        turtle.fd(50)
        turtle.pendown()
        turtle.end_poly()
        H = turtle.get_poly()
        turtle.register_shape("myFavouriteHexagon", H)
        turtle.shape("myFavouriteHexagon")
Example #11
0
def draw_berry_dos(top_size, bottom_size):
    straw_tri = {}

    draw_here = turtle.pos() # start pos
    face_this_way = turtle.heading()

    turtle.goto(draw_here) # "start"
    straw_tri.update({"start": draw_here})
    turtle.setheading(face_this_way)

    turtle.color("red")
    turtle.begin_poly() # create polygon
    turtle.begin_fill()
    turtle.circle(top_size, 180)

    point_1 = turtle.pos() # "first point"
    straw_tri.update({"first point" : point_1})
    turtle.lt(30)
    turtle.forward(70)

    point_2 = turtle.pos() # "second point"
    straw_tri.update({"second point" : point_2})

    turtle.circle(bottom_size, 100)


    point_3 = turtle.pos() # "third point"
    straw_tri.update({"third point" : point_3})
    turtle.rt(30)
    turtle.goto(draw_here) # return to start

    turtle.end_fill()
    turtle.end_poly() # close polygon
    my_strawberry = turtle.get_poly()
    return(straw_tri)
Example #12
0
def makeshape() :
        B = 15
        turtle.begin_poly()
        turtle.fd(B)
        turtle.rt(45)
        turtle.fd(sqrt(2)*B)
        turtle.rt(45)
        turtle.fd(4 * B)
        turtle.rt(135)
        turtle.fd(sqrt(8)*B)
        turtle.rt(45)
        turtle.fd(3*B)
        turtle.lt(90)
        turtle.fd(B)
        turtle.lt(45)
        turtle.fd(sqrt(2)*B)
        turtle.lt(45)
        turtle.fd(4 * B)
        turtle.lt(135)
        turtle.fd(sqrt(8)*B)

        turtle.end_poly()
        poly = turtle.get_poly()
        turtle.register_shape('rocket', poly)

        turtle.begin_poly()
        turtle.circle(100, 360)
        turtle.end_poly()
        poly = turtle.get_poly()
        turtle.register_shape('sun', poly)
Example #13
0
def make_circle(point, radius):
    """draw a circle centered on point"""
    turtle.seth(90)
    turtle.setpos(point[0] + radius, point[1])
    turtle.begin_poly()
    turtle.circle(radius)
    turtle.end_poly()
    return turtle.get_poly()
Example #14
0
def createHand(name, length):
    turtle.reset()
    move(-length * 0.01)
    turtle.begin_poly()
    turtle.forward(length * 1.01)
    turtle.end_poly()
    hand = turtle.get_poly()
    turtle.register_shape(name, hand)
Example #15
0
def getHand(name: str):
    d = {"second": 4, "minute": 5, "hour": 7, "point": 3}
    turtle.goto(d[name], 0)
    turtle.begin_poly()
    turtle.circle(d[name])
    turtle.end_poly()
    turtle.register_shape(name, turtle.get_poly())
    turtle.clear()
Example #16
0
def mkHand(name, length):
    turtle.reset()
    Move(-length * 0.1)
    turtle.begin_poly()
    turtle.forward(length * 1.1)
    turtle.end_poly()
    handForm = turtle.get_poly()
    turtle.register_shape(name, handForm)
Example #17
0
def mkHand(name, length):  #注册turtle形状,建立表针turtle
    turtle.reset()
    Skip(-length * 0.1)
    turtle.begin_poly()
    turtle.forward(length * 1.1)
    turtle.end_poly()
    handForm = turtle.get_poly()
    turtle.register_shape(name, handForm)
Example #18
0
def reg_bullet():
    turtle.home()
    turtle.setpos(0, -5)
    turtle.begin_poly()
    turtle.circle(5, None, None)
    turtle.end_poly()
    circ = turtle.get_poly()
    turtle.register_shape('bullet', circ)
Example #19
0
def getCircle(n, radius):
    turtle.begin_poly()
    vertice = Vec2D(radius, 0)
    for i in range(n):
        vertice.rotate(i * 360 / n)
        turtle.goto(vertice)
    turtle.end_poly()
    return turtle.get_poly()
Example #20
0
def shape_a_turtle():
    turtle.penup()
    turtle.begin_poly()
    star_onTurtle(5)
    turtle.end_poly()
    turtle.pendown()
    star = turtle.get_poly()
    turtle.register_shape('star', star)
Example #21
0
def indicator(name, length):
    goto(tl, -length * 0.1)
    tl.begin_poly()
    tl.fd(length * 1.1)
    tl.end_poly()
    sh = tl.get_poly()
    tl.register_shape(name, sh)
    tl.reset()
Example #22
0
def makepop(fn, *args):
    turtle.home()
    turtle.begin_poly()
    fn(*args)
    turtle.end_poly()
    name = 'pop%d' % len(POPS)
    turtle.register_shape(name, turtle.get_poly())
    POPS.append(name)
Example #23
0
def maketree(name, scale, L):
	turtle.home()
	turtle.begin_poly()
	stack = [ (0, 0) ]
	maketree_r(stack, L, scale)
	turtle.end_poly()
	poly = turtle.get_poly()
	turtle.register_shape(name, poly)
Example #24
0
def reg_bullet():
    turtle.home()
    turtle.setpos(0, -5)
    turtle.begin_poly()
    turtle.circle(5, None, None)
    turtle.end_poly()
    circ = turtle.get_poly()
    turtle.register_shape('bullet', circ)
Example #25
0
def makepop(fn, *args):
	turtle.home()
	turtle.begin_poly()
	fn(*args)
	turtle.end_poly()
	name = 'pop%d' % len(POPS)
	turtle.register_shape(name, turtle.get_poly())
	POPS.append(name)
Example #26
0
def makeshape(name, scale, L):
    turtle.home()
    turtle.begin_poly()
    stack = [(0, 0)]
    makeshape_r(stack, L, scale)
    turtle.end_poly()
    poly = turtle.get_poly()
    turtle.register_shape(name, poly)
Example #27
0
def makeground():
    for i in range(GROUNDLEN - 3, GROUNDLEN + 9):
        turtle.home()
        turtle.begin_poly()
        turtle.fd(i)
        turtle.end_poly()
        name = 'gr%d' % i
        turtle.register_shape(name, turtle.get_poly())
        GROUND.append(name)
Example #28
0
def radar_chart(data):
    # Some "typical" test data
    #print "Hello"
    length=len(data) # stores the length of the data provided
    turtle.home()   # Sets the turtle to position (0,0)
    division=360/length #what angle is needed for invidual lines
    poslist=[] #list to store current position
    valpos=[]   #list to store position
    j=0
    turtle.hideturtle() #hides the arrow
        #Draw the foundation of the Radar Chart
    for i in range(length): # Loop until all the given data is plotted
        turtle.forward(200) #move turtle forward
        turtle.dot(10,"black") # Draw the black dot at the end of each data
        nowpos=turtle.pos() # store the current position
        poslist.append(nowpos) #append the current position to list
        #turtle.hideturtle()
        turtle.setpos(nowpos[0]+10,nowpos[1]) #get the turtle to new postion to write data
        turtle.write(data[i], True, align="center") # Write the label of data
        turtle.setpos(nowpos[0],nowpos[1]) #return to the previous position
        turtle.back(200) #return home
        turtle.left(division) # rotate by the specific angle
    turtle.home()    # return to turtle home
    #Connect the ends points of the radar chart
    for i in poslist: #
        turtle.setpos(i[0],i[1])
        #turtle.setpos(i[j],i[j+1])
        #turtle.forward(100)
        #turtle.home()
        #turtle.degree(division)
        #turtle.heading()
        #turtle.forward(100)
    turtle.setpos(poslist[0][0],poslist[0][1])
    turtle.home()
    #Draw green Dots 
    for i in range(length):
        incval=data[i]
        turtle.forward(incval*2)
        turtle.dot(15,"green")
        nowpos=turtle.pos()
        valpos.append(nowpos) 
        turtle.back(incval*2)
        turtle.left(division)
    turtle.begin_poly()
    turtle.fill(True)
    #Fill the green Dots
    for i in valpos:
        turtle.setpos(int(i[0]),int(i[1]))
    turtle.setpos(valpos[0][0],valpos[0][1])
    turtle.end_poly()
    p = turtle.get_poly()
    turtle.register_shape("jpt", p)
    turtle.color("Green", "Green")
    turtle.begin_fill()
    #turtle.p(80)
    turtle.end_fill()
    turtle.fill(False)
Example #29
0
def reg_sun():
    global sundiam
    turtle.home()
    turtle.setpos(0, -sundiam / 2)
    turtle.begin_poly()
    turtle.circle(sundiam / 2, None, None)
    turtle.end_poly()
    circ = turtle.get_poly()
    turtle.register_shape('sun', circ)
Example #30
0
def mkHand(name, length):
    # 注册Turtle形状,建立表针Turtle
    turtle.reset()
    Skip(-length * 0.1)#将笔挪到-0.1×length处
    turtle.begin_poly()#开始画线
    turtle.forward(length * 1.1)#向前画1.1×length的长度
    turtle.end_poly()#结束画线
    handForm = turtle.get_poly()#将所画形状get到
    turtle.register_shape(name, handForm)#将该形状注册为“name”
Example #31
0
def reg_sun():
    global sundiam
    turtle.home()
    turtle.setpos(0, -sundiam / 2)
    turtle.begin_poly()
    turtle.circle(sundiam/2, None, None)
    turtle.end_poly()
    circ = turtle.get_poly()
    turtle.register_shape('sun', circ)
Example #32
0
def rect():
    turtle.begin_poly()
    while len(turtle.get_poly()) <= 4:
        if len(turtle.get_poly()) == 1 or len(turtle.get_poly()) == 3:
            turtle.forward(100)
        else:
            turtle.forward(200)
        turtle.left(90)
    turtle.done()
Example #33
0
def makeground():
	for i in range(GROUNDLEN-3, GROUNDLEN+9):
		turtle.home()
		turtle.begin_poly()
		turtle.fd(i)
		turtle.end_poly()
		name = 'gr%d' % i
		turtle.register_shape(name, turtle.get_poly())
		GROUND.append(name)
Example #34
0
def zeichne_vollen_zeiger(name, laenge, spitze):
    # Diese Funktion zeichnet einen gefüllten Zeiger
    trt.reset()
    jump(-laenge * 0.15)
    trt.begin_poly()
    zeiger(laenge, spitze)
    trt.end_poly()
    hand_form = trt.get_poly()
    trt.register_shape(name, hand_form)
Example #35
0
def makePoint(pointName, len):  # 钟的指针,时针、分针、秒针
    t.penup()
    t.home()
    t.begin_poly()
    t.back(0.1 * len)
    t.forward(len * 1.1)
    t.end_poly()
    poly = t.get_poly()
    t.register_shape(pointName, poly)  # 注册为一个shape
Example #36
0
def createTriangleShape(coords):
    turtle.penup()
    turtle.begin_poly()
    turtle.setposition(coords[0])
    turtle.setposition(coords[1])
    turtle.setposition(coords[2])
    turtle.setposition(coords[0])

    tri_shape = turtle.get_poly()
    turtle.register_shape('my_triangle', tri_shape)
Example #37
0
def shapeHand(name, length):
    turtle.reset()
    #turtle.penup()
    #turtle.forward(-length * 0.01)
    #turtle.pendown()
    turtle.begin_poly()
    turtle.forward(length)
    turtle.end_poly()
    hand = turtle.get_poly()
    turtle.register_shape(name, hand)
Example #38
0
def koch_snowflake(turtle, steps, length):
    turtle.begin_poly()

    for _ in range(3):
        koch_curve(turtle, steps, length)
        turtle.right(120)

    turtle.end_poly()

    return turtle.get_poly()
Example #39
0
 def __make_hands(self,name,length):
     """
     Draws the hand of clock.
     """
     turtle.reset()
     self.__skip(-length * 0.1)
     turtle.begin_poly() #The beginning of recoding the polygon vertices.
     turtle.forward(length * 1.1)
     turtle.end_poly() #The beginning of recoding the polygon vertices, and connects the last vertice with the first vertice.
     hand_form = turtle.get_poly()
     turtle.register_shape(name, hand_form)
Example #40
0
def mkHand(name, length):
    #注册turtle形状,建立表针turtle
    turtle.reset()
    Skip(-length*0.1)
    #开始记录多边形的顶点,当前的位置是多边形的第一个顶点
    turtle.begin_poly()
    turtle.forward(length*1.1)
    #停止记录多边形的顶点,当前位置是多边形的最后一个顶点,将于第一个顶点相连
    turtle.end_poly()
    #返回最后记录的多边形
    handForm = turtle.get_poly()
    turtle.register_shape(name, handForm)
Example #41
0
def mkHand(name, length):  
    # 注册Turtle形状,建立表针TuConsolartle  
    turtle.reset()  
    Skip(-length * 0.1)  
    # 开始记录多边形的顶点。当前的乌龟位置是多边形的第一个顶点。  
    turtle.begin_poly()  
    turtle.forward(length * 1.1)  
    # 停止记录多边形的顶点。当前的乌龟位置是多边形的最后一个顶点。将与第一个顶点相连。  
    turtle.end_poly()  
    # 返回最后记录的多边形。  
    handForm = turtle.get_poly()  
    turtle.register_shape(name, handForm)  
Example #42
0
def maketweendata(kf1, kf2, steps, scale):
	global _kfsegments
	assert len(kf1) == len(kf2)	# must be able to match segments up

	L = []
	for i in range(len(kf1)):
		[ (x1, y1), (x2, y2) ] = normalize(kf1, i, scale)

		# Euclidean distance gives segment length
		seglen = ( (x2 - x1) ** 2 + (y2 - y1) ** 2 ) ** 0.5

		# make line segment into shape
		turtle.home()
		turtle.begin_poly()
		turtle.fd(seglen)
		turtle.end_poly()
		name = 'kf%d' % _kfsegments
		_kfsegments += 1
		turtle.register_shape(name, turtle.get_poly())

		# and compute initial heading
		heading = getheading(x1, y1, x2, y2)

		# extract out corresponding segment from key frame 2
		[ (x1b, y1b), (x2b, y2b) ] = normalize(kf2, i, scale)

		# use it to compute deltas for x, y, and heading; this is
		# where we need to be after N steps
		dx = x1b - x1
		dy = y1b - y1
		dh = getheading(x1b, y1b, x2b, y2b) - heading
		# weird special case that cropped up between BKF3 and BKF4 of
		# bird flap, where the computed delta in the heading takes the
		# long way around, as it were - adjust it to compensate
		if dh > 180:
			dh = dh - 360
		elif dh < -180:
			dh = dh + 360
		dx /= steps
		dy /= steps
		dh /= steps

		# place everything in a container
		c = Tween()
		c.name = name
		c.x, c.y = x1, y1
		c.heading = heading
		c.dx, c.dy = dx, dy
		c.dh = dh
		L.append(c)

	return L
Example #43
0
def build_poly():
    turtle.begin_poly()
    turtle.forward(100)
    turtle.left(90)

    turtle.forward(100)
    turtle.left(90)

    turtle.forward(100)
    turtle.left(90)

    turtle.forward(100)
    turtle.left(90)
    turtle.end_poly()
Example #44
0
def eraser(x, y, a, b): # 
    turtle.up()
    gotoxy(x, y)
    turtle.seth(0)
    turtle.begin_fill()
    turtle.begin_poly()
    n = 0
    while n<=1:
        turtle.fd(a)
        turtle.right(90)
        turtle.fd(b)
        turtle.right(90)
        n += 1
    turtle.end_poly()
    turtle.end_fill()
Example #45
0
def makepoly(B, R, L):
	turtle.home()			# return to known location & orientation

	turtle.begin_poly()
	turtle.lt(90)
	turtle.fd(B / 2)
	for i in range(3):
		turtle.rt(90)
		turtle.fd(B)
	turtle.rt(90)
	turtle.fd(B / 2)
	turtle.lt(90)
	turtle.fd(L)
	turtle.circle(R)
	turtle.end_poly()
	return turtle.get_poly()
Example #46
0
def eraser(x, y, xs, ys): # 
    turtle.up()
    gotoxy(x, y)
    turtle.seth(0)
    turtle.color("blue", "white")
    turtle.begin_fill()
    turtle.begin_poly()
    n = 0
    while n<=1:
        turtle.fd(a)
        turtle.right(90)
        turtle.fd(b)
        turtle.right(90)
        n += 1
    turtle.end_poly()
    turtle.end_fill()
Example #47
0
def makeshipshape():
	turtle.home()			# return to known location & orientation

	# cockpit is a trapezoid - figure out angles and length of side
	adj = (S / 3 - S / 8) / 2
	thetarad = math.atan2(S, adj)
	theta = math.degrees(thetarad)
	hyp = S / math.sin(thetarad)

	turtle.begin_poly()
	turtle.bk(S * 1/2 / 2)		# origin = center of wing - move to back
	turtle.lt(90)			# left wing
	turtle.fd(S / 2)
	turtle.rt(30)			# left rear turret
	turtle.bk(S / 8)
	turtle.fd(S / 8)
	turtle.rt(60)
	turtle.fd(S * 1/2)
	turtle.rt(60)			# left front turret
	turtle.fd(S / 8)
	turtle.bk(S / 8)
	turtle.rt(30)
	turtle.fd(S / 3)		# join of wing and left side of cockpit
	turtle.lt(theta)		# left side of cockpit
	turtle.fd(hyp)
	turtle.rt(theta)
	turtle.fd(S / 8)		# front of cockpit
	turtle.rt(theta)		# right side of cockpit
	turtle.fd(hyp)
	turtle.lt(theta)		# join of right side of cockpit and wing
	turtle.fd(S / 3)		# right wing
	turtle.rt(30)			# right front turret
	turtle.bk(S / 8)
	turtle.fd(S / 8)
	turtle.rt(60)
	turtle.fd(S * 1/2)
	turtle.rt(60)			# right rear turret
	turtle.fd(S / 8)
	turtle.bk(S / 8)
	turtle.rt(30)
	turtle.fd(S / 2)
	turtle.end_poly()

	poly = turtle.get_poly()
	turtle.register_shape('spaceship', poly)
Example #48
0
def makeshape():
    """
    Define the shapes of the various elements of the game.

    :return: None
    """
    B = 15

    s1 = turtle.Shape("compound")
    landerS = ((B, B-5), (B-5, B), (-B+5, B), (-B, B-5), (-B, -B+5), (-B+5, -B), (B-5, -B), (B, -B+5))
    leg1 = ((B-5, -B), (B, -B), (B+3, -B-10), (B, -B-10), (B+6, -B-10), (B+3, -B-10))
    leg2 = ((-B+5, -B), (-B, -B), (-B-3, -B-10), (-B, -B-10), (-B-6, -B-10), (-B-3, -B-10))
    s1.addcomponent(landerS, "white", 'black')
    s1.addcomponent(leg1, "white", "black")
    s1.addcomponent(leg2, "white", "black")
    turtle.register_shape('lander', s1)
    s2 = turtle.Shape("compound")
    s2.addcomponent(landerS, "white", "black")
    s2.addcomponent(leg1, "white", "black")
    s2.addcomponent(leg2, "white", "black")
    motor = ((0, -B), (B/3, -B*2), (0, -B*2 -2), (-B/3, -B*2))
    s2.addcomponent(motor, "red", "red")
    turtle.register_shape('lander with motor', s2)

    turtle.begin_poly()
    turtle.rt(90)
    turtle.fd(60)
    turtle.lt(90)
    turtle.circle(60)
    turtle.end_poly()
    poly = turtle.get_poly()
    turtle.register_shape('sun', poly)

    s = turtle.Shape("compound")
    groundS = ((-320, 120), (-280, 41), (-240, 27), (-200, 59), (-160, 25), (-120, 43), (-80, 56), (-40, 20), (0, 20),
               (40, 20), (80, 44), (120, 28), (160, 66), (200, 29), (240, 64), (280, 34), (320, 140), (320, 0),
               (-320, 0))
    s.addcomponent(groundS, "black", "black")
    turtle.register_shape('ground', s)
Example #49
0
def maketileshape():
	turtle.home()			# return to known location & orientation

	turtle.begin_poly()		# square
	for i in range(4):
		turtle.fd(B)
		turtle.rt(90)
	turtle.end_poly()
	poly1 = turtle.get_poly()

	# don't put this inside begin_poly...end_poly or it draws an extra line
	turtle.goto( (B / 2, -B * 2/3 - B/6) )

	turtle.begin_poly()		# circle, inside square
	turtle.circle(B / 3)
	turtle.end_poly()
	poly2 = turtle.get_poly()

	cs = turtle.Shape('compound')
	# args are poly, fill color, line color
	cs.addcomponent(poly1, 'gray', 'black')
	cs.addcomponent(poly2, 'blue', 'gray42')

	turtle.register_shape('tile', cs)
Example #50
0
def build_poly2():
    turtle.begin_poly()
    turtle.right(90)
    turtle.forward(200)
    turtle.end_poly()
Example #51
0
# Stamp a copy of the turtle shape onto the canvas
#   at the current turtle position. Return a stamp_id
#   for that stamp, which can be used to delete it by
#   calling clearstamp(stamp_id).
turtle.stamp()

turtle.position()
"""

for i in range(8):
    turtle.stamp()
    turtle.fd(30)


turtle.home()
turtle.begin_poly()
turtle.fd(100)
turtle.lt(20)
turtle.fd(30)
turtle.lt(60)
turtle.fd(50)
turtle.end_poly()
turtle.get_poly()



turtle.done()


Example #52
0
def makeshape():
    """
    Define the shapes of the various elements of the game.

    :return: None
    """
    B = 15

    s1 = turtle.Shape("compound")
    landerS = ((B, B-5), (B-5, B), (-B+5, B), (-B, B-5), (-B, -B+5), (-B+5, -B), (B-5, -B), (B, -B+5))
    leg1 = ((B-5, -B), (B, -B), (B+3, -B-10), (B, -B-10), (B+6, -B-10), (B+3, -B-10))
    leg2 = ((-B+5, -B), (-B, -B), (-B-3, -B-10), (-B, -B-10), (-B-6, -B-10), (-B-3, -B-10))
    s1.addcomponent(landerS, "white", 'black')
    s1.addcomponent(leg1, "white", "black")
    s1.addcomponent(leg2, "white", "black")
    turtle.register_shape('lander', s1)
    s2 = turtle.Shape("compound")
    s2.addcomponent(landerS, "white", "black")
    s2.addcomponent(leg1, "white", "black")
    s2.addcomponent(leg2, "white", "black")
    motor = ((0, -B), (B/3, -B*2), (0, -B*2 -2), (-B/3, -B*2))
    s2.addcomponent(motor, "red", "red")
    turtle.register_shape('lander with motor', s2)

    turtle.begin_poly()
    turtle.rt(90)
    turtle.fd(60)
    turtle.lt(90)
    turtle.circle(60)
    turtle.end_poly()
    poly = turtle.get_poly()
    turtle.register_shape('sun', poly)

    s = turtle.Shape("compound")
    s.addcomponent(groundS, "black", "black")
    turtle.register_shape('ground', s)
    global nGrounds, breaking_points, groundS1
    total_length = -groundS[0][0] - groundS[-1][0]
    nGrounds = total_length // WIDTH
    breaking_points = [round((total_length/nGrounds)*i)-(WIDTH//2) for i in range(nGrounds+1)]
    groundS1 = groundS[:]
    for i in range(1):
        locals()['sG'+str(i)] = turtle.Shape("compound")
        if i == 0:
            locals()['sG'+str(i)].addcomponent(groundS, "black", "black")
            turtle.register_shape('ground', locals()['sG'+str(i)])
        else:
            local_groundS = globals()['groundS'+str(i)][:-2]
            breaking_point_bounds = [(j, j+1) for j in range(len(local_groundS)-1)
                                     if local_groundS[j][0] <= breaking_points[i] <= local_groundS[j+1][0]][0]
            j0, j1 = breaking_point_bounds
            delta = abs(local_groundS[j0][1] - local_groundS[j1][1]) / (local_groundS[j1][0] - local_groundS[j0][0])
            if local_groundS[j0][1] > local_groundS[j1][1]:
                breaking_point_y = delta * local_groundS[j1][1] * (local_groundS[j1][0] - breaking_points[i]) \
                                   + local_groundS[j1][1]
            else:
                breaking_point_y = delta * local_groundS[j0][1] * (breaking_points[i] - local_groundS[j0][0]) \
                                   + local_groundS[j0][1]
            globals()['groundS'+str(i+1)] = tuple([(breaking_points[i] - tWIDTH, int(breaking_point_y))] \
                                            + [(p[0] - tWIDTH, p[1]) for p in local_groundS[j1:]] \
                                            + [(p[0] + tWIDTH, p[1]) for p in local_groundS[:j1]] \
                                            + [(WIDTH, int(breaking_point_y)), (-tWIDTH, int(breaking_point_y))])
            locals()['sG'+str(i)].addcomponent(globals()['groundS'+str(i+1)], "black", "black")
            turtle.register_shape('ground'+str(i), locals()['sG'+str(i)])
Example #53
0
def makenothing():
	# there's much ado about it
	turtle.begin_poly()
	turtle.end_poly()
	turtle.register_shape('none', turtle.get_poly())
Example #54
0
def makeshape():
    """
    Define the shapes of the various elements of the game.

    :return: None
    """
    # Lander shapes
    B = 15
    s1 = turtle.Shape("compound")
    landerS = ((B, B-5), (B-5, B), (-B+5, B), (-B, B-5), (-B, -B+5), (-B+5, -B), (B-5, -B), (B, -B+5))
    leg1 = ((B-5, -B), (B, -B), (B+3, -B-10), (B, -B-10), (B+6, -B-10), (B+3, -B-10))
    leg2 = ((-B+5, -B), (-B, -B), (-B-3, -B-10), (-B, -B-10), (-B-6, -B-10), (-B-3, -B-10))
    s1.addcomponent(landerS, "white", 'black')
    s1.addcomponent(leg1, "white", "black")
    s1.addcomponent(leg2, "white", "black")
    turtle.register_shape('lander', s1)
    s2 = turtle.Shape("compound")
    s2.addcomponent(landerS, "white", "black")
    s2.addcomponent(leg1, "white", "black")
    s2.addcomponent(leg2, "white", "black")
    motor = ((0, -B), (B/3, -B*2), (0, -B*2 -2), (-B/3, -B*2))
    s2.addcomponent(motor, "red", "red")
    turtle.register_shape('lander with motor', s2)

    # Sun shape
    turtle.begin_poly()
    turtle.rt(90)
    turtle.fd(60)
    turtle.lt(90)
    turtle.circle(60)
    turtle.end_poly()
    poly = turtle.get_poly()
    turtle.register_shape('sun', poly)

    # Ground shapes
    s = turtle.Shape("compound")
    s.addcomponent(groundS, "black", "black")
    turtle.register_shape('ground', s)
    # Create 2 others grounds to create a wrap-up scrolling effect
    # To do that we cut the first third of the ground to put it at the end
    global nGrounds, breaking_points, groundS1
    total_length = -groundS[0][0] * 2
    if random_ground == 2:
        nGrounds = 1
    else:
        nGrounds = 3
    breaking_points = [round((total_length/nGrounds)*i-(WIDTH/2)) for i in range(nGrounds+1)]
    groundS1 = groundS[:]
    for i in range(3):
        locals()['sG'+str(i)] = turtle.Shape("compound")
        if i == 0:  # groundS is groundS1
            locals()['sG'+str(i)].addcomponent(groundS, "black", "black")
            turtle.register_shape('ground', locals()['sG'+str(i)])
        else:  # Create the 2 others "copies" of the ground
            local_groundS = globals()['groundS'+str(i)][:-2]  # The previous ground to "move"
            # The breaking points are the points of the cutting vertical line
            # We first get their bounds to know between which points to cut
            breaking_points_boundsL = [(j, j+1) for j in range(len(local_groundS)-1)
                                       if local_groundS[j][0] <= breaking_points[0] < local_groundS[j+1][0] or
                                       local_groundS[j+1][0] < breaking_points[0] <= local_groundS[j][0]]
            globals()['groundS'+str(i+1)] = []
            end = []
            for breaking_point_bounds in range(len(breaking_points_boundsL)):
                # Search the y of the breaking point.
                j0, j1 = breaking_points_boundsL[breaking_point_bounds]
                if breaking_point_bounds != len(breaking_points_boundsL)-1:
                    nextJ = breaking_points_boundsL[breaking_point_bounds+1][0]
                else:
                    nextJ = None
                # Determine the y of the breaking point
                try:
                    delta = abs(local_groundS[j0][1] - local_groundS[j1][1]) / \
                        abs(local_groundS[j1][0] - local_groundS[j0][0])
                except ZeroDivisionError:
                    delta = 0
                if local_groundS[j0][1] > local_groundS[j1][1]:
                    breaking_point_y = (delta * (local_groundS[j1][0] - breaking_points[0])) + local_groundS[j1][1]
                else:
                    breaking_point_y = (delta * (breaking_points[0] - local_groundS[j0][0])) + local_groundS[j0][1]
                globals()['groundS'+str(i+1)] += [(minG, int(breaking_point_y))]
                end += [(maxG, int(breaking_point_y))]
                # Add the points that are before the next breaking point
                currentJ = j0
                while nextJ is not None and currentJ <= nextJ:
                    p = local_groundS[currentJ]
                    if local_groundS[currentJ][0] > breaking_point_y:
                        globals()['groundS'+str(i+1)] += [(p[0] - (breaking_points[0] - minG), p[1])]
                    else:
                        end += [(maxG - (breaking_points[0] - p[0]), p[1])]
                    currentJ += 1

            # Create a new ground by doing the shifting
            globals()['groundS'+str(i+1)] = tuple(globals()['groundS'+str(i+1)] +
                                                  [(p[0] - (breaking_points[0] - minG), p[1])
                                                   for p in local_groundS[j1:]] +
                                                  [(maxG - (breaking_points[0] - p[0]), p[1])
                                                   for p in local_groundS[:j1]] +
                                                  end + [(maxG, 0), (minG, 0)])
            locals()['sG'+str(i)].addcomponent(globals()['groundS'+str(i+1)], "black", "black")
            turtle.register_shape('ground'+str(i+1), locals()['sG'+str(i)])