Moved here, because Programming Questions is reserved to questions showing some code to work on...
The classical solution is to use a secondary variable holding the previous value of your variable (that's the value that get bigger, not the variable itself!).
An example:
- void setup()
- {
- size(800, 800);
- frameRate(5); // Slow motion
- background(255);
- }
-
- float x = 100;
- float px = x;
-
- void draw()
- {
- fill(255, 10);
- rect(0, 0, width, height);
- float rnd = random(-15, 15);
- // Variable value can increase or decreases
- x += rnd;
- if (x > px)
- {
- stroke(#FF0000);
- line(x, 0, x, height);
- }
- else
- {
- stroke(#00FF00, 100);
- line(x, 0, x, height);
- }
- px = x;
- }