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)
   Colouring with same hue
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: Colouring with same hue  (Read 360 times)
ssdesign

WWW
Colouring with same hue
« on: Jan 18th, 2005, 10:15pm »

Hi,
I have created this sketch using Paul Bourke's SuperShapes equation.
 
I am able to generate gray scale sketch as you can see in the code below.
 
What I wanted to know is, how can I create a coloured sketch (colours of same colour range) of the same code.
 
Code:

// Super Shapes
// sajid saiyed December, 2004
// www.ssdesigninteractive.com/g2
 
float j,k;
int ji,ki;
float current;
 
float scale = width*6;
float xoff = width*2;
float yoff = width/1.7;
 
float x1,jj;
float y1;
float x=0.1;
float y=0.1;
 
float a = 1;
float b = 1;
float NP = 800;
float t1,t11,t111,t2,t22,t222;
float phi;
float r;
 
float gs = 0.5;
float gx = 0.5;
float gy = 0.5;
int dim = 500;
 
void setup(){
  size(500, 500);
  background(255);
  for(int ss=0; ss<8; ss++){
    float m=random(1/6,19/6);
    float n1=random(0.1,0.3);
    float n2=random(1.7);
    float n3=random(1.7);
    for(int dd=0; dd<80; dd++){
 sajid(m,n1,n2,n3);
    }
    //jj = jj+5;
  }
 
}
 
void loop(){
}
 
void sajid(float m1,float n11,float n22,float n33){
  float m=m1;
  float n1=n11;
  float n2=n22;
  float n3=n33;
 
  for(int i=0; i<NP; i++){
    //phi = (i*TWO_PI)/NP;
    phi = random(0, 12*PI);
    t111 = cos(m*phi/4)/a;
    t11 = abs(t111);
    t1 = pow(t11,n2);
 
    t222 = sin(m*phi/4)/b;
    t22 = abs(t222);
    t2 = pow(t22,n3);
 
    r = pow(t1+t2, 1/n1)-0.5;
 
    if(abs(r) == 0){
 x1 = 0;
 y1 = 0;
    } else{
 r = 1/r;
 x1 = r*cos(phi)+jj;
 y1 = r*sin(phi);
    }
 
    float d = sqrt((x1-x)*(x1-x) + (y1-y)*(y1-y));
    x = x1;
    y = y1;
    j = x * scale + xoff;
    k = y * scale + yoff;
    ji = int(j);
    ki = int(k);
    tpoint(int((x/gs+gx)*dim),int((y/gs+gy)*dim), ji, ki);
 
  }
}
 
void tpoint(int x1, int y1, int ji, int ki) {
  current = blue(get(x1,y1));
  // set the drawing color to the current color minus a small offset
  stroke(current-5);
  //stroke(0);
  point(x1,y1);
 
}
 
void mousePressed() {
float x=0.1;
float y=0.1;
  background(255);
  for(int ss=0; ss<8; ss++){
    float m=random(1/6,19/6);
    float n1=random(0.1,0.3);
    float n2=random(1.7);
    float n3=random(1.7);
    for(int dd=0; dd<80; dd++){
 sajid(m,n1,n2,n3);
    }
    //jj = jj+5;
  }
}
 

 
Some of this code might look dirty to an expert programmer, but I have to clean this once I get the desired effect
 

:: form follows function ::
st33d

WWW Email
Re: Colouring with same hue
« Reply #1 on: Jan 19th, 2005, 4:20pm »

Code:

//red
void tpoint(int x1, int y1, int ji, int ki) {
  current = green(get(x1,y1));
  // set the drawing color to the current color minus a small offset
  stroke(255,current-5,current-5);
  //stroke(0);
  point(x1,y1);
}
//green
void tpoint(int x1, int y1, int ji, int ki) {
  current = red(get(x1,y1));
  // set the drawing color to the current color minus a small offset
  stroke(current-5,255,current-5);
  //stroke(0);
  point(x1,y1);
}
//blue
void tpoint(int x1, int y1, int ji, int ki) {
  current = red(get(x1,y1));
  // set the drawing color to the current color minus a small offset
  stroke(current-5,current-5,255);
  //stroke(0);
  point(x1,y1);
}

It's a start I suppose.
 
Update:
Code:

background(150,150,130);
 
void tpoint(int x1, int y1, int ji, int ki) {
  float current1 = green(get(x1,y1));
  float current2 = red(get(x1,y1));
  float current3 = blue(get(x1,y1));
  // set the drawing color to the current color minus a small offset
  stroke(current2+1,current1+1,current3-5);
  //stroke(0);
  point(x1,y1);
}

This is probably not what you want but I'm having fun none the less.
« Last Edit: Jan 19th, 2005, 4:32pm by st33d »  

I could murder a pint.
ssdesign

WWW
Re: Colouring with same hue
« Reply #2 on: Jan 19th, 2005, 7:40pm »

wow, that was cool.
 
I experimented with some variations in this line:
 
Code:

stroke(current2+1,current1+1,current3-5);  

 
Here are some schemes which i liked:
 
CYAN & BLUE
stroke(current2-5,current1-1,current3+5);  
 
RED & ORANGE
stroke(current2+2,current1-2,current3-5);  
 
Also if you want to go ahead and try some variations, here are a few things:
 
1. Try changing the value of "g2":
 
Code:

//try changing this to greater value "1" or "6"
// this is the scaling factor
float gs = 0.5;

 
2. Also play around a bit with these values in the "setup()" or "mousePressed()" functions:
 
Code:

// refer "http://astronomy.swin.edu.au/~pbourke/curves/supershape/" for some hints
float m=random(1/6,19/6);
float n1=random(0.1,0.3);
float n2=random(1.7);
float n3=random(1.7);

 
« Last Edit: Jan 19th, 2005, 7:47pm by ssdesign »  

:: form follows function ::
Pages: 1 

« Previous topic | Next topic »