PYTHON TRINKET
Play Snake. Eat the food at the coordinate point, but don't eat yourself! In the game of Snake, the player uses the arrow keys to move a "snake" around the board. As the snake finds food, it eats the food, and thereby grows larger. The game ends when the snake either moves off the screen or moves into itself.
WORLD RECORD :
Medusa, a reticulated python, clocked in at 7.67 meters (25 feet, 2 inches) long in its official world record measurement, on October 12, 2011.
Snake, classic arcade game. Exercises 1. How do you make the snake faster or slower? 2. How can you make the snake go around the edges? 3. How would you move the food? 4. Change the snake to respond to arrow keys.
1. SNAKE GAME PYTHON CODE
from turtle import *
from random import randrange
from freegames import square,vector
food=vector(0,0)
snake=[vector(10,0)]
aim=vector(0,-10)
def change(x, y):
aim.x=x
aim.y=y
def inside(head): #boundary
return -200 < head.x < 190 and -200 < head.y <190
def move(): #-1 forward move
head=snake[-1].copy()
head.move(aim)
#head that hits boundary line it is out
#Head crosses its own body it is also out
if not inside(head) or head in snake:
square(head.x,head.y,9,'red')
update()
return
snake.append(head)
if head==food:
print('Snake',len(snake))
food.x=randrange(-15,15)*10
food.y=randrange(-15,15)*10
else:
snake.pop(0)
clear()
for body in snake:#snake body
square(body.x, body.y,9,'green')
#food
square(food.x,food.y,9,'red')
update()
ontimer(move,100)
setup(420,420,370,0)
hideturtle()
tracer(False)
listen() #update in every sec
#user input key value
onkey(lambda:change(10,0),'Right')
onkey(lambda:change(-10,0),'Left')
onkey(lambda:change(0,10),'Up')
onkey(lambda:change(0,-10),'Down')
move()
done()
# Run it and enjoy. Indentation is important
You need some free game module to run this program.
- Turtle module
- Random module
- Freegames module
To install turtle - Turtle graphics, check this link:
https://docs.python.org/3/library/turtle.html
To install freegames, check this link:
https://pypi.org/project/freegames/
To know more about onkey() function, check this link:
https://docs.python.org/2/library/turtle.html
2. COLOR SPIRAL
import turtle
import time
turtle.pensize(2)
turtle.bgcolor("black")
colors = ["red", "yellow", 'purple', 'blue']
turtle.tracer(False)
for x in range(400):
turtle.forward(2 * x)
turtle.color(colors[x % 4])
turtle.left(89) # Changing numbers will have different effects
turtle.tracer(True)
turtle.done()
3. ROSE PAINTING
'''
ROSE
'''
import turtle
# Set the initial position
turtle.penup()
turtle.left(90)
turtle.fd(200)
turtle.pendown()
turtle.right(90)
#
turtle.fillcolor("red")
turtle.begin_fill()
turtle.circle(10, 180)
turtle.circle(25, 110)
turtle.left(50)
turtle.circle(60, 45)
turtle.circle(20, 170)
turtle.right(24)
turtle.fd(30)
turtle.left(10)
turtle.circle(30, 110)
turtle.fd(20)
turtle.left(40)
turtle.circle(90, 70)
turtle.circle(30, 150)
turtle.right(30)
turtle.fd(15)
turtle.circle(80, 90)
turtle.left(15)
turtle.fd(45)
turtle.right(165)
turtle.fd(20)
turtle.left(155)
turtle.circle(150, 80)
turtle.left(50)
turtle.circle(150, 90)
turtle.end_fill()
# Petal 1
turtle.left(150)
turtle.circle(-90, 70)
turtle.left(20)
turtle.circle(75, 105)
turtle.setheading(60)
turtle.circle(80, 98)
turtle.circle(-90, 40)
# Petal 2
turtle.left(180)
turtle.circle(90, 40)
turtle.circle(-80, 98)
turtle.setheading(-83)
# Leaf 1
turtle.fd(30)
turtle.left(90)
turtle.fd(25)
turtle.left(45)
turtle.fillcolor("green")
turtle.begin_fill()
turtle.circle(-80, 90)
turtle.right(90)
turtle.circle(-80, 90)
turtle.end_fill()
turtle.right(135)
turtle.fd(60)
turtle.left(180)
turtle.fd(85)
turtle.left(90)
turtle.fd(80)
# Leaf 2
turtle.right(90)
turtle.right(45)
turtle.fillcolor("green")
turtle.begin_fill()
turtle.circle(80, 90)
turtle.left(90)
turtle.circle(80, 90)
turtle.end_fill()
turtle.left(135)
turtle.fd(60)
turtle.left(180)
turtle.fd(60)
turtle.right(90)
turtle.circle(200, 60)
turtle.done()
4. TREE BRANCHES
from turtle import *
from random import *
from math import *
def tree(n, l):
pd() # next pen
# Shadow effect
t = cos(radians(heading() + 45)) / 8 + 0.25
pencolor(t, t, t)
pensize(n / 3)
forward(l) # draw branches
if n > 0:
b = random() * 15 + 10 # right branch deflection angle
c = random() * 15 + 10 # Left branch deflection angle
d = l * (random() * 0.25 + 0.7) # the length of the next branch
# Turn right at an angle and draw the right branch
right(b)
tree(n - 1, d)
# Turn left at an angle and draw the left branch
left(b + c)
tree(n - 1, d)
# Turn back
right(c)
else:
# Painting leaves
right(90)
n = cos(radians(heading() - 45)) / 4 + 0.5
pencolor(n, n * 0.8, n * 0.8)
circle(3)
left(90)
# Add 0.3 times the falling leaves
if (random() > 0.7):
pu()
# Drifting down
t = heading()
an = -40 + random() * 40
setheading(an)
dis = int(800 * random() * 0.5 + 400 * random() * 0.3 + 200 * random() * 0.2)
forward(dis)
setheading(t)
# Painting leaves
pd()
right(90)
n = cos(radians(heading() - 45)) / 4 + 0.5
pencolor(n * 0.5 + 0.5, 0.4 + n * 0.4, 0.4 + n * 0.4)
circle(2)
left(90)
pu()
# Back
t = heading()
setheading(an)
backward(dis)
setheading(t)
pu()
backward(l) # backward
bgcolor(0.5, 0.5, 0.5) # background color
ht() # hide turtle
speed(0) # Speed, 1-10 progressive, 0 fastest
# tracer(0, 0) # This line determines whether it is dynamic
pu() # lift pen
backward(100)
left(90) # Turn left 90 degrees
pu() # lift pen
backward(300) # backward 300
tree(12, 100) # Recursive 7 layers
done()
5. DRAW TREE
import turtle as T
import random
import time
# Draw the torso of cherry blossoms (60,t)
def Tree(branch, t):
time.sleep(0.0005)
if branch > 3:
if 8 <= branch <= 12:
if random.randint(0, 2) == 0:
t.color('snow') # white
else:
t.color('lightcoral') # light coral
t.pensize(branch / 3)
elif branch < 8:
if random.randint(0, 1) == 0:
t.color('snow')
else:
t.color('lightcoral') # light coral
t.pensize(branch / 2)
else:
t.color('sienna') # ochre (zhě) color
t.pensize(branch / 10) # 6
t.forward(branch)
a = 1.5 * random.random()
t.right(20 * a)
b = 1.5 * random.random()
Tree(branch - 10 * b, t)
t.left(40 * a)
Tree(branch - 10 * b, t)
t.right(20 * a)
t.up()
t.backward(branch)
t.down()
# Falling petals
def Petal(m, t):
for i in range(m):
a = 200 - 400 * random.random()
b = 10 - 20 * random.random()
t.up()
t.forward(b)
t.left(90)
t.forward(a)
t.down()
t.color('lightcoral') # light coral
t.circle(1)
t.up()
t.backward(a)
t.right(90)
t.backward(b)
# Drawing area
t = T.Turtle()
# Canvas size
w = T.Screen()
t.hideturtle() # hide brush
t.getscreen().tracer(5, 0)
w.screensize(bg='wheat') # wheat
t.left(90)
t.up()
t.backward(150)
t.down()
t.color('sienna')
# Paint the torso of cherry blossoms
Tree(60, t)
# Falling petals
Petal(200, t)
w.exitonclick()
6. CHRISTMAS TREE
from turtle import *
import random
import time
n = 100.0
speed("fastest")
screensize(bg='seashell')
left(90)
forward(3 * n)
color("orange", "yellow")
begin_fill()
left(126)
for i in range(5):
forward(n / 5)
right(144)
forward(n / 5)
left(72)
end_fill()
right(126)
color("dark green")
backward(n * 4.8)
def tree(d, s):
if d <= 0: return
forward(s)
tree(d - 1, s * .8)
right(120)
tree(d - 3, s * .5)
right(120)
tree(d - 3, s * .5)
right(120)
backward(s)
tree(15, n)
backward(n / 2)
for i in range(200):
a = 200 - 400 * random.random()
b = 10 - 20 * random.random()
up()
forward(b)
left(90)
forward(a)
down()
if random.randint(0, 1) == 0:
color('tomato')
else:
color('wheat')
circle(2)
up()
backward(a)
right(90)
backward(b)
time.sleep(60)
7. PIGLET PAGE
from turtle import *
def nose(x, y):
"""Draw nose"""
pensize(5)
pencolor((255, 155, 192))
penup()
# Move the turtle to the specified coordinates
goto(x, y)
pendown()
# Set the direction of the turtle (0-East, 90-North, 180-West, 270-South)
setheading(-30)
begin_fill()
fillcolor(255, 192, 203)
a = 0.4
for i in range(120):
if 0 <= i < 30 or 60 <= i < 90:
a = a + 0.08
# Turn left 3 degrees
left(3)
# Move forward
forward(a)
else:
a = a - 0.08
left(3)
forward(a)
end_fill()
penup()
setheading(90)
forward(25)
setheading(0)
forward(10)
pendown()
# Set the color of the brush (red, green, blue)
pencolor(255, 155, 192)
setheading(10)
begin_fill()
circle(5)
color(160, 82, 45)
end_fill()
penup()
setheading(0)
forward(20)
pendown()
pencolor(255, 155, 192)
setheading(10)
begin_fill()
circle(5)
color(160, 82, 45)
end_fill()
def head(x, y):
"""Drawing head"""
color((255, 155, 192), "pink")
penup()
goto(x, y)
setheading(0)
pendown()
begin_fill()
setheading(180)
circle(300, -30)
circle(100, -60)
circle(80, -100)
circle(150, -20)
circle(60, -95)
setheading(161)
circle(-300, 15)
penup()
goto(-100, 100)
pendown()
setheading(-30)
a = 0.4
for i in range(60):
if 0 <= i < 30 or 60 <= i < 90:
a = a + 0.08
lt(3) # turn left 3 degrees
fd(a) # step forward to a
else:
a = a - 0.08
lt(3)
fd(a)
end_fill()
def ears(x, y):
"""Draw ears"""
color((255, 155, 192), "pink")
penup()
goto(x, y)
pendown()
begin_fill()
setheading(100)
circle(-50, 50)
circle(-10, 120)
circle(-50, 54)
end_fill()
penup()
setheading(90)
forward(-12)
setheading(0)
forward(30)
pendown()
begin_fill()
setheading(90)
circle(-50, 50)
circle(-10, 120)
circle(-50, 56)
end_fill()
def eyes(x, y):
"""Drawing Eyes"""
color((255, 155, 192), "white")
penup()
setheading(90)
forward(-20)
setheading(0)
forward(-95)
pendown()
begin_fill()
circle(15)
end_fill()
color("black")
penup()
setheading(90)
forward(12)
setheading(0)
forward(-3)
pendown()
begin_fill()
circle(3)
end_fill()
color((255, 155, 192), "white")
penup()
seth(90)
forward(-25)
seth(0)
forward(40)
pendown()
begin_fill()
circle(15)
end_fill()
color("black")
penup()
setheading(90)
forward(12)
setheading(0)
forward(-3)
pendown()
begin_fill()
circle(3)
end_fill()
def cheek(x, y):
"""Draw cheeks"""
color((255, 155, 192))
penup()
goto(x, y)
pendown()
setheading(0)
begin_fill()
circle(30)
end_fill()
def mouth(x, y):
"""Drawing mouth"""
color(239, 69, 19)
penup()
goto(x, y)
pendown()
setheading(-80)
circle(30, 40)
circle(40, 80)
def body(x, y):
'''Draw the body'''
penup()
goto(x, y)
pencolor('red')
fillcolor(250, 106, 106)
pendown()
begin_fill()
setheading(-66)
circle(-450, 17)
setheading(180)
forward(185)
setheading(85)
circle(-450, 17)
end_fill()
'''Right hand'''
penup()
goto(110, -45)
pendown()
pensize(8)
pencolor(255, 192, 203)
setheading(30)
circle(-400, 10)
penup()
goto(167, -5)
pendown()
setheading(-120)
forward(20)
left(100)
forward(20)
'''Left hand'''
penup()
goto(-25, -45)
pendown()
pencolor(255, 192, 203)
setheading(150)
circle(400, 10)
penup()
goto(-78, -6)
pendown()
setheading(-60)
forward(20)
right(100)
forward(20)
def feet1(x, y):
pensize(7)
pencolor(255, 192, 203)
penup()
goto(x, y)
setheading(-90)
pendown()
forward(10)
penup()
goto(x - 12, y - 10)
pendown()
pencolor(238, 201, 0)
fillcolor(238, 230, 132)
begin_fill()
setheading(0)
forward(24)
right(90)
forward(36)
right(90)
forward(40)
circle(-10, 180)
forward(16)
left(90)
forward(12)
end_fill()
def feet2(x, y):
pensize(7)
pencolor(255, 192, 203)
penup()
goto(x, y)
setheading(-90)
pendown()
forward(10)
penup()
goto(x - 12, y - 10)
pendown()
pencolor(238, 201, 0)
fillcolor(238, 230, 132)
begin_fill()
setheading(0)
forward(24)
right(90)
forward(36)
right(90)
forward(40)
circle(-10, 180)
forward(16)
left(90)
forward(12)
end_fill()
def tail(x, y):
pensize(8)
penup()
goto(x, y)
pendown()
pencolor(255, 192, 203)
setheading(-5)
circle(30, 100)
circle(10, 180)
circle(20, 150)
def backg(x):
penup()
goto(-420, x)
setheading(0)
fillcolor(50, 205, 50)
begin_fill()
forward(840)
right(90)
forward(300)
right(90)
forward(840)
right(90)
forward(300)
end_fill()
setheading(0)
fillcolor(0, 191, 255)
begin_fill()
forward(840)
left(90)
forward(600)
left(90)
forward(840)
left(90)
forward(600)
end_fill()
def cloude1(x, y):
""" """
penup()
goto(x, y)
setheading(90)
fillcolor(255, 255, 255)
begin_fill()
a = 0.4
for i in range(120):
if 0 <= i < 30 or 60 <= i < 90:
a = a + 0.14
# Turn left 3 degrees
left(3)
# Move forward
forward(a)
else:
a = a - 0.15
left(3)
forward(a)
end_fill()
def cloude2(x, y):
""" """
penup()
goto(x, y)
setheading(90)
fillcolor(255, 255, 255)
begin_fill()
a = 0.4
for i in range(120):
if 0 <= i < 30 or 60 <= i < 90:
a = a + 0.15
# Turn left 3 degrees
left(3)
# Move forward
forward(a)
else:
a = a - 0.13
left(3)
forward(a)
end_fill()
def setting():
"""Setting parameters"""
pensize(5)
# Hide turtle
hideturtle()
colormode(255)
color((255, 155, 192), "pink")
setup(840, 700)
speed(10)
def main():
"""Main function"""
setting()
backg(0)
body(105, -20)
nose(-100, 100)
head(-69, 167)
ears(0, 160)
eyes(0, 140)
cheek(80, 10)
mouth(-20, 30)
feet1(10, -150)
feet2(90, -150)
tail(130, -110)
cloude1(-200, 200)
cloude2(300, 300)
done()
if __name__ == '__main__':
main()
8. COLORED LIGHT SPHERE
import turtle as t
import random
t.speed('fast')
t.hideturtle()
t.bgcolor('black')
i = 0
temp = ''
colors = ['blue', 'red', 'yellow', 'green', 'cyan', 'purple','white', 'orange', 'brown']
while i < 180:
rand_color = random.choice(colors)
while rand_color == temp:
rand_color = random.choice(colors)
t.pencolor(rand_color)
t.penup()
t.goto(0, 0)
t.forward(100)
t.pendown()
if i % 2 == 0:
t.forward(300)
else:
t.forward(200)
t.left(2)
i += 1
temp = rand_color
9. SPRING COLOR TUNNEL
import turtle as t
import random
t.speed('fast')
t.hideturtle()
t.bgcolor('black')
i = 0
while i < 135:
t.pencolor('cyan')
t.penup()
t.goto(0, 0)
t.forward(200)
t.pendown()
t.circle(100)
t.left(2)
i += 1
10. LAYER CAKE CHALLENGE
from turtle import *
from shapes import *
# another shape.py
myPen = Turtle()
myPen.shape("turtle")
myPen.speed(10)
myPen.hideturtle()
window = turtle.Screen()
window.bgcolor("#69D9FF")
y = -140
#Inititalise the dictionary
ingredients = {}
#Add items to the dictionary
ingredients["strawberry"]="pink"
ingredients["milk chocolate"]="#BF671F"
ingredients["matcha"]="#93c572"
ingredients["icing sugar"]="#FFFFFF"
### Now let's preview the layer cake
#let's draw the plate
draw_rectangle(turtle, "white", -150, y-10, +300, 10)
#Iterate through each layer of the list
draw_rectangle(myPen, ingredients["milk chocolate"], -120, y, 240, 30)
y+=30
draw_rectangle(myPen, ingredients["strawberry"], -120, y, 240, 35)
y+=35
addIcing(myPen, ingredients["icing sugar"],120,y)
y+=10
draw_rectangle(myPen, ingredients["milk chocolate"], -100, y, 200, 20)
y+=20
draw_rectangle(myPen, ingredients["strawberry"], -100, y, 200, 40)
y+=40
addIcing(myPen, ingredients["icing sugar"],100,y)
y+=10
draw_rectangle(myPen, ingredients["milk chocolate"], -70, y, 140, 24)
y+=24
draw_rectangle(myPen, ingredients["strawberry"], -70, y, 140, 36)
y+=36
addIcing(myPen, ingredients["icing sugar"],70,y)
y+=10
draw_rectangle(myPen, ingredients["matcha"], -4, y, 8, 60)
y+=65
draw_star(myPen, "white", 2, y, 10)
PART 2: shapes.py
# This is a custom module we've made.
# Modules are files full of code that you can import into your programs.
# This one teaches our turtle to draw various shapes.
import turtle
import math
def draw_circle(turtle, color, x, y, radius):
turtle.penup()
turtle.color(color)
turtle.fillcolor(color)
turtle.goto(x,y)
turtle.pendown()
turtle.begin_fill()
turtle.circle(radius)
turtle.end_fill()
def draw_rectangle(turtle, color, x, y, width, height):
turtle.hideturtle()
turtle.penup()
turtle.color(color)
turtle.fillcolor(color)
turtle.goto(x,y)
turtle.pendown()
turtle.begin_fill()
for i in range (2):
turtle.forward(width)
turtle.left(90)
turtle.forward(height)
turtle.left(90)
turtle.end_fill()
turtle.setheading(0)
def draw_star(turtle, color, x, y, size):
turtle.penup()
turtle.color(color)
turtle.fillcolor(color)
turtle.goto(x,y)
turtle.pendown()
turtle.begin_fill()
turtle.right(144)
for i in range(5):
turtle.forward(size)
turtle.right(144)
turtle.forward(size)
turtle.end_fill()
turtle.setheading(0)
def addIcing(turtle,color,x,y):
turtle.penup()
turtle.color(color)
turtle.fillcolor(color)
turtle.goto(-x-2,y+10)
turtle.pendown()
turtle.begin_fill()
for z in range(-x-3,x+3):
turtle.goto(z,y-10-10*math.cos((z/100)*2*math.pi))
turtle.goto(x+3,y+10)
turtle.goto(-x-3,y+10)
turtle.end_fill()
11. CONFESSION
import turtle
import math
t = turtle.pen()
t = turtle
t.up()
t.goto(0, 150)
t.down()
t.color('red')
t.begin_fill()
t.fillcolor('red')
t.speed(1)
t.left(45)
t.forward(150)
t.right(45)
t.forward(100)
t.right(45)
t.forward(100)
t.right(45)
t.forward(100)
t.right(45)
t.forward(250 + math.sqrt(2) * 100)
t.right(90)
t.speed(2)
t.forward(250 + 100 * math.sqrt(2))
t.right(45)
t.forward(100)
t.right(45)
t.forward(100)
t.right(45)
t.forward(100)
t.right(45)
t.forward(150)
t.end_fill()
t.goto(-10, 0)
t.pencolor('white')
# L
t.pensize(10)
t.goto(-50, 0)
t.goto(-50, 80)
t.up()
# I
t.goto(-100, 0)
t.down()
t.goto(-160, 0)
t.goto(-130, 0)
t.goto(-130, 80)
t.goto(-160, 80)
t.goto(-100, 80)
t.up()
# O
t.goto(10, 25)
t.down()
t.right(45)
t.circle(25, extent=180)
t.goto(60, 55)
t.circle(25, extent=180)
t.goto(10, 25)
t.up()
t.goto(75, 80)
t.down()
t.goto(100, 0)
t.goto(125, 80)
t.up()
t.goto(180, 80)
t.down()
t.goto(140, 80)
t.goto(140, 0)
t.goto(180, 0)
t.up()
t.goto(180, 40)
t.down()
t.goto(140, 40)
# U
t.up()
t.goto(-40, -30)
t.down()
t.goto(-40, -80)
t.circle(40, extent=180)
t.goto(40, -30)
t.hideturtle()
12. LITTLE YELLOW MAN
import turtle
t = turtle.Turtle()
wn = turtle.Screen()
turtle.colormode(255)
t.hideturtle()
t.speed(10)
t.penup()
t.pensize(4)
t.goto(100, 0)
t.pendown()
t.left(90)
t.color((0, 0, 0), (255, 255, 0))
# Body painting coloring
t.begin_fill()
t.forward(200)
t.circle(100, 180)
t.forward(200)
t.circle(100, 180)
t.end_fill()
# Right eye drawing and coloring
t.pensize(12)
t.penup()
t.goto(-100, 200)
t.pendown()
t.right(100)
t.circle(500, 23)
t.pensize(3)
t.penup()
t.goto(0, 200)
t.pendown()
t.seth(270)
t.color("black", "white")
t.begin_fill()
t.circle(30)
t.end_fill()
t.penup()
t.goto(15, 200)
t.pendown()
t.color("black", "black")
t.begin_fill()
t.circle(15)
t.end_fill()
t.penup()
t.goto(35, 205)
t.color("black", "white")
t.begin_fill()
t.circle(5)
t.end_fill()
# Left eye drawing and coloring
t.pensize(3)
t.penup()
t.goto(0, 200)
t.pendown()
t.seth(90)
t.color("black", "white")
t.begin_fill()
t.circle(30)
t.end_fill()
t.penup()
t.goto(-15, 200)
t.pendown()
t.color("black", "black")
t.begin_fill()
t.circle(15)
t.end_fill()
t.penup()
t.goto(-35, 205)
t.color("black", "white")
t.begin_fill()
t.circle(5)
t.end_fill()
# Mouth draw coloring
t.penup()
t.goto(-20, 100)
t.pendown()
t.seth(270)
t.color("black", "white")
t.begin_fill()
t.circle(20, 180)
t.left(90)
t.forward(40)
t.end_fill()
# Pants draw color
t.penup()
t.goto(-100, 0)
t.pendown()
t.seth(0)
t.color("black", "blue")
t.begin_fill()
t.forward(20)
t.left(90)
t.forward(40)
t.right(90)
t.forward(160)
t.right(90)
t.forward(40)
t.left(90)
t.forward(20)
t.seth(270)
t.penup()
t.goto(-100, 0)
t.circle(100, 180)
t.end_fill()
# Left pants belt
t.penup()
t.goto(-70, 20)
t.pendown()
t.color("black", "blue")
t.begin_fill()
t.seth(45)
t.forward(15)
t.left(90)
t.forward(60)
t.seth(270)
t.forward(15)
t.left(40)
t.forward(50)
t.end_fill()
t.left(180)
t.goto(-70, 30)
t.dot()
# Right pants belt
t.penup()
t.goto(70, 20)
t.pendown()
t.color("black", "blue")
t.begin_fill()
t.seth(135)
t.forward(15)
t.right(90)
t.forward(60)
t.seth(270)
t.forward(15)
t.right(40)
t.forward(50)
t.end_fill()
t.left(180)
t.goto(70, 30)
t.dot()
# Feet
t.penup()
t.goto(4, -100)
t.pendown()
t.seth(270)
t.color("black", "black")
t.begin_fill()
t.forward(30)
t.left(90)
t.forward(40)
t.seth(20)
t.circle(10, 180)
t.circle(400, 2)
t.seth(90)
t.forward(20)
t.goto(4, -100)
t.end_fill()
t.penup()
t.goto(-4, -100)
t.pendown()
t.seth(270)
t.color("black", "black")
t.begin_fill()
t.forward(30)
t.right(90)
t.forward(40)
t.seth(20)
t.circle(10, -225)
t.circle(400, -3)
t.seth(90)
t.forward(21)
t.goto(-4, -100)
t.end_fill()
# Left hand
t.penup()
t.goto(-100, 50)
t.pendown()
t.seth(225)
t.color("black", "yellow")
t.begin_fill()
t.forward(40)
t.left(90)
t.forward(35)
t.seth(90)
t.forward(50)
t.end_fill()
# Right hand
t.penup()
t.goto(100, 50)
t.pendown()
t.seth(315)
t.color("black", "yellow")
t.begin_fill()
t.forward(40)
t.right(90)
t.forward(36)
t.seth(90)
t.forward(50)
t.end_fill()
#
t.penup()
t.goto(0, -100)
t.pendown()
t.forward(30)
#
t.penup()
t.goto(0, -20)
t.pendown()
t.color("yellow")
t.begin_fill()
t.seth(45)
t.forward(20)
t.circle(10, 180)
t.right(90)
t.circle(10, 180)
t.forward(20)
t.end_fill()
#
t.penup()
t.color("black")
t.goto(-100, -20)
t.pendown()
t.circle(30, 90)
t.penup()
t.goto(100, -20)
t.pendown()
t.circle(30, -90)
# Overhead
t.penup()
t.goto(2, 300)
t.pendown()
t.begin_fill()
t.seth(135)
t.circle(100, 40)
t.end_fill()
t.penup()
t.goto(2, 300)
t.pendown()
t.begin_fill()
t.seth(45)
t.circle(100, 40)
t.end_fill()
Python is an excellent choice for rapid prototyping of games. But it has limits with performance. Therefore for more resource-intensive games, you should consider the industry standard which is C# with Unity or C++ with Unreal. Some popular games like EVE Online and Pirates of the Caribbean were created using Python.
Comments
Post a Comment