11<!doctype html>
2-
32< html >
43< head >
5- < title > Draw Something</ title >
6-
7- < meta charset ="utf-8 ">
8-
9- < script type ="text/javascript " src ="../src/tracking.js "> </ script >
10- < script type ="text/javascript " src ="../src/tracker/color.js "> </ script >
11- < script type ="text/javascript " src ="js/splines.js "> </ script >
12-
13- < style type ="text/css ">
14- canvas {
15- -moz-transform : scale (-1 , 1 );
16- -o-transform : scale (-1 , 1 );
17- -webkit-transform : scale (-1 , 1 );
18- filter : FlipH;
19- transform : scale (-1 , 1 );
20- position : absolute;
21- top : 305px ;
22- left : 54px ;
23- }
24- # iphoneContainer {
25- width : 425px ;
26- height : 757px ;
27- margin : 0 auto;
28- position : relative;
29- background : url (img/iphone.png);
30- }
31- # selected {
32- width : 30px ;
33- height : 30px ;
34- border : 3px solid # 000 ;
35- border-radius : 7px ;
36- position : absolute;
37- display : none;
38- }
39- # selected .pencil {
40- bottom : 153px ;
41- display : block;
42- left : 73px ;
43- }
44- # selected .erase {
45- bottom : 153px ;
46- display : block;
47- left : 128px ;
48- }
49- </ style >
50- </ head >
51- < body >
524
53- < div id ="iphoneContainer ">
54- < div id ="selected "> </ div >
55- </ div >
56-
57- < script >
58- var videoCamera = new tracking . VideoCamera ( ) . hide ( ) . render ( ) . renderVideoCanvas ( '#iphoneContainer' ) ;
59-
60- var plotCanvas = new tracking . Canvas ( ) . render ( ) ,
61- drawSegments = [ ] ,
62- eraseFound = false ,
63- pencilFound = false ,
64- segment = 0 ,
65- selectedElement = document . getElementById ( 'selected' ) ;
66-
67- videoCamera . track (
68- {
69- type : 'color' ,
70- color : 'magenta' ,
71- onFound : function ( track ) {
72- if ( ! drawSegments [ segment ] ) {
73- drawSegments [ segment ] = [ ] ;
74- }
75-
76- drawSegments [ segment ] . push ( track . x , track . y ) ;
77-
78- if ( ! pencilFound ) {
79- selectedElement . className = 'pencil' ;
80- }
81-
82- pencilFound = true ;
83- } ,
84- onNotFound : function ( ) {
85- if ( pencilFound ) {
86- segment ++ ;
87- pencilFound = false ;
88- selectedElement . className = '' ;
89- }
5+ < title > tracking.js - draw something</ title >
6+
7+ < meta charset ="utf-8 ">
8+
9+ < script src ="../src/tracking.js "> </ script >
10+ < script src ="../src/tracker/color.js "> </ script >
11+ < script src ="js/splines.js "> </ script >
12+
13+ < style >
14+ canvas {
15+ -moz-transform : scale (-1 , 1 );
16+ -o-transform : scale (-1 , 1 );
17+ -webkit-transform : scale (-1 , 1 );
18+ filter : FlipH;
19+ transform : scale (-1 , 1 );
20+ position : absolute;
21+ top : 305px ;
22+ left : 54px ;
23+ }
24+ # iphoneContainer {
25+ width : 425px ;
26+ height : 757px ;
27+ margin : 0 auto;
28+ position : relative;
29+ background : url (img/iphone.png);
9030 }
91- }
92- ) ;
93-
94- videoCamera . track (
95- {
96- type : 'color' ,
97- color : 'cyan' ,
98- onFound : function ( track ) {
99- segment = 0 ;
100- drawSegments = [ ] ;
101-
102- if ( ! eraseFound ) {
103- selectedElement . className = 'erase' ;
104- }
105-
106- eraseFound = true ;
107- } ,
108- onNotFound : function ( ) {
109- if ( eraseFound ) {
110- eraseFound = false ;
111- selectedElement . className = '' ;
112- }
31+ # selected {
32+ width : 30px ;
33+ height : 30px ;
34+ border : 3px solid # 000 ;
35+ border-radius : 7px ;
36+ position : absolute;
37+ display : none;
11338 }
114- }
115- ) ;
116-
117- ( function loop ( ) {
118- for ( var i = 0 , len = drawSegments . length ; i < len ; i ++ ) {
119- drawSpline ( videoCamera . canvas . context , drawSegments [ i ] , 0.5 , false ) ;
120- }
121- requestAnimationFrame ( loop ) ;
122- } ( ) ) ;
123- </ script >
39+ # selected .pencil {
40+ bottom : 153px ;
41+ display : block;
42+ left : 73px ;
43+ }
44+ # selected .erase {
45+ bottom : 153px ;
46+ display : block;
47+ left : 128px ;
48+ }
49+ </ style >
50+
51+ </ head >
52+ < body >
53+
54+ < div id ="iphoneContainer ">
55+ < div id ="selected "> </ div >
56+ </ div >
57+
58+ < script >
59+ var videoCamera = new tracking . VideoCamera ( ) . hide ( ) . render ( ) . renderVideoCanvas ( '#iphoneContainer' ) ;
60+
61+ var plotCanvas = new tracking . Canvas ( ) . render ( ) ,
62+ drawSegments = [ ] ,
63+ eraseFound = false ,
64+ pencilFound = false ,
65+ segment = 0 ,
66+ selectedElement = document . getElementById ( 'selected' ) ;
67+
68+ videoCamera . track (
69+ {
70+ type : 'color' ,
71+ color : 'magenta' ,
72+ onFound : function ( track ) {
73+ if ( ! drawSegments [ segment ] ) {
74+ drawSegments [ segment ] = [ ] ;
75+ }
76+
77+ drawSegments [ segment ] . push ( track . x , track . y ) ;
78+
79+ if ( ! pencilFound ) {
80+ selectedElement . className = 'pencil' ;
81+ }
82+
83+ pencilFound = true ;
84+ } ,
85+ onNotFound : function ( ) {
86+ if ( pencilFound ) {
87+ segment ++ ;
88+ pencilFound = false ;
89+ selectedElement . className = '' ;
90+ }
91+ }
92+ }
93+ ) ;
94+
95+ videoCamera . track (
96+ {
97+ type : 'color' ,
98+ color : 'cyan' ,
99+ onFound : function ( track ) {
100+ segment = 0 ;
101+ drawSegments = [ ] ;
102+
103+ if ( ! eraseFound ) {
104+ selectedElement . className = 'erase' ;
105+ }
106+
107+ eraseFound = true ;
108+ } ,
109+ onNotFound : function ( ) {
110+ if ( eraseFound ) {
111+ eraseFound = false ;
112+ selectedElement . className = '' ;
113+ }
114+ }
115+ }
116+ ) ;
117+
118+ ( function loop ( ) {
119+ for ( var i = 0 , len = drawSegments . length ; i < len ; i ++ ) {
120+ drawSpline ( videoCamera . canvas . context , drawSegments [ i ] , 0.5 , false ) ;
121+ }
122+ requestAnimationFrame ( loop ) ;
123+ } ( ) ) ;
124+ </ script >
124125
125126</ body >
126127</ html >
0 commit comments