Permalink
Browse files

adding example yourapp

  • Loading branch information...
dennda committed Jul 6, 2011
1 parent dc5987e commit dcb00ea5de4e9d1d9496558510b4954a9c256358
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -0,0 +1,12 @@
+Touchtracer
+===========
+
+Touchtracer is a simple example to draw lines under every touches detected
+on your hardware.
+
+Android
+-------
+
+You can copy/paste this directory into /sdcard/kivy/touchtracer in your
+android device.
+
View
@@ -0,0 +1,3 @@
+title=Touchtracer
+author=Kivy team
+orientation=portrait
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -0,0 +1,83 @@
+print 'SETUP KIVY >>'
+from kivy.logger import Logger
+import logging
+Logger.setLevel(logging.DEBUG)
+
+from kivy.config import Config
+Config.remove_option('input', 'default')
+Config.remove_option('input', 'mactouch')
+Config.set('graphics', 'fullscreen', 'auto')
+print 'SETUP KIVY << done'
+
+
+try:
+ import kivy
+ kivy.require('1.0.6')
+
+ from kivy.app import App
+ from kivy.uix.floatlayout import FloatLayout
+ from kivy.graphics import Color, Rectangle, Point
+ from random import random
+ from math import sqrt
+
+
+ def calculate_points(x1, y1, x2, y2, steps=5):
+ dx = x2 - x1
+ dy = y2 - y1
+ dist = sqrt(dx * dx + dy * dy)
+ if dist < steps:
+ return None
+ o = []
+ m = dist / steps
+ for i in xrange(1, int(m)):
+ mi = i / m
+ lastx = x1 + dx * mi
+ lasty = y1 + dy * mi
+ o.extend([lastx, lasty])
+ return o
+
+
+ class Touchtracer(FloatLayout):
+
+ def on_touch_down(self, touch):
+ win = self.get_parent_window()
+ ud = touch.ud
+ ud['group'] = g = str(touch.uid)
+ with self.canvas:
+ ud['color'] = Color(random(), 1, 1, mode='hsv', group=g)
+ ud['lines'] = (
+ Rectangle(pos=(touch.x, 0), size=(1, win.height), group=g),
+ Rectangle(pos=(0, touch.y), size=(win.width, 1), group=g),
+ Point(points=(touch.x, touch.y), source='particle.png',
+ pointsize=5, group=g))
+
+ def on_touch_move(self, touch):
+ ud = touch.ud
+ ud['lines'][0].pos = touch.x, 0
+ ud['lines'][1].pos = 0, touch.y
+
+ points = ud['lines'][2].points
+ oldx, oldy = points[-2], points[-1]
+ points = calculate_points(oldx, oldy, touch.x, touch.y)
+ if points:
+ lp = ud['lines'][2].add_point
+ for idx in xrange(0, len(points), 2):
+ lp(points[idx], points[idx+1])
+
+ def on_touch_up(self, touch):
+ ud = touch.ud
+ self.canvas.remove_group(ud['group'])
+
+
+ class TouchtracerApp(App):
+ title = 'Touchtracer'
+ icon = 'icon.png'
+
+ def build(self):
+ return Touchtracer()
+
+ # if __name__ in ('__main__', '__android__'):
+ TouchtracerApp().run()
+except Exception, inst:
+ print 'caught:', inst
+ import traceback; traceback.print_exc()
View
@@ -0,0 +1,130 @@
+print 'SETUP KIVY >>'
+from kivy.logger import Logger
+import logging
+Logger.setLevel(logging.DEBUG)
+
+from kivy.config import Config
+Config.remove_option('input', 'default')
+Config.remove_option('input', 'mactouch')
+Config.set('graphics', 'fullscreen', 'auto')
+print 'SETUP KIVY << done'
+
+
+
+from kivy.graphics.opengl import *
+
+
+def buildShader(source, shaderType):
+ shaderHandle = glCreateShader(shaderType)
+ glShaderSource(shaderHandle, source)
+ glCompileShader(shaderHandle)
+
+ compileSuccess = glGetShaderiv(shaderHandle, GL_COMPILE_STATUS)
+
+ if compileSuccess == GL_FALSE:
+ messages = None
+ glGetShaderInfoLog(shaderHandle, sizeof(messages), 0, messages);
+ print 'error compiling shader', messages
+
+ return shaderHandle
+
+
+#struct Vertex {
+# float Position[2];
+# float Color[4];
+#};
+
+def render():
+ coords = [
+ -0.5, -0.866,
+ 0.5, -0.866,
+ 0, 1,
+ -0.5, -0.866,
+ 0.5, -0.866,
+ 0, -0.4
+ ]
+
+ colors = [
+ 1, 1, 0.5, 1,
+ 1, 1, 0.5, 1,
+ 1, 1, 0.5, 1,
+ 0.5, 0.5, 0.5,
+ 0.5, 0.5, 0.5,
+ 0.5, 0.5, 0.5
+ ]
+
+ glViewport(0, 0, 768, 1024)
+
+ vertexShader = buildShader("attribute vec4 Position; attribute vec4 SourceColor; varying vec4 DestinationColor; uniform mat4 Projection; uniform mat4 Modelview; void main(void) { DestinationColor = SourceColor; gl_Position = Projection * Modelview * Position; }", GL_VERTEX_SHADER)
+ fragmentShader = buildShader("varying lowp vec4 DestinationColor; void main(void) { gl_FragColor = DestinationColor; }", GL_FRAGMENT_SHADER)
+
+ m_simpleProgram = glCreateProgram()
+ glAttachShader(m_simpleProgram, vertexShader);
+ glAttachShader(m_simpleProgram, fragmentShader);
+ glLinkProgram(m_simpleProgram);
+
+ linkSuccess = glGetProgramiv(m_simpleProgram, GL_LINK_STATUS)
+ if linkSuccess == GL_FALSE:
+ infolog = glGetProgramInfoLog(m_simpleProgram)
+ print "error linking shader", infolog
+
+ glUseProgram(m_simpleProgram)
+
+ a = 1.0 / 2
+ b = 1.0 / 3
+ ortho = [
+ a, 0, 0, 0,
+ 0, b, 0, 0,
+ 0, 0, -1, 0,
+ 0, 0, 0, 1
+ ]
+
+
+ projectionUniform = glGetUniformLocation(m_simpleProgram, "Projection")
+# glUniformMatrix4fv(projectionUniform, 1, 0, ortho)
+ glUniformFoo(projectionUniform, 1., 1.)
+
+ zRotation = [
+ 1, 0, 0, 0,
+ 0, 1, 0, 0,
+ 0, 0, 1, 0,
+ 0, 0, 0, 1
+ ]
+
+ modelviewUniform = glGetUniformLocation(m_simpleProgram, "Modelview")
+# glUniformMatrix4fv(modelviewUniform, 1, 0, zRotation)
+ glUniformFoo(modelviewUniform, 2., 3.)
+
+ glClearColor(0.3, 0.4, 0.5, 1)
+ glClear(GL_COLOR_BUFFER_BIT)
+
+
+ positionSlot = glGetAttribLocation(m_simpleProgram, "Position")
+ colorSlot = glGetAttribLocation(m_simpleProgram, "SourceColor")
+
+ glEnableVertexAttribArray(positionSlot);
+ glEnableVertexAttribArray(colorSlot);
+
+ stride = 6
+
+ glVertexAttribPointer(positionSlot, 2, GL_FLOAT, GL_FALSE, 0, coords);
+ glVertexAttribPointer(colorSlot, 4, GL_FLOAT, GL_FALSE, 0, colors);
+
+ vertexCount = 6
+ glDrawArrays(GL_TRIANGLES, 0, vertexCount);
+
+ glDisableVertexAttribArray(positionSlot);
+ glDisableVertexAttribArray(colorSlot);
+
+
+while True:
+ from kivy.core.sdl import setup_window, poll, flip
+ from time import sleep
+
+ setup_window(768, 1024, False, True)
+
+ while True:
+ poll()
+ render()
+ flip()
+ sleep(1/60.)
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -0,0 +1,116 @@
+def server():
+ import code, socket, sys
+
+ server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ for port in range(5000, 5010):
+ try:
+ server_socket.bind(('', port))
+ print "bound to port", port
+ break
+ except socket.error:
+ pass
+ server_socket.listen(1)
+ client_socket, address = server_socket.accept()
+ print 'I got a connection from ', address
+
+ _stdout, _stderr = sys.stdout, sys.stderr
+
+ socketFile = client_socket.makefile('rw')
+ sys.stdout = sys.stderr = socketFile
+
+ def socket_input(prompt):
+ socketFile.write(prompt)
+ socketFile.flush()
+ return socketFile.readline().rstrip()
+
+ try:
+ code.interact(readfunc=socket_input, local=globals())
+ finally:
+ client_socket.close()
+
+
+print 'SETUP KIVY >>'
+from kivy.logger import Logger
+import logging
+Logger.setLevel(logging.DEBUG)
+
+from kivy.config import Config
+Config.remove_option('input', 'default')
+Config.remove_option('input', 'mactouch')
+Config.set('graphics', 'fullscreen', 'auto')
+print 'SETUP KIVY << done'
+
+
+try:
+ from kivy.uix.button import Button
+ from kivy.uix.widget import Widget
+ from kivy.uix.label import Label
+ from kivy.uix.boxlayout import BoxLayout
+ from kivy.app import App
+ from kivy.graphics import Color, Rectangle
+ from random import random as r
+ from functools import partial
+ from kivy.clock import Clock
+ from kivy.core.window import Window
+ from kivy.graphics.transformation import Matrix
+# Window.clearcolor = (0, 0, 1, 1)
+
+
+
+ class MatrixWidget(Widget):
+# deg = 0
+ def on_touch_up(self, touch):
+# mwm = Window.render_context['modelview_mat']
+# mwm.rotate(self.deg * 180. / 3.14, r(), r(), r())
+#
+# self.deg += 10
+
+ projection_mat = Matrix()
+# projection_mat.view_clip(0.0, Window.width, 0.0, Window.height, -100.0, 100.0, 0)
+ Window.render_context['projection_mat'] = projection_mat
+ print touch.pos
+
+ class StressCanvasApp(App):
+
+ def add_rects(self, *largs):
+ print 'adding_rects', '=' * 80
+ wid = self.wid
+ count = 1000
+ print 'adding', count, 'rects'
+ with wid.canvas:
+ for x in xrange(count):
+ Color(r(), 1, 1, mode='hsv')
+ Rectangle(pos=(r() * 100. - 50.,
+ r() * 100. - 50.), size=(100 * r(), 200 * r()))
+ def build(self):
+ print "building"
+ wid = MatrixWidget()
+ self.wid = wid
+ wid.pos = (-9999, -9999)
+ wid.size = (9999, 9999)
+ Clock.schedule_interval(self.add_rects, 0.5)
+
+
+
+ with Window.canvas:
+ Color(1, 0, 1, mode='hsv')
+ Rectangle(pos=(-10000, -10000), size=(20000, 20000))
+
+ return wid
+
+
+
+
+ if __name__ in ('__main__', '__android__'):
+ #TouchtracerApp().run()
+ StressCanvasApp().run()
+except Exception, inst:
+ import traceback
+ print 'caught exception', inst
+ traceback.print_exc()
+
+ server()
+
+
+'''
+'''
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -0,0 +1,26 @@
+#:kivy 1.0
+#:import kivy kivy
+
+<Touchtracer>:
+ canvas:
+ Color:
+ rgb: 1, 1, 1
+ Rectangle:
+ source: 'data/images/background.jpg'
+ size: self.size
+
+ BoxLayout:
+ padding: 10
+ spacing: 10
+ size_hint: 1, None
+ pos_hint: {'top': 1}
+ height: 24
+ Image:
+ size_hint: None, None
+ size: 24, 24
+ source: 'data/logo/kivy-icon-32.png'
+
+ Image:
+ size_hint: None, None
+ size: 24, 24
+ source: 'testpattern.png'
View
BIN icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit dcb00ea

Please sign in to comment.