Skip to content

Instantly share code, notes, and snippets.

@SpaceVoyager
Created June 9, 2015 11:47
Show Gist options
  • Save SpaceVoyager/096276149007cc41df42 to your computer and use it in GitHub Desktop.
Save SpaceVoyager/096276149007cc41df42 to your computer and use it in GitHub Desktop.
xiaobaitu.py
# 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()
self.body = Layer(Rect(center.x -200, center.y -300, 400, 400))
# self.body.background = Color(1, 0, 0)
self.body.image = 'Rabbit_Face'
self.root_layer.add_layer(self.body)
self.ear = Layer(Rect(100, 200, 200, 200))
self.ear.image = '_propeller'
self.body.add_layer(self.ear)
self.angle = 0
def draw(self):
# Update and draw our root layer. For a layer-based scene, this
# is usually all you have to do in the draw method.
background(0, 0, 0)
self.root_layer.update(self.dt)
self.root_layer.draw()
def touch_began(self, touch):
self.angle += 720
# Animate the layer to the location of the touch:
x, y = touch.location.x, touch.location.y
new_frame = Rect(x - 200, y - 200, 400, 400)
self.body.animate('frame', new_frame, 1.0, curve=curve_bounce_out)
self.ear.animate('rotation', self.angle)
def touch_moved(self, touch):
pass
def touch_ended(self, touch):
pass
run(MyScene())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment