# Duración de un elemento y secuencia

**URL:** https://discourse.processing.org/t/duracion-de-un-elemento-y-secuencia/15646
**Category:** Español
**Created:** [November 19, 2019, 10:21pm UTC](https://discourse.processing.org/t/duracion-de-un-elemento-y-secuencia/15646 "2019-11-19T22:21:04Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![humano](https://avatars.discourse-cdn.com/v4/letter/h/dbc845/32.png) [@humano](https://discourse.processing.org/u/humano)
#### Post date: [November 19, 2019, 10:21pm UTC](https://discourse.processing.org/t/duracion-de-un-elemento-y-secuencia/15646/1 "2019-11-19T22:21:04Z")

</div>

Estoy intentando que aparezca un texto en la pantalla durante 3 segundos y luego aparezca otro texto diferente. He conseguido programar el primer texto correctamente, pero no sé que función tengo que usar para desaparezca a los 3 segundos y se vea el segundo texto.

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [November 20, 2019, 6:34am UTC](https://discourse.processing.org/t/duracion-de-un-elemento-y-secuencia/15646/2 "2019-11-20T06:34:35Z")

</div>

use timer  
[https://processing.org/reference/millis\_.html](https://processing.org/reference/millis_.html)

* * *

a deluxe edition:

```auto
int step = 0;
long ts, tr;
long[] animator={12000, 7000, 20000}; // ________ time schedule in msec

void timer() {
  tr = animator[step] - ( millis() - ts ) ; //_ for show remaining time only
  if ( millis() - ts > animator[step] ) {
    // do whatever you have to do
    println(timeString() + " end step "+step);
    step++;
    ts = millis();
    if ( step >= animator.length ) step = 0; //- auto repeat
  }
}

void setup() {
  println( timeString() );
}

void draw() {
  background(200, 200, 0);
  fill(0);
  text( "step "+step+" tr "+(tr/1000), 10, height/2); //_ show remaining time
  timer();
}

String timeString() {
  return ""+year() + "-" + nf(month(), 2) + "-" + nf(day(), 2) + "_" +
    nf(hour(), 2) + "_" + nf(minute(), 2) + "_" + nf(second(), 2);
}

```

---

<div class="post-metadata">

### Author: ![humano](https://avatars.discourse-cdn.com/v4/letter/h/dbc845/32.png) [@humano](https://discourse.processing.org/u/humano)
#### Post date: [November 20, 2019, 2:04pm UTC](https://discourse.processing.org/t/duracion-de-un-elemento-y-secuencia/15646/3 "2019-11-20T14:04:04Z")

</div>

No hay un modo más sencillo? '🙂

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [November 20, 2019, 2:14pm UTC](https://discourse.processing.org/t/duracion-de-un-elemento-y-secuencia/15646/4 "2019-11-20T14:14:23Z")

</div>

```auto
String myText = "TEXT A";
boolean init = true;

void timer() {
  if ( init ) {
    if ( millis() > 3000 ) { 
      myText = "TEXT B";
      init = false;
      println("timeout");
    }
  }
}

void setup() {
}
void draw() {
  background(200,200,0);
  timer();
  text(myText, 10, 10);
}

```

---

<div class="post-metadata">

### Author: ![hamoid](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hamoid/32/58_2.png) [@hamoid](https://discourse.processing.org/u/hamoid)
#### Post date: [November 20, 2019, 2:45pm UTC](https://discourse.processing.org/t/duracion-de-un-elemento-y-secuencia/15646/5 "2019-11-20T14:45:06Z")

</div>

En este video lo explico en inglés, pero igual se entiende el programa sin ver el vídeo?

[https://funprogramming.org/91-Timelines-tell-a-story.html](https://funprogramming.org/91-Timelines-tell-a-story.html)

---

<div class="post-metadata">

### Author: ![humano](https://avatars.discourse-cdn.com/v4/letter/h/dbc845/32.png) [@humano](https://discourse.processing.org/u/humano)
#### Post date: [November 25, 2019, 9:31pm UTC](https://discourse.processing.org/t/duracion-de-un-elemento-y-secuencia/15646/6 "2019-11-25T21:31:18Z")

</div>

El código es fácil de entender y funciona en mi programa, pero cuando aparece scene2(), scene1() no se borra y queda debajo, ambas son escenas estáticas. ¿Cómo puedo conseguir que scene1() dure 3 segundos, se borre y empiece scene2()? Mi código es

```auto
void draw (){
  int m = millis();
  if(m < 3000) {
    scene1();
  } else if(m > 3000) {
    scene2();
  }

```

Gracias

---

<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: [November 25, 2019, 10:30pm UTC](https://discourse.processing.org/t/duracion-de-un-elemento-y-secuencia/15646/7 "2019-11-25T22:30:47Z")

</div>

Hello,

> [@Animation that transitions using frameCount](https://discourse.processing.org/t/animation-that-transitions-using-framecount/15378):
>
> A very simple example that transitions through scenes over time: // Author: GLV // Date: 2019-11-10 // Description: // Animate over time using frameCount // A very simple example that: // Uses frameCount to keep track of time // Fades in and out by modifying alpha component of HSB color // Cycles through HSB colors int scene = 0; int sec = 60; float alpha = 0; void setup() { size(500, 500); textSize(36); textAlign(CENTER, CENTER); colorMode(HSB, 360, 100, 100, 100); } void draw()…

🙂

---

<div class="post-metadata">

### Author: ![humano](https://avatars.discourse-cdn.com/v4/letter/h/dbc845/32.png) [@humano](https://discourse.processing.org/u/humano)
#### Post date: [November 25, 2019, 10:57pm UTC](https://discourse.processing.org/t/duracion-de-un-elemento-y-secuencia/15646/8 "2019-11-25T22:57:51Z")

</div>

Mi código es

```auto
void draw (){
  int m = millis();
  if(m < 3000) {
    scene1();
  } else if(m > 3000) {
    scene2();
  } 

```

¿Sugieres con ese ejemplo que en vez de usar if y else if use switch? ¿Se usa de la misma forma?

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [November 26, 2019, 2:10am UTC](https://discourse.processing.org/t/duracion-de-un-elemento-y-secuencia/15646/9 "2019-11-26T02:10:42Z")

</div>

-1- please format your code `</> code button `  
and post running code we can test.

-2- your question why drawing scene1 is not erased after 3 sec?  
you need the `background();` at the beginning of draw ( or in all `sceneX(){};` )

-3- what you want your program to do if `millis() == 3000`  
sorry, bad trick question, your if logic should be revised

```auto
void setup() {}

void draw () {
  background(200, 200, 0);
  if (millis() < 3000) scene1();
  else scene2();
}

void scene1() { 
  text("scene 1", 10, 10);
}
void scene2() {
  text("scene 2", 10, 10);
}

```

-4-  
using `if`  
[https://processing.org/reference/if.html](https://processing.org/reference/if.html)

or `switch`  
[https://processing.org/reference/switch.html](https://processing.org/reference/switch.html)  
is up to you.

---

<div class="post-metadata">

### Author: ![humano](https://avatars.discourse-cdn.com/v4/letter/h/dbc845/32.png) [@humano](https://discourse.processing.org/u/humano)
#### Post date: [November 26, 2019, 12:40pm UTC](https://discourse.processing.org/t/duracion-de-un-elemento-y-secuencia/15646/10 "2019-11-26T12:40:37Z")

</div>

Gracias, usando background() al principio de draw() lo consigo.
