Skip to content

Instantly share code, notes, and snippets.

@yelluw
Last active May 15, 2017 21:41
Show Gist options
  • Save yelluw/60c1606bad7270ffb181b868ec8f2ce8 to your computer and use it in GitHub Desktop.
Save yelluw/60c1606bad7270ffb181b868ec8f2ce8 to your computer and use it in GitHub Desktop.
Helping beginner with scope issues.
from turtle import *
import Tkinter
class flag(object):
'''
classdocs
'''
def __init__(self, params):
'''
Constructor
'''
self.turtle = Turtle()
def setup(self):
'''
setup the turtle
'''
self.turtle.hideturtle()
self.turtle.pensize(5)
self.turtle.pendown()
self.turtle.color('white')
self.turtle.begin_fill()
def rectangle(self)
'''
Rectangle
'''
print(self.turtle.xcor())
self.turtle.forward(250)
print(self.turtle.xcor())
self.turtle.right(90)
self.turtle.forward(250)
self.turtle.right(90)
self.turtle.forward(450)
self.turtle.right(90)
self.turtle.forward(250)
self.turtle.pos()
print(round(self.turtle.xcor(), 5))
print(self.turtle.ycor())
self.turtle.right(90)
self.turtle.forward(200)
self.turtle.end_fill()
self.turtle.penup()
self.turtle.goto(0, 0)
self.turtle.pendown()
self.turtle.forward(-30)
def stars_border(self):
'''Stars Border'''
self.turtle.color('blue')
self.turtle.begin_fill()
self.turtle.right(90)
print(self.turtle.xcor())
print(self.turtle.ycor())
self.turtle.forward(140)
self.turtle.right(90)
self.turtle.forward(170)
self.turtle.right(90)
self.turtle.forward(140)
self.turtle.right(90)
self.turtle.forward(170)
self.turtle.end_fill()
flag = flag()
flag.setup()
flag.star_borders
def flag_stars(self):
'''
Constructor
'''
turtle.setheading(-10)
count_int = int()
turtle.speed(40)
turtle.penup()
vara = -190
varb = -5
count_stars = 7
count_rows = 1
for num1 in range(1, 10):
count_rows = count_rows + 1
for num in range(1, count_stars):
turtle.goto(vara, varb) # Location of stars
#turtle.goto(-190, -5)
turtle.pendown()
turtle.color('white')
turtle.begin_fill()
'''Loop for a star '''
for side in range(5):
turtle.forward(4)
turtle.right(120)
turtle.forward(4)
turtle.right(72 - 120)
turtle.end_fill()
turtle.penup()
vara = vara + 30 # changes location of stars
#2nd row
if count_rows == 2:# 2nd row
vara = -175
varb = -20
#3rd row
elif count_rows == 3:
vara = -190
varb = -35
#4th row
elif count_rows == 4:
vara = -175
varb = -50
#5th row
elif count_rows == 5:
vara = -190
varb = -65
#6th row
elif count_rows == 6:
vara = -175
varb = -80
#7th row
elif count_rows == 7:
vara = -190
varb = -95
#8th row
elif count_rows == 8:
vara = -175
varb = -110
#9th row
elif count_rows == 9:
vara = -190
varb = -125
if count_stars == 7:
count_stars = 6
else:
count_stars = 7
turtle.penup()
turtle.end_fill()
stars = flag_stars()
flag.stars()
def flag_stripes(self):
'''
Constructor
'''
vara = 2
varb = 2
counter = 0
turtle.penup()
turtle.position()
turtle.goto(2, 2)
turtle.pendown()
''' Stripes loop'''
for num in range(1, 10):
turtle.penup()
counter = counter + 1
turtle.goto(vara, varb)
turtle.pendown()
turtle.color('red')
turtle.begin_fill()
#Stripe size/1st stripe
turtle.forward(250)
turtle.right(90)
turtle.forward(19)
turtle.right(90)
turtle.forward(280)
turtle.right(90)
turtle.forward(19)
turtle.right(90)
turtle.forward(30)
turtle.end_fill()
#2nd stripe
if counter == 2:
vara = 2
varb = -38
#3rd stripe
elif counter == 3:
vara = 2
varb = -76
#4th stripe
elif counter == 4:
vara = 2
varb = -114
#5th stripe
elif counter == 5:
vara = -174
varb = -152
#6th stripe - 1st Long stripe
elif counter == 6:
vara = -174
varb = -190
turtle.color('red')
turtle.begin_fill()
turtle.forward(426)
turtle.right(90)
turtle.forward(19)
turtle.right(90)
turtle.forward(426)
turtle.right(90)
turtle.forward(19)
turtle.right(90)
#7th stripe - 2nd Long stripe
elif counter == 7:
vara = -174
varb = -228
turtle.color('red')
turtle.begin_fill()
turtle.forward(426)
turtle.right(90)
turtle.forward(19)
turtle.right(90)
turtle.forward(426)
turtle.right(90)
turtle.forward(19)
turtle.right(90)
#7th stripe - 3rd Long stripe
elif counter == 8:
vara = -174
varb = -266
turtle.color('red')
turtle.begin_fill()
turtle.forward(426)
turtle.right(90)
turtle.forward(19)
turtle.right(90)
turtle.forward(426)
turtle.right(90)
turtle.forward(19)
turtle.right(90)
turtle.end_fill()
break
stripes = flag_stripes()
flag.stripes()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment