Loading...
Logo
Processing Forum
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.



Copy code

  1. void setup() {

  2.   /////Setup  
  3.   size (750, 750);
  4.   smooth();
  5.   background (30, 30, 40);
  6.   translate(width/2, height/2);
  7.   rotate(-PI/2);


  8.   /////Load DATA
  9.   String[] lines = loadStrings("test.txt");

  10.   float days = 360.00/lines.length;
  11.   float deg = 0;
  12.   while (deg<360.00 -days) {

  13.     // Create Data Array  
  14.     for (int i= 0; i< lines.length; i++) {   
  15.       String[] pieces = split(lines[i], '\t'); 
  16.       String[] mon = split(lines[i], '.'); 
  17.       int d = int(mon[0]);
  18.       //     int m = int(mon[1]);
  19.       int[] m = new int[lines.length];
  20.       int b = int(pieces[1]);

  21.       m[i] = int(mon[1]);

  22.       /////////////// THE SUN SCALA
  23.       float k = map(b, 0, 10, 150, 350);
  24.       float angle = radians(deg);
  25.       float radius = k;
  26.       float x = cos(angle) * radius;
  27.       float y = sin(angle) * radius;

  28.       float raycolor = norm(radius, 200, 350);

  29.       strokeWeight(2);
  30.       stroke(255, (80+(170*raycolor)), 0);
  31.       strokeCap(SQUARE);
  32.       line(x, y, 0, 0);

  33.       deg += days;


  34.       /////////////// THE DAY SEGMENTATION

  35.       float mMul = ((360.00/lines.length)/2) + (360.00/lines.length) * i;
  36.       float angleMon = radians(mMul);
  37.       float xMon = cos(angleMon) * 370;
  38.       float yMon = sin(angleMon) * 370;

  39.       strokeWeight(0.1);
  40.       stroke(255);
  41.       line(xMon, yMon, 0, 0);

  42.       /////////////// THE MONTH SEGMENTATION

  43.       /*      
  44.        int m1 = m[i];
  45.        int m2 = m[i-1];   ///// Don't know how to solve this.
  46.        
  47.        
  48.        float mTest = m1 / m2;
  49.        
  50.        if ( mTest != 1 )
  51.        {   
  52.        strokeWeight(1);
  53.        
  54.        stroke(255);
  55.        }   
  56.        */
  57.       line(xMon, yMon, 0, 0);
  58.     }
  59.   }

  60.   ////////// WHITE MIDDLE CIRCLE

  61.   noStroke();
  62.   ellipse(0, 0, 300, 300);
  63. }


  64. void draw () {
  65. }

Replies(3)

My guess
  int[] m = new int[lines.length] ;
belongs outside the loop, otherwise you are creating a new array for each iteration of the loop.

When developing code a few strategically placed println( whatever) can be very informative, as in

println("i= " & i, " mon[" & i & "]= " & mon[i] & " mon[" & i-1 & "]= "  & mon[i-1])


And you can use m1 != m2 to know when they are different...
Thanks a lot.

And this solved the problem for me...

I put 
 int[] m = new int[lines.length] ;
outsider of the loop

and the code looks like this now:


Copy code
  1.       if (i == 0)
  2.       {
  3.         strokeWeight(0.3);
  4.         line(xMon, yMon, 0, 0);
  5.       }

  6.       if (i > 0) {
  7.         float m1 = m[i];
  8.         float m2 = m[i-1];

  9. //        println(m1 + " / " + m2 +" = "+ test);
  10.         if (m1 != m2)
  11.         {
  12.           strokeWeight(0.3);
  13.           line(xMon, yMon, 0, 0);
  14.         }
  15.         else {
  16.           strokeWeight(0.1);
  17.           line(xMon, yMon, 0, 0);
  18.         }