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.
IndexProcessing DevelopmentLibraries,  Tool Development › How do you use "color" in your lib
Page Index Toggle Pages: 1
How do you use "color" in your lib? (Read 1091 times)
How do you use "color" in your lib?
Apr 6th, 2007, 7:57am
 
I am trying to learn java by writing new libs for processing. (I've mastered processing...)... I've managed to create simple libs that only do stuff to the console. Now I want to make one that draws something.
but I couldn't even go "color BorderColor"... in

class button
color BorderColor
...etc.

Although I know how to use processing core methods, like "parent.println("line")".

Thanks
Re: How do you use "color" in your lib?
Reply #1 - Apr 6th, 2007, 8:23am
 
color = int

int myColor = color(0,0,0); // black

ben: i think things like this should maybe go into the libraries page

F
Re: How do you use "color" in your lib?
Reply #2 - Apr 6th, 2007, 10:09am
 
To add to what fjen said, color isn't really a type, processing translates it to an int behind the scenes when you hit the run button on a sketch. So you can just treat is as an int most fo the time, and will probably make things quicker if you do bit-munging on it rather than using red() green() etc..
Re: How do you use "color" in your lib?
Reply #3 - Apr 7th, 2007, 5:37am
 
Yeah... I was kinda stumped when I could use "PFont" and "PImage" but not color.... heh.
Re: How do you use "color" in your lib?
Reply #4 - Nov 11th, 2007, 5:56pm
 
Hello,

I've been trying to get this working in netbeans, but I can't...here's a snippet of code:



class pattern {
   
   int strokeColour;
   int fillColour;


  //constuructor
   public pattern(gui g, String name) {  
       
       theGui = g;
   
       //colours
       fillColour = color(255,150,40);
       strokeColour = color(255,100,40);

       ...
}

I get this error:

symbol  : method color(int,int,int)
location: class com.robinfencott.pattern
       fillColour = color(255,150,40);
1 error
BUILD FAILED (total time: 0 seconds)


Any idea what am I doing wrong?

Kind regards,
Robin.
Re: How do you use "color" in your lib?
Reply #5 - Jan 9th, 2008, 4:47am
 
all of processing's methods are actually instance methods of the class "PGraphics". So,

Possibilities:
  • make your pattern class extend PApplet, and its the main class. (probably not what you want)
  • Pass a PApplet as a parameter, and then call (g.color(int,int,int)
  • Make your PApplet a Singleton of its class:
      MyPApplet.getInstance().color(int,int,int)

    Of course, if you get the source code for processing, you could figure out what the color method does for each colorspace, copy the code, de-genericize it for just 1 specific colorspace, and make it a static-method in your classes.

    Decisions, decisions... have fun!
  • Re: How do you use "color" in your lib?
    Reply #6 - Feb 4th, 2008, 10:37pm
     
    I just wrote a smart class with a bunch of static methods for the color creation. It's been a part of a workshop at my university and I think no "real" crack got in touch with it jet. Would be nice to get some feedback.

    Color.java: http://interface.fh-potsdam.de/beyond_processing/wiki/lecture/java/shapelib/src/edu/fhp/shapeLib/util/Color.java

    documentation: http://interface.fh-potsdam.de/beyond_processing/wiki/doku.php?id=colors
    Re: How do you use "color" in your lib?
    Reply #7 - Feb 4th, 2008, 10:56pm
     
    Erk! There's absolutely no reason to go via Strings and "Long" to get a simple int value...

    return (int)Long.parseLong(String.format("%02X%02X%02X%02X",theAlpha, theGrey, theGrey, theGrey), 16);

    can be just:
    return (theAlpha<<24)+(theGrey<<16)+(theGray<<8)+theGrey;

    Or

    return (theAlpha<<24)+(theRed<<16)+(theGreen<<8)+theBlue;

    Also in your final method rgb(int,int,int,int), your 2nd Alpha test is wrong, it should be >255, not >0
    Page Index Toggle Pages: 1