Skip to content

Instantly share code, notes, and snippets.

@MightyThor
Created April 16, 2013 17:35
Show Gist options
  • Save MightyThor/5397880 to your computer and use it in GitHub Desktop.
Save MightyThor/5397880 to your computer and use it in GitHub Desktop.
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 += 1
new_point = [self.counter, self.old_position[1] + 50*math.sin(self.counter)]
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]
graphing = GraphDot()
graphing.add_line(new_position)
if self.counter > self.width:
self.counter = 0.0
self.old_position = [0,0]
self.canvas.clear()
class GraphDot(Widget):
graph = ObjectProperty()
def add_line(self, coords):
self.theline(points = (coords[0], coords[1]))
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()
#:kivy 1.5.1
<MainView>:
newdot: graphdot
GraphDot:
id: graphdot
<GraphDot>:
size: 20,20
canvas:
Ellipse:
size: self.size
pos: self.center
Line:
id: theline
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment