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 & HelpSyntax Questions › how to make something inside an area
Page Index Toggle Pages: 1
how to make something inside an area (Read 1034 times)
how to make something inside an area
Apr 20th, 2010, 12:56pm
 
hey! I have a shape that i would like to fill with vectors and did't want them to "get out" of it ( at least not much).

The shape isn't regular at all. I'ts like the silluette of a thingy (as in male of a chicken Tongue)

can someone tell me how to do this?
Re: how to make something inside an area
Reply #1 - Apr 20th, 2010, 2:32pm
 
Use the silhouette as a mask() of your drawing.
See, for example, Kaleidoscope: How would I do this thread.
Re: how to make something inside an area
Reply #2 - Apr 20th, 2010, 2:45pm
 
is it the only way? while i was searching i came across this
http://www.hypeframework.org/02_examples/shapelayout/content/02_shapelayout/

which is exactly what i wanted to do. Is it possible to do it in Processing?
Re: how to make something inside an area
Reply #3 - Apr 20th, 2010, 10:59pm
 
I made something similar in the past:
Code:
int MIN_RAD = 10;
int MAX_RAD = 100;
int MAIN_RAD = 250;
int CIRCLE_NB = 222;

void setup()
{
 size(500, 500);
 background(255);
 noStroke();
 
 int centerX = width / 2;
 int centerY = height / 2;
 
 for (int i = 0; i < CIRCLE_NB; i++)
 {
   float d = random(0, MAIN_RAD - MIN_RAD);
   float a = random(0, TWO_PI);
   float x = centerX + d * cos(a);
   float y = centerY + d * sin(a);
   float r = random(MIN_RAD, min(MAX_RAD, MAIN_RAD - d));
   color c = lerpColor(#00FF00, #0000FF, (1 + cos(a))/2);
   
   fill(c);
   ellipse(x, y, r * 2, r * 2);
 }
}

But it is limited to a circle shape...
For more complex shapes, a classical way is to draw it on a PGraphics in a monochrome way and use the corresponding array of pixels as a boolean array: one color = in shape, background color = out of shape.
Then you can draw random numbers and reject them if out of shape, or make an array of bounds (for each line of pixels, pair(s) of start of shape/end of shape coordinates), etc.

Processing doesn't offer a ShapeLayout class out of the box, it is a rater low level (pixel level, as opposed to scenegraph level) framework.
Re: how to make something inside an area
Reply #4 - Apr 21st, 2010, 4:02am
 
wow! that's too much for me to handle! LOL I'll dig into it. Already made the PGraphic but never done a array of pixels or a boolean array.
Re: how to make something inside an area
Reply #5 - Apr 21st, 2010, 4:39am
 
thanks again! it was very inspiring! i resolved it a different way tho! i made the pg graphics but instead of making the pixel array i did a

color a = object.get(x,y);

and then made a

if(a==-16777216){
ellipse(x,y,10,10);
}
and it didn't draw nothing outside the shape!

because -16777216 was the value that the get would give me when i did a println(a);
Re: how to make something inside an area
Reply #6 - Apr 21st, 2010, 4:54am
 
Yes, get(x, y) is slower than using a pixel array but it is simpler to use and if speed is OK for you, it is perfect.
Re: how to make something inside an area
Reply #7 - Apr 21st, 2010, 5:08am
 
yes, speed isn't a problem! I would like to learn that way tho! so i can use it some other time! thanks for your help!
Page Index Toggle Pages: 1