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)
   how to get current stroke/fill color?
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: how to get current stroke/fill color?  (Read 1747 times)
fli


how to get current stroke/fill color?
« on: May 15th, 2003, 2:34pm »

This seems like a silly question, but I can't figure it out- stroke() and fill() will set the current stroke/fill colors, but how do I _get_ the current stroke and fill colors?
 
I would like to write some helper methods that do some drawing that will store the current stroke/fill colors before setting them and restore them before returning.
 
Perhaps stroke() and fill() can return the previous color after setting them?
 
Francis
 
Martin

122417302122417302martingomez_listsmg1ph WWW Email
Re: how to get current stroke/fill color?
« Reply #1 on: May 15th, 2003, 2:51pm »

void setup()
{
  size(200,200);
  background(255);
}
   
void draw()
{
  fill( 255, 201, 0, 255 );
  stroke( 0, 0, 0, 255 );
  rectMode(CENTER_DIAMETER);
  rect(width/2,height/2,width-20,height-20);
  println( "fill \\ r: " + g.fillRi + ", g: " +  
    g.fillGi + ", b: " + g.fillBi + ", a: " +  
    g.fillAi );
  println( "stroke \\ r: " + g.strokeRi +
    ", g: " + g.strokeGi + ", b: " + g.strokeBi +
    ", a: " + g.strokeAi );  
}
 
Martin

122417302122417302martingomez_listsmg1ph WWW Email
Re: how to get current stroke/fill color?
« Reply #2 on: May 15th, 2003, 3:14pm »

int myFill[] = new int[4];
int myStroke[] = new int[4];
 
void setup()
{
  size(200,200);
  background(255);
  fill( 255, 201, 0, 255 );
  stroke( 0, 0, 0, 255 );
}
 
void loop()
{
  rectMode(CENTER_DIAMETER);
  rect(width/2,height/2,width-20,height-20);
}
 
void mousePressed()
{
  storCurFill();
  storCurStroke();
  fill( 0, 104, 201, 255 );
}
 
void mouseReleased()
{
  fill( myFill[0], myFill[1], myFill[2], myFill[3] );
}
 
void storCurFill()
{
  myFill[0] = g.fillRi;
  myFill[1] = g.fillGi;
  myFill[2] = g.fillBi;
  myFill[3] = g.fillAi;
}
 
void storCurStroke()
{
  myStroke[0] = g.strokeRi;
  myStroke[1] = g.strokeGi;
  myStroke[2] = g.strokeBi;
  myStroke[3] = g.strokeAi;
}
 
Martin

122417302122417302martingomez_listsmg1ph WWW Email
Re: how to get current stroke/fill color?
« Reply #3 on: May 15th, 2003, 3:19pm »

color cFill, cStroke;
 
void setup()
{
  size(200,200);
  background(255);
  fill( 255, 201, 0, 255 );
  stroke( 0, 0, 0, 255 );
}
 
void loop()
{
  rectMode(CENTER_DIAMETER);
  rect(width/2,height/2,width-20,height-20);
}
 
void mousePressed()
{
  storCurFill();
  storCurStroke();
  fill( 0, 104, 201, 255 );
}
 
void mouseReleased()
{
  fill(cFill);
}
 
void storCurFill()
{
  cFill = color(g.fillRi, g.fillGi, g.fillBi, g.fillAi);
}
 
void storCurStroke()
{
  cStroke = color(g.strokeRi, g.strokeGi, g.strokeBi, g.strokeAi);
}
 
fry


WWW
Re: how to get current stroke/fill color?
« Reply #4 on: May 20th, 2003, 7:45pm »

yipes, someone's been peeking at the code!
 
a necessary disclaimer for anything found inside the code and that we haven't documented... g.fillXX and the rest are not guaranteed to work like that forever, and may change.
 
the simplest way to do it is:
color f = g.filli;  
or
color s = g.strokei;
but those may change to just g.fill (or just 'fill') and g.stroke (or just 'stroke') if it's something that people want to use a lot.
 
Martin

122417302122417302martingomez_listsmg1ph WWW Email
Re: how to get current stroke/fill color?
« Reply #5 on: May 21st, 2003, 4:11pm »

hehe
 
i think it's cool to be able to have current stroke and fill values accessible globally. a few added bytes won't really hurt.
 
fry


WWW
Re: how to get current stroke/fill color?
« Reply #6 on: Jun 25th, 2003, 7:05pm »

k, i've added this for 56:
 
color f = fill();
color s = stroke();
color b = background();
 
Pages: 1 

« Previous topic | Next topic »