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
   Syntax
(Moderators: fry, REAS)
   Draw Order Problems
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: Draw Order Problems  (Read 342 times)
theserge


Draw Order Problems
« on: Dec 21st, 2004, 10:12pm »

I'm having problems with the draw order.  My code can explain it best:
 
<code>
void setup(){
  size(400,400);
  smooth();
}
 
void loop(){
  background(200);
  translate(200,200); //try commenting this line out!
 
  line(0,0,20,20);
  rect(0,0,10,10);
  rect(20,20,15,15);
 
  fill(0,255,0);
  triangle(300,350,350,320,300,300);
}
</code>
 
Note that the line runs through the rect even though it I send the command before.  Try to comment the translate line out.  Now it works fine.  Any ideas or workarounds?
 
gll

WWW Email
Re: Draw Order Problems
« Reply #1 on: Dec 23rd, 2004, 8:13am »

That's the smooth() option.
Try with noSmooth(), it won't draw the line in.
 
That's a problem. I guess that it will be fixed soon or it has been fixed.
 

guillaume LaBelle
theserge


Re: Draw Order Problems
« Reply #2 on: Dec 23rd, 2004, 10:06am »

You don't get the erroneous line overlap without the smooth() option?  Mine does the exact same thing with smooth() on and off.  Are you changing anything else?
 
gll

WWW Email
Re: Draw Order Problems
« Reply #3 on: Dec 23rd, 2004, 4:50pm »

Right, there's a problem with translate, but I guess that it's related to how smooth() works. Try to use push() + pop() to put the lines slightly under the other surfaces.
 
Not working:
Code:
 push();
  translate(0,0,-3.4435);
  line(0,0,20,20);  
  pop();
  rect(0,0,10,10);  
  rect(20,20,15,15);

 
Working:
Code:
 push();
  translate(0,0,-3.4436); <-- I had +0.0001
  line(0,0,20,20);  
  pop();
  rect(0,0,10,10);  
  rect(20,20,15,15);

 

guillaume LaBelle
st33d

WWW Email
Re: Draw Order Problems
« Reply #4 on: Jan 6th, 2005, 7:03pm »

I have a problem like this but slightly different. I got fed up with trying to figure out how to do it in Processing so I just adapted the code into Flash. But Flash can't export a copy of the screen content. I want the image to be smooth() and for the flower stalk to go behind the petals. Has this been resolved in v.69? Am I wishing for the impossible?
 
Code:

int w = 300;
int h = 300;
flower f1 = new flower(w/2,h/2,5,10,3);
robot r1 = new robot(100,h-(25*9.5),25);
void setup(){
size (w,h);
//
//un-reminder the command below...
//
//smooth();
}
void draw(){
f1.draw();
r1.draw();
}
class symbol {
float x,y,s;
}//class;
class flower extends symbol {
int p;
int le;
flower(float x, float y, int p, float s, int le){
this.x = x;
this.y = y;
this.p = p;
this.s = s;
this.le = le;
}
void draw(){
stroke(0);
fill(255);
line(x,y,width/2,height);
for (int i = 0; i < p; i++){
float t1 = (TWO_PI/p)*i;
float t2 = (TWO_PI/p)*(i+1);
beginShape(POLYGON);
bezierVertex(x+cos(t1)*s,y+sin(t1)*s);
bezierVertex(x+cos(t1)*(s*3),y+sin(t1)*(s*3));
bezierVertex(x+cos(t2)*(s*3),y+sin(t2)*(s*3));
bezierVertex(x+cos(t2)*s,y+sin(t2)*s);
endShape();
}
ellipse(x-s,y-s,s*2,s*2);
for (int i = 0; i < le; i++){
//draw leaf
float o = (s*1.5);
if (int(random(2))==1){o = -(s*1.5);}
float r = (s*3)+(random(s*3));
beginShape(POLYGON);
bezierVertex(x,y+(r));
bezierVertex(x+(o),(y+(r))-s);
bezierVertex(x+(o),(y+(r))-s);
bezierVertex(x+(o*2),y+(r));
endShape();
beginShape(POLYGON);
bezierVertex(x,y+(r));
bezierVertex(x+(o),(y+(r))+s);
bezierVertex(x+(o),(y+(r))+s);
bezierVertex(x+(o*2),y+(r));
endShape();
}
}//draw;
}//class;
class robot extends symbol {
robot(float x, float y, float s){
this.x = x;
this.y = y;
this.s = s;
}
void draw(){
stroke(0);
fill(255);
//head
beginShape(POLYGON);
vertex(x-s,y);
vertex(x+s,y);
vertex(x+s,y+(s*2));
vertex(x,y+(s*3));
vertex(x-s,y+(s*2));
endShape();
//neck
line(x,y+(s*3),x,y+(s*3.5));
//body
rect(x-(s/2),y+(s*3.5),s,s*3);
//legs
line(x-(s/4),y+(s*6.5),x-(s/4),y+(s*9.5));
line(x+(s/4),y+(s*6.5),x+(s/4),y+(s*9.5));
//feet
beginShape(POLYGON);
bezierVertex(x-(s/4),y+(s*8.5));
bezierVertex(x-s,y+(s*8.5));
bezierVertex(x-s,y+(s*8.5));
bezierVertex(x-s,y+(s*9.5));
vertex(x-(s/4),y+(s*9.5));
endShape();
beginShape(POLYGON);
bezierVertex(x+(s/4),y+(s*8.5));
bezierVertex(x+s,y+(s*8.5));
bezierVertex(x+s,y+(s*8.5));
bezierVertex(x+s,y+(s*9.5));
vertex(x+(s/4),y+(s*9.5));
endShape();
//eyes
ellipse(x+(s/3),y+(s/3),(s*1.25),(s*1.25));
ellipse(x-(s*1.5),y+(s/3),(s*1.25),(s*1.25));
//arms
bezier(x-(s/2),y+(s*3.5),x-(s/2),y+(s*3.5),x-s,y+(s*5.5),x-s,y+(s*6.5));  
bezier(x+(s/2),y+(s*3.5),x+(s/2),y+(s*3.5),x+s,y+(s*5.5),x+s,y+(s*6.5));  
//hands
beginShape(POLYGON);
vertex(x-s,y+(s*6.5));
vertex(x-s,y+(s*7.5));
vertex(x-(s/2),y+(s*7));
endShape();
beginShape(POLYGON);
vertex(x+s,y+(s*6.5));
vertex(x+s,y+(s*7.5));
vertex(x+(s/2),y+(s*7));
endShape();
}
}//class;

 
I was thinking of the Flash sending params to a popup applet that is written on the fly. Then that applet can save a copy of the image. I find the pixelated draw a bit unsightly though. But smooth() wrecks the drawing.
 
Flash version:
http://www.st33d.net/flash/harold.html
 

I could murder a pint.
Pages: 1 

« Previous topic | Next topic »