/
P4ATest.pde
58 lines (52 loc) · 1.37 KB
/
P4ATest.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
/*
Processing for Android test
Context: Processing
*/
float ballX, ballY; // position of the ball
// file to save data for pause and resume:
String datafile = "sketchFile.dat";
void setup() {
// create a font for the screen:
String[]fontList = PFont.list();
PFont androidFont = createFont(fontList[0], 24, true);
textFont(androidFont, 24);
}
void draw() {
// color theme: Sandy stone beach ocean diver by ps
// http://kuler.adobe.com:
background(#002F2F);
fill(#EFECCA);
// show the mouse X and Y and finger pressure:
text("mouseX:" + mouseX, 10, 50);
text("mouseY:" + mouseY, 10, 80);
text("motionPressure:" + motionPressure, 10, 170);
// move the ball if the person is pressing:
if (mousePressed) {
ballX = mouseX;
ballY = mouseY;
}
// draw a nice blue ball where you touch:
fill(#046380);
ellipse(ballX, ballY, 50, 50);
}
void pause() {
// make a string of the ball position:
String ballPos = ballX+ "\n" + ballY;
/// put the string in an array and save to a file:
String[] data = {
ballPos
};
saveStrings(datafile, data);
}
void resume() {
//load the data file:
String[] data = loadStrings(datafile);
// if there's a file there:
if (data != null) {
// and there are two strings, get them for X and Y:
if (data.length > 1) {
ballX = float(data[0]);
ballY = float(data[1]);
}
}
}