Skip to content

Instantly share code, notes, and snippets.

@SpaceVoyager
Created August 14, 2015 11:58
Show Gist options
  • Save SpaceVoyager/d87bd3e6c7261a088826 to your computer and use it in GitHub Desktop.
Save SpaceVoyager/d87bd3e6c7261a088826 to your computer and use it in GitHub Desktop.
auto-rotate-test.py
# cannon clipart downloaded from
# http://www.clker.com/cliparts/7/9/9/b/1206570465701485742johnny_automatic_cannon_3.svg.med.png
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)
bottom_center = Point(self.bounds.w/2, 0)
self.layer = Layer(Rect(bottom_center.x - 64, bottom_center.y, 128, 128))
self.layer.image = '_cannon'
self.root_layer.add_layer(self.layer)
self.angle = 90
self.direction = 'counter_clock_wise'
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.40, 1.00, 0.80)
if self.angle > 180:
self.direction = 'clock_wise'
if self.angle < 0:
self.direction = 'counter_clock_wise'
if self.direction == 'counter_clock_wise':
self.angle += 1
else:
self.angle -= 1
self.layer.animate('rotation', self.angle, 1/60)
self.root_layer.update(self.dt)
self.root_layer.draw()
def touch_began(self, touch):
pass
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