# Having trouble slowing my screen display

**URL:** <https://discourse.processing.org/t/having-trouble-slowing-my-screen-display/25453>\
**Category:** Coding Questions\
**Created:** [November 16, 2020, 12:38am UTC](https://discourse.processing.org/t/having-trouble-slowing-my-screen-display/25453 "2020-11-16T00:38:34Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![luigipasto](https://avatars.discourse-cdn.com/v4/letter/l/45deac/32.png) [@luigipasto](https://discourse.processing.org/u/luigipasto)\
**Post date:** [November 16, 2020, 12:38am UTC](https://discourse.processing.org/t/having-trouble-slowing-my-screen-display/25453/1 "2020-11-16T00:38:34Z")

</div>

Hi, this is my first attempt at writing code. The goal seemed quite modest but I’m getting bogged down. I’m reading tabular data from a csv file, and writing to the screen one row of the table at the time. What I’d like to do at this point is write the first row at the top, wait a specified amount of time, then write the next, and so forth. I’ve tried using frameRate, and millis below but it’s getting me tied in knots! Any help getting past this obstacle, and onto the next, would be appreciated.

Table table;  
PFont f;  
int previousDisplayTime;  
int deltaTime;

void setup() {

f = createFont(“Arial”,16,true);  
textFont(f,18);  
fill(0);  
fullScreen();  
background (255);  
Integer vertical = 25;  
table = loadTable(“data.csv”, “header”);  
line(width/2,0,width/2,height);

deltaTime = 2000;  
previousDisplayTime = 0;

if (millis() \> previousDisplayTime + deltaTime) {

```
for (int i=0; i<table.getRowCount(); i++){

  for (int j=0; j<table.getColumnCount(); j++){
  
    text(table.getInt(i,j), width/2-70+j*40,vertical);
  }
vertical = vertical+30;
}

```

}  
}

---

<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 16, 2020, 12:54am UTC](https://discourse.processing.org/t/having-trouble-slowing-my-screen-display/25453/2 "2020-11-16T00:54:16Z")

</div>

Hello,

I suggest you start by working through the tutorials and examples here:

> **[Tutorials \\ Processing.org](https://processing.org/tutorials/)**

> **[Getting Started \\ Processing.org](https://processing.org/tutorials/gettingstarted/)**

See the references for each function you are using and understand setup() and draw():

> **[setup() \\ Language (API) \\ Processing 3+](https://processing.org/reference/setup_.html)**

  

> **[draw() \\ Language (API) \\ Processing 3+](https://processing.org/reference/draw_.html)**

`:)`

---

<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:** [November 16, 2020, 8:41am UTC](https://discourse.processing.org/t/having-trouble-slowing-my-screen-display/25453/3 "2020-11-16T08:41:35Z")

</div>

Hi @luigipasto

Setup() runs only once, so it and only draws all at once when the code is completed.  
draw() on the contrary is a loop that draws, when not specifically determined by frameRate(), or including timers, around 60 times per second. So the executing code with the timer you have to put there, in draw(). Reading the links provided above is really necessary to give you a more detailed explanation.

---

<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 16, 2020, 11:48am UTC](https://discourse.processing.org/t/having-trouble-slowing-my-screen-display/25453/4 "2020-11-16T11:48:44Z")

</div>

Hello,

You were given some pointers to start your journey.

In the future please format your code before posting:

[https://discourse.processing.org/faq#format-your-code](https://discourse.processing.org/faq#format-your-code)

> [@luigipasto](#):
>
> this is my first attempt at writing code

Simplify it, understand it and then integrate code.

Try writing just a timer first.

Your example did not display text to screen as is.  
This is a first pass at your efforts and formatted as an example of how to post code and do some debugging:

```auto
Table table;
PFont f;
int previousDisplayTime;
int deltaTime;

void setup() 
  {
  //f = createFont(“Arial”,16,true); //Replaced
  //textFont(f,18); //Replaced:
  textSize(18);
  fill(0);
  //fullScreen(); //Replaced:
  size(400, 400);
  background (255);
  //Integer vertical = 25; //Why did you do this? Replaced:
  int vertical = 25;
  table = loadTable ("data.csv", "header");
  line(width/2,0,width/2,height);
  
  deltaTime = 2000;
  previousDisplayTime = 0;
  
  println("d1");
  
  //if (millis() > previousDisplayTime + deltaTime) //Try this uncommented
    {
    for (int i=0; i<table.getRowCount(); i++)
      {
      for (int j=0; j<table.getColumnCount(); j++)
        {
        text(table.getInt(i,j), width/2-70+j*40,vertical);
        }
      vertical = vertical+30;
      }
    }
  println("d2");  
  }

```

data.csv:

> c1,c2  
> 1,1  
> 2,2  
> 3,3

I then added a draw(), moved some code and was able to integrate a timer.  
Your timer is not working yet.  
Use some println() statements to see what your timer is doing.

Comment code with a // to help debugging; see my example.

This forum has plenty of timer examples to search for if you need some insight; I encourage you to try this on your own first.

`:)`

---

<div class="post-metadata">

**Author:** ![luigipasto](https://avatars.discourse-cdn.com/v4/letter/l/45deac/32.png) [@luigipasto](https://discourse.processing.org/u/luigipasto)\
**Post date:** [November 16, 2020, 9:34pm UTC](https://discourse.processing.org/t/having-trouble-slowing-my-screen-display/25453/5 "2020-11-16T21:34:54Z")

</div>

Thank you for your suggestions. The reason I wrote the code in the Setup() section is that the concept of 2 loops (getting values from tabular data) within a loop (Draw()) is really confusing to me. I’ll give it a try, and likely will return with more issues 🙂

---

<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 17, 2020, 12:41am UTC](https://discourse.processing.org/t/having-trouble-slowing-my-screen-display/25453/6 "2020-11-17T00:41:01Z")

</div>

Some minimal modifications to get you started.

Uses frameRate(1).

```auto
Table table;
int vertical = 25;

int i = 0;

void setup() 
  {
  size(200, 200);
  fill(0);
  background (255);
  table = loadTable("data.csv", "header");
  line(width/2, 0, width/2, height);
  
  frameRate(1);
  }
  
void draw()
  { 
  background(255); //Try it with and without background.
  
  //for (int i=0; i<table.getRowCount(); i++)
    {
    for (int j=0; j<table.getColumnCount(); j++)
      {
      text(table.getInt(i,j), width/2-70+j*40,vertical);
      }
    vertical = vertical+30;
    }
  
  i++; //Starts to replace the *for loop* but needs some work!
  }    

```

Use the table in previous example.  
This will crash and you can add code to correct that.

`:)`

---

<div class="post-metadata">

**Author:** ![luigipasto](https://avatars.discourse-cdn.com/v4/letter/l/45deac/32.png) [@luigipasto](https://discourse.processing.org/u/luigipasto)\
**Post date:** [November 17, 2020, 2:25am UTC](https://discourse.processing.org/t/having-trouble-slowing-my-screen-display/25453/7 "2020-11-17T02:25:53Z")

</div>

Thanks glv, I appreciate your help with this. I took your advice and completed started from scratch. The code now does everything I want it to do in the most simple way I can come up with, except the timing part. I’m playing with both millis() and your last suggestion of getting rid of a loop in draw() and using frameRate(). So far, no go. I’ll post my latest efforts sometime tomorrow for some more wisdom from the community. I’m spent now 🙂

---

<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 17, 2020, 11:25am UTC](https://discourse.processing.org/t/having-trouble-slowing-my-screen-display/25453/8 "2020-11-17T11:25:29Z")

</div>

Hello,

There are many ways to do a timer and I have tried them all at one time or another.

You can use millis(), frameCount, Time & Date functions (see reference), counter, Java timer class, etc.

Slowing down frameRate us useful for slowing things down and I often use it for debugging or as required.

The default frameRate for draw() (stated in the reference) can be used as is or set and is used for animation or as required.

It is important to understand the flow of setup() and draw() before integrating a “timer” in your code.

Some good stuff here:

[![](https://img.youtube.com/vi/o8dffrZ86gs/hqdefault.jpg "3.1: Flow (setup and draw) - Processing Tutorial") ](https://www.youtube.com/watch?v=o8dffrZ86gs)

Example timer with millis():

> [@Need assistance with timing! \[millis()\]](https://discourse.processing.org/t/need-assistance-with-timing-millis/18854/4):
>
> I provided a simple example: int whattimeisitnow; int whattimeisitatstartofstopwatch; int timepassedtoresetstopwatch = 1000; //setup runs once void setup() { whattimeisitatstartofstopwatch = millis(); } //draw loops 60 frames per sec void draw() { whattimeisitnow = millis(); if (whattimeisitnow \> whattimeisitatstartofstopwatch + timepassedtoresetstopwatch) { println("1000 ms have passed!"); whattimeisitatstartofstopwatch = millis(); //reset st…

You can add more println() statements to see value of variables as it progresses:

> **Timer \< Expand for code**
>
> ```auto
> int whattimeisitnow;
> int whattimeisitatstartofstopwatch;
> int timepassedtoresetstopwatch = 1000;
> 
> //setup runs once
> void setup()
> {
> whattimeisitatstartofstopwatch = millis();  
> println(whattimeisitatstartofstopwatch);
> }
> 
> //draw loops 60 frames per sec  
> void draw()
> {
> whattimeisitnow = millis();
> if (whattimeisitnow > whattimeisitatstartofstopwatch + timepassedtoresetstopwatch)  
> {
> println("1000 ms have passed! Time elapsed (ms): ", whattimeisitnow);
> whattimeisitatstartofstopwatch = millis(); //reset stopwatch and start over
> }
> }
> 
> ```

`:)`

---

<div class="post-metadata">

**Author:** ![luigipasto](https://avatars.discourse-cdn.com/v4/letter/l/45deac/32.png) [@luigipasto](https://discourse.processing.org/u/luigipasto)\
**Post date:** [November 18, 2020, 10:53pm UTC](https://discourse.processing.org/t/having-trouble-slowing-my-screen-display/25453/9 "2020-11-18T22:53:45Z")

</div>

```auto
Table table;
int LineSpacing;
int interval;
int previousTime;
int currentTime;

void setup() 
{
  textSize(18);
  fill(0);
  size(500, 600);
  background (255);
  table = loadTable ("data2.csv");
  interval=2000; //2 second delay
  previousTime=0;
  noLoop();
}

void draw()
{
  LineSpacing=10;
  line(width/2, 0, width/2, height); //draw line down center of screen
  
  //currentTime=millis();
  //while (millis() - previousTime <= interval)
  //{
  // // wait for interval value to be exceeded
  //}  
  
  for (int i=0; i<table.getRowCount(); i++)
  {
    for (int j=0; j<table.getColumnCount(); j++) 
    {
      text(table.getFloat(i, j), width/2-170+j*180, height-LineSpacing);
      if (j<1)
      {
        text("Latitude", width/2-90+j*110, height-LineSpacing);
      } else
      {
        text("longitude", width/2-15+j*110, height-LineSpacing);
      }
    }
    if (height-LineSpacing<=0)
    {  
      background(255);
      LineSpacing=10;
      line(width/2, 0, width/2, height);
    } else
    {
      LineSpacing = LineSpacing+25;
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![luigipasto](https://avatars.discourse-cdn.com/v4/letter/l/45deac/32.png) [@luigipasto](https://discourse.processing.org/u/luigipasto)\
**Post date:** [November 18, 2020, 11:02pm UTC](https://discourse.processing.org/t/having-trouble-slowing-my-screen-display/25453/10 "2020-11-18T23:02:34Z")

</div>

data2.csv contains 2 columns of numbers and any number of rows.  
The code actually does what I want, except for the timing. It reads from data2.csv, then sends one row at a time to the screen and formats. You’ll note that I added noLoop() to the setup(), as the looping in draw() is killing me. I want the code to go through the tabular data once and write to screen each row one at a time. Without the noLoop() the font gets darker as the code is run repeatedly in draw(). I’ve tried the different strategies proposed, the commented section is my last attempt (failure). The delay is added at the begining but then the rows all appear at the same time. I’m lost!

By the way, you’ve been extremely patient with me, and I am appreciative.

---

<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 19, 2020, 1:03am UTC](https://discourse.processing.org/t/having-trouble-slowing-my-screen-display/25453/11 "2020-11-19T01:03:32Z")

</div>

> [@luigipasto](#):
>
> The delay is added at the begining but then the rows all appear at the same time

_ **A delay and a timer are two different things.** _

I provided an example that slows down the frameRate to 1 fps ( **f** rame **p** er **s** econd) to allow you to see what is happening.

You can use the default frameRate which is 60 fps and a timer of your choice to increment the i variable every 2000ms.

In my previous example the variable i is no longer in a for loop so you have to add some code to test for conditions:

if (i\>=5)  
{  
i = 0;  
noLoop();  
}

This is your project and I am working with your code.

There are many ways to work with tables and timers; you have to start slowly and build on that.

See the processing website for references, tutorials and examples:

> **[Welcome to Processing!](https://processing.org/)**
>
> Processing is a flexible software sketchbook and a language for learning how to code. Since 2001, Processing has promoted software literacy within the visual arts and visual literacy within technology…

And the Coding Train may have a tutorial.

`:)`

---

<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 19, 2020, 1:11am UTC](https://discourse.processing.org/t/having-trouble-slowing-my-screen-display/25453/12 "2020-11-19T01:11:11Z")

</div>

> [@luigipasto](#):
>
> Without the noLoop() the font gets darker as the code is run repeatedly in draw()

If you do not clear the background at the start of each loop() if will continue to paint over it (keep adding to canvas) and start to do this. It does not draw perfectly over each frame with each cycle of draw() and appears to get darker.

Read this to understand:

> **[background() / Reference](https://processing.org/reference/background_.html)**
>
> The background() function sets the color used for the background of the Processing window. The default background is light gray. This function is typically used within draw() to clear th…

It takes a while to grasp the flow of setup() and draw() for new programmers.  
You just have to work through this.

`:)`

---

<div class="post-metadata">

**Author:** ![luigipasto](https://avatars.discourse-cdn.com/v4/letter/l/45deac/32.png) [@luigipasto](https://discourse.processing.org/u/luigipasto)\
**Post date:** [November 19, 2020, 1:33am UTC](https://discourse.processing.org/t/having-trouble-slowing-my-screen-display/25453/13 "2020-11-19T01:33:18Z")

</div>

If I clear the background will I loose the last row printed to screen? I need the rows to cumulate one at the time from the bottom of the screen to the top. I may be misunderstanding a lot here.

Regarding delay vs timer, I considered that a delay of a specific time is a timer. I’m not sure how these are different conceptually but of course I believe you that they are different in code. I’ll keep thinking about this…

---

<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 19, 2020, 3:04am UTC](https://discourse.processing.org/t/having-trouble-slowing-my-screen-display/25453/14 "2020-11-19T03:04:48Z")

</div>

> [@luigipasto](#):
>
> If I clear the background will I loose the last row printed to screen?

Yes

> **Example 1 with frameRate(1) and no background**
>
> ```auto
> int sec = 1;
> int y;
> 
> void setup()
> {
> size(300, 300);
> frameRate(1);
> background(255); 
> }
>   
> void draw()
> {
> //background(255); //Try with and without background()
> println("f: ", frameCount);
>   
> //for (int y=0; y<5; y++) //rows
> {
> for (int x=0; x<5; x++) //columns
> {
> //println(x,y);
> String s = str(x) + ", " + str(y); //x and y in a string for text()
>         
> //text
> fill(0);
> textSize(16);
> textAlign(CENTER, CENTER);
> text(s, 50*x+50, 50*y+50); //Spacing and offset
>         
> ///point
> stroke(255, 0, 0);
> strokeWeight(2);
> point(x*5, y*5);
> }
> }
>   
> y++; //Will keep incrementing each draw() cycle; needs some code to set a limit.
> println("y: ", y);
>   
> if (y>=5) 
> {
> y = 0;
> noLoop();
> }  
> }
> 
> ```

> **Example 2 with frameRate timer and a background**
>
> ```auto
> int sec = 1;
> int y;
> int yLimit = 0;
> 
> void setup()
> {
> size(300, 300);
> //frameRate(1); //Default is 60 when this is commented
> background(255); 
> }
>   
> void draw()
> {
> background(255); //Try with and without background()
> println("f: ", frameCount);
>   
> if (frameCount%60 == 0) //This is the modulo operator
> {
> yLimit++;  
> println(yLimit);
> if (yLimit>=5) 
> { 
> noLoop();
> }
> }
>   
>   
> for (int y=0; y<yLimit; y++) //rows
> {
> for (int x=0; x<5; x++) //columns
> {
> //println(x,y);
> String s = str(x) + ", " + str(y); //x and y in a string for text()
>         
> //text
> fill(0);
> textSize(16);
> textAlign(CENTER, CENTER);
> text(s, 50*x+50, 50*y+50); //Spacing and offset
>         
> ///point
> stroke(255, 0, 0);
> strokeWeight(2);
> point(x*5, y*5);
> }
> }
>   
> //y++; //Will keep incrementing each draw() cycle; needs some code to set a limit.
> //println("y: ", y);
>   
> //if (y>=5) 
> // {
> // y = 0;
> // noLoop();
> // }  
> }
> 
> ```

> [@luigipasto](#):
>
> delay vs timer

Delays should not be used in draw():

> **[delay() / Reference](https://processing.org/reference/delay_.html)**
>
> The delay() function causes the program to halt for a specified time. Delay times are specified in thousandths of a second. For example, running delay(3000) will stop the program for thr…

Use a timer and time events to update as required.

Try to integrate a millis() timer.

Use println() statements to see variables as code is executed.

> **[println() / Reference](https://processing.org/reference/println_.html)**
>
> The println() function writes to the console area, the black rectangle at the bottom of the Processing environment. This function is often helpful for looking at the data a program is producing…

Timer examples:

> **[25 life-saving tips for Processing](https://amnonp5.wordpress.com/2012/01/28/25-life-saving-tips-for-processing/)**
>
> I have bundled a huge number and variety of code examples in this single mega-post. Please learn from my mistakes and experiences! ;-)

Note:  
`timer = millis()` should _also_ be in setup() in Amnon examples above; if you use a println() to see value you will see why.

`:)`

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [November 19, 2020, 5:30am UTC](https://discourse.processing.org/t/having-trouble-slowing-my-screen-display/25453/15 "2020-11-19T05:30:51Z")

</div>

A simple countdown/delay library: ⏱

> <https://gist.github.com/GoToLoop/ea4db8a8622e27541213da3c9a43ca21>

It’s a wrapper for class TimerTask:

> **[TimerTask (Java SE 11 & JDK 11 )](https://docs.Oracle.com/en/java/javase/11/docs/api/java.base/java/util/TimerTask.html)**

---

<div class="post-metadata">

**Author:** ![luigipasto](https://avatars.discourse-cdn.com/v4/letter/l/45deac/32.png) [@luigipasto](https://discourse.processing.org/u/luigipasto)\
**Post date:** [November 22, 2020, 10:52pm UTC](https://discourse.processing.org/t/having-trouble-slowing-my-screen-display/25453/16 "2020-11-22T22:52:17Z")

</div>

Thanks again. I think I’ll put this aside for a few weeks and come back to it when my mind is a little clearer. I have 120 term papers to correct and I’m not looking forward to it…

Thanks again for all you suggestions.
