Made an epic showcase website and API!
This commit is contained in:
parent
9e21e4dbdd
commit
1907fad7c5
89 changed files with 36444 additions and 3 deletions
|
|
@ -1,45 +0,0 @@
|
|||
from turtle import Turtle
|
||||
STARTING_POSITIONS = [(0, 0), (-20, 0), (-40, 0)]
|
||||
MOVE_DISTANCE = 20
|
||||
UP = 90
|
||||
DOWN = 270
|
||||
LEFT = 180
|
||||
RIGHT = 0
|
||||
|
||||
class Snake:
|
||||
|
||||
def __init__(self):
|
||||
self.segments = []
|
||||
self.create_snake()
|
||||
self.head = self.segments[0]
|
||||
|
||||
def create_snake(self):
|
||||
for position in STARTING_POSITIONS:
|
||||
segment = Turtle(shape="square")
|
||||
segment.color("white")
|
||||
segment.penup()
|
||||
segment.goto(position)
|
||||
self.segments.append(segment)
|
||||
|
||||
def move(self):
|
||||
for segment_index in range(len(self.segments) - 1, 0, -1):
|
||||
new_x = self.segments[segment_index - 1].xcor()
|
||||
new_y = self.segments[segment_index - 1].ycor()
|
||||
self.segments[segment_index].goto(new_x, new_y)
|
||||
self.head.forward(MOVE_DISTANCE)
|
||||
|
||||
def up(self):
|
||||
if self.head.heading() != DOWN:
|
||||
self.head.setheading(90)
|
||||
|
||||
def down(self):
|
||||
if self.head.heading() != UP:
|
||||
self.head.setheading(270)
|
||||
|
||||
def left(self):
|
||||
if self.head.heading() != RIGHT:
|
||||
self.head.setheading(180)
|
||||
|
||||
def right(self):
|
||||
if self.head.heading() != LEFT:
|
||||
self.head.setheading(0)
|
||||
Loading…
Add table
Add a link
Reference in a new issue