FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Programs
(Moderators: fry, REAS)
   points over lines
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: points over lines  (Read 338 times)
steph

Email
points over lines
« on: Aug 15th, 2004, 10:27pm »

hi,
 
I need some help. sometimes points do not draw over lines as I expect them to. I have this little code I've been working on with my father today to illustrate it:
 
Code:

//parametres de vue
//zoom
float dim = 10;
//translation
float trans = 50;
 
float a = 0;
 
//matrice de points. premier chiffre = nombre de points
float p[][] = new float[4][3];
 
void setup(){
size(200,200);
//framerate(30);
 
//point 1
p[0][0]=6;
p[0][1]=1+(5/sqrt(3));
p[0][2]=10*sqrt(2/3);
}
 
void loop() {
background(0);
a += 0.01;
rotatepoints();
drawlines();
drawpoints();
//delay(100);
}
 
void rotatepoints() {
//point 2
p[1][0]=6+((10/sqrt(3))*cos(a));
p[1][1]=1+(5/sqrt(3))+((10/sqrt(3))*sin(a));
p[1][2]=20*sqrt(2/3);
//point 3
p[2][0]=6+((10/sqrt(3))*cos(a+(2*PI/3)));
p[2][1]=1+(5/sqrt(3))+((10/sqrt(3))*sin(a+(2*PI/3)));
p[2][2]=20*sqrt(2/3);
//point 4
p[3][0]=6+((10/sqrt(3))*cos(a+(4*PI/3)));
p[3][1]=1+(5/sqrt(3))+((10/sqrt(3))*sin(a+(4*PI/3)));
p[3][2]=20*sqrt(2/3);
}
 
 
void drawpoints() {
stroke(255);
for (int i = 0; i<p.length; i++){
point((p[i][0]*dim)+trans,(p[i][1]*dim)+trans,p[i][2]*dim);
//point(int((p[i][0]*dim)+trans),int((p[i][1]*dim)+trans),int(p[i][2]*dim));  
}
}
 
void drawlines() {
stroke(75);
for (int i = 0; i<p.length; i++){
for (int j = i; j<p.length;j++){
//stroke(random(255),random(255),random(255));
line((p[i][0]*dim)+trans,(p[i][1]*dim)+trans,p[i][2]*dim,(p[j][0]
*dim)+trans,(p[j][1]*dim)+trans,p[j][2]*dim);  
}
}
}

 
sorry if it's kind of chaotic.. basically one function sets new coords for the triangle base, then another functions draws the lines between its points, then the third draws the points. as you can see we can only see glimpses of two points.
 
if I don't call the function drawlines(), then all the points are perfectly displayed.
 
now, if I do call drawlines(), but change this line in the drawpoints function:
Code:

point((p[i][0]*dim)+trans,(p[i][1]*dim)+trans,p[i][2]*dim);

to this:
Code:

point(int((p[i][0]*dim)+trans),int((p[i][1]*dim)+trans),int(p[i][2]*dim));  

(converting the coords to integers)
 
then I see the points, but they're jumpy. sometimes they have two pixels, sometimes one, and sometimes they disappear.
 
if I don't call drawlines(), they're still jumpy but never disappear.
 
in both cases, in this example, if I call drawpoints() before drawlines() it doesn't seem to make any difference.
 
in this little piece of code, if I draw the point before the line, it does make a difference:
Code:

void setup(){
size(200,200);
background(0);
}
void loop(){
stroke(50);
line(20,100,120,100);
stroke(255);
point(40,100);
}

 
why do the lines sometimes "hide" the points?
 
thanks.
 
REAS


WWW
Re: points over lines
« Reply #1 on: Aug 16th, 2004, 5:41am »

there is a bug with the current implementation of lines where they appear on top of all geometry. this will be fixed in a future release. for now, you can work around it by using the translate() function to force geometry forward and backward.
 
Pages: 1 

« Previous topic | Next topic »