Loading...
Processing Forum
Recent Topics
All Forums
Screen name:
ibutsch
ibutsch's Profile
1
Posts
1
Responses
0
Followers
Activity Trend
Last 30 days
Last 30 days
Date Interval
From Date :
To Date :
Go
Loading Chart...
Posts
Responses
PM
Show:
All
Discussions
Questions
Expanded view
List view
Private Message
How to compare two consecutive elements of an Array?
[3 Replies]
06-Apr-2012 08:04 AM
Forum:
Programming Questions
Hey there,
there actually has been a post with pretty much the same question.
But unfortunately it didn't solved my problem.
I want to compare two consecutive elements of an array.
In this case the array is filled with values from a string loaded from a text doc.
This test.txt is a list of all the days in 2012. Each day has a value from 1-10.
This so far is no problem. But I would like to have a thicker stroke when the month changes.
So my thought was, to compare the recent value withe the previous by dividing them.
And if the result is unequal 1, there has been a change in month.
so far my thoughts.
But how can I get the previous value?
The problem is located in the "Month Segmentation" of the code.
If anybody needs the test.txt please let me know.
thx.
void setup() {
/////Setup
size (750, 750);
smooth();
background (30, 30, 40);
translate(width/2, height/2);
rotate(-PI/2);
/////Load DATA
String[] lines = loadStrings("test.txt");
float days = 360.00/lines.length;
float deg = 0;
while (deg<360.00 -days) {
// Create Data Array
for (int i= 0; i< lines.length; i++) {
String[] pieces = split(lines[i], '\t');
String[] mon = split(lines[i], '.');
int d = int(mon[0]);
// int m = int(mon[1]);
int[] m = new int[lines.length];
int b = int(pieces[1]);
m[i] = int(mon[1]);
/////////////// THE SUN SCALA
float k = map(b, 0, 10, 150, 350);
float angle = radians(deg);
float radius = k;
float x = cos(angle) * radius;
float y = sin(angle) * radius;
float raycolor = norm(radius, 200, 350);
strokeWeight(2);
stroke(255, (80+(170*raycolor)), 0);
strokeCap(SQUARE);
line(x, y, 0, 0);
deg += days;
/////////////// THE DAY SEGMENTATION
float mMul = ((360.00/lines.length)/2) + (360.00/lines.length) * i;
float angleMon = radians(mMul);
float xMon = cos(angleMon) * 370;
float yMon = sin(angleMon) * 370;
strokeWeight(0.1);
stroke(255);
line(xMon, yMon, 0, 0);
/////////////// THE MONTH SEGMENTATION
/*
int m1 = m[i];
int m2 = m[i-1]; ///// Don't know how to solve this.
float mTest = m1 / m2;
if ( mTest != 1 )
{
strokeWeight(1);
stroke(255);
}
*/
line(xMon, yMon, 0, 0);
}
}
////////// WHITE MIDDLE CIRCLE
noStroke();
ellipse(0, 0, 300, 300);
}
void draw () {
}
«Prev
Next »
Moderate user : ibutsch
Forum