Login   Register  
Icontem

File: app.js

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Arturs Sosins  >  Titanium Gestures  >  app.js  >  Download  
File: app.js
Role: Example script
Content type: text/plain
Description: Example using Gesture module
Class: Titanium Gestures
Recognize touch gesture shapes using Titanium
Author: By
Last change:
Date: 2012-06-18 14:02
Size: 2,681 bytes
 

Contents

Class file image Download
/*************************************************************
 * This script is developed by Arturs Sosins aka ar2rsawseen, http://appcodingeasy.com
 * Feel free to distribute and modify code, but keep reference to its creator
 *
 * Gestures module provides a way to define and detect gestures. 
 * You can define your own gestures, by providing array of points, 
 * that defines shape and provide callback function for each shape.
 *
 * For more information, examples and online documentation visit: 
 * http://appcodingeasy.com/Titanium-Mobile/Titanium-Gesture-recognition
**************************************************************/

var win = Titanium.UI.createWindow({  
    title:'Gestures example',
    backgroundColor:'#000',
    width: "100%",
    heiht: "100%",
    top: 0,
    left: 0,
    modal: true,
    exitOnClose: true
});

var label = Titanium.UI.createLabel({
	color:'#fff',
	text:"Try to draw line, square, rectangle, zigzag, triangle, equilateral triangle, check or circle.",
	top: 20,
	font:{fontSize:20,fontFamily:'Helvetica Neue'},
	textAlign:'center',
	width:'auto'
});

win.add(label);

var result = Titanium.UI.createLabel({
	color:'#fff',
	text:"Result: ",
	top: 100,
	font:{fontSize:20,fontFamily:'Helvetica Neue'},
	textAlign:'center',
	width:'auto'
});

win.add(result);

var callback = function(name){
	result.setText("Result: " + name);
};

//create countdown
var Gestures = require('Gestures');

var gest = new Gestures(win, {
	autoTrack: true,
	allowRotation: true,
	inverseShape: true,
	points: 33
});

gest.addGesture("Line", [
	{x: 0, y: 0},
	{x: 0, y: 100}
], callback);

gest.addGesture("Square", [
	{x: 0, y: 0},
	{x: 200, y: 0},
	{x: 200, y: 200},
	{x: 0, y: 200},
	{x: 0, y: 0}
], callback);

gest.addGesture("Rectangle", [
	{x: 0, y: 0},
	{x: 210, y: 0},
	{x: 210, y: 100},
	{x: 0, y: 100},
	{x: 0, y: 0}
], callback);

gest.addGesture("ZigZag", [
	{x: 0, y: 0},
	{x: 50, y: 87},
	{x: 100, y: 0},
	{x: 150, y: 87}
], callback);

gest.addGesture("Triangle", [
	{x: 0, y: 0},
	{x: 100, y: 100},
	{x: 0, y: 100},
	{x: 0, y: 0}
], callback);

gest.addGesture("Equilateral Triangle", [
	{x: 0, y: 0},
	{x: 50, y: 87},
	{x: 100, y: 0},
	{x: 0, y: 0}
], callback);

gest.addGesture("Check", [
	{x: 0, y: 0},
	{x: 50, y:100},
	{x: 100, y: 0},
], callback);

var x = 0;
var y = -100;
var circle = [];
var totalPoints = 72;
var step = (Math.PI*2)/totalPoints;

for(var angle = 1; angle < totalPoints; angle++)
{
	var newX = x*Math.cos(angle*step)-y*Math.sin(angle*step);
	var newY = y*Math.cos(angle*step)+x*Math.sin(angle*step);
	var point = {x: newX, y: newY};
	circle.push(point);
}

gest.addGesture("Circle", circle, callback)
win.open();