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 & HelpOther Libraries › geomerative to draw on shapes
Page Index Toggle Pages: 1
geomerative to draw on shapes (Read 753 times)
geomerative to draw on shapes
Feb 17th, 2009, 2:09am
 
I am trying to draw objects in a particular shape/area.  Normally I could find a way by using the coordinates of a particular area but this time I am using a pretty complex shape.  I want to draw the objects on the land of a world map outline.  I can begin to think of ways to get processing to interpret a world map image and draw the objects based on that interpretation (for instance having a silhouette of the map and having it only draw on the black pixels).  But I dont know if there is an easier way or even how to do that exactly because I am a newbie.  Also eventually I would like to seperate where I want to draw the objects to different continents (which would be a flaw in my pixel plan).

I was led to the geomerative library by others that mentioned it may help.  Is there any way I can use the spapes generated with this library in order to draw on top of them??

Thanks for listening
Re: geomerative to draw on shapes
Reply #1 - Feb 18th, 2009, 12:20pm
 
I don't understand if you are trying to draw objects inside shapes or along the shape's curve.

Anyway both should be posible with geomerative.  But they require a bit of coding.

If you are just trying to draw objects inside shapes, then I think the pixel method could be better and easier.  If you want different objects in different continents just use different colors for each continent.

If what you are trying to do is draw objects along shapes then use the methods getPoint (to know where to place the objects) and getTangent (to know how to rotate the objects).

ricard
Re: geomerative to draw on shapes
Reply #2 - Feb 18th, 2009, 3:48pm
 
I am trying to draw objects inside shapes.  I would do the pixel method but I really don't want to seperate them by color, rather seperate them by shape so I can have the same color on all of them but still decide which objects I want to place in which shape.  Here is a snippit of the code I am using which is taken from the tutorial 23.

Code:

grp.draw();
RPoint p = new RPoint(mouseX-width/2, mouseY-height/2);
for(int i=0;i<grp.countChildren();i++){
if(grp.children[i].contains(p)){
RG.ignoreStyles(true);
fill(0,100,255,250);
noStroke();
grp.children[i].draw();}
RG.ignoreStyles(ignoringStyles);
}


grp is my RShape

What I would like to do is get the pixels of a particular child (grp.children[i]) and get my object to draw at those pixels as an area so I am not drawing on every pixel.

ps.  kudos on the library, really cool stuff had fun just playin around with it, will use it more.
Re: geomerative to draw on shapes
Reply #3 - Feb 18th, 2009, 4:40pm
 
I think then you should present your problem differently.  Instead of saying "give me all the pixels in a given shape" you should say "for each point where I could draw objects, is the point inside a given shape".

Your code should look something like this:
Code:

float xspace = width/100.0; // If you want 100 rows per screen
float yspace = height/100.0; // If you want 100 cols per screen
for(int i=0; i<grp.countChildren(); i++) {
for(int x=0; x<width; x+=xspace) {
for(int y=0; y<height; y+=yspace) {
if(grp.contains.children[i](new RPoint(x, y))) {
// draw your object at point x, y
}
}
}
}


Note: I haven't tested this code, it's just an idea.
Re: geomerative to draw on shapes
Reply #4 - Feb 23rd, 2009, 2:49pm
 
hey ricard

i tried

Code:

   for (int i = 0; i < grp.countChildren(); i ++) {
   for(int x = 0; x < width; x+=xspace) {
     for(int y=0; y<height; y+=yspace) {
       if(grp.children[i].contains(new RPoint(x,y))) {
         ellipse(x,y,10,10);


and sometimes would only draw about 1/5  of my shapes, but either way it would take a long time.  so I have resorted to doing my pixel method:

Code:

   for(int x = 0; x < width; x+=xspace) {
     for(int y=0; y<height; y+=yspace) {
        if(get(x,y) == pink) {
          // draw object


this works for drawing on everypoint in my object.  however, I want to limit the number of objects and draw them at random points.  To do this, I think I should get all my x,y points on an array then choose a specific point at random.  However I have trouble doing this because I do not know how to construct my array because I dont know count of the x and y points I am getting.  Also, I am not sure how to pick a random array spot.

ps. your sight is really cool, i really like all the caligraphy
Page Index Toggle Pages: 1