We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello,
I'm new to processing (started learning it yesterday), so I apologize for the simple questions. Any how, I need to make a data structure of sorts. To better explain, let me give you an example:
1 True 3.3 2.2
2 True 2.5 1.1
3 False 2.2 3.2
4 True 2.3 6.9
Now, I want to create an array that holds all this information and be able to access it. So, if I were to get 3's information, I'd get - False, 2.2, 3.2.
I'm sure it's quite simple, but I've watched YouTube videos and read references about classes, but they seem a bit more complex than what I want to do. Or is using classes sloppy? What is the recommended method?
Also, I want to make it expandable since I don't know how many times this will be entered - do I use an ArrayList? If so, how do I read and write to it?
Thank you!
Tien
Answers
there is a good tutorial about classes / oop
http://processing.org/tutorials/objects/
this is what you need. [New Version]
It should be all quite clear.
In a class you collect the properties (your information e.g. - False, 2.2, 3.2.) and the methods (print it, draw it whatever)
The class goes from { down to the very last }
The class is then used like a type (like int or boolean e.g.)
in the 1st line we make our ArrayList of type Ellipse
in setup we
first make a new Ellipse ellipseTest using new
and we push this Ellipse into the ArrayList with add
The word "new" ist interesting. The class is the concept (the abstract idea/ cookie maker) of an ellipse and only with "new" we make an existing thing from it (the thing / the cookie) with real color and position.
in draw()
we read it with get from the ArrayList
and draw it
@Chrisir the link is missing : )
http://processing.org/tutorials/objects/
In OOP the equivalent of a struct is a class with all members public so for your data
and to create your array list
and to access the data
Oh, @quark beaten me 1st! Anyways, here's my example too: ~:>
guys, intentionally I gave him something different but similar to his problem
so he can make the adaptions and learn by himself...
don't you guys agree with my intention...?
;-)
@Chrisir your intentions are fine but anyone who thinks that using classes might be sloppy obviously needs an extra hand. :D
Absolutely!
:D
Hahaha. While I appreciate your intention, I had a project that I needed finished before the night was over. :D
I'm not a programmer by any means - my boss laughed at the fact that one of the programming languages that I first learned was Fortran... which I learned over twenty years ago. So, for not having programmed since, me completing an actually useful Processing sketch isn't too shabby. :P (Making a printable "binary LP" to be read by infrared sensor array.)
Thanks, though, to everyone here. Hopefully I'll learn the true use of classes later and redeem myself.
Tien