Created
January 24, 2017 15:32
-
-
Save brvier/1b0a875613c60f656084bef93662bd70 to your computer and use it in GitHub Desktop.
Kivy Experimental not working unfinished radargraph
This file contains 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
from math import cos, sin, pi | |
from kivy.app import App | |
from kivy.uix.widget import Widget | |
from kivy.graphics import Color, Ellipse, Line, Mesh | |
from kivy.properties import ListProperty | |
from kivy.clock import Clock | |
import itertools | |
import random | |
class RadarGraph(Widget): | |
datas = ListProperty() | |
def __init__(self,): | |
Widget.__init__(self, ) | |
self.bind(datas=self.redraw) | |
Clock.schedule_once(self.on_touch_down, 1) | |
def on_touch_down(self, touch): | |
self.datas = [random.random() for i in range(5)] | |
def redraw(self, *args): | |
if len(self.datas) < 0: | |
return | |
self.canvas.clear() | |
angle = 2*pi / len(self.datas) | |
rayon = min(self.center_x * 0.9, self.center_y * 0.9) | |
with self.canvas: | |
Color(.9, .9, .9) | |
for idx in range(len(self.datas)): | |
x = self.center_x + rayon*cos(angle*idx) | |
y = self.center_y + rayon*sin(angle*idx) | |
Line(points=[self.center_x, self.center_y, x, y], width=1.0) | |
Color(0, 1., 0) | |
Line(points=list(itertools.chain.from_iterable( | |
[(self.center_x + rayon*val * cos(angle*idx), | |
self.center_y + rayon*val * sin(angle*idx)) | |
for idx, val in enumerate(self.datas)])), width=1.0, close=True) | |
Color(0, 1., 0, 0.5) | |
Mesh(vertices=list(itertools.chain.from_iterable( | |
[(self.center_x + rayon*val * cos(angle*idx), | |
self.center_y + rayon*val * sin(angle*idx),0,0) | |
for idx, val in enumerate(self.datas)])), | |
indices=range(len(self.datas)), | |
mode='triangle_fan') | |
print(list(itertools.chain.from_iterable( | |
[(self.center_x + rayon*val * cos(angle*idx), | |
self.center_y + rayon*val * sin(angle*idx)) | |
for idx, val in enumerate(self.datas)]))) | |
class TestRadarGraphApp(App): | |
def build(self): | |
return RadarGraph() | |
if __name__ == '__main__': | |
TestRadarGraphApp().run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment