would you please tell me what is the role of first number(-1) in code below in processing?
please find short executable code bellow. please note that after executing this code in processing, a circle and several lines will be appear. and they will change via sound level detected by microphone.
"import ddf.minim.*;
import ddf.minim.analysis.*;
Minim minim;
BeatDetect beat;
AudioInput player;
int r = 200;
float rad = 70;
void setup()
{
size(displayWidth, displayHeight);
minim = new Minim(this);
player = minim.getLineIn();
beat = new BeatDetect();
background(-1);
}
void draw()
{
beat.detect(player.mix);
fill(#1A1F18, 20);
noStroke();
rect(0, 0, width, height);
translate(width/2, height/2);
noFill();
fill(-1, 200);
if (beat.isOnset()) rad = rad*1.1;
else rad = 70;
ellipse(0, 0, 2*rad, 2*rad);
stroke(-1, 50);
int bsize = player.bufferSize();
for (int i = 0; i < bsize - 1; i+=5)
{
float x = (r)*cos(i*2*PI/bsize);
float y = (r)*sin(i*2*PI/bsize);
float x2 = (r + player.left.get(i)*1000)*cos(i*2*PI/bsize);
line(x, y, x2, y2);
}
}"
Best Regards
It's the same as fill(255,50)
, just one less character to type in fill(-1,50);
(think of it as shorthand).
The color type is stored as an unsigned integer.
Here's a basic sketch to illustrate the point:
void setup(){
println(color(254,254,254));
println(color(255,254,254));
println(color(255,255,254));
println(color(255,255,255));
println(color(255));
}
void draw(){
//same as fill(255,50);
fill(-1,50);
rect(0,0,width,height);
line(mouseX,mouseY,pmouseX,pmouseY);
}
Notice the values printed in console.
Also notice when you move the mouse, you see trails.
That's because a white (color(255)
or color(-1)
) rectangle with alpha set to 50 is drawn, only partially clearing the buffer.