-
Notifications
You must be signed in to change notification settings - Fork 0
/
mouseRecord.pde
130 lines (88 loc) · 2.19 KB
/
mouseRecord.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import java.awt.MouseInfo;
import java.awt.Point;
import java.util.*;
PrintWriter output;
PGraphics Trail;
float WinScale = 0.4;
boolean PressedOnce = false;
boolean StoreInFile = true;
Sample LastSample;
int counter;
class Sample {
int x;
int y;
long time;
Sample( int ix, int iy, long iTime ) {
x = ix;
y = iy;
time = iTime;
}
}
void setup() {
size(int(1920*2*WinScale), int(1200*WinScale));
colorMode( RGB, 1);
frameRate(30);
Trail = createGraphics( width, height );
Trail.beginDraw();
Trail.colorMode( RGB, 1);
Trail.blendMode(ADD);
Trail.endDraw();
Date d = new Date();
long t = d.getTime();
String fileName=(new Long(t)).toString();
fileName = "out/" + fileName + ".txt";
if( StoreInFile ) {
println( "Saving Output : " + fileName);
output = createWriter(fileName);
}
LastSample = new Sample(0,0,t);
counter = 0;
}
void draw() {
background(0);
Point mouse;
mouse = MouseInfo.getPointerInfo().getLocation();
Date d = new Date();
long t = d.getTime();
String tStr=(new Long(t)).toString();
Sample sample = new Sample(mouse.x, mouse.y, t);
if( LastSample.x != sample.x || LastSample.y != sample.y ) {
Trail.beginDraw();
Trail.stroke(0.1);
Trail.line( sample.x*WinScale, sample.y*WinScale, LastSample.x*WinScale, LastSample.y*WinScale);
Trail.endDraw();
if( StoreInFile ) {
output.println(mouse.x + " " + mouse.y + " " + t);
counter ++;
}
}
image( Trail, 0, 0 );
LastSample = sample;
fill(1,0,0);
text( mouse.x, 10, 20 );
text( mouse.y, 50, 20 );
text( tStr, 100, 20 );
text( frameRate, width-50, 20 );
text( counter, 10, height-20 );
}
void saveImg() {
Date d = new Date();
long t = d.getTime();
String filename=(new Long(t)).toString();
filename = "out/"+ filename + ".jpg";
Trail.save(filename);
}
void keyPressed(){
if (key=='s'){
saveImg();
}
if (key=='q'){
if( StoreInFile ){
output.flush(); // Write the remaining data
output.close(); // Finish the file
println( "Closing output and quiting" );
}
saveImg();
exit(); // Stop the program
}
}