Skip to content

Instantly share code, notes, and snippets.

@ssophwang
Created August 5, 2017 14:02
Show Gist options
  • Save ssophwang/d5b6cb61c922fabe59069e936eeaed28 to your computer and use it in GitHub Desktop.
Save ssophwang/d5b6cb61c922fabe59069e936eeaed28 to your computer and use it in GitHub Desktop.
lines.py
from scene import *
import ui
class MyScene (Scene):
def setup(self):
self.background_color = 'midnightblue'
self.points = []
self.point_size = 10
def touch_began(self, touch):
x, y = touch.location
this_point = ShapeNode(path=ui.Path.oval(0, 0, self.point_size, self.point_size), fill_color='white', stroke_color='clear')
this_point.position = (x , y)
self.add_child(this_point)
self.points.append((x, y))
line_path = ui.Path()
line_path.move_to(0,0)
line_path.line_to(-1000, 1000)
line_path.line_width = 5
# line_path.close()
test_line = ShapeNode(path=line_path, fill_color='white', stroke_color='red')
test_line.position = (x,y)
self.add_child(test_line)
# As a function:
#def button_tapped(sender):
# print 'button tapped'
view = SceneView()
view.scene = MyScene()
button = ui.Button(title = 'fit best line with gradient descent algorithm')
button.tint_color = (1.0, 1.0, 1.0)
button.corner_radius = 5
button.border_width = 1
button.border_color = (0.6, 0.6, 0.6)
button.width = 400
button.x = 300
button.y = 700
#button.action = button_tapped
view.add_subview(button)
view.present()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment