<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
      <title>Tagged with millis() - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=millis%28%29</link>
      <pubDate>Sun, 08 Aug 2021 19:24:21 +0000</pubDate>
         <description>Tagged with millis() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedmillis%28%29/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>How to switch from one text (using Geomerative) to an other according to a changing duration timer?!</title>
      <link>https://forum.processing.org/two/discussion/28062/how-to-switch-from-one-text-using-geomerative-to-an-other-according-to-a-changing-duration-timer</link>
      <pubDate>Tue, 19 Jun 2018 08:46:44 +0000</pubDate>
      <dc:creator>lolonulu</dc:creator>
      <guid isPermaLink="false">28062@/two/discussions</guid>
      <description><![CDATA[<p>Hello,
I asked a very close question brillantly answered by <a href="/two/profile/jeremydouglas">@jeremydouglas</a> few time ago, now I'd like to have a different duration for each text. In the sketch below the changePhraseTimer() works, but not the changePhraseTimerN(), we don't see the last text and it doesn't loop properly. Could someone help me with this issue please ?!
Thanks a lot in advance. L</p>

<pre><code>import generativedesign.*;
import geomerative.*;
// List of a list of points. 1rst the numbre of phrases: 4,  the 2nd indicate the number of points
RPoint[][] myPoints = new RPoint[5][0];
RFont font;
PFont f;
Attractor attractor;

String [][] phraseSets = new String [4][0];
String [] FR1 = {
  "On me dit de te haïr et je m'y efforce", 
  "Je t'imagine cruel, violent, implacable", 
  "Mais à te voir je n'ai bientôt plus de force", 
  "Et de te blesser je suis bien incapable", 
};
String [] FR2 = {
  "Tous mes camarades combattent avec rage", 
  "Et pleurent la nuit au souvenir des supplices", 
  "Infligés à leurs frères qui sont du même âge", 
  "Et rêvent comme eux de toucher une peau lisse"
};
String [] FR3 =
  {"Et de pouvoir enfin caresser des obus", 
  "Autres que ceux produits par le pouvoir obtus", 
  "Je rêve de quitter ces boyaux infernaux"
};
String [] FR4 = {
  "De laisser ces furieux des deux bords du Rhin", 
  "Et de pouvoir embrasser ta chute de rein", 
  "Et porter notre amour sur les fonts baptismaux"
};

//TEXT
final color textColor = color(245);
int fontSize;

// TIME
int startTime;
int initTime;
int lineSpacing;
int index;
int state;
float duration;
int dur1;

//----------------SETUP---------------------------------------------------------------------------------------

void setup() {
  size(1920, 1080, JAVA2D);
  //add phrases to list
  phraseSets[0]=FR1;
  phraseSets[1]=FR2;
  phraseSets[2]=FR3;
  phraseSets[3]=FR4;

  smooth();
  RG.init(this);
  font = new RFont("FreeSans.ttf", 86, CENTER);
  stroke(textColor);
  strokeWeight(0.05);
  //INIT
  drawPhrases(phraseSets[0]);

   // TIME
  startTime=millis();
  initTime=millis();
  index=0;
  lineSpacing =150;
}

//----------------DRAW----------------------------------------------------------------------------------

void draw() {
  background(255);
  state =0;


  // TEXTS
  // draw on the center of the screen
  translate(width/2, height/2);
  // draw phrases vertically centered by moving the top up by half the line spaces
  translate(0, -1.0*lineSpacing*(phraseSets[index].length-1)/2.0);
  // loop through lines
  for (int i=0; i&lt; myPoints.length; i++) {
    // draw a line
    for (int j=0; j&lt; myPoints[i].length-1; j++) {
      pushMatrix(); 
      translate(myPoints[i][j].x, myPoints[i][j].y);
      noFill();
      stroke(0, 200);
      strokeWeight(0.25);
      float angle = TWO_PI*10;
      rotate(j/angle);
      bezier(-2*(noise(10)), 10, 25*(noise(10)), -5, 2*noise(5), -15, 10, -3);
      //bezier(-10*(noise(20))+mouseX/15, 30+mouseY/10, -10*(noise(10))+mouseX/15, 20+mouseY/15, -20*noise(20)+mouseX/15, -20+mouseY/5, 10+mouseX/15, -10+mouseY/15);
      popMatrix();
    }
    // move to the next line
    translate(0, lineSpacing);
  }
  //check Timer and redraw phrases if time has passed

  changePhraseTimerN();
  //changePhraseTimer(duration*4, phraseSets);

}

//----------------INITIALIZE----------------------------------------------------------------------------------------------------------------------------------------
void drawPhrases(String [] phrases) {
  myPoints = new RPoint[phrases.length][0];
  for (int j=0; j&lt;phrases.length; j++) {
    RGroup myGroup = font.toGroup(phrases[j]);
    myGroup = myGroup.toPolygonGroup();
    myPoints[j] = myGroup.getPoints();
  }
}

//----------------TIMER----------------------------------------------------------------------------------------------------------------------------------------

/*void changePhraseTimer( float duration, String [][] phraseSets) {
 duration = sounds[0].length()-150;
 if (millis()-startTime &gt; duration*4) {
 index =(index+1) % phraseSets.length; 
 //drawPhrases(phraseSets[index]);
 //startTime = millis();
 }
 }*/

void changePhraseTimerN() {
  dur1=11500;

  if (millis()-startTime &gt; dur1+1400) {
    index =(index+1) % phraseSets[1].length; 
    drawPhrases(phraseSets[index]);
    startTime= millis();
  } else if (millis()-startTime &gt; dur1-800) {
    index =(index+1) % phraseSets[2].length; 
    drawPhrases(phraseSets[index]);
    startTime= millis();
  } else if (millis()-startTime &gt; dur1+1000) {
    index =(index+1) % phraseSets[3].length; 
    drawPhrases(phraseSets[index]);
    startTime= millis();
  } else if (millis()-startTime &gt; dur1*2-8000) {
    drawPhrases(phraseSets[0]);
    startTime= millis();
  }
}


//----------------TEXT ATTRACTOR INIT----------------------------------------------------------------------------------------------------------------------------------------
void initAttractor(int i) {
  if (i&gt;=4 &amp;&amp; i&lt;8) {
    i-=4;
  } else if (i&gt;=8 &amp;&amp; i&lt;11) {
    i-=8;
  } else if (i&gt;=11 &amp;&amp; i&lt;14) { 
    i-=11;
  } else if (i&gt;14) {
    i=0;
  }

  float x = 0;
  float y =-50; 
  // println(i); 
  attractor = new Attractor(x, y, myPoints[i]);
}


class Attractor {

  float force_radious = 100;
  float maxForce = 15;
  RPoint position;
  RPoint[] points;

  Attractor(float x, float y, RPoint[] p) {
    points = p;
    position = new RPoint(x, y);
  }

  void attract() {

    for (int i =0; i &lt; points.length; i++) {

      float d= points[i].dist(position);
     // println ("d : "+d);
      if (d &lt; force_radious) {   
        RPoint desired = new RPoint(points[i]);
        //points[i]= new RPoint(points[i]);
        //println( "avant x : "+ points[i].x +" y: "+points[i].y);
        desired.sub(position);
        desired.normalize();
        desired.scale(map(d, 0, force_radious, maxForce, 0));
        points[i].add(desired);
         //println( "après x : "+ points[i].x +" y: "+points[i].y);
      }
    }
  }
  void display () {
    stroke(0);
   strokeWeight(2);
  // ellipse (position.x, position.y-750, 30, 30);
  }
  void moveTo(float x, float y){
    position.x=x;
    position.y=y;

  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Eggs disappearing in mid-air as they are going down</title>
      <link>https://forum.processing.org/two/discussion/27857/eggs-disappearing-in-mid-air-as-they-are-going-down</link>
      <pubDate>Thu, 26 Apr 2018 19:28:42 +0000</pubDate>
      <dc:creator>arrowencer</dc:creator>
      <guid isPermaLink="false">27857@/two/discussions</guid>
      <description><![CDATA[<p>eggs disappear midway as they are going down, please send help! idk if its the timer or array problem, but if anyone can detect why it disappears at random times, then please send the correct code</p>

<pre><code> PImage pan;
 PImage egg;
 PImage goldegg;
 PImage rottenegg;

 Pan catcher;
 Timer timer;
 Normal[] normal; 
 Golden[] golden;
 Rotten[] rotten;
 int totalNormal = 0;
 int totalGolden = 0;
 int totalRotten = 0;

 void setup() {
   size(500, 500);
   imageMode(CENTER);

   catcher = new Pan(20); 
   normal = new Normal[10];
   golden = new Golden[5];
   rotten = new Rotten[5];
   timer = new Timer(3000);
   timer.start();
 }

 void draw() {
   background(250, 237, 235);

   catcher.setLocation(mouseX, 450); 
   catcher.display(); 


   if (timer.isFinished()) {

     normal[totalNormal] = new Normal();
     totalNormal++ ;

     golden[totalGolden] = new Golden();
     totalGolden++;

     rotten[totalRotten] = new Rotten();
     totalRotten++;

     if (totalNormal &gt;= normal.length) {
       totalNormal = 0; 
     }

     if (totalGolden &gt;= golden.length) {
      totalGolden = 0;
     }

     if (totalRotten &gt;= rotten.length) {
       totalRotten = 0;
     }

     timer.start();
   }


   for (int i = 0; i &lt; totalNormal; i++ ) {
     normal[i].move();
     normal[i].display();

     if (catcher.collision(normal[i])) {
       normal[i].caught();
     }
   }

   for (int i = 0; i &lt; totalGolden; i++) {
    golden [i].move();
    golden[i].display();

    if(catcher.collision(golden[i])) {
      golden[i].caught();
    }
   }

   for (int i = 0; i &lt;totalRotten; i++){
     rotten[i].move();
     rotten[i].display();

     if(catcher.collision(rotten[i])) {
       rotten[i].caught();
     }
   }
 }
 class Golden {
   float x, y, r;
   float speed;

   Golden() {
     r = 10;
     x = random(width);
     y = -20;
     speed = 4;
   }

   void move() {
     y += speed;
   }


 //  boolean atBottom() {

 //    if (y &gt; height + r) { 
 //      return true;
 //    } else {
 //      return false;
 //    }
 //  }


   void display() {
     goldegg = loadImage ("GoldenEgg.png");

     for (int i = 2; i &lt; r; i++ ) {
     image(goldegg, x, y);
     }
   }


   void caught() {
    speed = 0; 
    y = -1000;
   }
 }
 class Normal {
   float x, y, r;
   float speed;

   Normal() {
     r = 10;
     x = random(width);
     y = -20;
     speed = random(1, 2);
   }

   void move() {
     y += speed;
   }


   //boolean atBottom() {

   //  if (y &gt; height + r) { 
   //    return true;
   //  } else {
   //    return false;
   //  }
   //}


   void display() {
     egg = loadImage ("RegularEgg.png");

     for (int i = 2; i &lt; r; i++ ) {
     image(egg, x, y);
     }
   }


   void caught() {
    speed = 0; 
    y = -1000;
   }
 }
 float r; 
   float x, y; 

   Pan(float tempR) {
     r = tempR;
     x = 0;
     y = 0;
   }

   void setLocation(float tempX, float tempY) {
     x = tempX;
     y = tempY;
   }

   void display() {
    pan = loadImage ("Pan.png");
    image(pan, x, y);

   }


   boolean collision(Normal n) {
    float d = dist(x, y, n.x, n.y); 

     if (d &lt; r + n.r) { 
       return true;
     } else {
       return false;
     }
   }

   boolean collision(Golden g) {
    float d = dist(x, y, g.x, g.y);

     if (d &lt; r + g.r) {
       return true;
     } else {
       return false;
    }
   }

   boolean collision(Rotten o) {
     float d = dist(x, y, o.x, o.y);

     if (d &lt; r + o.r) {
       return true;
     } else {
       return false;
     }
   }
  }
 class Rotten {
   float x, y, r;
   float speed;

   Rotten() {
     r = 10;
     x = random(width);
     y = -20;
     speed = 3;
   }

   void move() {
     y += speed;
   }


   //boolean atBottom() {

   //  if (y &gt; height + r) { 
   //    return true;
   //  } else {
   //    return false;
   //  }
   //}


   void display() {
     rottenegg = loadImage ("RottenEgg.png");

     for (int i = 2; i &lt; r; i++ ) {
     image(rottenegg, x, y);
     }
   }

   void caught() {
    speed = 0; 
    y = -1000;
   }
 }
 class Timer {

   int savedTime; 
   int totalTime; 

   Timer(int tempTotalTime) {
     totalTime = tempTotalTime;
   }


   void start() {

     savedTime = millis();
   }


   boolean isFinished() { 

     int passedTime = millis()- savedTime;
     if (passedTime &gt; totalTime) {
       return true;
     } else {
       return false;
     }
   }
 }
</code></pre>
]]></description>
   </item>
   <item>
      <title>Time delay in python mode?</title>
      <link>https://forum.processing.org/two/discussion/23846/time-delay-in-python-mode</link>
      <pubDate>Thu, 17 Aug 2017 23:13:00 +0000</pubDate>
      <dc:creator>netrate</dc:creator>
      <guid isPermaLink="false">23846@/two/discussions</guid>
      <description><![CDATA[<p>Is there a way to create a time delay in python mode?</p>
]]></description>
   </item>
   <item>
      <title>How to show a flag for 16 milliseconds</title>
      <link>https://forum.processing.org/two/discussion/26994/how-to-show-a-flag-for-16-milliseconds</link>
      <pubDate>Thu, 22 Mar 2018 18:07:55 +0000</pubDate>
      <dc:creator>Rayle</dc:creator>
      <guid isPermaLink="false">26994@/two/discussions</guid>
      <description><![CDATA[<p>Hello.</p>

<p>I'm trying to make an experiment where I need to show a national flag for only 16 or 18 milliseconds, inmmediately followed by a 300 milliseconds mask. I thought that millis() was a good solution. But it seems to me that sometimes the flag is not showed. I don't know why. Maybe I have to change the frame rate, or millis() is not reliable. Dou you have any idea about why that happens? Thank you very much.</p>

<p>This is the code:</p>

<pre><code>Flag Spain;
Mask mask;

PImage img;

float scale;

void setup() {
  fullScreen();
  noStroke();
  scale = displayHeight/10;
  Spain = new Flag();
  mask = new Mask();

  img = loadImage ("pic4.png");

  frameRate(64);
}

void draw() {
  background (255, 234, 150);

  Spain.showFlag();
  mask.showMask();

}

void keyPressed() {
   if (key == 'e' || key == 'E') {
    exit();
  }
}

class Flag {

  void showFlag() {
    if(millis() &gt; 2000 &amp;&amp; millis() &lt;=2100) {
      rectMode(CENTER);
    colorMode(RGB, 255, 255, 255);
    fill(255, 0, 17);
    rect(displayWidth/2, (displayHeight/2)-33, 134, 22);
    rect(displayWidth/2, (displayHeight/2)+33, 134, 22);
    fill(255, 234, 0);
    rect(displayWidth/2, (displayHeight/2), 134, 44);
    }
  }
}

class Mask {
 void showMask() {
   if (millis() &gt; 2016 &amp;&amp; millis() &lt; 2316) {
   imageMode(CENTER);
   image(img,displayWidth/2, displayHeight/2, 134, 88);
  } 
 }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to rotate text around box?</title>
      <link>https://forum.processing.org/two/discussion/26284/how-to-rotate-text-around-box</link>
      <pubDate>Thu, 08 Feb 2018 17:13:23 +0000</pubDate>
      <dc:creator>mellon_collie</dc:creator>
      <guid isPermaLink="false">26284@/two/discussions</guid>
      <description><![CDATA[<p>Hi! First of all, I want to apologize for my bad English. I have the assingment in which I have to:</p>

<ul>
<li>play music from mp3 file</li>
<li>create a box and make it rotating, changing sizes and colors</li>
<li>create a circle by clicking on a screen and make the circle moving down outside of the screen</li>
<li>import txt file and make lines of text from this file rotating around the box</li>
</ul>

<p>I managed to do 3 tasks (although not very good, I think), but I have no idea how to cope with the fourth one. Any suggestions? This is my code, maybe someone may have some suggestions on how to improve other tasks.</p>

<p>Thank you very much.</p>

<pre><code>import ddf.minim.*;
Minim minim;
AudioPlayer player;

void setup(){
  size(500,500,P3D);
  background(#F0AB16);
  smooth();

  minim=new Minim(this);
  player=minim.loadFile("music.mp3",512);
  player.play(); 
}

void draw(){
  background(#F0AB16);

  if (mouseButton==LEFT){
     fill(#CE2A92);
     ellipse(mouseX,mouseY,100,100);
      mouseY++;
  if (mouseY &gt; height) {
    ;
  }
  }

  translate(width/2,height/2);
  rotateX(millis()/1000.0f);
  rotateY(millis()/1000.0f);
  fill(255.0*sin(millis()/650.0),255.0*sin(millis()/800.0),255.0*sin(millis()/1000.0));
  box(250*abs(sin(millis()/1000.0))); 

}
</code></pre>
]]></description>
   </item>
   <item>
      <title>General program practices for an "effects gallery"</title>
      <link>https://forum.processing.org/two/discussion/26238/general-program-practices-for-an-effects-gallery</link>
      <pubDate>Sun, 04 Feb 2018 20:45:38 +0000</pubDate>
      <dc:creator>maurobarreca</dc:creator>
      <guid isPermaLink="false">26238@/two/discussions</guid>
      <description><![CDATA[<p>I currently have a sketch that reproduces what's drawn on the screen and displays it on a LED matrix.</p>

<p>My idea for this sketch is to draw a layered gallery of effects (simple realtime Processing made animations), but I'm not sure of how to store these effects (each one being a little portion of code).</p>

<p>I need to:</p>

<ul>
<li>Store collection of effects sequences</li>
<li>Each collection stores a sequence of layered animations ("layered animations" means up to 4 animations running on top of each other</li>
<li>Each animation has variables that can be modified by the user (as speed, hue, etc.)</li>
</ul>

<p>I know that the animations can be stored as functions and called when necessary, ordered by "layer". And maybe each collection can be also a function that calls the needed animations.</p>

<p>What structure do you recommend? I'm fairly new in Processing and Java, so I don't know the best practices for this scenario. Maybe storing the animations on a separate file and importing it? (to mantain a cleaner code)</p>
]]></description>
   </item>
   <item>
      <title>How to play a minim track at a specific time using millis()</title>
      <link>https://forum.processing.org/two/discussion/26299/how-to-play-a-minim-track-at-a-specific-time-using-millis</link>
      <pubDate>Sat, 10 Feb 2018 13:17:19 +0000</pubDate>
      <dc:creator>amycroft</dc:creator>
      <guid isPermaLink="false">26299@/two/discussions</guid>
      <description><![CDATA[<p>I am attempting to write a code which sets of a beep at controlled but random intervals using millis and minim. I can't understand why the beeps are not playing using the code below. Can anyone help?</p>

<p>I am very new to processing!</p>

<p>Thank you,</p>

<p>Amy</p>

<p>&lt;</p>

<p>pre lang="javascript"&gt;</p>

<pre><code> import ddf.minim.*;
    import ddf.minim.AudioPlayer;

    import oscP5.*;
    import netP5.*;

    OscP5 oscP5;
    NetAddress otherSketch;

    Minim minim;
    AudioPlayer beep;

    PFont f;
    int [] beeps = new int [5];
    int ms;
    int start;
    int totalBeeps;
    boolean pressEnter;

    void setup(){
      size (512,200,P3D);
      f= createFont ("Georgia",16);

      boolean pressEnter = false;
      totalBeeps = 0;
      oscP5 = new OscP5(this,8001); /* start oscP5, listening for incoming messages at port 12000 */
      otherSketch = new NetAddress("127.0.0.1",8000);

    beeps [0] = int(random(10,60))*1000;//these numbers aren't right but give an earlier beep!
    beeps [1] = int(random(1260,1739))*1000;
    beeps [2] = int(random(1860,2339))*1000;
    beeps [3] = int(random(2460,2939))*1000;
    beeps [4] = int(random(3060,3539))*1000;

    printArray (beeps);

    minim = new Minim(this);
    beep = minim.loadFile ("ping.wav");

    }

    void keyPressed() { //boolean controlling the start screen.
      if (keyCode == ENTER) { 
        start = millis();
        pressEnter = true;
      }
    }

    void draw (){

    background (255);
    textFont (f,16);
    fill (0);

    int ms = millis()-start;

    println(ms);

      if (pressEnter)//this boolean controls the start screen and initiates the timer -resetting millis to 0 when ENTER is pressed.
      {
        text("The experiment has begun and these are the random beep times:",10,40);
        text(beeps[0],10,70);
        text("milliseconds",80,70);
        text(beeps[1],10,90);
        text("milliseconds",80,90);
        text(beeps[2],10,110);
        text("milliseconds",80,110);
        text(beeps[3],10,130);
        text("milliseconds",80,130);
        text(beeps[4],10,150);
        text("milliseconds",80,150);

        OscMessage myMessage = new OscMessage("/time in milliseconds");//this isn't the correct place but a test
        myMessage.add(ms); 
        oscP5.send(myMessage, otherSketch); 
      }else {
        text("Press Enter to begin",10,100);
      }

    for (int i=0;i&lt;beeps.length;i++){ //this for loop should initiate the beeps in the array to sound if their value matches int ms (which is millis - millis when ENTER pressed) 
    if (beeps[i] == ms) 
         {
      beep.play();
      totalBeeps =totalBeeps+1;
        }
      else if ( beep.position() == beep.length() )
      {
        beep.rewind();
       }
      }
    }
</code></pre>

<p></p>
]]></description>
   </item>
   <item>
      <title>Any precedence of built-in functions? (text(), delay()...etc...)</title>
      <link>https://forum.processing.org/two/discussion/24498/any-precedence-of-built-in-functions-text-delay-etc</link>
      <pubDate>Wed, 11 Oct 2017 20:50:53 +0000</pubDate>
      <dc:creator>lowbpro</dc:creator>
      <guid isPermaLink="false">24498@/two/discussions</guid>
      <description><![CDATA[<p>Hi friends,</p>

<p>I am just wondering below code, a simple one:</p>

<pre><code>void setup() {
  size(200,200);
  background(0);
}

void draw() {
  fill(255);
  text("hi",80,80);
  delay(1000);
  text("hi2",80,80);
  background(0);
  text("hi3",80,80);
}
</code></pre>

<p>My thought is that the window will show "hi", then wait for 1 second, show "hi2", clean up, then "hi3".
However, what i see is: keep showing "hi3".
What's more strange is that, when i go into debugger mode step by step, I find "hi" is not showing up at all! So i get confused if, within the draw() loop, there is precedence of these regular functions?
Thanks to all!</p>
]]></description>
   </item>
   <item>
      <title>a question about frameRate</title>
      <link>https://forum.processing.org/two/discussion/23941/a-question-about-framerate</link>
      <pubDate>Sun, 27 Aug 2017 18:27:18 +0000</pubDate>
      <dc:creator>Rouzbelious</dc:creator>
      <guid isPermaLink="false">23941@/two/discussions</guid>
      <description><![CDATA[<p>Hello everyone,</p>

<p>I am playing with clock functions in processing and I was curious if Is it possible to have different frame rate for drawing different objects in a sketch?  in below sketch some dots are randomly drawn in approximate place of endpoints of a clock and I want to draw each bunch of points with different speed. anyone has any idea?</p>
]]></description>
   </item>
   <item>
      <title>millis() function</title>
      <link>https://forum.processing.org/two/discussion/23934/millis-function</link>
      <pubDate>Sat, 26 Aug 2017 12:55:29 +0000</pubDate>
      <dc:creator>coyote</dc:creator>
      <guid isPermaLink="false">23934@/two/discussions</guid>
      <description><![CDATA[<p>wgar</p>
]]></description>
   </item>
   <item>
      <title>I need to count off seconds in a arbitrary range.</title>
      <link>https://forum.processing.org/two/discussion/23458/i-need-to-count-off-seconds-in-a-arbitrary-range</link>
      <pubDate>Sun, 16 Jul 2017 01:05:40 +0000</pubDate>
      <dc:creator>JBradley</dc:creator>
      <guid isPermaLink="false">23458@/two/discussions</guid>
      <description><![CDATA[<p>I am working on a project where I need to repetitively cycle through a time interval in seconds limited to something other that 60 seconds. The seconds() function only cycles through 60 seconds. Is there a way to reset it on command? When your program starts running, where is the 0 second reference?</p>
]]></description>
   </item>
   <item>
      <title>Timing with millis()</title>
      <link>https://forum.processing.org/two/discussion/23293/timing-with-millis</link>
      <pubDate>Mon, 03 Jul 2017 07:29:23 +0000</pubDate>
      <dc:creator>NewStudent</dc:creator>
      <guid isPermaLink="false">23293@/two/discussions</guid>
      <description><![CDATA[<p>hey guys i am currently trying to recreate the game bang which is for mobile phone i wanted to give the player a second to get ready so i wrote this code:</p>

<pre><code>long previous;

void setup() {
  size(600, 600);
}

void draw() {
  previous = millis();
  while (millis() - previous &lt;= 1000) {
  }
  background(0);
  previous = millis();
  while (millis() - previous &lt;= 1000) {
  }
  background(255);
}
</code></pre>

<p>But when i start the skecth it waits a second background becomes white and does nothing else. What can i do to solve this problem?</p>

<p>Thanks.</p>
]]></description>
   </item>
   <item>
      <title>deltaFix , my solution to no deltaTime</title>
      <link>https://forum.processing.org/two/discussion/23277/deltafix-my-solution-to-no-deltatime</link>
      <pubDate>Sat, 01 Jul 2017 19:17:00 +0000</pubDate>
      <dc:creator>grimofdoom</dc:creator>
      <guid isPermaLink="false">23277@/two/discussions</guid>
      <description><![CDATA[<p>I have created a, kind of simple, formula for both emulating deltaTime and creating a 'game speed'; into a single variable. As I am not the best with math, I called the variable 'deltaFix', as it was my fix to the problem and also adds more to it.</p>

<p>I tried looking for information on using deltaTime, but read that it was a local variable that in inaccessible. So for being able to emulate it, I took a small amount of time to create it on my own for my needs and decided to share it because it is a bit more useful than 'just' normal deltaTime.</p>

<p>There are 2 variables that can be 'played with' to get the game running how you want it. FPS changes the screen's frameRate, and is used for determining 'deltaFix'. GAMESPEED is how fast you want the game running at (normal is 60, fast is 120, slow is 30), and also used to determine deltaFix. previousMilli is just a spot holder for the millis(), to compare frame start to frame start. deltaDiv is used as a small float placeholder to adjust the speed slightly to account for the time difference in frames (if frame 1 took a little longer to run, then frame 2 will be slightly adjusted by that)- so that the variable will not have a sudden drop due to frame rate slowing down (it is very minor, and unnoticeable; but useful if you had a sudden lag).</p>

<p>First step is to set the FPS (I usually set it to 120) and GAMESPEED (I usually set it to 60); before setup. Then in setup, I define frameRate to FPS, decide the size of the screen, then provide a previousMilli starting point (this will cause frame 1 to have a larger jump than every other frame.</p>

<p>inside draw, at the very beginning, I do my main operations for determining deltaDiv and deltaFix. deltaDiv is simply previousMilli divided by millis(), in order to get that minor (or by chance large) time difference between frames. deltaFix is a 2 step equation. First, we determine the base multiplier to properly give the GAMESPEED based on the chosen FPS. Then we multiply that by deltaDiv to apply the frame rate difference. All that is left is to make prebiousMilli = milis(), and the calculation portion is done.</p>

<p>To show an example of how it can be used, I made a simple square that moves in a singular pattern constantly, and multiplied it's movements by deltaDiv. So, while the gamespeed is at 120, I can freely adjust the FPS- and it will always be at the same point in space at the same point in time- no matter the FPS.</p>

<p>I am more then sure this can be made more accurate and faster; and has some flaws probably (I am an amateur programmer, with barely any memory of High School math from 2 years ago). I am actually using this formula in a game engine that I am developing using Processing, because why not- plus there is no game engine available that is up to date with processing currently.</p>

<pre><code>final float FPS = 120;
final float GAMESPEED = 60;

float previousMilli, deltaDiv, deltaFix;

float x = 1;
float y = 1;
void setup() {
  frameRate(FPS);
  size(640, 480, P3D);
  previousMilli = millis();
}

void draw() {
  deltaDiv = previousMilli / millis();
  deltaFix = (GAMESPEED / FPS) * deltaDiv;
  previousMilli = millis();
  background(0, 0, 0);
  x += 1 * deltaFix;
  y += 1 * deltaFix;
  rect(x, y, 25, 25);
  if (x &gt; 665) {
    x = 0;
  }
  if (y &gt; 505) {
    y = 0;
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to use millis() to display images every x seconds?</title>
      <link>https://forum.processing.org/two/discussion/23003/how-to-use-millis-to-display-images-every-x-seconds</link>
      <pubDate>Fri, 09 Jun 2017 16:59:53 +0000</pubDate>
      <dc:creator>brianna0811</dc:creator>
      <guid isPermaLink="false">23003@/two/discussions</guid>
      <description><![CDATA[<p>Hi, 
I have an array of candy images which are randomly chosen. There are candies falling and I want to make a new one fall  every 5 seconds, and I know I have to use millis() - but how would I implement it into my program? I tried using millis() like so:</p>

<pre><code>int time = millis();
  if (time&lt;5*1000)
  {
    image(goodCandy[rand], randX, goodY, randCandyW, randCandyH);
    goodY = goodY + (candySpeed * yDirCandy);
    time = millis();
  }
</code></pre>

<p>But it only appears for 5 seconds then goes away. 
I also tried:</p>

<pre><code> int time = millis();
  if (millis() - time &gt;= 5000)
  {
    image(goodCandy[rand], randX, goodY, randCandyW, randCandyH);
    goodY = goodY + (candySpeed * yDirCandy);
    time = millis();
  }
</code></pre>

<p>But it didn't work.</p>

<p>Here's the simplified code:</p>

<pre><code>    PImage [] goodCandy = new PImage [3];
    int candySpeed = 20;
    int yDirCandy = 1;
    int candyY = 10;
    int candyX = 200;
    int candyW = 187;
    int candyH = 121;
    int randCandyW = 100;
    int randCandyH = 100;

    int goodY = -200;

    int rand=(int) (2*Math.random()) +1;
    int randX = (int) (1500*Math.random())+20;

    void setup() {
    for (int i=0; i&lt;goodCandy.length; i++) {
      goodCandy[i] = loadImage("goodCandy" + i + ".png");
    }

    void draw() {
    if (current=="play") {
    loadStuff();
    }
    }

    void loadStuff() {

      image(candy, candyX, candyY, candyW, candyH);  //original candy
      candyY = candyY + (candySpeed * yDirCandy);

      int time = millis();
      if (millis() - time &gt;= 5000)
      {
        image(goodCandy[rand], randX, goodY, randCandyW, randCandyH);
        goodY = goodY + (candySpeed * yDirCandy);
        time = millis();
      }

      //for (int i=0; i&lt;time; i++) {
      //  image(goodCandy[rand], randX, goodY, randCandyW, randCandyH);
      //  goodY = goodY + (candySpeed * yDirCandy);
      //  time = millis();
      //}
    }
</code></pre>

<p>Any ideas how I could make millis() work so I can have a random candy falling every 5 seconds?
Thanks</p>
]]></description>
   </item>
   <item>
      <title>How to use timer (millis()) properly</title>
      <link>https://forum.processing.org/two/discussion/22459/how-to-use-timer-millis-properly</link>
      <pubDate>Mon, 08 May 2017 13:33:00 +0000</pubDate>
      <dc:creator>BodegaB</dc:creator>
      <guid isPermaLink="false">22459@/two/discussions</guid>
      <description><![CDATA[<p>Hi everybody,</p>

<p>i will post my code below, what im trying to accomplish is that when my x and y variables reach certain value and stay in those valuse for 5 sec, i want R, G and B values to change after that,and than reset that timer again, this is what i have come up with for now, but what happens is, when x and y fulfill that IF statement it instantly changes those R G B values , it doesnt wait for 5 sec like i would want to.. pls help if you can...</p>

<pre><code>int start, timer1;
int R=0, G=0, B=0;
int leftSensor, rightSensor;

void Setup(){
...
start = millis();
...
}

void draw(){
...
red(leftSensor, rightSensor, timer1);
...
}

 void red(int x, int y, int t)
{
      if(x &lt;= 62 &amp;&amp; x &gt;=58 &amp;&amp; y&lt;=65 &amp;&amp; y &gt;= 63 )
  {
      t = millis()-start;
      if(t &gt;= 5000){
      R = 204; G = 0; B = 0;
      }
  }
  t = 0;
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to specify a time frame for key press?</title>
      <link>https://forum.processing.org/two/discussion/22516/how-to-specify-a-time-frame-for-key-press</link>
      <pubDate>Thu, 11 May 2017 07:19:11 +0000</pubDate>
      <dc:creator>catjaa</dc:creator>
      <guid isPermaLink="false">22516@/two/discussions</guid>
      <description><![CDATA[<p>Hey,
I am somewhat new to processing and I am trying to make a sort of game for a school project. It is an interactive game where the player is shown a video and within the last ten-ish seconds they have to make a choice by pressing a key, this will then take them to the next part of the story. My question is, is there a way to specify a time frame within which the player can press the key so that if they press the key outside of that time frame nothing happens? Right now if the key is pressed before the ten second countdown at the end it goes on to the next video, which kind of ruins the experience.</p>

<p>I'm not really sure how to correctly add code to this post so if you need to see any, let me know and I will try to figure it out.</p>
]]></description>
   </item>
   <item>
      <title>When does millis start?</title>
      <link>https://forum.processing.org/two/discussion/22272/when-does-millis-start</link>
      <pubDate>Fri, 28 Apr 2017 20:36:27 +0000</pubDate>
      <dc:creator>Sjors</dc:creator>
      <guid isPermaLink="false">22272@/two/discussions</guid>
      <description><![CDATA[<p>Real quick question, does millis start when you reach void draw or does it start at setup?</p>
]]></description>
   </item>
   <item>
      <title>How can i display the seconds? (And some other beginner questions)</title>
      <link>https://forum.processing.org/two/discussion/22217/how-can-i-display-the-seconds-and-some-other-beginner-questions</link>
      <pubDate>Wed, 26 Apr 2017 05:24:27 +0000</pubDate>
      <dc:creator>GottfriedBoehm</dc:creator>
      <guid isPermaLink="false">22217@/two/discussions</guid>
      <description><![CDATA[<p>Hi folks,</p>

<p>i just discovered Processing and learning it since 3 days. It is my first programming experience, so please forgive me if the questions are dumb.  :\"&gt;</p>

<p>I would be really happy if you can help me.</p>

<p>Cheers :-h</p>

<blockquote class="Quote">
  <p>Issues:</p>
  
  <p>-I could not display the seconds. I just tried append the result of frameRate/60 to IntList inventoryTime and display it as text on the screen and if ball is outside of height inventoryTime.clear(); but i think it is was just stupid idea.</p>
  
  <p>-My score screen doesn't work perfectly. I think another stupid idea of me.</p>
  
  <p>-Ball doesn't return if it hits the racket. No idea about this, even it should be a stupid idea. I could think no solution for this.</p>
</blockquote>

<pre>void setup() {
  size(600, 400);
  background(#C70039);
  smooth();
  noStroke();
}

float ballX = 0;
float ballY = 0;
float speedX = random(2, 4);
float speedY = random(2, 5);
color cWon = #C70039;
color cLost = #FF5733;
int score = 0;

void draw() {
  IntList timeInventory;
  timeInventory = new IntList();
  timeInventory.append(frameCount/60);    
  background(cWon);
  println (timeInventory);
  println (ballY);

  if (ballX &lt; 0 || ballX &gt; width) speedX = -speedX;
  {
    ballX += speedX;
    ballY += speedY;
    ellipse(ballX, ballY, height/15, height/15);

    float boardLimit = constrain(mouseX, width/6, width/1.2);
    rectMode (CENTER);
    rect (boardLimit, height/1.05, width/3, height/20, height/3);

    textSize(height/25);
    textAlign(TOP);
    text("Time:" + timeInventory.get(0) +"s", height/40, height/20);

    float paddle = 1000/(score+10);
    float distance = abs (mouseX-ballX);
    if (distance &lt; paddle) score += 1;
    textSize(height/28);
    text("Score:" + score, height/40, height/10);
  }
  if (ballY &gt; height) {
    background(cLost);
    textSize(height/10);
    textAlign(CENTER);
    text("TRY AGAIN", width/2, height/2);
    timeInventory.clear();
  }
}

void mouseClicked() {
  if (ballY &gt; height) {
    ballX=random(0, width);
    ballY=0;
  }
}</pre>
]]></description>
   </item>
   <item>
      <title>How to replicate random vector movement along several axises</title>
      <link>https://forum.processing.org/two/discussion/21778/how-to-replicate-random-vector-movement-along-several-axises</link>
      <pubDate>Mon, 03 Apr 2017 11:02:45 +0000</pubDate>
      <dc:creator>fagerli</dc:creator>
      <guid isPermaLink="false">21778@/two/discussions</guid>
      <description><![CDATA[<p>Sorry about the confusing formulation of the title. I simply didn't know how to formulate what i'm asking in a short sentence.</p>

<p>I have code that increments a vector in a random direction every 3 seconds, with easing. What I need to figure out is how to do this with all the vectors in all the directions (x and y). Basically, i'm trying to have a shape where all the vectors of the shape move about randomly on the canvas.</p>

<pre><code>float incr =0.2;
float xpos = 120;
int lastTimeCheck;
  int timeIntervalFlag = 3000; 
float x;
float y;
float easing = 0.05;

void setup() {

  size(500,707);
  stroke(255);
  lastTimeCheck = millis();

}





void draw() {
  background(49,48,48);
  float ran = random(2.3);

   if ( millis() &gt; lastTimeCheck + timeIntervalFlag ) {
    lastTimeCheck = millis();
    if (ran &gt; 1) {
    incr = 0.2;
    incr = incr*-1;

  }
  else if (ran &lt; 1) {
    incr = 0.2;

  }
  }


  if (xpos &lt; 0) {
    xpos = 0;

  }
xpos = xpos+incr;


  float targetX = xpos;
  float dx = targetX - x;
  x += dx * easing;

  beginShape();

    vertex(x,120);

    vertex(250,220);

    vertex(200,320);

    vertex(70,335);

  endShape();
  println(xpos);


}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How do I time animations when i'm using an array?</title>
      <link>https://forum.processing.org/two/discussion/21793/how-do-i-time-animations-when-i-m-using-an-array</link>
      <pubDate>Tue, 04 Apr 2017 09:45:30 +0000</pubDate>
      <dc:creator>fagerli</dc:creator>
      <guid isPermaLink="false">21793@/two/discussions</guid>
      <description><![CDATA[<p>I have here code that randomly either increments or decrements an x value using an array and a loop. The loop goes through and picks either an incrementation or a decrementation at random. It then stores that in an array. It goes through 4 loops and outputs 4 x values at each loop. I then use those 4 values and put them in 4 vertex(). The desired result is a shape where each vertex moves about randomly on the canvas.</p>

<p>What I would like to implement is a time delay on the change between increment and decrement. I want to make each point travel in one direction for at least 3000 milliseconds before it might change direction again. I have tried using an if-statment that checks if 3 seconds have passed before it runs the part of the code that randomly chooses an increment or a decrement. The problem is that it only checks every 3000 milliseconds overall, rather than checking if 3000 milliseconds have passed for each single x-value. Basically what I need is for the code to check each spot in the x[] array and see if 3000 milliseconds have passed since it randomly incremented or decremented. Hope I've explained in enough detail.</p>

<p>Here's the code I have written:</p>

<pre><code>int lastTimeCheck;
int timeIntervalFlag = 3000; 
float[] x = new float[4];
float[] incr = new float [4];
void setup() {
  smooth();
  size(500, 707);
  stroke(255);
  lastTimeCheck = millis()/4;
  noFill();
}

void draw() {
  background(49, 48, 48);

  for (int i = 0; i &lt; 4; i++) {

    if ( millis() &gt; lastTimeCheck + timeIntervalFlag ) {
    lastTimeCheck = millis();
    float ran = random(2);


    if (ran &gt; 1) {
      incr[i] = 0.5;
      incr[i] = incr[i]*-1;
    } else if (ran &lt; 1) {
      incr[i] = 0.5;
    }
   }


    println("i ran");

    if (x[i] &gt; width || x[i] &lt; 0) {
      incr[i] = incr[i]*-1;
    }



    x[i] = x[i] + incr[i];



    // println(x[i] + "loop" +i+ incr[i]);
  }
  beginShape();
  vertex(x[0]+20, 40);
  vertex(x[1]+20, width-40);
  vertex(x[2]+20, height-40);
  vertex(x[3]+20, 100);


  endShape(CLOSE);
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Growing Circle</title>
      <link>https://forum.processing.org/two/discussion/21230/growing-circle</link>
      <pubDate>Tue, 07 Mar 2017 17:08:45 +0000</pubDate>
      <dc:creator>th0mato</dc:creator>
      <guid isPermaLink="false">21230@/two/discussions</guid>
      <description><![CDATA[<p>Hey, I want a circle to grow  per second and reach a limit. I don't want to set the framrate down, because it seems to affect the mousePressed section, which I also want to use. How can I make the circle grow step by step and then reset the count variable? Maybe I messed up a little..</p>

<pre><code>int startTime;
float a=30;
float count;
boolean start=false;

void setup()
{
  size(800,800);
  background(0);
  startTime=millis()/1000;
}

void draw()
{
  println(count);
  if(start)
  {
      count=millis()/1000 - startTime;
      a=a+count*10;
  }
      if(a&gt;=290);
    {
      start=false;
      //startTime=millis()/1000;

    }
ellipse(width/2,height/2,a,a);
 // println(a);
}

void mousePressed()
{
      start=true;
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Save the time when mouse is pressed to use it in a variable - Python Mode</title>
      <link>https://forum.processing.org/two/discussion/21027/save-the-time-when-mouse-is-pressed-to-use-it-in-a-variable-python-mode</link>
      <pubDate>Mon, 27 Feb 2017 11:40:38 +0000</pubDate>
      <dc:creator>avocado</dc:creator>
      <guid isPermaLink="false">21027@/two/discussions</guid>
      <description><![CDATA[<p>Hello,</p>

<p>I'm trying to save the time in a variable to use it for a figure to disappear 10 seconds after it appears or disappear randomly.
and for every figure that appears on screen.</p>

<p>At the moment It saves the time many times.</p>

<pre><code>"""
Mouse Press.

Move the mouse to position the shape.
Press the mouse button to invert the color.
"""
#tick=millis()


def update_tick():
    #text(12)
    #textAlign(CENTER)
    pd= millis()/1000
    return pd

def setup():
    global times
    size(640, 360)
    noSmooth()
    fill(126)
    background(102)
    times=[]


def draw():
    #times=[]
    the_time=update_tick()
    if mousePressed:

        stroke(255)
        line(mouseX - 66, mouseY, mouseX + 66, mouseY)
        line(mouseX, mouseY - 66, mouseX, mouseY + 66)
        times.append(the_time) 
        print times
    else:
        stroke(0)
</code></pre>

<h2>Thank you!!</h2>
]]></description>
   </item>
   <item>
      <title>Random 'if'</title>
      <link>https://forum.processing.org/two/discussion/20892/random-if</link>
      <pubDate>Mon, 20 Feb 2017 08:51:04 +0000</pubDate>
      <dc:creator>skaarup91</dc:creator>
      <guid isPermaLink="false">20892@/two/discussions</guid>
      <description><![CDATA[<p>Hi</p>

<p>I'm very new to processing and I'm having trouble using random. I want 'if' to react when the difference between TimeMeasurement and millis is a random number between 2000 and 10000. How do I do this?</p>

<p>The program runs when I type e.g. "if (difference &gt; 5000)", but not when I use random.</p>

<p>Can you help?</p>

<pre><code>int TimeMeasurement = 0; 

void setup() {
 size(800,600);
}

void draw() {
  background(255);
  fill(255, 0, 0);
  ellipse(400, 300, 20, 20);

  int difference = millis() - TimeMeasurement; 
  println(millis() + " - " + TimeMeasurement); 

  if (difference = random(2000, 10000)) { // this is not working - why? 
    background(255);
    fill(93, 224, 102);
    ellipse(400, 300, 300, 300);
  }
}

void keyPressed() { // 
  TimeMeasurement = millis(); 
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>movingSquares</title>
      <link>https://forum.processing.org/two/discussion/20678/movingsquares</link>
      <pubDate>Mon, 06 Feb 2017 08:11:56 +0000</pubDate>
      <dc:creator>cygig</dc:creator>
      <guid isPermaLink="false">20678@/two/discussions</guid>
      <description><![CDATA[<p>I was experimenting with OOP and arrays. A bunch of squares eating one another out.</p>

<p><a href="https://www.openprocessing.org/sketch/404134" target="_blank" rel="nofollow">https://www.openprocessing.org/sketch/404134</a></p>
]]></description>
   </item>
   <item>
      <title>How do I scale real motion (e.g., miles/hour) to pixels/second?</title>
      <link>https://forum.processing.org/two/discussion/19715/how-do-i-scale-real-motion-e-g-miles-hour-to-pixels-second</link>
      <pubDate>Tue, 13 Dec 2016 01:47:17 +0000</pubDate>
      <dc:creator>ElusivePi</dc:creator>
      <guid isPermaLink="false">19715@/two/discussions</guid>
      <description><![CDATA[<p>Daniel Shiffman made a tutorial on <a rel="nofollow" href="https://www.youtube.com/watch?v=YIKRXl3wH8Y">how to draw a moving ball</a>.</p>

<p>In it I commented (reproduced below) on the following lines of code:</p>

<pre><code>  float circleX;
  float xspeed = 0.2;

  void draw(){
  ...
  ellipse(circleX,height/2,32,32);
  circleX = circleX + xspeed;
  }
</code></pre>

<p>We're using floating arithmetic to implement motion that occurs in discrete steps in our program. Correct me if I'm wrong: There is no notion of ".2" of a pixel (a fraction of a pixel) and that the ellipse function, in its implementation, is overloaded so that the location of the ellipse is drawn at  Floor(x_position, y_position) for float variables x_position, y_position.</p>

<p>By using floating values,  we force processing to implicitly reference a step function to determine where to draw an ellipse. So if we have a step size of .2, the variable that stores position must increment by the step size 5 times before we actually see the ellipse move 1 pixel unit over. <strong>The delay in motion that we perceive corresponds to the delay resulting from incrementing the float to the next highest whole number that processing interprets as a new coordinate.</strong></p>

<hr />

<p>If the above bolded statement is true and the delay is a function of the time required to increment a float, is it then necessary to measure this delay in order to perform unit conversion (mi/hr to px/sec)?</p>

<p>The end goal is to map some real-world rate to a rate represented in processing such that the rate in processing isn't affected by variables that a programmer can't control (cpu scheduling, for instance). Basically, if I wanted a mapping of 70mi/hr to 70px/sec, I'd like for the processing rate to be a consistent 70px/sec and not 67px/sec or 80px/sec.</p>
]]></description>
   </item>
   <item>
      <title>keyPressed and keyReleased functions NOT WORKING! Help!</title>
      <link>https://forum.processing.org/two/discussion/19339/keypressed-and-keyreleased-functions-not-working-help</link>
      <pubDate>Sun, 27 Nov 2016 21:57:09 +0000</pubDate>
      <dc:creator>MyName</dc:creator>
      <guid isPermaLink="false">19339@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>I have been trying a ton of different approaches with keyPressed and keyReleased functions. One example is this:</p>

<pre><code>void power ()
{
  float time = 0;
 while(keyPressed)
 {
   if(key == ' ' &amp;&amp; power&lt;max_power)
    power +=.01; 
    delay(10);
    println(power);
 }
</code></pre>

<p>Here, ideally, every time I press the space bar, and the power is below a certain value, we increment the power.However, even when I RELEASE the space bar, power continues to be incremented until max_power. This doesn't make any sense to me because when any of the keys are NOT being pressed, the while is essentially like while(FALSE). So I don't see how it could continue to be incremented. Not sure if the problem lies in the fact that I put this function in void loop, but whats happening seems very counterintuitive.</p>

<p>I tried this other function as well to count the time, but this does not work either:</p>

<pre><code> float time = 0;
float final_time;
void setup ()
{

}
void loop ()
{
  println(time+"   "+final_time);

}
void keyPressed()
{
 time = millis(); 
}
void keyReleased()
{
  final_time = time;
  time = 0;
}
</code></pre>

<p>Or I've tried this as well to count the time:</p>

<pre><code>float time = 0;
void setup ()
{

}
void loop ()
{
if (keyPressed)
{
  delay(100);
  time+=.1;
}
println(time);
}
</code></pre>

<p>But this doesn't work either....</p>

<p>I'm sure there is something very simple behind my error.</p>

<p>Thank you!!!!</p>
]]></description>
   </item>
   <item>
      <title>Why does changing one line slow down my timer?</title>
      <link>https://forum.processing.org/two/discussion/19069/why-does-changing-one-line-slow-down-my-timer</link>
      <pubDate>Wed, 16 Nov 2016 12:49:38 +0000</pubDate>
      <dc:creator>mahela007</dc:creator>
      <guid isPermaLink="false">19069@/two/discussions</guid>
      <description><![CDATA[<p>Hello guys. I'm starting out with processing and I'm trying to make a stop watch with a pause function. I have gotten a working timer and the code is below: However, replacing line 16 with the code on line 17 (i.e uncommenting line 17 and commenting out line 16) produces a massive slow down in the timer.. milliseconds pass like seconds. I cannot understand why this happens.. any help would be greatly appreciated. 
(I want line 17 to work, line 16 is just a debugging line. )</p>

<p>The logic behind using the variable totalTime was so that I could pause the timer by stopping the incrementation whenever the user triggered the pause action. When the timer is not paused (the pausing code hasn't been added yet), totalTime is incremented by 2 when 2 milliseconds pass.</p>

<pre><code>       int timeBefore=0;
        int totalTime = 0;
        void setup(){
          size(512,128);
        }

        void draw(){
          background(125);
          int timeNow = millis();
          if ((timeNow - timeBefore)&gt; 2){
            timeBefore = timeNow;
            totalTime += 2;


          }
          drawTime(width/2,height/2,millis());
          //drawTime(width/2,height/2,totalTime);

        }


        void drawTime(int x, int y, int milliSeconds) {

          //String to store the time value
          //String timeString = "";
          //String hours="";
          String mins="";
          String sec="";
          String mills="";


          //**Do some error checking here
          if (milliSeconds&lt;0) {
            println("Something went wrong when displaying the time");
            return; //
          } else {
            mills= str(((milliSeconds)%1000)/10); //divide by 100 so that we display only two digits
            mills = formatTime(mills,2);
            sec = str((milliSeconds/1000) % 60);
            sec = formatTime(sec,2);
            mins = str(milliSeconds/(60*1000)); //not modding by 20 because we can count minutes indefinitely
            mins = formatTime(mins,2);
            text (mins+":"+sec+":"+mills,x,y);
          }
        }

        //function to format strings to always have a fixed number of digits
        String formatTime(String input, int digits){

          while (input.length() &lt; digits){
            input = "0"+input;
          }

          return input;


        }'
</code></pre>
]]></description>
   </item>
   <item>
      <title>Show running time at the end of process</title>
      <link>https://forum.processing.org/two/discussion/18073/show-running-time-at-the-end-of-process</link>
      <pubDate>Mon, 05 Sep 2016 01:38:41 +0000</pubDate>
      <dc:creator>siminan87</dc:creator>
      <guid isPermaLink="false">18073@/two/discussions</guid>
      <description><![CDATA[<p>Hi guys I need some help. I want to display the time an application has been running for at the end of a process how do I do this. Thank you in advance.</p>
]]></description>
   </item>
   <item>
      <title>DeltaTime</title>
      <link>https://forum.processing.org/two/discussion/18478/deltatime</link>
      <pubDate>Sun, 09 Oct 2016 22:05:26 +0000</pubDate>
      <dc:creator>poisson86</dc:creator>
      <guid isPermaLink="false">18478@/two/discussions</guid>
      <description><![CDATA[<p>Hey, I'm doing a game and I'd like to know if it's possible to have the delta time in Processing ? :)</p>
]]></description>
   </item>
   <item>
      <title>Move object over specified time period</title>
      <link>https://forum.processing.org/two/discussion/18268/move-object-over-specified-time-period</link>
      <pubDate>Fri, 23 Sep 2016 21:58:16 +0000</pubDate>
      <dc:creator>jeffthompson</dc:creator>
      <guid isPermaLink="false">18268@/two/discussions</guid>
      <description><![CDATA[<p>I'd like to move an object from one position to another over a specified period of time in milliseconds, but am thoroughly stuck (maybe because it's Friday night and I have been staring at this screen too long).</p>

<p>I have this code, hacked from one of the examples:</p>

<pre><code>float x,y;
float startX,startY, endX,endY;
float distX, distY;
float percent;
float step = 0.01;


void setup() {
  size(800,800);

  startX = width/2;
  startY = height/2;

  endX = 100;
  endY = 100;

  distX = endX - startX;
  distY = endY - startY;
  percent = 0;
}

void draw() {
  background(255);

  percent += step;
  if (percent &lt; 1.0) {
    x = startX + (percent * distX);
    y = startY + (percent * distY);
  }  

  fill(255,150,0);
  noStroke();
  ellipse(x,y, 50,50);  
}
</code></pre>

<p>It moves the ball nicely and I can change the <code>step</code> variable to set the speed, but I really would like to get it so the movement happens over exactly 1000 milliseconds, for example.</p>

<p>Help!</p>
]]></description>
   </item>
   </channel>
</rss>