Exemple #1
0
    def force_field_effect(self, turtle):
        """Find turtle's position relative to its origin. Check if
        it's in the force field, then apply force field effect if
        so."""
        relpos_x = turtle.xcor() - self.origin[0]
        relpos_y = turtle.ycor() - self.origin[1]

        if self.xcor[0] < relpos_x < self.xcor[1] and \
                self.ycor[0] < relpos_y < self.ycor[1]:
            if self.type_ == 'positive':
                if self.effect == 'gravity':
                    turtle.S()
                elif self.effect == 'color':
                    turtle.n()
            else:
                if self.effect == 'gravity':
                    turtle.s()
                elif self.effect == 'color':
                    turtle.m()
Exemple #2
0
    def force_field_effect(self, turtle):
        """Find turtle's position relative to its origin. Check if
        it's in the force field, then apply force field effect if
        so."""
        relpos_x = turtle.xcor() - self.origin[0]
        relpos_y = turtle.ycor() - self.origin[1]

        if self.xcor[0] < relpos_x < self.xcor[1] and \
                self.ycor[0] < relpos_y < self.ycor[1]:
            if self.type_ == 'positive':
                if self.effect == 'gravity':
                    turtle.S()
                elif self.effect == 'color':
                    turtle.n()
            else:
                if self.effect == 'gravity':
                    turtle.s()
                elif self.effect == 'color':
                    turtle.m()
#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()