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 › shiffman book ?
Page Index Toggle Pages: 1
shiffman book ?? (Read 308 times)
shiffman book ??
Jan 11th, 2009, 9:42pm
 
if anyone has the book learning processing, maybe they can help me understand this

i am just learning about pixels[loc] and kind of stuck at exercise 15-16, which isnt published in his answers online

trying to make a simple radial gradient

here's what i have so far

size(255,255);
loadPixels();

//Loop through every pix column

for(int x = 0; x < width; x++) {
 
//Loop through every pix row
 for(int y = 0; y < height; y++) {
   int loc = x + y*width;
   float distance =     ;
   pixels[loc] =      ;
 }
}
Re: shiffman book ??
Reply #1 - Jan 11th, 2009, 10:44pm
 
I can give you the answer (and will if you want), but I prefer to push in the right direction...
Hints:
- Remember to use updatePixels() at the end! Otherwise you will see nothing.
- distance should use the dist() function to compute the distance between the current point (x, y) and the center of the sketch (width/2, height/2).
- Now, you can define a color for this pixel, using color() function with the computed distance.
Re: shiffman book ??
Reply #2 - Jan 11th, 2009, 11:00pm
 
thanks

i am still getting my head around using the looped x,y values and pixels[loc] (1D format)  

so the bottom would be something like this?

distance = dist(x,y,width/2,height/2);
color c = color(distance);
pixels[loc] = c;


Re: shiffman book ??
Reply #3 - Jan 11th, 2009, 11:24pm
 
Yes, exactly!
You can make variations, like pixels[loc] = color(0, 0, distance); for example.
Page Index Toggle Pages: 1