I am trying to create an ArrayList of color values so I can utilize the features it has for dynamically slotting values in and out at various places. But as color is a primitive data type, it will not work in an array list. I have read that the value can be “contained” within in an object. But I have not found any examples of how to make write this class in Processing. I am still quite new to OOP, and ONLY have experience with processing so far, so I am having a brain tangle trying to conceive how to do it. I have read that Java has these built in but the examples shown in Java aren’t making sense to me yet.
A bit more info, I am using a for loop to generate the series of colors I want to put in the array. SO using an object starts to seem almost like its a function… and that makes me feel more confused at this point. But I am sure it will make sense eventually.
Can someone show me how to write this in Processing?
class ColorContainer {
color col1=color(0);
ColorContainer(color c_) {
col1=c_;
} // the constructor
} // the class
See reference class and website | tutorials | objects
Step 2 : before setup ()
ArrayList<ColorContainer> listC = new ArrayList();
Step 3
In setup make a for loop using lerpColor
for(int i=0;i<100;i++) {
float amt=map(i,0,100,0,1);// tells point between 2 colors for lerpColor
color c1=color(255,0,0);
color c2=color(0,255,0);
listC.add(new ColorContainer(lerpColor(c1,c2,amt));
} // for
You might like to use processing convenience implementation of an Integer list IntList see javadocs and reference. Apparently not well known? Using color to my mind is just plain confusing, it just another one of those processing convenience methods, but is well embedded.
WOW excellent, I just checked and saw your replies. I need to get some non screen time(sleep) now but I will be on this first thing AM. Thank you so much!
Thank you both for your help… I dunno why I find it hard to comprehend the container… I am close but some how its confusing. I will persevere because it seems like a concept that will help me in the future.
But the Int List is pretty straight forward and has the methods i am looking for so I will probably go with that for the purpose of completing my current project.
thanks you both so much!
Monkstone your right about color being a brainmangler I am actually using HSB just to keep it simpler to cycle colors. Works but has its own issues too.
Regarding the container; in the for loop, after each cycle through the loop, a new color is generated. Each of those colors need to be stored someplace in order to be retrieved for use later in the program.
also,
That is my approach too. It’s not always evident what is going on behind the scenes, but it will start to make sense the more you work with it.
Keep in mind that you also have multiple color palette library options, including Nice Color Palettes and ColorSheme. There is also some palette generation code in Dawsome Toolkit, I believe.
I am not sure if I understand your question but I recently had to work with color arrays for a color filter that I wrote in Processing. You wrote:
But in my script I have done exactly that and it is able to compare and assign color values from these lists. So for example, the Array list looks like this:
I expect this of no help to @Eyetoof who wants to use ArrayList methods. The IntList is an apparently not well known convenience class that has a similar interface to the ArrayList.
I looked at Toxilibs material. I am very new to coding and have only really used processing. Is this a library that will install to processing? Is there a way to use their algorithms for an analogous palette for example, in my code as its java?
If so how do I go about it. I have only done very basic library stuff for my college course, importing and using the video library for instance, and a bit of the midi library. I know how to import a library at least :).
I vaguely remember someone doing something in processing re colour blindness, but can’t remember where. If you do install toxiclibs there are some color-utils examples to follow (where toxi makes use of Iterator class) in recent versions of processing it needs to be explicitly imported as does the collection class see screenshot showing examples index and one running example.