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)
   stroke / noStroke for single instances
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: stroke / noStroke for single instances  (Read 367 times)
g1ga

Email
stroke / noStroke for single instances
« on: Nov 10th, 2004, 12:00pm »

hi, i'm an italian guy, this is my first post. I would know if there is a way to draw two ellipses one with stroke and the other without stroke. Some advice? Bye
 
toxi

WWW
Re: stroke / noStroke for single instances
« Reply #1 on: Nov 10th, 2004, 12:11pm »

how about using stroke() and noStroke()...
 
Code:
void draw() {
  ellipseMode(CENTER_DIAMETER);
  background(128); // 50% grey background
  stroke(255); // use white stroke
  fill(255,255,0); // yellow fill
  ellipse(25, 75, 40, 40);
  noStroke();  // turn off stroke
  fill(0,255,255); // cyan fill
  ellipse(75, 25, 40, 40);
}
 

http://toxi.co.uk/
g1ga

Email
Re: stroke / noStroke for single instances
« Reply #2 on: Nov 10th, 2004, 12:23pm »

thanks for cut & paste from the reference... ehehehe . So if i want to apply stroke to a single graphic object i have to do a method for that object that first set the stroke on/off and then redraw the object...
 
toxi

WWW
Re: stroke / noStroke for single instances
« Reply #3 on: Nov 10th, 2004, 12:29pm »

not really cut&paste, but hey...
 
stroke() or noStroke() settings will remain active until they're changed again. so if you draw 10000 objects with stroke you don't have to call stroke() for every single one of them... makes sense?
 

http://toxi.co.uk/
g1ga

Email
Re: stroke / noStroke for single instances
« Reply #4 on: Nov 10th, 2004, 12:47pm »

if i do this:
 
void setup(){
size(400,400);
stroke(55);
fill(150);
ellipseMode(CENTER_DIAMETER);
 
myEllipse g1ga = new myEllipse(200,200);
g1ga.stroked();
 
myEllipse g1ga2 = new myEllipse(300,300);
g1ga2.noStroked();
 
ellipse(350,350,15,15);
 
}
 
 
class myEllipse {
 
int mySize = 15;
float x,y;
int strokeColor = 55;
 
  myEllipse(float _x, float _y){
    x = _x;
    y = _y;
  }
   
  void stroked(){
  stroke(strokeColor);
  ellipse(x,y,mySize,mySize);
  }
   
  void noStroked(){
  noStroke();
  ellipse(x,y,mySize,mySize);
  }  
 
}
 
the third ellipse has no stroke becuse the second called noStroke() that is valid for all the environment. i don't like this...
 
toxi

WWW
Re: stroke / noStroke for single instances
« Reply #5 on: Nov 10th, 2004, 1:34pm »

well, what can i say?! you don't like it, so work around it... you have the freedom, so use it! question is also why you're drawing the 3rd ellipse using the default syntax if you went through all the trouble of setting up a class structure. furthermore, i think if you work so much with stroked/non-stroked objects, it'd be wise to integrate a "stroke" property in the class and only have a single draw method, like:
 
Code:
class Ellipse {
  int size = 15;
  float x,y;
  int strokeColor;
  boolean isStroked;
 
  Ellipse(float _x, float _y){
    x = _x;
    y = _y;
    isStroked=false;
  }
   
  void stroke(int c){
    strokeColor=c;
    isStroked=true;
  }
 
  void noStroke() {
    isStroked=false;
  }
 
  void draw() {
    if (isStroked) {
 stroke(strokeColor);
    } else {
 noStroke();
    }
    ellipse(x,y,mySize,mySize);
  }
}
« Last Edit: Nov 10th, 2004, 1:35pm by toxi »  

http://toxi.co.uk/
g1ga

Email
Re: stroke / noStroke for single instances
« Reply #6 on: Nov 11th, 2004, 9:53am »

ok thanks a lot... it's a good idea
 
Pages: 1 

« Previous topic | Next topic »