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.
IndexProgramming Questions & HelpSyntax Questions › Beginner problem; fading and recursion
Page Index Toggle Pages: 1
Beginner problem; fading and recursion (Read 244 times)
Beginner problem; fading and recursion
Jan 8th, 2009, 2:56am
 
Hallo.
I'm a rank beginner, but I thought a small PHP background might let me be ambitious.  Apparently not.
But while I go back to the basics, could you folks perhaps let me know what I'm doing wrong?

My plan was to make a red screen (well, rectangle) pulse according to a midi clock I was planning on adding later.  I wanted a red to black fade similar to Robert Hodgin's video with Bitshifter (http://vimeo.com/2148419)
Basically wanted to mimic that effect, play around with recursion a we bit, and hopefully build into a slightly larger thingy

I seem to have the numbers doing (vaguely) what I want according to the Println function, though the map function isn't acting like I'd expect it to.  The maximum mapped numbers are returning values higher than it should, whereas it also occasionally goes below what it should.  I am very confused.

But slightly more importantly to my short attention span and need for immediate results, the goddamn fill and rect functions aren't working producing anything and I can't figure out why.
Please help?

Many thanks

Code:

import processing.opengl.*;
import promidi.*;

int bpm = 120;
int frate = 30;
float fmath;
float lPha = 0;
int fram = 0;
float pulse;


void setup() {
size(640,480,P2D);
frameRate(frate);
colorMode(HSB);
background(0,255,255);
smooth();
noStroke();
rectMode(CORNER);
}




void draw() {
pulse = bpm / frate;
for(int i = 0; fram-1 <= i; i++) {
fmath = (bpm / pulse) - fram;
lPha = ceil(map(fmath,0,frate-1,0,255));
fill(0,lPha,lPha);
rect(0,0,width,height);
if(fram > (bpm / pulse)) { i = 0;}
if(fram-1 >= (bpm / pulse)) { fram = 0;} else{ fram++; };
println(fram + " - " + pulse + " - " + fmath + " - " + lPha);

}

}
Re: Beginner problem; fading and recursion
Reply #1 - Jan 8th, 2009, 10:36am
 
There are many ways to do so.

One way would be using frameCount. But you don't have much control over it.
Code:


void setup() {
size(640,480);
frameRate(30);
colorMode(HSB);
noStroke();
}


void draw() {
background(0, 255- (frameCount%255), 255-(frameCount%255));
}


The other would be using an increment
Code:

int value;

void setup() {
size(640,480);
frameRate(30);
colorMode(HSB);
noStroke();
value = 255;
}


void draw() {
fill(0,value, value);
value -= 10;
if (value <= 0) { value = 255; };
rect(0,0,width,height);
}


Last but not least time based using millis();

Re: Beginner problem; fading and recursion
Reply #2 - Jan 8th, 2009, 6:27pm
 
Cool cool.  Got it working, many thanks!
Page Index Toggle Pages: 1