Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
74 lines (60 sloc) 2.61 KB
# must be installed to use this. Due to monitor driver compatibility reasons windows computers worked best for my testing. Testing was completed with a Planar Helium PCT2785 27" monitor.
# Everytime the touchscreen is pressed draw a random colored square and send the x & y percentages to the web server.
import kivy
import urllib.request
from import App
from kivy.uix.widget import Widget
from import NumericProperty, ReferenceListProperty,\
from kivy.vector import Vector
from kivy.clock import Clock
from kivy.core.window import Window
import json
from import *
from kivy.config import Config
from random import randint
import datetime as dt
class RawCord(Widget):
already_published = []
def was_point_already_published(self,x,y):
tmp_set = [x,y]
if tmp_set in self.already_published:
return True
if self.was_similar_point_already_published(x,y):
return True
return False
def was_similar_point_already_published(self,x,y):
tolerance = float(0.03)
for tmp_set in self.already_published:
if float(tmp_set[0]) > (float(x) * (1 - tolerance)) and float(tmp_set[0]) < (float(x) * (1 + tolerance)) and float(tmp_set[1]) > (float(y) * (1 - tolerance)) and float(tmp_set[1]) < (float(y) * (1 + tolerance)):
return True
return False
def on_touch_down(self, touch):
with self.canvas:
Color(float(randint(3,10)/10), float(randint(3,10)/10), float(randint(3,10)/10))
#I've yet to figure out why but by touch.y values are 1 cm higher than the actual touch. My screen is 33.5 cm tall. Therefore I am subtracting 1 cm worth of pixels from touch.y
adjusted_y = float(touch.y) - (1.0/33.5*float(windowsize_height()))
square_size = 300
x_per = float(touch.x) / float(windowsize_width())
y_per = float(touch.y) / float(windowsize_height())
if not self.was_point_already_published(x_per,y_per):
Rectangle(pos=(touch.x - (square_size/2),adjusted_y - (square_size/2)), size=(square_size,square_size))
with urllib.request.urlopen('' + str(x_per) + '&touch_api_y=' + str(y_per) + '&touch_api_type=1') as response:
html =
class RawCordApp(App):
def build(self):
g = RawCord()
Window.size = (windowsize_width(), windowsize_height())
Window.clearcolor = (1, 1, 1, 1)
return g
def windowsize_width():
return 1600
def windowsize_height():
return 900
if __name__ == '__main__':
Window.fullscreen = True