Skip to content

Instantly share code, notes, and snippets.

View SpaceVoyager's full-sized avatar

Yuhang Wang SpaceVoyager

View GitHub Profile
# draws a bunch of Christmas trees
# writen by Yuhang Wang for A2PyKids
import canvas
from math import sin, cos, pi
# draws a star
def draw_star(x, y, inner_r, outer_r, jags):
canvas.set_fill_color(1,1,0.2)
canvas.move_to(x, y + outer_r)
s = 'bob is cool, really?'
print s
# An more interesting Pyhthonista 'Hello World' program
# Written by Yuhang Wang for A2PyKids
import console
import canvas
from random import random
import speech
# Ask for your name and then write it in random color on screen
canvas.set_size(1000, 600)
canvas.set_fill_color(random(), random(), random())
# Rabbit with a spining propeller
from scene import *
from random import random
class MyScene (Scene):
def setup(self):
# This will be called before the first frame is drawn.
# Set up the root layer and one other layer:
self.root_layer = Layer(self.bounds)
center = self.bounds.center()
@SpaceVoyager
SpaceVoyager / fathers day.py
Created June 13, 2015 20:47
fathers day.py
# Example father's day card with animation and sound
import canvas
import speech
from time import sleep
sleepfor = 0.1 # the number of seconds to sleep for
canvas.set_size(1000,600)
canvas.draw_image('_family', 0, 0, 1000, 600)
@SpaceVoyager
SpaceVoyager / draw_filled_semicircle.py
Created June 20, 2015 19:38
draw_filled_semicircle.py
import canvas
# This functions draws a filled semicircle with center at (center_x, center_y)
# and radius = radius
# Note that it actually draws 64 curve segments to approximate the semicircle
# You can use this function to draw the top part of a mushroom
def draw_filled_semicircle(center_x, center_y, radius):
import math
canvas.move_to(center_x-radius, center_y)
n = 64
@SpaceVoyager
SpaceVoyager / maddening circles.py
Created June 29, 2015 01:05
maddening circles.py
from scene import *
from random import random
class MyScene (Scene):
counter = 0
centers = []
radius = 30
def setup(self):
@SpaceVoyager
SpaceVoyager / draw-animals.py
Created July 18, 2015 19:54
draw-animals.py
from scene import *
class MyScene (Scene):
rabbit_centers = []
wolf_centers = []
def setup(self):
# This will be called before the first frame is drawn.
pass
@SpaceVoyager
SpaceVoyager / crazy bubbles.py
Created July 19, 2015 19:25
crazy bubbles.py
from scene import *
import math
from random import random
class MyScene (Scene):
circles = []
max_score = 0
game_began = False
@SpaceVoyager
SpaceVoyager / crazy bubbles 2.py
Created July 26, 2015 18:51
crazy bubbles 2.py
from scene import *
import math
from random import random
class MyScene (Scene):
circles = []
max_score = 0
game_began = False
speed = 1