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.
IndexProgramming Questions & HelpPrograms › Drawing (in a way)
Page Index Toggle Pages: 1
Drawing (in a way) (Read 705 times)
Drawing (in a way)
Oct 14th, 2006, 9:09pm
 
Okay so now that this is all changed around and I'm trying to get the shape of the drawn brush (sort of like a paint brush) to be a medicine wheel (ellipse with four arcs of different hues--red, black, yellow, white), it's now broken. It runs but doesn't do anything when the mouse presses down. I'm sure I accidentally deleted something or I need to change the hue values but not sure how...


int scn[];

void setup()
{
 size(600, 600);
 background(#ffffff);
 scn = new int[width*height];
 preserveScreen();
}

void draw()
{
 restoreScreen();
}

void mouseDragged() {
 alphaFrame(mouseX, mouseY);
}

void keyReleased() {
 fill(#ffffff);
 noStroke();
 ellipse(0, 0, width, height);
 preserveScreen();
}

void preserveScreen() {
 loadPixels();
 for (int i = 0; i < width*height; i++) {
   scn[i] = pixels[i];
 }
}

void restoreScreen() {
 for (int i = 0; i < width*height; i++) {
   pixels[i] = scn[i];
 }
 updatePixels();
}

void alphaFrame(float xin, float yin)
{
 int x = int(xin);
 int y = int(yin);
 int s = 200;
 s/=2;
 
 // the radius of the circle
 int radius = 50;
 for(int i=x-radius; i<x+radius; i++) {
   for(int j=y-radius; j<y+radius; j++) {
     // check if the pixel (i,j) is in the circle
     if (dist(i, j, x, y) < radius) {
       int rgb = scn[j*width + i];
       int r = (rgb >> 16) & 0xff;
       int g = (rgb >> 8) & 0xff;
       int b = rgb & 0xff;

       // first quadrant (12-3 oclock)
       if (x < i && j < y){
         if (r > 1) r--;
         if (g > 1) g--;

       // second quadrant (3-6 oclock)
       }
       else if(x < i && j > y){
         if (r < 255) r++;
         if (g < 255) g++;

       // third quadrant (6-9 oclock)
       }
       else if(x > i && j < y){
         if (g < 255) g--;

       // fourth quadrant (9-12 oclock)
       }
       else{
         if (g < 255) g++;
         
       scn[j*width + i] = 0xff000000 | (r << 16) | (g << 8) | (b);
       }
     }
   }
 }
}
Re: Drawing (in a way)
Reply #1 - Oct 14th, 2006, 11:52pm
 
move the last scn[blabla one line down:

  else{
    if (g < 255) g++;
   
  }
  scn[j*width + i] = 0xff000000 | (r << 16) | (g << 8) | (b);

-seltar
Page Index Toggle Pages: 1