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 & HelpPrograms › About one tutorial programme
Page Index Toggle Pages: 1
About one tutorial programme (Read 473 times)
About one tutorial programme
May 12th, 2009, 3:29am
 
Hi,everyone.I am just reading one example named "LetterK",and feel somehow hard to understand.One question,what's the use of the two parameters of "foregroundcolor" and "backgroundcolor"?And how do they fuction?It seems to be an intriguing tech in this example.Can you be so kind as to explain it to me in detail?Thank you.
Re: About one tutorial programme
Reply #1 - May 12th, 2009, 4:12am
 
there is nothing special about the color.

you can simple change it to .

Code:

float px, py;
float pfx, pfy;
float pv2, pvx, pvy;
float pa2, pax, pay;
float pMass, pDrag;

void setup() {
size(640, 360, P3D);
noStroke();

initParticle(0.6, 0.9, width/2, height/2);
}

void draw() {
background(255);
pushMatrix();

iterateParticle(0.15*(-px+mouseX), 0.15*(-py+(height-mouseY)));

translate(width/2, height/2, 0);
fill(0);
drawK();

pushMatrix();
translate(0, 0, 1);
translate(0.75 * (px-width/2), -0.75 * (py-height/2), 0);
translate(0.75 * (px-width/2), -0.75 * (py-height/2), 0);
rotateZ(atan2(-(py-height/2), (px-width/2)) + PI/2);
rotateX(PI);
rotateZ(-(atan2(-(py-height/2), (px-width/2)) + PI/2));

fill(100);
drawK();
popMatrix();

translate(0.75 * (px-width/2), -0.75 * (py-height/2), 2);
rotateZ(atan2(-(py-height/2), (px-width/2)) + PI/2);

fill(255);
beginShape(QUADS);
vertex(-640, 0);
vertex( 640, 0);
vertex( 640, -360);
vertex(-640, -360);
endShape();

popMatrix();

}

void initParticle(float _mass, float _drag, float ox, float oy) {
px = ox;
py = oy;
pv2 = 0.0;
pvx = 0.0;
pvy = 0.0;
pa2 = 0.0;
pax = 0.0;
pay = 0.0;
pMass = _mass;
pDrag = _drag;
}

void iterateParticle(float fkx, float fky) {
// iterate for a single force acting on the particle
pfx = fkx;
pfy = fky;
pa2 = pfx*pfx + pfy*pfy;
if (pa2 < 0.0000001) {
return;
}
pax = pfx/pMass;
pay = pfy/pMass;
pvx += pax;
pvy += pay;
pv2 = pvx*pvx + pvy*pvy;
if (pv2 < 0.0000001) {
return;
}
pvx *= (1.0 - pDrag);
pvy *= (1.0 - pDrag);
px += pvx;
py += pvy;
}

void drawK() {
pushMatrix();

scale(1.5);
translate(-63, 71);
beginShape(QUADS);
vertex(0, 0, 0);
vertex(0, -142.7979, 0);
vertex(37.1992, -142.7979, 0);
vertex(37.1992, 0, 0);

vertex(37.1992, -87.9990, 0);
vertex(84.1987, -142.7979, 0);
vertex(130.3979, -142.7979, 0);
vertex(37.1992, -43.999, 0);

vertex(77.5986-.2, -86.5986-.3, 0);
vertex(136.998, 0, 0);
vertex(90.7988, 0, 0);
vertex(52.3994-.2, -59.999-.3, 0);
endShape();
//translate(63, -71);
popMatrix();
}




All he does is to store the colors in color variables which makes it easier to change them and reuse them. Look at for more information
http://processing.org/reference/color_.html

Re: About one tutorial programme
Reply #2 - May 12th, 2009, 4:14am
 
OK, I found back the example (it is in 3D/Typography).
As the names imply, foregroundColor (capital C, it is important in Processing!) is the color used to draw things (used in the fill() function).
backgroundColor is just... the color of the background! Ie. of the surface/area of the sketch. It is used in the background() call, although I see it also in a fill() call.
The latter is used to mask part of the moving copy of the K, giving the illusion of folding. (Replace it with fill(#000000); to visualize it.)
Beside that, I am not good enough in 3D to fully understand what is going on!  Shocked
Page Index Toggle Pages: 1