<jupyter_start><jupyter_text>Python Tutorial 3 Flappy Turtle Tzer-jen Wei<jupyter_code>from turtle import *
screensize(216, 500)
setup(288, 512)
import glob
glob.glob("*.gif")
for f in glob.glob("*.gif"):
    addshape(f)
shape("bird2.gif")
up()
speed(0)<jupyter_output><empty_output><jupyter_text>Add a background<jupyter_code>bgpic("bg1.gif")<jupyter_output><empty_output><jupyter_text>Try main loop<jupyter_code>mainloop()<jupyter_output><empty_output><jupyter_text>Add a exit key<jupyter_code>onkey(bye, 'q')
listen()
mainloop()<jupyter_output><empty_output><jupyter_text>put everything together<jupyter_code>from turtle import *
import glob
def turtle_setup():
    screensize(216, 500)
    setup(288, 512)
    for f in glob.glob("*.gif"):
        addshape(f)
    shape("bird2.gif")
    up()
    speed(0)
    bgpic("bg1.gif")
    onkey(bye, 'q')
    listen()<jupyter_output><empty_output><jupyter_text>Update Bird Fly Animation<jupyter_code>from time import time       
turtle_setup()
start_time = time()
def update():
    t = time() - start_time
    shape("bird%d.gif" % abs(int(t * 4) % 4 - 1))
    ontimer(update, 10)
update()
mainloop()<jupyter_output><empty_output><jupyter_text>Put into a class<jupyter_code>from time import time
class Game:
    def __init__(self):
        turtle_setup()
        self.start_time = time()
        self.update()        
        mainloop()
    def update(self):
        t = time() - self.start_time
        shape("bird%d.gif" % abs(int(t * 4) % 4 - 1))
        ontimer(self.update, 10)
game = Game()<jupyter_output><empty_output><jupyter_text>Let the bird fly<jupyter_code>from math import sin
def update(self):
    t = time() - self.start_time
    goto(0, 50*sin(t))
    shape("bird%d.gif" % abs(int(t * 4) % 4 - 1))
    ontimer(self.update, 10)
Game.update = update
game = Game()
turtle_setup()
shape('ground.gif')
def GIFTurtle(fname):
    t = Turtle(fname + ".gif")
    t.speed(0)
    t.up()
    return t
from time import time
from math import sin
bg_width = 286
class Game:
    def __init__(self):
            turtle_setup()
            self.grounds = [GIFTurtle("ground") for i in range(3)]
            self.start_time = time()
            self.update()             
            mainloop()
    def update(self):
        t = time() - self.start_time
        goto(0, 50*sin(t))
        shape("bird%d.gif" % abs(int(t * 4) % 4 - 1))
        x = int(t * 100)
        bg_base = -(x % bg_width)
        for i in range(3):
            self.grounds[i].goto(bg_base + bg_width * (i - 1), -200)
        ontimer(self.update, 10)
Game()
%run flappybird.py
%load flappybird.py<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14513073133762788, 'fraction_numerical': 0.026525198938992044, 'mean_word_length': 3.306688417618271, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '91004', 'license': 'MIT', 'n_tokens_mistral': 1049, 'n_tokens_neox': 976, 'n_words': 204, 'path': 'Tutorial 2.ipynb', 'repo_name': 'tjwei/PythonTutorial', 'size': '2639'}