Loading...
Logo
Processing Forum
jpugarte1's Profile
3 Posts
2 Responses
0 Followers

Activity Trend

Last 30 days
Show:
Private Message
    Hi everyone. I'm having a really hard time trying to do what it seems to be a pretty simple task: creating an array of rectangles that can be filled with one of four different colors. The screen is "divided" in four regions (upper left, upper right, lower left, lower right) and the rectangle's color is assigned depending on which region it is located.

    The problem is I'm getting some rectangles in the upper row with the colors that is supposed to be assigned to the lower row rectangles. 

    This is my code:

    1. int altura = 1000;
    2. int cuadrado = 100;
    3. float vacio = 99.5;
    4. Cajita[][] cajitas;// = new Cajita [altura/2][altura/2];

    5. void setup()
    6. {
    7.   size (altura, altura);
    8.   cajitas = new Cajita [(altura/cuadrado)][(altura/cuadrado)];
    9.   frameRate(1);
    10.   background(0);
    11.   
    12.   for (int i = 0; i < (altura/cuadrado); i++)
    13.   {
    14.     if (i < ((altura/cuadrado)/2))
    15.     {
    16.       for (int j = 0; j < (altura/cuadrado); j++)
    17.       {
    18.         if (j < ((altura/cuadrado)/2))
    19.         {
    20.           float test = random(0,100);
    21.           boolean _ocupado = test < vacio;
    22.           //color col = color(int(map(float(i), 0.0, float(altura/cuadrado)/2, 50.0, 255.0)),int(map(float(j), 0.0, float(altura/cuadrado)/2, 50.0, 255.0)),50);     
    23.           color col0 = color(255,0,0);
    24.           cajitas[i][j] = new Cajita(i*(cuadrado), j*(cuadrado), cuadrado, col0, _ocupado);
    25.           cajitas[i][j].create();
    26.           /*if (cajitas[i][j].ocupadin()==true)
    27.           {
    28.             cajitas[i][j].create();
    29.             
    30.           }*/          
    31.         }
    32.         else
    33.         {
    34.           float test = random(0,100);
    35.           boolean _ocupado = test < vacio;
    36.           //color col = color(50, int(map(float(i), 0.0, float(altura/cuadrado)/2, 50.0, 255.0)),int(map(float(j), float(altura/cuadrado)/2, float(altura/cuadrado), 50.0, 255.0)));       
    37.           color col1 = color(0,255,0);
    38.           cajitas[i][j] = new Cajita(i*(cuadrado), j*(cuadrado), cuadrado, col1, _ocupado);
    39.           cajitas[i][j].create();
    40.           /*if (cajitas[i][j].ocupadin()==true)
    41.           {
    42.             cajitas[i][j].create();
    43.             
    44.           }*/  
    45.         }
    46.       }
    47.     }
    48.     else
    49.     {
    50.       for (int j = 0; j < (altura/cuadrado); j++)
    51.       {
    52.         if (j < ((altura/cuadrado)/2))
    53.         {
    54.           float test = random(0,100);
    55.           boolean _ocupado = test < vacio;
    56.           //color col = color(int(map(float(i), float(altura/cuadrado)/2, float(altura/cuadrado), 50.0, 255.0)),50, int(map(float(j), 0.0, float(altura/cuadrado)/2, 50.0, 255.0)));     
    57.           color col2 = color(0,0,255);
    58.           cajitas[i][j] = new Cajita(i*(cuadrado), j*(cuadrado), cuadrado, col2, _ocupado);          
    59.           cajitas[i][j].create();
    60.           /*if (cajitas[i][j].ocupadin()==true)
    61.           {
    62.             cajitas[i][j].create();
    63.             
    64.           }*/  
    65.         }
    66.         else
    67.         {
    68.           float test = random(0,100);
    69.           boolean _ocupado = test < vacio;
    70.           //color col = color(int(map(float(i), float(altura/cuadrado)/2, float(altura/cuadrado), 50.0, 255.0)),int(map(float(j), float(altura/cuadrado)/2, float(altura/cuadrado), 50.0, 255.0)), int(map(float(j), float(altura/cuadrado)/2, float(altura/cuadrado), 50.0, 255.0)));  
    71.           color col3 = color(255,0,255);
    72.           cajitas[i][j] = new Cajita(i*(cuadrado), j*(cuadrado), cuadrado, col3, _ocupado);           
    73.           cajitas[i][j].create();
    74.           /*if (cajitas[i][j].ocupadin()==true)
    75.           {
    76.             cajitas[i][j].create();
    77.             
    78.           }*/  
    79.         }
    80.       }
    81.     } 
    82.   }  
    83. }
    And this is the Class Cajita code:

    1. class Cajita
    2. {
    3.   int x, y, d;
    4.   color micolor;
    5.   boolean ocupado;
    6.   
    7.   Cajita (int _x, int _y, int _d, color _c, boolean _o)
    8.   {
    9.     x = _x;
    10.     y = _y;
    11.     d = _d;
    12.     micolor = _c;
    13.     ocupado = _o;
    14.   }
    15.   
    16.   void create()
    17.   {     
    18.     rect(x,y,d,d);
    19.     fill(micolor);    
    20.   }
    21.   
    22.   boolean ocupadin()
    23.   {
    24.     return ocupado;
    25.   }
    26.   
    27.   color micolor()
    28.   {
    29.     return micolor;
    30.   }
    31.   
    32.   void updateLive(color newColor)
    33.   {
    34.     ocupado = true;
    35.     rect(x,y,d,d);
    36.     fill(newColor);  
    37.   }
    38.   
    39.   void updateDead()
    40.   {
    41.     ocupado = false;
    42.     rect(x,y,d,d);
    43.     fill(0,0,0);
    44.   }
    45. }

    Can anyone help me? I've been stuck with this problems for almost 1 week!!! Any help is very much appreciated.

    Cheers!

    Hi. I need some help with a project I'm working on. 

    I've developed a sketch with an array of boxes that are modified in its size depending on the input of the webcam. It works with a face detection system, so the boxes that are close to the coordinates of the person in front of the computer, get bigger.

    So, what I want to do is to store the animation of the boxes changing its size (for instance, during 60 seconds) and then export thhat animated boxes into a 3dsmax. I hope the objects could get imported into 3dsmax (or maya, cinema4d, etc.) mantaining their animated status, so then I could render the animation in 3dsmax or any similar software.

    So, does anybody know if there is a way to do that in processing?? Any help will be appreciated.

    Thanks in advance.
    Regards. 
    Hi, I'm trying to write a code to make convex polygon tesellations. I have just started, and I'm having problems regarding finding a point on a circumference (over its perimeter).



    As the image shows, I have 4 points and 2 circumferences.

    p1 is the center of circumference 1
    p2 is the center of circumference 2
    p3 is a point wich controls the radius of circumference 1 (therefore, it's contained in its perimeter)

    p4 is the one giving me troubles; this point should control the circumference 2 radius (they are not linked yet, but it doesn't matter now). this point should be at an 120º angle with p3. 

    in order to do that, i calculated the gradient of the segment p1_p3. Having that, I used the atan() function to get its angle in radians (I assume it's the angle between that segment and an horizontal one). After that, I converted the angle from radians to degrees, and I used it to find the (x,y) coordinates over the circumference using trigonometric equations. 

    The problem is that p4, wich in the image is at 120º from p3, goes from that to 60º, depending on the value of the angle calculation based on the p1_p3 segment. And I would like it to be allways 120º... I'm sorry I can't be more specific, my english is not good, specially in math specialized terms.

    Here is the code, highlighting the part regarding my issues.

    1. // GLOBAL VARIABLES
    2. float Radio1 = 300;
    3. float RadioVariable1;

    4. // Coordenadas Punto Móvil 1 (centro Circulo 1)
    5. float Pto1X;
    6. float Pto1Y;
    7. float NewPto1X = 0.0;
    8. float NewPto1Y = 0.0;

    9. //Coordenadas Punto Móvil 2 (centro Circulo 2)
    10. float Pto2X;
    11. float Pto2Y;
    12. float NewPto2X;
    13. float NewPto2Y;

    14. //Coordenadas Punto Móvil 3 (Determina Radio Circulo 1)
    15. float Pto3X;
    16. float Pto3Y;
    17. float NewPto3X;
    18. float NewPto3Y;

    19. //Booleanas
    20. boolean locked1 = false;
    21. boolean over1 = false;
    22. boolean locked2 = false;
    23. boolean over2 = false;
    24. boolean locked3 = false;
    25. boolean over3 = false;

    26. void setup () {
    27.   size (800,600);
    28.   Pto1X = width/2.0;
    29.   Pto1Y = height/2.0;
    30.   Pto2X = width/1.5;
    31.   Pto2Y = height/2.0;
    32.   Pto3X = height/1.1;
    33.   Pto3Y = width /2.0;
    34.   smooth();
    35. }

    36. void draw () {
    37.   background (0);
    38.   
    39.   // Circulo 1
    40.   if (pow(mouseX - Pto1X, 2) + pow(mouseY - Pto1Y, 2) <= pow(2,5))  {
    41.     over1 = true;
    42.     if (!locked1) {
    43.       fill (255);
    44.       stroke (255,0,0);
    45.     }
    46.   }
    47.   else {
    48.     fill (255);
    49.     stroke (255);
    50.     over1 = false;
    51.   }
    52.   
    53.   RadioVariable1 = sqrt(pow(Pto1X - Pto3X,2)+ pow(Pto1Y - Pto3Y,2)); 
    54.   ellipse (Pto1X, Pto1Y, 10, 10);
    55.   Circulo (Pto1X, Pto1Y, RadioVariable1*2, RadioVariable1*2);
    56.   
    57.   //Circulo 2
    58.   if (pow(mouseX - Pto2X, 2) + pow(mouseY - Pto2Y, 2) <= pow(2,5))  {
    59.     over2 = true;
    60.     if (!locked2) {
    61.       fill (255);
    62.       stroke (255,0,0);
    63.     }
    64.   }
    65.   else {
    66.     fill (255);
    67.     stroke (255);
    68.     over2 = false;
    69.   }
    70.   ellipse (Pto2X, Pto2Y, 10, 10);
    71.   Circulo (Pto2X, Pto2Y, Radio1, Radio1);
    72.   
    73.   //Circulo 3
    74.   if (pow(mouseX - Pto3X, 2) + pow(mouseY - Pto3Y, 2) <= pow(2,5))  {
    75.     over3 = true;
    76.     if (!locked3) {
    77.       fill (255);
    78.       stroke (255,0,0);
    79.     }
    80.   }
    81.   else {
    82.     fill (255);
    83.     stroke (255);
    84.     over3 = false;
    85.   }
    86.   // Calculo Pendiente
    87.   float M = (Pto1X - Pto3X) / (Pto1Y - Pto3Y);
    88.   float preAnguloRad = atan (M);
    89.   float preAnguloDeg = preAnguloRad*(180/3.14159265);
    90.   float Angulo = 330 - preAnguloDeg;
    91.   println (preAnguloDeg);
    92.   float Pto4X = Pto1X + cos(radians(Angulo)) * RadioVariable1;
    93.   float Pto4Y = Pto1Y + sin(radians(Angulo)) * RadioVariable1;
    94.   ellipse (Pto3X, Pto3Y, 10, 10);
    95.   ellipse (Pto4X, Pto4Y, 10,10);
    96.   translate (width - Pto1X, height - Pto1Y);
    97. }

    98. void mousePressed () {
    99.  if (over1) {
    100.   locked1 = true;
    101.   fill (255);
    102.  } 
    103.  else {
    104.   locked1 = false; 
    105.  }
    106.  if (over2) {
    107.   locked2 = true;
    108.   fill (255); 
    109.  }
    110.  else {
    111.   locked2 = false; 
    112.  }
    113.  if (over3) {
    114.   locked3 = true;
    115.   fill (255); 
    116.  }
    117.  else {
    118.   locked3 = false; 
    119.  }
    120.  NewPto1X = mouseX - Pto1X;
    121.  NewPto1Y = mouseY - Pto1Y;
    122.  NewPto2X = mouseX - Pto2X;
    123.  NewPto2Y = mouseY - Pto2Y;
    124.  NewPto3X = mouseX - Pto3X;
    125.  NewPto3Y = mouseY - Pto3Y;
    126. }

    127. void mouseDragged() {
    128.  if (locked1) {
    129.   Pto1X = mouseX - NewPto1X;
    130.   Pto1Y = mouseY - NewPto1Y;
    131.  }
    132.  if (locked2) {
    133.   Pto2X = mouseX - NewPto2X;
    134.   Pto2Y = mouseY - NewPto2Y;
    135.  }  
    136.  if (locked3) {
    137.   Pto3X = mouseX - NewPto3X;
    138.   Pto3Y = mouseY - NewPto3Y;
    139.  }  
    140. }

    141. void mouseReleased(){
    142.  locked1 = false;
    143.  locked2 = false; 
    144.  locked3 = false; 
    145. }

    146. void Circulo (float x,float y,float r1,float r2){
    147.  noFill(); 
    148.  stroke (255);
    149.  ellipse (x,y,r1,r2);
    150. }

    Thanks in advance.