Created
March 23, 2013 15:51
-
-
Save KristerV/5228168 to your computer and use it in GitHub Desktop.
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 random import random | |
from kivy.app import App | |
from kivy.uix.widget import Widget | |
from kivy.uix.button import Button | |
from kivy.graphics import Color, Ellipse, Line | |
class MyPaintWidget(Widget): | |
def on_touch_down(self, touch): | |
color = (random(), 1, 1) | |
with self.canvas: | |
Color(*color, mode='hsv') | |
d = 30. | |
Ellipse(pos=(touch.x - d / 2, touch.y - d / 2), size=(d, d)) | |
touch.ud['line'] = Line(points=(touch.x, touch.y), width = 30) | |
def on_touch_move(self, touch): | |
touch.ud['line'].points += [touch.x, touch.y] | |
class MyPaintApp(App): | |
def build(self): | |
parent = Widget() | |
painter = MyPaintWidget() | |
clearbtn = Button(text='Clear') | |
parent.add_widget(painter) | |
parent.add_widget(clearbtn) | |
def clear_canvas(obj): | |
painter.canvas.clear() | |
clearbtn.bind(on_release=clear_canvas) | |
return parent | |
if __name__ == '__main__': | |
MyPaintApp().run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment