We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
How to delay? (Read 852 times)
How to delay?
Oct 12th, 2009, 9:51am
 

Hello, world!

I'm new in Processing, actualy I've only started using it because I have to make something creative with it as a "homework"(long story)

So far I like it, it's very comprehensive Smiley

So, the question is:

I have a sequence of actions that I want to correspond with background music, I feel things are going too fast,

I tried using delay(); funcion, but it doesn't work properly:

the cicle starts banyway, as if unaware of delay at all.

Could please someone help me? It´s not finished, btw

import ddf.minim.*;
import ddf.minim.signals.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;

PImage img;
int x = 30;
PFont fontA;
Minim minim;
AudioPlayer song;

void setup(){
 size(800, 600);
 background(255);
 img = loadImage("door.jpg");
 minim = new Minim(this);
 song = minim.loadFile("rolling_stones_-_paint_it_black.mp3");
 fontA = loadFont("Ziggurat-HTF-Black-32.vlw");
 smooth();

}

void draw(){
 
 song.play();
 
 fill(0);
 textFont(fontA, 32);
 text("Rolling Stones", x, 60);
 text("Paint", x, 95);
 text("it", x, 130);
 text("Black", x, 165);
 
 delay(1000);
 
 imageMode(CENTER);
 image(img, 400, 300);
 tint(0,0);
 
 for ( int i = 0; i < random(600); i++) {
     stroke(0);
     fill(0);
     ellipse(random(800), random(600),20,20);
 
 }
}
Re: How to delay?
Reply #1 - Oct 12th, 2009, 10:07am
 
Search 'delay' in the forum, you will see why it is a bad idea to use it in animations... Smiley

Short answer: count time since start of sketch, trigger events when time reaches some milestones (secondstones...).
Re: How to delay?
Reply #2 - Oct 12th, 2009, 10:07am
 
I see a window* and I want it painted #000000...

millis() is your friend; it returns the milliseconds the program's been running.  The bps throughout the song may vary, and without using a beat-detection algorithm you may just have to tweak it by hand...but, minim does have a beatDetect class.  You can also use frameRate ( n ); to set the maximum frames per second, but for accurate timing across platforms you should probably keep track of millis and update when time-since-last-update > specified-interval.

*PApplet...
Re: How to delay?
Reply #3 - Oct 13th, 2009, 9:09am
 
thank you, both of you, I'll try to make something out of it, though I think it's better to pick up another idea
Page Index Toggle Pages: 1