Created
April 16, 2013 18:34
-
-
Save MightyThor/5398369 to your computer and use it in GitHub Desktop.
Simple graph
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#:kivy 1.5.1 | |
<MainView>: | |
newdot: graphdot | |
size: root.size | |
GraphDot: | |
center: 0, self.center_y | |
id: graphdot | |
<GraphDot>: | |
size: 20,20 | |
canvas: | |
Ellipse: | |
size: self.size | |
pos: self.center |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kivy | |
kivy.require('1.5.1') | |
from kivy.app import App | |
from kivy.clock import Clock | |
from kivy.uix.floatlayout import FloatLayout | |
from kivy.uix.widget import Widget | |
from kivy.properties import ObjectProperty, ReferenceListProperty, NumericProperty, ListProperty | |
from kivy.vector import Vector | |
from kivy.graphics import Color, Ellipse, Line | |
import math | |
class MainView(Widget): | |
newdot = ObjectProperty() | |
old_position = [0,0] | |
counter = 0.0 | |
def update(self,dt): | |
self.counter += 0.2 | |
new_point = [self.counter*5, 50*math.sin(self.counter) + self.height/2] | |
self.add_point(new_point) | |
def add_point(self, new_position): | |
self.newdot.center_y = new_position[1] | |
self.newdot.center_x = new_position[0] | |
position = self.old_position + new_position | |
self.old_position = new_position[:] | |
print position | |
with self.newdot.canvas: | |
Color(1,0,1) | |
self.line = Line(points=self.old_position + new_position, width=2) | |
if new_position[0] > self.width: | |
self.counter = 0.0 | |
self.old_position = [0,0] | |
self.canvas.clear() | |
class GraphDot(Widget): | |
pass | |
class SimpleGraphApp(App): | |
starting_point = [0,0] | |
def build(self): | |
parent = MainView() | |
Clock.schedule_interval(parent.update,1/5) | |
return parent | |
if __name__=='__main__': | |
SimpleGraphApp().run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment