We are about to switch to a new forum software. Until then we have removed the registration on this forum.
hy there, i want to create a variable to store different kind of variables. that i could pass to functions which need more than one parameter. i am looking for something like the "color" class or what it is.______ instead of passing three or four variables you can just pass one color object.
bsp:
color c = color(204, 153, 0);
background( c);
this is how the color would work and below is what i would like to do. any help is wellcomed, what could also help is how did they implement the "color" class. by the way is it a class or something else. thanks in advance
Func1(String, int, float); // function declaration
myThing mc = myClass("hello", 1,2.0); // object init
func1(mc); // call function with object as param
Answers
the formatting went wrong there , i hope you still understand want i wanted to write
i think i know how they did it with the color, its probaly the fill or background method that's been implemented to accept an object of type color, if anyone knows more, leave a comment
For correctly formatting posted code here, please highlight it and hit CTRL+K! (%)
Neither color(), nor fill(), stroke(), background() etc., accept object types. All of them are primitive
float
data-types!The color "class" in Processing is a special case. Don't look to it for a lot of inspiration, as it'll probably just be confusing.
What you're looking for sounds a lot like a class that encapsulates the different kinds of data you want to group together.
You could also look into varargs.
This post below got a Colour container: ;;)
http://forum.processing.org/two/discussion/1273/what-is-the-triple_dot-character-and-what-causes-errors-regarding-it
The color "class" in Processing does not exist.
In Processing the
color
data type is the same as a Javaint
Before compiling the sketch code the Processing pre-processor replaces all occurrences ofcolor
withint
. The only exception is whencolor
is followed by a(
, in which case it is a call to thecolor()
method.It is possible to define Java methods that have a variable number of parameters, for example the code below has a method called myMethod where you can pass any number of parameters (including none) of any type.
This creates the following output
Number of params = 0
Number of params = 3
String
Float
Boolean
I think what the OP wants is some basic object oriented programming. I threw together a tutorial going over the basics of OOP in Processing, it might help: http://staticvoidgames.com/tutorials/objects/index.jsp
Also, Dan Shiffman's teaching videos are awesome.
Here he is on objects: http://icm.shiffman.net/7.0/
Are looking for a function that accepts a custom obj? That's simple:
also you can return your object in a function.