Im nearly done with a project I'm making on processing. 100 arcs are scaling from the center while spinning around the canvas, in sequential order. I've received help in the form of code that does
exactly what I'm looking for, though I forgot to ask the person who helped me out explain a few things. I can almost understand what's going on, but there are a few concepts that I can't grasp just yet (which is why I'm here).
Here is the code:
//----Segment class----
class Segment
{
int myColorIndex;
float myStart;
float myStop;
float myScale;
Segment( int _colorIndex, float _start, float _stop, float _scale )
I get most of what's happening here, except for the following:
Lines 24-27
"void simulate"? I checked the processing language section and couldn't find anything pertaining to the word "simulate." I understand that "void" denotes that no value will be returned, but I've got no idea what simulate means.
Lines 48-53
If I'm not mistaken, this is the equation that produces each arc. I understand how a "for" iteration works (initialize, test, update). However I don't get how (i)(TWO_PI) / (length of array) creates 100 matching arcs. If someone could explain this formula, and how it works, I'd greatly appreciate it.
Lastly I tried writing out the formula and doing the math by hand to see what I came up with, but I cant determine what the length of the array is so I dont have all the variables I need to figure it out. How do you determine where the length of the array is at, at any given moment?
Lines 76-89
I don't understand any of this last part :) though I realize that "update" is an int. The fact that it's name is update throws me off, as if it is an inherent function of processing, but I just can't wrap my head around whats happening in these last lines.
Anything you guys [and gals] have to offer in terms of help or perspective would be great!
Relatively new to Processing, but I had this idea on how to artistically represent a data set, and Processing feels like the way to go here. I'm only in my second week of programming, but am really excited for this piece.
The Idea:
-Essentially 100 arcs will (one by one) scale from the center of the frame to just beyond the parameters of the frame, while rotating around around the frame until all 100 arcs have scaled out.
-The color of each arc is randomly selected from 8 options, but based on a set of data.
Example:
r = a random number from 0 - 100; if r equals a number between 67 - 100, the fill for an arc will be brown. if r equals a number between 30 - 67, the fill for an arc will be pink. etc...
-The data set is eight different percentages totaling one hundred.
Example:
Population of Yale based on race (numbers made up) -- 30% white men 20% white men 20% asian men 10%asian women 5% black men 10% black women 2% latino men 3% latino women(8 values = 8 color options)
So, I've assigned all eight color choices a variable, and I've gotten an arc to scale and rotate, but I can't get the fill of the arcs to be randomly chosen from the 8 color choices. I'll get the error that
"The operator >= is undefined".
Here is my code:
//----Variables----
float angle = 0; float f = 0; float r = random(100);
color c1 = #663C20; color c2 = #C45B31;
color c3 = #E6CCCE; color c4 = #FFE296;
color c5 = #7D2A35; color c6 = #BA3FB2;
color c7 = #B4BA6C; color c8 = #D6D315;
float a1 = 0;float a2 = 0;float a3 = 0;
//----Variables----
//-----Setup------
void setup()
{
size(400,400);
smooth();
noStroke();
}
//------Setup------
//------Draw------
void draw ()
{
background(#FAD7E9);
angle = angle + .1;
translate(width/2, height/2);
rotate(radians(angle));
if (r >= 1)
{
f = c8;
}
else if (1 < r && r <= 3)
{
f = c6;
}
else if (3 < r && r <= 7)
{
f = c4;
}
else if (7 < r && r <= 10)
{
f = c2;
}
else if (10 < r && r <= 14)
{
f = c7;
}
else if (14 < r && r >= 33)
{
f = c5;
}
else if (33 < r && r <= 63)
{
f = c3;
}
else if (63 < r && r <= 100)
{
f = c1;
}
fill(f);
//----1st-Arc-----
pushMatrix();
a1 = a1 + 0.01;
if (a1 > 1)
{
a1 = 1;
}
scale(a1);
arc(0, 0, 600, 600, radians(0), radians(3.6));
popMatrix();
//----1st-Arc------
//----2nd-Arc------
pushMatrix();
if (a1<0.5){
a2=0;
}
else {
a2 = a2 + 0.01;
}
if (a2 > 1.0)
{
a2 = 1;
}
scale(a2);
arc(0, 0, 600, 600, radians(3.7), radians(7.3));
popMatrix();
//----2nd-Arc------
//----3rd-Arc------
pushMatrix();
if (a2<0.5){
a3=0;
}
else {
a3 = a3 + 0.01;
}
if (a3 > 1.0)
{
a3 = 1;
}
scale(a3);
arc(0, 0, 600, 600, radians(7.4), radians(11));
popMatrix();
//----3rd-Arc------
}
//-----Draw-----
I understand they way I'm going about this requires 100 variables for each arc (a1, a2, a3... a100), which is why any guidance or help on where to look, what to do, or how to implement this would be excellent. Again only 2 weeks into Processing, but any help is greatly appreciated. One can only fly solo for so long :)