Skip to content

Instantly share code, notes, and snippets.

@msh9
Last active August 29, 2015 13:58
Show Gist options
  • Save msh9/9966998 to your computer and use it in GitHub Desktop.
Save msh9/9966998 to your computer and use it in GitHub Desktop.
Rotating
<MyGame>:
FloatLayout:
size: self.parent.width, self.parent.height
MyWidget:
id: widget
pos_hint: {'x': 0, 'y': .5 }
<MyWidget>:
canvas.before:
PushMatrix
Rotate:
angle: self.angle
axis: 0, 0, 1
origin: self.x, self.y
canvas:
Ellipse:
pos: self.x + 10, self.y - 5
size: 30, 10
canvas.after:
PopMatrix
Ellipse:
pos: self.x - 10, self.y - 10
size: 20, 20
__author__ = 'michael hughes'
import kivy
# require at least kivy 1.8
kivy.require('1.8.0')
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.properties import NumericProperty
import math
class MyWidget(Widget):
angle = NumericProperty(0)
def on_touch_down(self, touch):
radians = math.atan2(touch.y - self.parent.center_y, touch.x)
self.angle = math.degrees(radians)
class MyGame(Widget):
pass
class MyApp(App):
def build(self):
"""Build creates the root game object
and starts it
"""
game = MyGame()
return game
if __name__ == '__main__':
MyApp().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment