Example #1
0
def draw_l(word):
    turtle.up()
    turtle.clear()
    turtle.setposition(0, 0)
    turtle.setheading(0)
    turtle.bk(INITIAL_POS[0])
    turtle.down()
    turtle.st()
    stack = []
    for char in word:
        if char == '0':
            turtle.fd(SIZE[0])
        if char == '1':
            turtle.fd(SIZE[0])
        if char == '[':
            stack.append((turtle.position(), turtle.heading()))
            turtle.lt(45)
        if char == ']':
            position, heading = stack.pop()
            turtle.up()
            turtle.setposition(position)
            turtle.setheading(heading)
            turtle.rt(45)
            turtle.down()
    turtle.ht()
Example #2
0
def alpha_beta_helper():
	global state, root, alpha_time
	initialize()
	print("PLEASE WAIT!!!")
	root = TreeNode(-1000)
	time1 = time.time()
	alpha_beta(root, 1, state)
	init_screen()
	drawLine()
	drawGrid()
	drawColumns()
	drawRows()
	caliberate()
	col = root.ans
	row = -1
	turtle.onscreenclick(goto)
	for i in range(4):
		if state[i][col] == 0:
			row = i
			break
	state[row][col] = 1
	drawDot(row, col, 1)
	var = (int)(input("Enter 1 to continue playing or 0 to stop."))
	time2 = time.time()
	alpha_time = time2-time1
	if(var == 1):
		turtle.clear()
		turtle.goto(0, 0)
		turtle.penup()
		turtle.right(270)
		alpha_beta_helper()
	else:
		write_analysis(3)
Example #3
0
def main():
  ap = ArgumentParser()
  ap.add_argument('--speed', type=int, default=10,
                  help='Number 1-10 for drawing speed, or 0 for no added delay')
  ap.add_argument('program')
  args = ap.parse_args()

  for kind, number, path in parse_images(args.program):
    title = '%s #%d, path length %d' % (kind, number, path.shape[0])
    print(title)
    if not path.size:
      continue
    pen_up = (path==0).all(axis=1)
    # convert from path (0 to 65536) to turtle coords (0 to 655.36)
    path = path / 100.
    turtle.title(title)
    turtle.speed(args.speed)
    turtle.setworldcoordinates(0, 655.36, 655.36, 0)
    turtle.pen(shown=False, pendown=False, pensize=10)
    for i,pos in enumerate(path):
      if pen_up[i]:
        turtle.penup()
      else:
        turtle.setpos(pos)
        turtle.pendown()
        turtle.dot(size=10)
    _input('Press enter to continue')
    turtle.clear()
  turtle.bye()
Example #4
0
    def tegnGitter(i0,i1,j0,j1):
        """Gitteret har søjler fra i0 til og med i1 og rækker fra
j0 til og med j1.  Først blankstilles lærredet"""
        xmin,ymin = toXY(i0,j0)
        xlen,ylen = (i1-i0+2)*cs,(j1-j0+2)*cs
        tt.clear()
        tt.penup()
        tt.color(kodefarve[4])
        # vandrette linjer
        x,y = xmin-cs/2,ymin
        tt.setheading(0) # øst
        for j in range(j0,j1+2):
            tt.goto(x,y)
            tt.pendown()
            tt.forward(xlen)
            tt.penup()
            y += cs
        # lodrette linjer
        x,y = xmin,ymin-cs/2
        tt.setheading(90) # nord
        for i in range(i0,i1+2):
            tt.goto(x,y)
            tt.pendown()
            tt.forward(ylen)
            tt.penup()
            x += cs
 def display(self):
     """Draw the whole board"""
     turtle.clear()
     for i in range(self.xsize):
         for j in range(self.ysize):
             self.draw(i, j)
     turtle.update()
Example #6
0
    def nextGeneration(self, step=True):
        self.refreshCanvas()
        self.dirty = True
        turtle.TurtleScreen._RUNNING = True
        self.screen.clear()
        self.screen.mode("standard")
        self.state = RUNNING

        self.selected = []
        self.configGUI(DISABLED, DISABLED, DISABLED, DISABLED, NORMAL, DISABLED,
                       "Drawing, please wait...", "red")

        if step:
            self.ge.set_fitnesses(self.fitness)
            self.ge.step()

        self.myt = MyTurtle(650, 650, 3, 3)
        turtle.clear()
        for i in range(self.n):
            for j in range(self.m):
                self.setUnselected(i, j)
                #Drawing l-system
#                phenotype = 'angle=6%d\ndepth=%d\nstep_size=10\ncircle_angle=20.5\naxiom=F\nF=F-F++F-F'%((i*j),(i*j))
                phenotype = self.ge.individuals[i*self.n+j].phenotype
                valid = self.draw_phenotype(
                    phenotype,
                    self.myt.index_to_pixel(i, "x") + self.myt.xside_box / 2.0,
                    self.myt.index_to_pixel(j, "y") + self.myt.yside_box / 2.0,
                    self.myt.xside,
                    self.myt.yside)
                if not valid:
                    self.setInvalid(i, j)

        self.configGUI(NORMAL, NORMAL, NORMAL, NORMAL, DISABLED, DISABLED, INSTRUCTIONS)
        self.set_listeners()
Example #7
0
 def display(self):
     turtle.clear()
     # draws all live cells from grid.state
     for i in range(self.xspan):
         for j in range(self.yspan):
             self.draw(i, j)
     turtle.update()
def animate_fw(slide1, slide2):
    for i in range(100):
        turtle.clear()
        draw_slide(slide1[0],slide1[1],-885+(i*8.85),0)
        draw_slide(slide2[0],slide2[1],i*8.85,0)
        turtle.update()
    return
Example #9
0
def message(m1, m2):             # 메시지를 화면에 표시하는 함수
    t.clear()
    t.goto(0, 100)
    t.write(m1, False, "center", ("", 20))
    t.goto(0, -100)
    t.write(m2, False, "center", ("", 15))
    t.home()
Example #10
0
def loop(x,y):
    if -50<x<50 and -5<y<45:
        turtle.clear()
        play()
    else:
        turtle.showturtle()
        turtle.goto(x, y)
def Run():
    #bounds
    nearRange = [0, 50]
    farRange = [50, 200]
    frusHL = 100

    #Logic
    nearDist = random.uniform(nearRange[0], nearRange[1])
    farDist = random.uniform(farRange[0], farRange[1])
    d = frusHL * 2
    an = nearDist
    af = farDist
    b = (d*d + af*af - an*an) / (2 * d)
    radius = math.sqrt(b*b + an*an)
    originY = -frusHL + b

    #text.insert('end', 'Origin: %d\n' % originY)

    #Render
    turtle.clear()
    turtle.hideturtle()
    turtle.tracer(0, 0)
    turtle.penup()
    turtle.goto(-farDist, frusHL)
    turtle.pendown()
    turtle.goto(-nearDist, -frusHL)
    turtle.goto(nearDist, -frusHL)
    turtle.goto(farDist, frusHL)
    turtle.goto(-farDist, frusHL)
    turtle.penup()
    DrawCircle(0, originY, radius);
    turtle.update()
 def cleargraph():
     global outwin
     try:
         outwin.destroy()
     except:
         None
     turtle.clear()
     gridlines(True)
     return
Example #13
0
def main(x,y):
	turtle.clear();
	j();
	a();
	z();
	d();
	e();
	e();
	p();
Example #14
0
def keys():
	turtle.clear()
	turtle.speed(0)
	turtle.pencolor("black")
	turtle.pu()
	paint (-250,325)
	turtle.goto(0,0)
	turtle.pd()
	turtle.speed(9)
	pensize=5
def main(loop_on, dots):
    #dots = int(input("How many dots? "))
    while loop_on:
        turtle_setup()
        draw_random_dots(dots)
        turtle.clear()
        print("")
    if not loop_on:
        turtle_setup()
        draw_random_dots(dots)
	def up() :
		if(len(info["tracks"])==1) :
			turtle.clear()
		turtle.fd(100)
		pos=turtle.pos()
		info["tracks"].append(pos)
		if(info["goalPos"][0]<=pos[0]<=info["goalPos"][0]+100 and info["goalPos"][1]<=pos[1]<=info["goalPos"][1]+100) :
			info["point"]+=1
			turtle.write("Done. Your point is "+str(info["point"]))
			time.sleep(2)
			reset(goal, turtle, info)
 def draw(self):
     xa,ya=self.pA
     xb,yb=self.pB
     xc,yc=self.pC
     turtle.up()
     turtle.goto(int(xa)*100,int(ya)*100)
     turtle.down()
     turtle.goto(int(xb)*100,int(yb)*100)
     turtle.goto(int(xc)*100,int(yc)*100)
     turtle.goto(int(xa)*100,int(ya)*100)
     turtle.clear()
def setGoal(turtle) :
	turtle.pencolor("Black")
	turtle.color("Black")
	turtle.clear()
	rangeX=turtle.window_width()/2-110
	rangeY=turtle.window_height()/2-110
	pos=(random.uniform(-rangeX, rangeX), random.uniform(-rangeY, rangeY))
	drawSquare(turtle, pos, 100)
	turtle.pencolor("WHITE")
	turtle.color("WHITE")
	return pos
	def drawShape(self, s, l):
		angle = 360 / s	# Calculating the angle to turn the turtle

		# For the number of sides
		for i in range(0, s):
			turtle.down()	# Put the pen down
			turtle.forward(l)	# Move the turtle forward (l)
			turtle.right(angle)	# Turn the turtle angle (angle)

		time.sleep(self.wait)	# turtle.exitonclick() doesn't seem to work (Error: object has no attribute 'exitonclick') so I've just put a sleep in there
		turtle.clear()	# Clearing the screen
def initialize(color='brown', smallest=1.0):
    '''Prepare to draw a von Koch Snowflake.'''
    turtle.setup(400, 300)
    turtle.screensize(350, 250)
    turtle.clear()
    turtle.up()
    turtle.goto(-100.0, 55.0)
    turtle.setheading(0)
    turtle.color(color)
    turtle.down()
    global smallestLineLength
    smallestLineLength = smallest
def drawPile(matrix):
	'''sends turtle to starting position, draws pile, then sends the turtle
	back to the starting position'''
	clear() # clears canvas to reduce RAM clogging
	matrixDim = (DOTSIZE+1)*len(matrix)
	pu()
	goto(-matrixDim,matrixDim)
	for i in range(0,len(matrix)):
		for j in range(0,len(matrix[0])):
			drawEntry(i,j,matrix,DOTSIZE)
			forward(2*DOTSIZE+DOTSIZE//4)
		goto(-matrixDim,matrixDim-(2*DOTSIZE+DOTSIZE//4)*(i+1))
Example #22
0
def fim():
    turtle.clear()
    move(0,0,0)
    if (-1)**board[3]==-1:
        turtle.write('Player 1 Ganhou!',False,'center',("Arial", 30, "normal"))
        reset()
        window.onclick(begin)
        window.listen()
    else:
        turtle.write('Player 2 Ganhou!',False,'center',("Arial", 30, "normal"))
        reset()
        window.onclick(begin)
        window.listen()
Example #23
0
def init_engine(delay=_ENGINEDELAY):
	'''
	(Re)initializes the game engine.  Only one game engine may exist
	at any one time.  The optional parameter specifies a delay added
	to each game time step, in seconds; the value may be a floating
	point number.
	'''
	global _e
	_e = _E(delay)

	turtle.pu()
	turtle.ht()
	turtle.clear()
Example #24
0
def check():
    if c_v_h() or board[0][0]==board[1][1]==board[2][2]or board[0][2] == board[1][1]==board[2][0]:
        return True
    
    elif board[3]==9:
        turtle.clear()
        move(0,0,0)
        turtle.color('black')
        turtle.write('Empate!',False,'center',("Arial", 30, "normal"))
        reset()
        window.onclick(begin)
        window.listen()
    else:
        return False
Example #25
0
def disp(A, cellsize = 1 / 10.5):
    turtle.clear()
    turtle.shape("square")
    turtle.penup()
    turtle.speed(0)
    turtle.shapesize(0.5, 0.5, 1)
    turtle.ht()
    top = len(A) / cellsize
    left = -len(A[0]) / cellsize
    for r in range(len(A)):
        for c in range(len(A[r])):
            if A[r][c]: 
                turtle.goto(c * 10.5 + left, top - r * 10.5)
                turtle.stamp()
Example #26
0
def level_1():
    turtle.clear()
    turtle.pu()
    turtle.speed(0)
    turtle.pensize(20)
    turtle.color("grey")
    turtle.goto(-220,220)
    turtle.pd()
    turtle.goto(220,220)
    turtle.goto(220,-220)
    turtle.goto(-220,-220)
    turtle.goto(-220,220)
    turtle.pu()
    turtle.goto(0,0)
def drawCircleTurtle(r,c):
    turtle.up()
    x = 0
    y = 0
    turtle.setpos(x+r,y)
    turtle.color(c,c)
    turtle.down()
    turtle.begin_fill()
    turtle.circle(r)
    turtle.end_fill()
    #I wanted to make sure the viewer saw the circle rather than having it just 
    #disappear.
    time.sleep(0.1)    
    turtle.clear()
def reset(goal, turtle, info) : 
	turtle.reset()
	turtle.clear()
	goal.reset()
	goal.clear()
	while True :
		goalPos=setGoal(goal)
		pos=turtle.pos()
		if(goalPos[0]<=pos[0]<=goalPos[0]+100 and goalPos[1]<=pos[1]<=goalPos[1]+100) :
			continue
		else :
			info["goalPos"]=goalPos
			info["tracks"]=[turtle.pos()]
			break
 def cleargraph():
     global outwin
     try:
         outwin.destroy()
     except:
         None
     if int(xmin_entry.get()) > 0:
         showerror("Error", "X Range Error: Please choose a value for x minimum less than or equal to 0.")
         return
     elif int(xmax_entry.get()) < 0:
         showerror("Error", "X Range Error: Please choose a value for x maximum greater than or equal to 0.")
     else:
         turtle.clear()
         gridlines(False,int(xmin_entry.get()),int(xmax_entry.get()))
         return
Example #30
0
def demo():
	turtle.title("3d cube demo") 
	cube = make_cube((100,100,100), 200)
	colors = [(f(),f(),f()) for _ in range(6)]
	turtle.tracer(0)
	x = 3**0.5 / 3
	axis = x, x, x
	camera = 500, 0, 0
	viewer = 550, 0, 0
	angle = 0.001
	while True:
		draw_axis(camera,viewer)
		draw_cube(cube,colors,camera,viewer)
		turtle.update()
		turtle.clear()
		rotate(cube, angle, axis)
Example #31
0
def drawSecond ():
	turtle.clear()
	turtle.reset()
	turtle.speed(100)
	array = [22, 24, 55, 84, 30]
	adjacentSort(array)
Example #32
0
def drawThird ():
	turtle.clear()
	turtle.reset()
	turtle.speed(100)
	array = [12, 34, 99, 55, 20]
	adjacentSort(array)
Example #33
0
>>> import turtle
>>> turtle.Screen()
<turtle._Screen object at 0x7fc4a9f32b20>
>>> turtle.pen()
{'shown': True, 'pendown': True, 'pencolor': 'black', 'fillcolor': 'black', 'pensize': 1, 'speed': 3, 'resizemode': 'noresize', 'stretchfactor': (1.0, 1.0), 'shearfactor': 0.0, 'outline': 1, 'tilt': 0.0}
>>> turtle.shape("turtle")
>>> turtle.forward(200)
>>> turtle.left(90)
>>> turtle.forward(200)
>>> turtle.left(90)
>>> turtle.forward(200)
>>> turtle.left(90)
>>> turtle.forward(200)
>>> turtle.left(90)
>>> 
>>> turtle.clear()
>>> for i in range(4):
	turtle.forward(200)
	turtle.left(90)

>>> turtle.clear()
>>> x=20
>>> for i in range(4):
	turtle.forward(x)
	turtle.left(90)
	x+=50

>>> turtle.clear()
>>> for i in range(400):
	turtle.forward(x)
	turtle.left(90)
Example #34
0
def move_plane():
    global t,counter_timer, charmove_counter
    
    if charmove_counter < charmove_delay:
        charmove_counter += 1
    else:
        move_character()
        charmove_counter = 0
    my_pos=plane.pos()
    x_pos= my_pos[0]
    y_pos=my_pos[1]

    if direction == RIGHT:
        #food and plane moving right
        plane.shape('planeaa.gif')
        plane.goto(x_pos+square_size,y_pos)
        print('you moved right')
        food_new_pos=plane.pos()
        food.goto(food_new_pos)
        food_new=food.stamp()
        food_pos.append(food_new_pos)
        food_drop_stamp.append(food_new)
        old_stamp=food_drop_stamp.pop(0)
        food.clearstamp(old_stamp)
        food_pos.pop(0)
        
    elif direction==LEFT:
        #food and plane moving to the left
        plane.shape('planeab.gif')
        plane.goto(x_pos-square_size,y_pos)
        print('you moved left')
        food_new_pos=plane.pos()
        food.goto(food_new_pos)
        food_new=food.stamp()
        food_pos.append(food_new_pos)
        food_drop_stamp.append(food_new)
        old_stamp=food_drop_stamp.pop(0)
        food.clearstamp(old_stamp)
        food_pos.pop(0)
        
    elif direction == DOWN:
        #dropping food when pressing down
        drop_food()
    new_pos=plane.pos()
    new_x_pos=new_pos[0]
    new_y_pos=new_pos[1]
    
    if new_x_pos>= RIGHT_EDGE:
        #plane appearing on the left if enters the right edge
        plane.hideturtle()
        plane.goto(-350,190)
        plane.showturtle()
        
    elif new_x_pos<=LEFT_EDGE:
        #plane appearing on the right if enters the left edge
        plane.hideturtle()
        plane.goto(350,190)
        plane.showturtle()
        
    counter_timer += 1
    if counter_timer == 10:
        printTime()
        counter_timer=0
    if t != -1 and life_counter != -1:
        turtle.ontimer(move_plane,TIMER_STEP)
    else:
        turtle.clear()
        turtle.goto(0,0)
        turtle.write("Time is up, you earned "+str(score)+" points!",align="Center",font=("Courier", 20,"bold"))
Example #35
0
def collision(turtle):
    for key in ('Up', 'Left', 'Right', 'Down', 'w', 'a', 'd', 's'):
        screen.onkey(None, key)  # disable game
    turtle.clear()  # remove the loser from the board!
if __name__ == "__main__":

    # Setup our drawning surface
    turtle.setup(1.0, 1.0)  # Sets up the size of the window
    turtle.Screen()  # Turns on the graphics window
    turtle.speed(0)

    #turtle.tracer(0,0) # turn off animation
    #drawStar()

    x = 0
    y = -200
    size = 100
    for t in range(110):
        turtle.tracer(0)
        turtle.clear()
        drawRocket(100, x, y + 0.1 * t * t)
        drawP(100)
        turtle.update()
        time.sleep(0.1)
        turtle.pendown()

    turtle.penup()
    turtle.setpos(0, 0.9)
    turtle.pendown()
    drawStar()
    turtle.update()

    ret = input("Press enter to exit.")
    turtle.Screen().bye()  # Turn off the graphics window
Example #37
0
h1 = 100
h2 = 80
x0, y0 = -100, -100

rect(l, h0, x0+0*l, y0)
rect(l, h1, x0+1*l, y0)
rect(l, h2, x0+2*l, y0)

def histo(H, l, x, y):
    for i, hi in enumerate(H):
        rect(l, hi, x+ i * l, y)
        
def histo_2(H, l, x, y):
    for i in range(len(H)):
        rect(l, H[i], x+ i * l, y)
        
H = [100, 50, 120, 12, -30, 60, 250, 100]
        
T.clear()
histo(H, 30, -200, -200)
T.exitonclick()
        
    




T.exitonclick()
    
    
    
Example #38
0
def intro(x, y):
    turtle.penup()
    turtle.hideturtle()
    turtle.write("Once upon a time, in a far away land,",
                 align=("center"),
                 font=("comic sans MS", 25, "bold"))
    time.sleep(4)
    turtle.clear()
    turtle.write("lived a princess and a prince.",
                 align=("center"),
                 font=("comic sans MS", 25, "bold"))
    time.sleep(4)
    characters_show()
    turtle.clear()
    turtle.write("One day, the dark queen came to the palace.",
                 align=("center"),
                 font=("comic sans MS", 25, "bold"))
    time.sleep(4)
    turtle.clear()
    turtle.write("She demanded to rule the kingdom, but the prince refused.",
                 align=("center"),
                 font=("comic sans MS", 20, "bold"))
    time.sleep(4)
    turtle.clear()
    turtle.write("She snnaped her fingers...",
                 align=("center"),
                 font=("comic sans MS", 25, "bold"))
    time.sleep(4)
    turtle.clear()
    turtle.bgcolor("black")
    turtle.color("white")
    player.hideturtle()
    prince.hideturtle()
    turtle.write("...and the palace went dark.",
                 align=("center"),
                 font=("comic sans MS", 25, "bold"))
    time.sleep(4)
    turtle.clear()
    turtle.bgcolor("white")
    turtle.color("black")
    player.showturtle()
    turtle.write("When the lights were back on, the prince was gone.",
                 align=("center"),
                 font=("comic sans MS", 25, "bold"))
    time.sleep(4)
    turtle.clear()
    speech.goto(player.xcor(), player.ycor() + 192)
    speech.showturtle()
    turtle.goto(speech.pos())
    turtle.write("I must find him!",
                 align=("center"),
                 font=("comic sans MS", 15, "bold"))
    time.sleep(4)
    turtle.clear()
    wizard.showturtle()
    speech.showturtle()
    speech.goto(100, wizard.ycor() + 183.5)
    turtle.goto(speech.pos())
    turtle.write("I will help you!",
                 align=("center"),
                 font=("comic sans MS", 15, "bold"))
    time.sleep(2.5)
    turtle.clear()
    turtle.write("ARE YOU READY?",
                 align=("center"),
                 font=("comic sans MS", 15, "bold"))
    time.sleep(4)
    turtle.clear()
    speech.goto(player.xcor(), player.ycor() + 192)
    turtle.goto(speech.pos())
    turtle.write("Yes!", align=("center"), font=("comic sans MS", 25, "bold"))
    time.sleep(4)
    turtle.clear()
    speech.hideturtle()
Example #39
0
 def reset_canvas(self):
     turtle.getpen().clear()
     turtle.clear()
     turtle.TurtleScreen._RUNNING = True
Example #40
0
    _prepare_distion(x, y, color)
    for i in range(2):
        tl.forward(20)
        tl.right(90)
        tl.forward(40)
        tl.right(90)
    tl.end_fill()


def write_helloI(x, y):
    tl.penup()
    tl.goto(x, y)
    tl.write("Happy,Halloween!!",
             True,
             align="center",
             font=("Arial", 48, "normal"))
    tl.stamp()


if __name__ == "__main__":
    import time

    while True:
        draw_face(0, -150)
        draw_tooth(-60, -20)
        draw_eyes(-80, 40)
        draw_head(-10, 150 + 30)
        write_helloI(-10, -260)
        time.sleep(5)
        tl.clear()
Example #41
0
def hpy_d7a0d7a7d794():
    """נקה את לוח הציור"""
    turtle.clear()
Example #42
0
def move_snake():

    my_pos = snake.pos()
    x_pos = my_pos[0]
    y_pos = my_pos[1]

    if direction == RIGHT:
        snake.goto(x_pos + SQUARE_SIZE, y_pos)
        print("you moved right!")
    elif direction == LEFT:
        snake.goto(x_pos - SQUARE_SIZE, y_pos)
        print("you moved left!")
    elif direction == UP:
        snake.goto(x_pos, y_pos + SQUARE_SIZE)
        print("you moved up!")
    elif direction == DOWN:
        snake.goto(x_pos, y_pos - SQUARE_SIZE)
        print("you moved down!")

    my_pos = snake.pos()

    if snake.pos() in pos_list:
        print("You hit yourself! Game over!")
        quit()

    pos_list.append(my_pos)
    new_stamp = snake.stamp()
    stamp_list.append(new_stamp)

    # here
    global food_stamps, food_pos, score
    if snake.pos() in food_pos:
        food_ind = food_pos.index(snake.pos())
        food.clearstamp(food_stamps[food_ind])
        food_pos.pop(food_ind)
        food_stamps.pop(food_ind)
        print("You have eaten the food!")
        make_food()
        bodystamp = snake.stamp()
        stamp_list.append(bodystamp)
        pos_list.append(bodystamp)

        score = score + 1
        #score_list.append(score)
        turtle.clear()
        turtle.write("SCORE : " + str(score))

        #global a
        #a = a+1
        #score = turtle.clone()
        #score.clear()
        #score.write(a)


######
    old_stamp = stamp_list.pop(0)
    snake.clearstamp(old_stamp)
    pos_list.pop(0)
    #######
    new_pos = snake.pos()
    new_x_pos = my_pos[0]
    new_y_pos = my_pos[1]

    if new_x_pos >= RIGHT_EDGE:
        print("You hit the right edge! Game over!")
        quit()
    elif new_x_pos <= LEFT_EDGE:
        print("You hit the left edge! Game over!")
        quit()
    elif new_y_pos >= UP_EDGE:
        print("You hit the top edge! Game over!")
        quit()
    elif new_y_pos <= DOWN_EDGE:
        print("You hit the top edge! Game over!")
        quit()
    turtle.ontimer(move_snake, TIME_STEP)
Example #43
0
def WASD(W):
    if (True):
        if (True):
            if (True):
                print("-")
                if (W == "w"):
                    turtle.forward(50)
                elif (W == "a"):
                    turtle.left(90)
                elif (W == "s"):
                    turtle.right(180)
                    turtle.forward(25)
                elif (W == "d"):
                    turtle.right(90)
                elif (W == "ss"):
                    turtle.backward(25)
                elif (W == "c"):
                    turtle.clear()
                elif (W == "r"):
                    turtle.reset()
                elif (W == "bgc"):
                    color = input("What color?")
                    turtle.bgcolor(color)
                elif (W == "shape"):
                    shape = input("What shape?")
                    turtle.shape(shape)
                elif (W == "pic"):
                    pic = input("Type the name of the pic")
                    turtle.bgpic(pic)
                elif (W == "efill"):
                    turtle.end_fill()
                elif (W == "sleep"):
                    print("Going to Sleep")
                    WASD("st")
                    wer = 0
                    while (wer < 10):
                        WASD("a")
                        wer = (wer + 1)
                    WASD("ht")
                    WASD("bcb")
                    input()
                    wer = 0
                    while (wer < 10):
                        WASD("a")
                        wer = (wer + 1)
                    WASD("ht")
                    WASD("r")
                    WASD("ht")
                    turtle.bgcolor("white")
                    WASD("stop")
                elif (W == "shutdown script"):
                    print("Running Shutdown Scripts")
                    turtle.shape("turtle")
                    wer = 0
                    WASD("st")
                    while (wer < 10):
                        WASD("a")
                        wer = (wer + 1)
                    WASD("ht")
                    #                 turtle.bgpic("shutdown")
                    WASD("bcb")
                    WASD("www")
                    WASD("d")
                    WASD("ww")
                elif (W == "fill"):
                    turtle.begin_fill()
                elif (W == "stop"):
                    return (3)
                elif (W == "bcb"):
                    turtle.bgcolor("black")
                elif (W == "2x2"):
                    WASD("w")
                    WASD("a")
                    WASD("w")
                    WASD("a")
                    WASD("w")
                    WASD("a")
                    WASD("w")
                    WASD("d")
                    WASD("w")
                    WASD("d")
                    WASD("w")
                    WASD("d")
                    WASD("w")
                    WASD("d")
                    WASD("w")
                    WASD("d")
                    WASD("w")
                    WASD("d")
                    WASD("w")
                    WASD("d")
                    WASD("w")
                    WASD("w")
                    WASD("d")
                    WASD("w")
                    WASD("d")
                    WASD("w")
                    WASD("d")
                    WASD("w")
                    WASD("w")
                    WASD("d")
                    WASD("w")
                    WASD("d")
                    WASD("w")
                    WASD("d")
                    WASD("w")
                    WASD("w")
                    WASD("d")
                    WASD("w")
                    WASD("d")
                    WASD("w")

                elif (W == "ww"):
                    turtle.forward(25)
                elif (W == "www"):
                    turtle.forward(100)
                elif (W == "wwww"):
                    turtle.forward(200)
                elif (W == "bgw"):
                    turtle.bgcolor("white")
                elif (W == "w2"):
                    turtle.forward(9500)
                elif (W == "w1"):
                    turtle.forward(4750)
                elif (W == "ht"):
                    turtle.ht()
                elif (W == "st"):
                    turtle.st()
                else:
                    print("invalid move")
            else:
                print("")
        else:
            print("")

    else:
        print("")
import turtle as t

t.bgcolor("black")
t.color("yellow")
t.speed(10)  # maximum speed

angle = 10

for i in range(10):
    angle = angle + 5
    for px in range(150):
        t.forward(px)
        t.left(angle)
    t.clear()
Example #45
0
def WASD(W):
    if (W == "/n"):
        nothing = (".")
    elif (W == "w input"):
        far = input("how many units?")
        far = float(far)
        turtle.forward(far)
    elif(W == 'w'):
        turtle.forward(20)
    elif (W == 'a'):
        turtle.left(90)
    elif (W == 'd'):
            turtle.right(90)
    elif (W == 'ss'):
        turtle.backward(25)
    elif (W == 'c'):
        turtle.clear()
    elif (W == 'r'):
        turtle.reset()
    elif (W == "bgc"):
       color = input("What color?")
       turtle.bgcolor(color)
    elif (W == "shape"):
        shape = input("What shape?")
        turtle.shape(shape)
    elif (W == "pic"):
        pic = input("Type the name of the pic")
        turtle.bgpic(pic)
    elif (W == "efill"):
        turtle.end_fill()
    elif (W == "fill"):
        turtle.begin_fill()
    elif (W == "2x2"):
        WASD("w")
        WASD("a")
        WASD("w")
        WASD("a")
        WASD("w")
        WASD("a")
        WASD("w")
        WASD("d")
        WASD("w")
        WASD("d")
        WASD("w")
        WASD("d")
        WASD("w")
        WASD("d")
        WASD("w")
        WASD("d")
        WASD("w")
        WASD("d")
        WASD("w")
        WASD("d")
        WASD("w")
        WASD("w")
        WASD("d")
        WASD("w")
        WASD("d")
        WASD("w")
        WASD("d")
        WASD("w")
        WASD("w")
        WASD("d")
        WASD("w")
        WASD("d")
        WASD("w")
        WASD("d")
        WASD("w")
        WASD("w")
        WASD("d")
        WASD("w")
        WASD("d")
        WASD("w")
        
        
    elif (W == "ww"):
        turtle.forward(25)
    elif (W == "www"):
        turtle.forward(100)
    elif (W == "wwww"):
        turtle.forward(200)
    elif (W == "b"):
        return(True)
    elif (W == " "):
        turtle.penup()
        WASD("w")
        turtle.pendown()
    else:
        print("invalid move")
        return ("invalid")
Example #46
0
 def reset(self):
     super(TurtleGui,self).reset()
     std_turtle.penup()
     std_turtle.home()
     std_turtle.clear()
     std_turtle.pendown()
Example #47
0
def start():
    global playing
    if playing == False:
        playing = True
        t.clear()
        play()
def move_snake():

    global direction
    my_pos = snake.pos()
    x_pos = my_pos[0]
    y_pos = my_pos[1]

    if direction == RIGHT:
        snake.goto(x_pos + square_size, y_pos)
        print("You moved right!")
    elif direction == LEFT:
        snake.goto(x_pos - square_size, y_pos)
        print("You moved left!")
    elif direction == UP:
        snake.goto(x_pos, y_pos + square_size)
        print("You moved up!")
    elif direction == DOWN:
        snake.goto(x_pos, y_pos - square_size)
        print("You moved down!")

    # stamp and record the snake's head
    my_pos = snake.pos()
    pos_list.append(my_pos)
    new_stamp = snake.stamp()
    stamp_list.append(new_stamp)

    # if the snake is eating food
    if snake.pos() in food_pos:
        food_ind = food_pos.index(snake.pos())
        food.clearstamp(food_stamps[food_ind])
        food_pos.pop(food_ind)
        score.append(food_ind)
        food_stamps.pop(food_ind)
        print("You have eaten a food!")
        make_food()
        turtle.clear()
        turtle.goto(200, 200)
        turtle.write(len(score), font=("Arial", 30))
        turtle.goto(-300, 0)
    else:
        # cleartsamps the tail and makes storage edits
        old_stamp = stamp_list.pop(0)
        snake.clearstamp(old_stamp)
        pos_list.pop(0)

    new_pos = snake.pos()
    new_x_pos = new_pos[0]
    new_y_pos = new_pos[1]

    if new_x_pos >= RIGHT_EDGE:
        turtle.goto(0, 0)
        turtle.write("The blue snake hit the right edge! game over!",
                     font=("Ariel", 30),
                     align="center")
        time.sleep(2)
        quit()

    elif new_x_pos <= LEFT_EDGE:
        turtle.goto(0, 0)
        turtle.write("The blue snake hit the left edge! game over!",
                     font=("Ariel", 30),
                     align="center")
        time.sleep(2)
        quit()

    elif new_y_pos >= UP_EDGE:
        turtle.goto(0, 0)
        turtle.write("The blue snake hit the up edge! game over!",
                     font=("Ariel", 30),
                     align="center")
        time.sleep(2)
        quit()

    elif new_y_pos <= DOWN_EDGE:
        turtle.goto(0, 0)
        turtle.write("The blue snake hit the down edge! game over!",
                     font=("Ariel", 30),
                     align="center")
        time.sleep(2)
        quit(pos_list)

    if pos_list[-1] in pos_list[0:-1]:
        turtle.goto(0, 0)
        turtle.write("The blue snake hit herself!",
                     font=("Ariel", 30),
                     align="center")
        time.sleep(2)
        quit()

    turtle.ontimer(move_snake, TIME_STEP)
def clear():
    turtle.clear()
# tutle.shape() 대신에 t.shape() 으로 사용가능

t.shape('turtle')

t.circle(50)  #원그리기 (반지름길이)
t.color('red')
t.pensize(3)  #선 굵기

for i in range(4):
    t.forward(100)
    t.left(90)

t.forward(100)
#t.hideturtle() # turtle 숨김
t.home()  # tutle 초기 위치로 옮김
t.clear()  # 화면을 초기 상태로

t.done()
'''
myTurtle = turtle.Turtle() # 객체선언
myTurtle.fillcolor('red') # 색
myTurtle.shape('turtle') # 객체 타입
myTurtle.shapesize(3,3,1) # 세로w, 가로 h, 윤곽선 b배
myTurtle.forward(100) # 앞으로 100픽셀
myTurtle.left(120) # left 각도 변경
myTurtle.forward(100) 
myTurtle.left(120)
myTurtle.forward(100) 
myTurtle.left(120)
#myTurtle.backward(50) # 뒤로 50 픽셀
#myTurtle.setheading(90) # 원점기준 지정각도 변경
 def back():
     turtle.clear()
     import showcase
def plant_tree():
    global price, istree
    if not istree:
        if price >= 2000:
            istree = True
            turtle.clear()
            writer.undo()
            writer.color("red")
            writer.write("$" + str(price),
                         False,
                         "center",
                         font=("Arial", 30, "bold"))
            time.sleep(0.2)
            screen.bgpic('forestobig.gif')
            trees_num = int(
                screen.textinput(
                    'With the money you have gained',
                    "How many trees would you like to plant? every tree cost 2$"
                ))
            tree_turtle = turtle.Turtle()
            tree_turtle.up()
            tree_turtle.shape("tree.gif")
            if (trees_num * 2) < price:
                for i in range(0, trees_num):
                    min_x = -int(1000 / 2 / SQUARE_SIZE) + 1
                    max_x = int(1000 / 2 / SQUARE_SIZE) - 1
                    min_y = -int(1000 / 2 / SQUARE_SIZE) - 1
                    max_y = int(1000 / 2 / SQUARE_SIZE) + 1

                    #Pick a position that is a random multiple of SQUARE_SIZE
                    pos_x = random.randint(min_x, max_x) * SQUARE_SIZE
                    pos_y = random.randint(min_y, max_y) * SQUARE_SIZE
                    tree_turtle.goto(pos_x, pos_y)
                    idtree = tree_turtle.stamp()
                    tree_list.append(idtree)
            #time.sleep(2)
            print("You planted " + str(trees_num) + " trees!")
            print("keep helping the enviorment")
            #for t in tree_list:
            #tree_turtle.clearstamp()
            price -= trees_num * 2
            time.sleep(4)
            tree_turtle.clearstamps()
            tree_turtle.ht()
            make_house()
            turtle.listen()
            writer.undo()
    else:
        turtle.clear()
        writer.undo()
        writer.goto(860, 440)
        writer.color("red")
        writer.write("$" + str(price),
                     False,
                     "center",
                     font=("Arial", 30, "bold"))
        time.sleep(0.2)
        screen.bgpic('forestobig.gif')
        trees_num = int(
            screen.textinput(
                'With the money you have gained',
                "How many trees would you like to plant? every tree cost 2$"))
        tree_turtle = turtle.Turtle()
        tree_turtle.up()
        tree_turtle.shape("tree.gif")
        if (trees_num * 2) < price:
            for i in range(0, trees_num):
                min_x = -int(1000 / 2 / SQUARE_SIZE) + 1
                max_x = int(1000 / 2 / SQUARE_SIZE) - 1
                min_y = -int(1000 / 2 / SQUARE_SIZE) - 1
                max_y = int(1000 / 2 / SQUARE_SIZE) + 1

                #Pick a position that is a random multiple of SQUARE_SIZE
                pos_x = random.randint(min_x, max_x) * SQUARE_SIZE
                pos_y = random.randint(min_y, max_y) * SQUARE_SIZE
                tree_turtle.goto(pos_x, pos_y)
                idtree = tree_turtle.stamp()
                tree_list.append(idtree)
        #time.sleep(2)
        print("You planted " + str(trees_num) + " trees!")
        print("keep helping the enviorment")
        #for t in tree_list:
        #tree_turtle.clearstamp()
        price -= trees_num * 2
        time.sleep(4)
        tree_turtle.clearstamps()
        tree_turtle.ht()
        make_house()
        turtle.listen()
        writer.undo()
Example #53
0
def printTime():
    #timer function:
    global t
    turtle.clear()
    turtle.write(t,font=("Courier",15,"normal"))
    t=t-1
Example #54
0
def tscheme_clear():
    """Clear the drawing, leaving the turtle unchanged."""
    _tscheme_prep()
    turtle.clear()
Example #55
0
 def setUp(self):
     turtle.clear()
     tortuga.clear()
Example #56
0
def reset():
    t.clear()  # 화면을 리셋
Example #57
0
def clearDrawing():  #radMin = 10 * random.randint(1, 11)
    turtle.clear()
Example #58
0
2.2 pen movement
'''
t.penup()  # alias pu() and up()
t.pendown()  # alias pd() and down()
t.forward(10)  # alias fd()
t.backward(10)  # alias bd()
t.right(10)  # right(radian) alias rt() for right()
t.left(10)  # left(radian)  alias lt() for left()
t.goto(5, 5)  # goto(x, y)    alias setpos() and setposition() for goto()
t.circle(100, 360, 50)  # circle(radius, radian=360, step=0)
# The center is radius units left of the turtle
'''
2.3 pen controller
'''
t.fillcolor('yellow')
t.color('red', 'yellow')  # pencolor() and fillcolor()
t.filling()  # Is current state a filling state?
t.begin_fill()  # begin to fill
t.end_fill()  # end fill
t.hideturtle()  # alias ht() make the arrow of the turtle invisible
t.showturtle()  # alias st() make the arrow of the turtle visible
'''
2.4 global control command
'''
t.clear()  # clear windows but perverse current state of turtle
t.reset()  # clear windows and reset turtle state
t.undo()  # undo last operation
t.isvisible()  # return
# stamp()       # copy current graphics
t.done()  # end turtle
Example #59
0
def number(x):
    for i in range(x, -1, -1):
        drawDigit(i)
        # 打印完一个数字就会清屏
        turtle.clear()
        turtle.goto(0, 0)
Example #60
0
def timer():  #the game timer
    global start_time
    turtle.goto(-330, 310)
    turtle.pencolor("navy")
    start_time = start_time - 1
    print(start_time)
    turtle.clear()
    turtle.write(start_time, font=("Ariel", 23, "normal", "bold"))
    if start_time == 0:
        plane.clear()
        hamburger.clear()
        pizza.clear()
        water.clear()
        cola.clear()
        uganda.clear()
        kenya.clear()
        egypt.clear()
        syria.clear()
        score_1.clear()
        bb.clear()
        u_score.clear()
        s_score.clear()
        k_score.clear()
        e_score.clear()
        pizza.clearstamps()
        pizza.hideturtle()
        cola.clearstamps()
        cola.hideturtle()
        hamburger.clearstamps()
        hamburger.hideturtle()
        water.clearstamps()
        water.hideturtle()
        syria.clearstamps()
        syria.hideturtle()
        uganda.clearstamps()
        uganda.hideturtle()
        kenya.clearstamps()
        kenya.hideturtle()
        egypt.clearstamps()
        egypt.hideturtle()
        plane.clearstamps()
        plane.hideturtle()
        turtle.clear()

        turtle.bgcolor("dodgerblue")
        turtle.pencolor("yellow")
        turtle.hideturtle()
        turtle.pensize(4)
        turtle.penup()
        turtle.goto(350, 350)
        turtle.pendown()
        turtle.goto(-350, 350)
        turtle.goto(-350, -350)
        turtle.goto(350, -350)
        turtle.goto(350, 350)
        turtle.penup()
        turtle.goto(0, 0)
        turtle.hideturtle()

        turtle.goto(-235, 170)
        turtle.pencolor("navy")
        turtle.write("You ran out of time!", font=("Ariel", 35, "normal"))
        turtle.goto(-150, 50)
        turtle.pencolor("floralwhite")
        turtle.write("Your score was: " + str(score),
                     font=("Ariel", 25, "normal"))
        turtle.goto(-320, -162)
        turtle.pencolor("darkslategray")
        turtle.write("GAME OVER :(", font=("Ariel", 62, "normal", "bold"))
        time.sleep(10)
        quit()
        print("you run out of time ")
    turtle.ontimer(timer, 1000)