Loading...
Processing Forum
Recent Topics
All Forums
Screen name:
elbucho
elbucho's Profile
1
Posts
0
Responses
0
Followers
Activity Trend
Last 30 days
Last 30 days
Date Interval
From Date :
To Date :
Go
Loading Chart...
Posts
Responses
PM
Show:
All
Discussions
Questions
Expanded view
List view
Private Message
Skip to number with ease/tween
[1 Reply]
25-Mar-2013 02:22 AM
Forum:
Programming Questions
Hello there dear people of Processing.
I'm now at my 4th day of learning Processing.
After a few brainbusters I've come to a point where I need your help.
I'm currently working on a test model of an idea that I have.
My goal is is have a step motor turning, with 8 magnets or rfid chips on the side.
This will be read by a sensor. This sensor will tell the software at what degrees (0, 45, 90, 135 etc) the step motor is.
The software will then adjust the movie to to right frame, according to the degrees of the step motor.
I've copy and pasted serval examples together and I've achieved some parts of it.
For now, the hardware part is just a press of the keyboard.
And instead of the movie, I have a timer.
But here's my problem. When the magnet passed the sensor (keyPressed),
the current frame will be skipped to the right number.
So you will have a cut in the movie(which is a timer for now).
I want to achieve a speed up or slow down to adjust to the correct frame.
I think this is possible by tweening or easing, but I don't know how to implement this.
Underneath is my code. I hope this and my question makes any sense to you. If not, tell me.
If you have any tips on making this work, please let me know.
El Bucho
///////////////////
///ElBucho////////
//////////////////
int actualSecs; //actual seconds elapsed since start
int startSec = 0 ; //used to reset seconds shown on screen to 0
int scrnSecs; //seconds displayed on screen (will be 0-360)
int restartSecs; //number of seconds elapsed at last click or 360 sec interval
int totalSec = 360; // total seconds
void setup() {
size(600, 500);
smooth();
PFont font;
font = createFont("Arial", 72); // Arial, 16 point, anti-aliasing on
textFont(font, 72);
}
void draw() {
background(0);
////////////////////////////////////
//*this section is the "mathy" part*//
////////////////////////////////////
actualSecs = millis()/50; //converts to timer.
scrnSecs = actualSecs - restartSecs; //seconds to be shown on screen
//the skip part
if ((scrnSecs) >= 338 && (scrnSecs) <= 359 ||(scrnSecs) >= 0 && (scrnSecs) <= 22) { //range 1 skip to 0 degrees
if (keyPressed) {
restartSecs = actualSecs - 0;
scrnSecs = 0;
}
}
if ((scrnSecs) >= 23 && (scrnSecs) <= 67) { //range 2 skip to 45 degrees
if (keyPressed) {
restartSecs = actualSecs - 45;
scrnSecs = 45;
}
}
if ((scrnSecs) >= 68 && (scrnSecs) <= 112) { //range 3 skip to 90 degrees
if (keyPressed) {
restartSecs = actualSecs - 90;
scrnSecs = 90;
}
}
if ((scrnSecs) >= 113 && (scrnSecs) <= 157) { //range 4 skip to 135 degrees
if (keyPressed) {
restartSecs = actualSecs - 135;
scrnSecs = 135;
}
}
if ((scrnSecs) >= 158 && (scrnSecs) <= 202) { //range 5 skip to 180 degrees
if (keyPressed) {
restartSecs = actualSecs - 180;
scrnSecs = 180;
}
}
if ((scrnSecs) >= 203 && (scrnSecs) <= 247) { //range 6 skip to 225 degrees
if (keyPressed) {
restartSecs = actualSecs - 225;
scrnSecs = 225;
}
}
if ((scrnSecs) >= 248 && (scrnSecs) <= 292) { //range 7 skip to 270 degrees
if (keyPressed) {
restartSecs = actualSecs - 270;
scrnSecs = 270;
}
}
if ((scrnSecs) >= 293 && (scrnSecs) <= 337) { //range 8 skip to 315 degrees
if (keyPressed) {
restartSecs = actualSecs - 315;
scrnSecs = 315;
}
}
// the text part
if ((scrnSecs) >= 0 && (scrnSecs) <= 22) { //range 1 skip to 0 degrees
text("1, 0-22 0*", width/2,height/4);
}
if ((scrnSecs) >= 23 && (scrnSecs) <= 67) { //range 2 skip to 45 degrees
text("2, 23-67 45*", width/2,height/4);
}
if ((scrnSecs) >= 68 && (scrnSecs) <= 112) { //range 3 skip to 90 degrees
text("3, 68-112 90*", width/2,height/4);
}
if ((scrnSecs) >= 113 && (scrnSecs) <= 157) { //range 4 skip to 135 degrees
text("4, 113-157 135*", width/2,height/4);
}
if ((scrnSecs) >= 158 && (scrnSecs) <= 202) { //range 5 skip to 180 degrees
text("5, 158-202 180*", width/2,height/4);
}
if ((scrnSecs) >= 203 && (scrnSecs) <= 247) { //range 6 skip to 225 degrees
text("6, 203-247 225*", width/2,height/4);
}
if ((scrnSecs) >= 248 && (scrnSecs) <= 292) { //range 7 skip to 270 degrees
text("7, 248-292 270*", width/2,height/4);
}
if ((scrnSecs) >= 293 && (scrnSecs) <= 337) { //range 8 skip to 315 degrees
text("8, 293-337 315*", width/2,height/4);
}
if ((scrnSecs) >= 338 && (scrnSecs) <= 359) { //range 9(1) skip to 0 degrees
text("9, 338-359 360*", width/2,height/4);
}
//if (keyPressed) { //if any key is pressed, restart timer
//restartSecs = actualSecs - skipSec ; //stores elapsed SECONDS
//scrnSecs = skipSec; //restart screen timer
//}
if (scrnSecs == totalSec) { //after 360 secs, restart second timer
restartSecs = actualSecs; //placeholder for this second in time
scrnSecs = startSec; //reset to zero
}
println(scrnSecs); //print timer to console (secs)
//displays time on screen
textAlign(CENTER);
fill(255);
text(nf(scrnSecs, 2), width/2, height/2);
}
«Prev
Next »
Moderate user : elbucho
Forum