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.
Page Index Toggle Pages: 1
some questions (Read 702 times)
some questions
Jul 16th, 2009, 8:28am
 
well first of all i would like to thank all the help that has been given to me and the other users! you have been great.

second of all i want to make a few questions that i would like to know and don't think its necessary to be starting new topics for each one of them.

the first one is :

i really like working with vector graphics previously drawed in illustrator and then feeding svgs into processing and i would like to know if its possible for me to have like 10 sets of diferent branches and 20 kinds of leaves and then say that i want to randomly spread an definite amount of leaves in the top of those branches


second question is :

i've began working with classes only a few days and i don't really know much about it so - is it possible to have classes inside classes? or run classes inside other class?


third question :

well this is kinda like the first one.... i have an array of stars, and an array of dogs, and an array of cats is it possible to  put them in other array with a name  so that i can randomly choose wich drawing to use with a name.length thing? using arrays within arrays?


sorry if im not being very clear, it's kind of confusing for me to explain too
Re: some questions
Reply #1 - Jul 16th, 2009, 8:42am
 
1) Yes.

2) Yes, actually the classes you create in a .pde files are already inside a class: the main one, named like your sketch, created on the fly in a transparent way by Processing. And yes, although you don't run classes, rather methods of the classes.

3) A bit confusing indeed...
Perhaps you mean:
Code:
PShape[] stars;
PShape[] dogs;
PShape[] cats;
... init the arrays above, loading SVG files or something ...
PShape[][] stuff = { stars, dogs, cats };
Re: some questions
Reply #2 - Jul 16th, 2009, 10:18am
 
that third question is exactly what interfaces are for.

http://java.sun.com/docs/books/tutorial/java/concepts/interface.html

which would allow you to, say

ArrayList thing = new ArrayList();
for (int i = 0 ; i < 10 ; i++) {
 int r = random(10);
 if (random < 3) {
   things.add(i, new Cat());
 }
 if (random == 4) {
   things.add(i, new Star());
 }
 if (random == 6) {
   things.add(i, new Fruit());
 }
...
}

for (int i = 0 ; i < 10 ; i++) {
 thing.get(i).draw();  // draw my thing
}

as long as each thing implements draw()

that said, given that Processing classes are inside another class i'm not sure you can do this in processing.
Re: some questions
Reply #3 - Jul 16th, 2009, 1:20pm
 
thanks for the answers! relating to the 1st question can someone explain to me how do i do it?
Re: some questions
Reply #4 - Jul 16th, 2009, 1:30pm
 
Sir, i think this might solve a lot of your problems at once.

http://beausievers.com/blog/index.php/2009/07/08/processing-tutorial-inheritance-and-abstract-classes/
Page Index Toggle Pages: 1