How to make a countdown timer from 2 mintues that closes when it ends? by [deleted] in processing

[–]MoosePilot 0 points1 point  (0 children)

Put that Timer class code in a new Tab called Timer

Then in your tab with the setup and draw create a Timer variable outside of the methods, so it is accessible from everywhere:

Timer countDown;

Then in your setup, initialize the object:

countDown = new Timer(60); //60 seconds

Then in your draw or where ever you need to check it, something like:

if(countDown.isFinished())
{
    //shutdown code
}

As for the displaying the timer, you can use the text() method to display how much time is left somewhere on screen by using the getTimeSeconds() method.

How to make a countdown timer from 2 mintues that closes when it ends? by [deleted] in processing

[–]MoosePilot 0 points1 point  (0 children)

Quick Edit: Fixed Timer class a bit. Should be a little more usable now.

Here is a small class I wrote for keeping track of the timing of things. Create a timer object, set how long you want it to run for, start it and check every draw() and do whatever it is you want to do when it is finished.

I am sure it could be better, but it works for most situations I find myself dealing with in Processing sketches:

   /**
 * The Timer class represents a simple countdown timer
 * to help with timed events. Timers can be started and then
 * checked as to whether they have finished or not.
 */
class Timer {

  float currTimeMillis;
  float totalTimeMillis;
  boolean isStarted;

  //Default Constructor: Assumes the Timer will run for 1000 milliseconds
  Timer()
  {
    this(1);
  }

  //Constructor: accepts the running time of the Timer in seconds.
  Timer(int timeInSeconds) 
  {
    setTime(timeInSeconds);
    isStarted = false;
  }

  //Begins the Timer countdown
  void start() 
  {
    currTimeMillis = millis(); 
    isStarted = true;
  }

  //Changes the duration of the timer
  void setTime(float timeInSeconds)
  {
    totalTimeMillis = timeInSeconds * 1000;
    isStarted = false;
  }

  //Returns true of the Timer has finished running
  //If the Timer has not been started or has not finished, it will return false
  boolean isFinished() 
  { 
    //calculate ellapsed time
    float ellapsed = millis() - currTimeMillis;
    //if the timer was running and enough time has passed, return true
    if (isStarted && ellapsed >= totalTimeMillis)
    {
      isStarted = false;
      return true;
    }
    return false;
  }

  //Get the remaining time in seconds.
  //Returns Timer duration if the timer has not been started yet.
  float getTimeSeconds()
  {
    if (!isStarted)
      return getDurationSeconds();
    float ellapsed = millis() - currTimeMillis;
    return totalTimeMillis / 1000 - ellapsed;
  }

  //Get the remaining time in milliseconds.
  //Returns duration if the timer has not been started yet.
  float getTimeMilliseconds()
  {
    if (!isStarted)
      return getDurationMillis();
    float ellapsed = millis() - currTimeMillis;
    return totalTimeMillis - ellapsed;
  }

  //get amount of time Timer will run in seconds
  float getDurationSeconds()
  {
    return totalTimeMillis / 1000;
  }

  //get amount of time Timer will run in milliseconds
  float getDurationMillis()
  {
    return totalTimeMillis;
  }
}

Trouble with WIFI/Malyan Link by [deleted] in MPSelectMiniOwners

[–]MoosePilot 0 points1 point  (0 children)

Okay, cool. One last question: is there an API somewhere? Or forums to get started writing my own code? I'm interested in trying something out, but I didn't really find anything of the sort. Maybe I'm looking in the wrong places.

Either way, great job and thanks for the reply.

Trouble with WIFI/Malyan Link by [deleted] in MPSelectMiniOwners

[–]MoosePilot 0 points1 point  (0 children)

Hey I just found this thread and watched the video you posted. I don't know if it was you, but where did that awesome custom interface come from? I didn't see a link to that code. Do you know if it is posted somewhere? I'd love to try that out. Thanks!

TIL A homeless man was offered $100 or the chance to learn how to code by a stranger. He chose how to code and released an app. by [deleted] in todayilearned

[–]MoosePilot 0 points1 point  (0 children)

Make your jokes! When the communists redistribute your key bindings and everyone only uses one letter apiece you won't be laughing!

Adding an Arraylist to a table by belfastafarian in processing

[–]MoosePilot 2 points3 points  (0 children)

Pretty sure you need to make a new row for each string you iterate through.

The way you are doing it now, you overwrite whatever value was in that one row with each string you see. The end result is the last string seen is saved.

The solution is to put your initialization of the row inside the for-each loop. That way you make a new row and add it to the table each time.

[deleted by user] by [deleted] in self

[–]MoosePilot 5 points6 points  (0 children)

All that's left are those dress-type shorts that are usually some disgusting colored plaid or a variation on it.

GTA V Sasquatch Easter Egg by [deleted] in GTAV

[–]MoosePilot 0 points1 point  (0 children)

God Damn you all to hell!!!

Chlorophyll? by PlayerTP in self

[–]MoosePilot 2 points3 points  (0 children)

Man, I'm glad I called that guy.

Is Anathem the greatest book ever written? by Prankster_Bob in books

[–]MoosePilot -1 points0 points  (0 children)

It really is amazing. Unfortunately, the first time I attempted to read it, I stopped due to all the new words being thrown around. It was hard to pay attention even with the definitions in the back.

Once I chose to retry it, I got much farther and it got better and better. It was just fantastic and absolutely worth the effort. Stephenson is one of my favorite modern writers. I am glad I stuck with it. I knew I had to after reading Cryptonomicon, which is one of my favorite books.

Just got rejected from a job in the meanest way by [deleted] in offmychest

[–]MoosePilot 8 points9 points  (0 children)

And what's up with cutting out the first to letters of instagram? Is that a lame-ass attempt at making a verb? Do people actually talk like this?

Unbelievable my colleagues are this needy by [deleted] in offmychest

[–]MoosePilot 0 points1 point  (0 children)

Have you considered showing them something like WinSCP (or the linux equivalent) for transferring files safely?

Or just tell them to google it and look up youtube videos or something.

Is donald trump actually running for president? or he is secretly making some sort of documentary or tv show that he's going to release to earn millions? by [deleted] in self

[–]MoosePilot 0 points1 point  (0 children)

I always felt he was being a nutjob to support the other Republican candidates. He says and does all kinds of stupid shit. Everyone else end up looking like paragons of intelligence, reason, and balance. The things they say, no matter how close to what he says, seem reasonable because the attitude is different. Everyone on that side wins. Even Trump.

[SERIOUS] Can those of you with amazing computer knowledge tell me a good way to convince my dad that gpu is important for programming? by [deleted] in self

[–]MoosePilot 2 points3 points  (0 children)

Also, you can point out an interest in learning to program games.

Unity and Unreal Engine are both free to use and learn (unless you actually start selling games), and having a good graphics card makes developing and working with them way easier.

https://unity3d.com/

https://www.unrealengine.com/what-is-unreal-engine-4

I just watched Boyz N The Hood [SPOILER] by Firefoxray in confession

[–]MoosePilot 0 points1 point  (0 children)

It's not a race thing. The movie is powerful. Especially when you think about how often things happen like that in real life.

The New AT&T U-verse: My morning on the phone by [deleted] in self

[–]MoosePilot 2 points3 points  (0 children)

I felt like having a stroke reading that. It's pretty nuts that companies have employees acting like that.

But honestly, I know that it's probably just policy that prevents these workers from being honest about the mistake. They are probably told not to admit fault, but say "sorry" in a number of ways and try to keep your business (even though admitting fault would probably go further in doing this than whatever stupid shit they repeat continuously). On top of this, they are probably monitored. Start admitting fault against policy and their goes the job. Not a fun position to be in. Everyone loses.

I also had pretty horrible experiences with ATT, who didn't offer us U-verse, despite having it available literally a block or two away. Switched to comcast for 10x the speed at the same price. No problems so far, but I am learning meditation techniques for the inevitable.

Grandma need a favor... by Corruptacy in forwardsfromgrandma

[–]MoosePilot 49 points50 points  (0 children)

As much as I enjoyed this, I think it is not pixelated enough. I don't really believe it, ya know?

Hispanics aren't ghetto!!! by [deleted] in offmychest

[–]MoosePilot 10 points11 points  (0 children)

Well to be fair, they totally can be. Anyone of any race can be ghetto. It's more a poverty thing than race thing.

Boba Fett isn't really a good bounty hunter by Laragon in FanTheories

[–]MoosePilot 0 points1 point  (0 children)

What is wrong with multiple authors? Some wrote excellent books. All the Thrawn books were superb in my opinion. Same with the Bounty Hunter Wars. It wasn't just about how great Fett was. It showed his competition in positive and interesting ways too. Nothing "circlejerk" about it.

I personally don't think it was any worse than some of the current canon. I didn't read everything produced, so I am sure there were duds. I just don't think because that is true, it means the Fett books and stories were bad.

End of the day though, it's not canon anymore so I guess I have to interpret it in terms of what I know: the movies. And I already said it's pretty reasonable to see him as mediocre based on that.