コード例 #1
0
ファイル: Tempo.py プロジェクト: Smx2020/Cours_Polytech
def afficherForme(forme, x, y, largeur, hauteur, rotation=0, couleur="black"):
    turtle.shape(forme) # Forme.
    turtle.setpos(x, y) # Coordonnées.
    turtle.shapesize((largeur-1)/20, (hauteur-1)/20) # Taille.
    turtle.settiltangle(90 + rotation) # Rotation.
    turtle.color(couleur) # Couleur.
    turtle.stamp() # Tamponner.
コード例 #2
0
 def update(self):
     turtle.shapesize(self.sizex, self.sizey)
     turtle.settiltangle(0)
     #screen wraparound
     if self.x >= WIDTH / 2:
         self.x = -WIDTH / 2
     elif self.x <= -WIDTH / 2:
         self.x = WIDTH / 2 - 2
     elif self.y >= HEIGHT / 2:
         self.y = -HEIGHT / 2
     elif self.y <= -HEIGHT / 2:
         self.y = HEIGHT / 2
     super().update()
     turtle.shapesize(0.1, 0.1)
コード例 #3
0
ファイル: asteroids.py プロジェクト: sbihel/retrogames
	def update(self):
		turtle.shapesize(self.sizex, self.sizey)
		turtle.settiltangle(0)
		#screen wraparound
		if self.x >= WIDTH / 2:
			self.x = -WIDTH / 2
		elif self.x <= -WIDTH / 2:
			self.x = WIDTH / 2 - 2
		elif self.y >= HEIGHT / 2:
			self.y = -HEIGHT / 2
		elif self.y <= -HEIGHT / 2:
			self.y = HEIGHT / 2
		super().update()
		turtle.shapesize(0.1, 0.1)
コード例 #4
0
    def update(self):
        turtle.shapesize(0.2, 0.2)
        turtle.settiltangle(0)

        #screen wraparound
        if self.x >= WIDTH / 2:
            self.x = -WIDTH / 2
        elif self.x <= -WIDTH / 2:
            self.x = WIDTH / 2 - 2
        elif self.y >= HEIGHT / 2:
            self.y = -HEIGHT / 2
        elif self.y <= -HEIGHT / 2:
            self.y = HEIGHT / 2

        super().update()

        if self.age >= SHOTLIFE:
            engine.del_obj(self)
            s.shots -= 1
コード例 #5
0
ファイル: asteroids.py プロジェクト: sbihel/retrogames
	def update(self):
		turtle.shapesize(0.2,0.2)
		turtle.settiltangle(0)
		
		#screen wraparound
		if self.x >= WIDTH / 2:
			self.x = -WIDTH / 2
		elif self.x <= -WIDTH / 2:
			self.x = WIDTH / 2 - 2
		elif self.y >= HEIGHT / 2:
			self.y = -HEIGHT / 2
		elif self.y <= -HEIGHT / 2:
			self.y = HEIGHT / 2
		
		super().update()

		if self.age >= SHOTLIFE:
			engine.del_obj(self)
			s.shots -= 1
コード例 #6
0
def main():
    #设置一个画面
    windows = turtle.Screen()
    #设置背景
    windows.bgcolor('blue')
    #生成一个黄色乌龟
    bran = turtle.Turtle()
    bran.shape('turtle')
    bran.color('yellow')
    turtle.reset()
    turtle.shape("circle")
    turtle.shapesize(5, 2)
    turtle.settiltangle(45)
    turtle.fd(50)
    turtle.settiltangle(-45)
    turtle.fd(50)
    #开始你的表演
    bran.speed(1)
    bran.circle(50, 360, 100)
コード例 #7
0
def backtrack(t, matrix, index, size, visited):
    # let's implement this recursively
    i = index[0]
    x = index[1]

    # base case
    if matrix[i][x] == 'e':
        win(t, size)
        return True, [i, x]

    print("i: ", i, "\tx: ", x)
    visited[i][x] = 1
    print(visited)
    curpos = t.pos()

    print(curpos)
    if valid_move(i - 1, x, matrix, visited) == True:
        t.settiltangle(90)
        print('moving right')
        t.goto(curpos[0], curpos[1] + size)
        t.dot()
        if backtrack(t, matrix, [i - 1, x], size, visited):
            return True

    if valid_move(i + 1, x, matrix, visited) == True:
        print('moving down')
        t.settiltangle(270)
        t.goto(curpos[0], curpos[1] - size)
        t.dot()
        if backtrack(t, matrix, [i + 1, x], size, visited):
            return True

    if valid_move(i, x - 1, matrix, visited) == True:
        print('moving left')
        t.settiltangle(180)
        t.goto(curpos[0] - size, curpos[1])
        t.dot()
        if backtrack(t, matrix, [i, x - 1], size, visited):
            return True

    if valid_move(i, x + 1, matrix, visited) == True:
        print('moving up')
        t.settiltangle(0)
        t.goto(curpos[0] + size, curpos[1])
        t.dot()
        if backtrack(t, matrix, [i, x + 1], size, visited):
            return True

    t.setpos(curpos)
    screen.update()

    return False
コード例 #8
0
    def simulate_with_steering(self, next_angle, params):
        """Run simulation to allow glider to be steered.

        Args:
            next_angle(func): Student submission function for gliders next turn angle.
            params(dict): Test parameters.

        Raises:
            Exception if error running submission.
        """
        self._reset()

        #make the test somewhat repeatable by seeding the RNG.
        random.seed(params['map_seed'])

        ourMapFunc = getMapFunc(params['map_seed'], params['map_freq'])
        #Student function is separate, so they can mess it up if they want.
        studentMapFunc = getMapFunc(params['map_seed'], params['map_freq'])

        target = glider.glider(
            params['target_x'],
            params['target_y'],
            5000 + random.randint(-50, 50),  #Altitude
            params['target_heading'],
            ourMapFunc)
        target.set_noise(params['measurement_noise'],
                         params['altitude_offset'], params['turning_noise'])

        other_info = None
        steps = 0
        tolerance = 10.0  #Double tolerance for steering task.

        # Set up the plotter if requested
        if PLOT_PARTICLES == True:
            import turtle
            s = turtle.Screen()
            s.tracer(0, 1)
            turtle.setup(width=800, height=800)
            turtle.setworldcoordinates(-WINDOW_SIZE, -WINDOW_SIZE, WINDOW_SIZE,
                                       WINDOW_SIZE)

            #Draw a cross at (0,0)
            turtle.penup()
            turtle.setposition(0, -5)
            turtle.pendown()
            turtle.setposition(0, 5)
            turtle.penup()
            turtle.setposition(-5, 0)
            turtle.pendown()
            turtle.setposition(5, 0)
            turtle.penup()

            turtle.setposition(target.x, target.y)
            turtle.pendown()
            turtle.shape("triangle")
            turtle.shapesize(0.2, 0.4)
            turtle.settiltangle(target.heading * 180 / math.pi)
            turtle.pencolor("red")

            turtleList = []

        try:
            while steps < params['max_steps']:
                target_meas = target.sense()
                target_height = target.get_height()
                result = next_angle(target_height, target_meas, studentMapFunc,
                                    other_info)
                if len(result) == 3:
                    steering, other_info, extra_points = result
                elif len(result) == 2:
                    steering, other_info = result
                    extra_points = None
                else:
                    print "next_angle did not return 2 or 3 return values!"

                steering = max(-PI / 8.0, steering)
                steering = min(steering, PI / 8.0)

                target.glide(steering)

                target_pos = (target.x, target.y)
                separation = self.distance((0, 0), target_pos)

                if PLOT_PARTICLES == True:

                    if extra_points != None:
                        #Add turtles if needed.
                        while len(extra_points) > len(turtleList):
                            newTurtle = turtle.Turtle()
                            newTurtle.penup()
                            turtleList.append(newTurtle)

                        #remove turtles if needed.
                        while len(extra_points) < len(turtleList):
                            turtleList[-1].hideturtle()
                            turtleList = turtleList[0:-1]

                        # Draw the particles, set angle and position of each turtle.
                        for i in range(len(extra_points)):
                            t = turtleList[i]
                            p = extra_points[i]
                            if len(p) > 2:
                                t.shape("triangle")
                                t.shapesize(0.2, 0.4)
                                t.settiltangle(p[2] * 180 / math.pi)
                            else:
                                t.shape("circle")
                                t.shapesize(0.1, 0.1)
                            t.setposition(p[0], p[1])

                    #Always show the actual glider.
                    turtle.setposition(target.x, target.y)
                    turtle.settiltangle(target.heading * 180 / math.pi)

                    s = turtle.Screen()
                    s.update()

                if VERBOSE == True:
                    actual_height = target.z
                    ground_height = ourMapFunc(target.x, target.y)
                    actual_dist_to_ground = actual_height - ground_height
                    print "Step: {} Actual Heading ({}) \n  Dist To (0,0) = {}\n ".format(
                        steps, target.heading, separation)

                if separation < tolerance:
                    self.glider_found.put(True)
                    self.glider_steps.put(steps)
                    return

                steps += 1

            self.glider_found.put(False)
            self.glider_steps.put(steps)

        except:
            self.glider_error.put(traceback.format_exc())
コード例 #9
0
def scheme_pencolor(x):
    turtle.settiltangle(x)
コード例 #10
0
def scheme_pencolor(x):
    turtle.settiltangle(x)
コード例 #11
0
import turtle
turtle.bgcolor("blue")
turtle.pensize(10)
turtle.color("green", "yellow")
turtle.begin_fill()
turtle.speed(1)
turtle.shape("turtle")
turtle.fd(50)
turtle.circle(70)
turtle.shapesize(5, 1)
turtle.settiltangle(90)
turtle.fd(100)
turtle.end_fill()

turtle.shape("square")
turtle.shaptransform(4, -1, 0, 2)
turtle.get_shapepoly()
turtle.end_fill()

turtle.reset()
turtle.resizemode("auto")
turtle.speed(6)
turtle.shape("triangle")
turtle.tilt(90)
turtle.shaptransform()
turtle.end_fill()