Hi, new to processing and programming with frames but not to programming so this is a bit embarrassing.
I’ve managed to make ellipses that expand and contract with no problem by using a state, but I’ve had this other issue a few times with decrementing other things. When I try to decrement, instead of reversing, the thing in question will stay at max and just try to -1 over and over. I thought this was due to not clearing and redrawing (due to framerate) but that seems to not help either.
Here is an example, where when the text hits “STRING_MAX” i’d like it to start shrinking. Instead, it will hover at 99-100.
final int SPACE_MIN = 10;
final int SPACE_MAX = 100;
final String message = "howdy!";
int space = 0;
int wordState = 0;
void setup()
{
size(500, 500);
space = SPACE_MIN;
wordState = 0;
}
void draw()
{
background(0);
if (space < SPACE_MAX) {
space ++;
// wordState = 1;
drawMessage();
} else if (space >= SPACE_MAX) {
clearMessage();
space --;
//wordState = 0;
drawMessage();
}
println(space);
}
void drawMessage() {
for (int i = 0; i < message.length(); i++)
{
char c = message.charAt(i);
text(c, space*i, mouseY);
}
}
void clearMessage() {
background(0);
}
Thank you!
well that’s quite obvious right? once space has reached 100, it will execute space-- once, which will make it 99. the next loop it’s smaller than SPACE_MAX again and increases by 1 (space++).
a way to solve this would be to activate a trigger once it’s reached SPACE_MAX and keep subtracting until it reaches SPACE_MIN (I guess that is eventually what you want?) and when that happens, reverse the trigger or undo it to make it start increasing again
2 Likes
Man, I must have had a total brain meltdown. I knew what was happening and with the way you worded the solution I got it:
final int SPACE_MIN = 10;
final int SPACE_MAX = 100;
final String message = "howdy!";
int space = 0;
int wordState = 0;
void setup()
{
size(500, 500);
space = SPACE_MIN;
wordState = 0;
}
void draw()
{
background(0);
if (space < SPACE_MAX && wordState == 0) {
space ++;
drawMessage();
if (space >= SPACE_MAX){
wordState = 1;
}
}
if (wordState == 1) {
clearMessage();
space --;
drawMessage();
if (space <= SPACE_MIN){
wordState = 0;
}
}
println(space);
}
void drawMessage() {
for (int i = 0; i < message.length(); i++)
{
char c = message.charAt(i);
text(c, space*i, mouseY);
}
}
void clearMessage() {
background(0);
}
I’m glad you got it working. there probably is a better or more elegant solution, but I guess as long as that’s not necessary I don’t see the need for it