Is there a way to make events happen at specific times?

I’m trying make it seem like a certain portion of an image “rots” (by using tint) after a certain time to show the decomposition rates of different types of recyclables and what not, but I can’t seem to find any tutorials or anything on the reference pages to get me started. So what I’m asking is 1) Is it even possible to do that in Processing? and 2) If so, how do you do it?

Also p.s. I’m going to use millis to time events since seconds just feels a little too long for me.

1 Like

use a timer using millis() (see reference)

A very quick and simple example I whipped up from scratch that may help:

int timeZero;
int timeNow;
int alpha = 0;
int sec;

void setup() 
	{
  size(500, 500);
	timeZero = millis(); 
  }

void draw() 
	{
  background(0);
  timeNow = millis();
  
  if (timeNow > (timeZero + 2000) && timeNow < (timeZero + 2000 + 4251))
    {
 // Do something cool here like change tint or alpha for a shape or just count!   
    stroke(255, 0, 0);
    strokeWeight(2);
    line(0, 0, alpha, alpha);
    alpha++;
    if (alpha >= 255) alpha = 255;
    println(alpha);
    }
  
  if (timeNow > 2000 + 4250)
    {
    strokeWeight(2);
    fill(255, 255, 0, alpha);
    circle(width/2, height/2, 50);
    }
  }

Can you tell me why I chose 4251 as my time offset?

:slight_smile:

2 Likes

Or if you want like you said use tint.


PImage pi1, pi2;
int tnt = 255;
int start_time;

void setup() {
  size(500, 500);
  background(255);
  stroke(255, 0, 0);
  strokeWeight(20);
  fill(0, 0, 255);
  ellipse(250, 250, 400, 400);
  pi1 = get(0, 0, width, height);
  image(pi1, 0, 0);
  pi2 = get(0, 0, width/2, height/2);
  start_time = millis();
  noStroke();
  fill(255);
}  

void draw() {
  if (millis()-start_time > 200) {
    tint(255, 255);
    image(pi1, 0, 0);
    rect(0, 0, width/2, height/2);
    tint(255, tnt);
    image(pi2, 0, 0);
    tnt -= 20;
    start_time = millis();
  }
}
1 Like

Does circle still work on PC?

Good one, I had to think about it.:blush:

1 Like

Line 12298. (Took a looong time to find that…)

Edit… i still can‘t figure it out… i even googled the numbers …

Yes it does.

https://processing.org/reference/circle_.html

On this page:
https://processing.org/download/

in the “list of revisions”:

image

:slight_smile:

1 Like

I had to ask. What are you looking for in this file?

No, i meant i still didn‘t figure out the 4251… as for the file, that‘s where the Circle method is in the PApplet. Idk how to do a link that directly goes to the line :sweat_smile: as for why it took a Long Time, cause “search on Page” doesn‘t find anything in the PApplet… it‘s just way too long…

Ah, I see… I think you are looking too far, it’s not that difficult, it’s just about cycles.