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

**URL:** <https://discourse.processing.org/t/is-there-a-way-to-make-events-happen-at-specific-times/16211>\
**Category:** Coding Questions\
**Created:** [December 7, 2019, 12:26pm UTC](https://discourse.processing.org/t/is-there-a-way-to-make-events-happen-at-specific-times/16211 "2019-12-07T12:26:18Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![pw00](https://avatars.discourse-cdn.com/v4/letter/p/d9b06d/32.png) [@pw00](https://discourse.processing.org/u/pw00)\
**Post date:** [December 7, 2019, 12:26pm UTC](https://discourse.processing.org/t/is-there-a-way-to-make-events-happen-at-specific-times/16211/1 "2019-12-07T12:26:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [December 7, 2019, 1:11pm UTC](https://discourse.processing.org/t/is-there-a-way-to-make-events-happen-at-specific-times/16211/2 "2019-12-07T13:11:14Z")

</div>

> [@pw00](#):
>
> after a certain time

use a timer using millis() (see reference)

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [December 7, 2019, 1:44pm UTC](https://discourse.processing.org/t/is-there-a-way-to-make-events-happen-at-specific-times/16211/3 "2019-12-07T13:44:56Z")

</div>

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

```auto
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?

🙂

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [December 7, 2019, 1:56pm UTC](https://discourse.processing.org/t/is-there-a-way-to-make-events-happen-at-specific-times/16211/4 "2019-12-07T13:56:24Z")

</div>

Or if you want like you said use tint.

```auto

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();
  }
}

```

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [December 7, 2019, 2:05pm UTC](https://discourse.processing.org/t/is-there-a-way-to-make-events-happen-at-specific-times/16211/5 "2019-12-07T14:05:54Z")

</div>

> [@glv](#):
>
> circle(width/2, height/2, 50);

Does circle still work on PC?

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [December 7, 2019, 2:14pm UTC](https://discourse.processing.org/t/is-there-a-way-to-make-events-happen-at-specific-times/16211/6 "2019-12-07T14:14:44Z")

</div>

> [@glv](#):
>
> Can you tell me why I chose 4251 as my time offset?

Good one, I had to think about it.😊

---

<div class="post-metadata">

**Author:** ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)\
**Post date:** [December 7, 2019, 2:15pm UTC](https://discourse.processing.org/t/is-there-a-way-to-make-events-happen-at-specific-times/16211/7 "2019-12-07T14:15:48Z")

</div>

> <https://github.com/processing/processing/blob/master/core/src/processing/core/PApplet.java>

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

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

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [December 7, 2019, 2:39pm UTC](https://discourse.processing.org/t/is-there-a-way-to-make-events-happen-at-specific-times/16211/8 "2019-12-07T14:39:09Z")

</div>

> [@noel](#):
>
> Does circle still work on PC?

Yes it does.

> **[circle() / Reference](https://processing.org/reference/circle_.html)**
>
> Draws a circle to the screen. By default, the first two parameters set the location of the center, and the third sets the shape's width and height. The origin may be changed with the ellipseMode()\<…

On this page:

> **[Download Processing](https://processing.org/download/)**
>
> Processing is open source and is available for macOS, Windows, and Linux. Projects created with Processing are also cross-platform, and can be used on macOS, Windows, Android, Raspberry Pi, and many o…

in the “list of revisions”:

![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/c/c1942494ad23c0a75c5471205cee12cdd57f6139.png)

🙂

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [December 7, 2019, 3:28pm UTC](https://discourse.processing.org/t/is-there-a-way-to-make-events-happen-at-specific-times/16211/9 "2019-12-07T15:28:12Z")

</div>

> [@Lexyth](#):
>
> Edit… i still can‘t figure it out… i even googled the numbers …

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

---

<div class="post-metadata">

**Author:** ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)\
**Post date:** [December 7, 2019, 4:03pm UTC](https://discourse.processing.org/t/is-there-a-way-to-make-events-happen-at-specific-times/16211/10 "2019-12-07T16:03:41Z")

</div>

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 😅 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…

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [December 7, 2019, 4:14pm UTC](https://discourse.processing.org/t/is-there-a-way-to-make-events-happen-at-specific-times/16211/11 "2019-12-07T16:14:03Z")

</div>

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