Skip to content

Instantly share code, notes, and snippets.

@jsbueno
Created February 4, 2017 16:36
Show Gist options
  • Save jsbueno/d669afc0e09bb2931b49cd928dcfd681 to your computer and use it in GitHub Desktop.
Save jsbueno/d669afc0e09bb2931b49cd928dcfd681 to your computer and use it in GitHub Desktop.
import pygame
from math import sin, cos, radians
linefunc = pygame.draw.line
color = 255,255,255
class Turtle:
def __init__(self, surf, pos=(0,0)):
self.surf = surf
self.x = pos[0]; self.y = pos[1]
self.drawing = True
self.angle = 0
def right(self, delta):
self.angle -= delta
self.angle %= 360
def left(self, delta):
self.angle += delta
self.angle %= 360
def forward(self, length):
tpos = self.x + length * cos(radians(self.angle)), self.y + length * sin(radians(self.angle))
if self.drawing:
linefunc(self.surf, color, (self.x, self.y), tpos)
self.x, self.y = tpos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment