controlp5 timeslider screen coords help
in
Contributed Library Questions
•
1 year ago
hi guys
any chance of some help with this code its almost working but not quite right
the coordinates plot to screen, the slider has some functionality but doesn't scroll through the plot forwards backwards
our pause.The plotting only changes the colour of ellipse when pause is pushed and that is accidental
any pointers are appreciated
kenb93
/**
* LoadFile 1
*
* Loads a text file that contains two numbers separated by a tab ('\t').
* A new pair of numbers is loaded each frame and used to draw a point on the screen.
*/
import controlP5.*;
ControlP5 controlP5;
int time;
boolean playPause = true; // true = play, false = pause
void play() { playPause = !playPause; } // toggle
String[] lines;
int index = 0;
void setup() {
size(400, 400);
background(0);
stroke(255);
frameRate(12);
lines = loadStrings("mytestlines3.txt");
smooth();
controlP5 = new ControlP5(this);
controlP5.addSlider("time",0,width,10,height-30,width-75,20);
controlP5.addButton("play",0,width-40,height-30,30,20);
}
void draw() {
if (playPause) { time++; controlP5.controller("play").setLabel("Pause"); }
else { controlP5.controller("play").setLabel("Play"); }
if (time >= width) { time = 0; } // reset when right side is reached (only useful for this particular sketch)
controlP5.controller("time").setValue(time); // set the slider to time value
//randomSeed(1); // controls the randomness, to get the same output every time
for (int i=index; i<time; i++) { // the time variable controls the output
float c = map(i,0,time,0,255);
fill(255,255,255);
// ellipse(i%width,random(height),40,40);
}
if (index < lines.length) {
String[] pieces = split(lines[index], '\t');
if (pieces.length == 2) {
int x = int(pieces[0]) * 2;
int y = int(pieces[1]) * 2;
beginShape();
ellipse(x, y,5,5);
endShape();
}
// Go to the next line for the next run through draw()
index = index + 1;
}
}
mytestlines3.txt
8
90
8
90
8
90
8
90
8
90
8
90
8
90
8
90
8
90
9
90
14
90
18
91
21
92
25
92
28
92
29
91
32
91
34
91
37
91
40
91
44
91
45
93
45
93
45
93
45
93
45
93
45
93
45
93
45
93
46
93
52
94
58
94
64
94
68
94
73
94
78
94
83
94
86
96
87
97
87
97
87
97
87
97
87
97
87
97
87
97
89
97
92
97
96
97
102
97
106
97
110
96
113
95
117
94
119
94
119
94
119
94
119
94
119
94
119
94
119
94
119
94
122
95
126
96
132
97
138
97
144
97
148
97
152
97
156
99
156
99
156
99
156
99
156
99
156
99
156
99
156
99
156
99
156
99
159
99
163
98
167
98
170
97
173
97
174
97
176
96
177
95
177
95
177
95
177
95
177
95
177
95
177
95
177
95
179
87
180
81
181
71
181
65
181
61
181
59
180
55
180
54
180
52
179
51
179
49
179
49
179
49
179
49
179
49
179
49
179
49
179
49
178
46
171
44
166
43
161
41
155
38
149
37
146
36
143
36
140
36
137
36
137
36
137
36
137
36
137
36
137
36
137
36
135
35
130
34
126
34
123
33
119
33
116
33
111
33
106
33
101
34
95
35
94
35
94
35
94
35
94
35
94
35
94
35
87
35
82
32
77
30
74
30
71
30
67
30
62
29
56
29
53
29
50
29
47
30
45
31
45
31
43
31
42
31
42
31
42
31
42
31
42
31
42
31
42
31
42
31
1