We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Three very specific questions
Page Index Toggle Pages: 1
Three very specific questions (Read 799 times)
Three very specific questions
Dec 24th, 2009, 2:40pm
 
Hello and merry christmas good people,

I'm using the Public Pixel Matrix library from mr. Patrick Borgeat, and I'm trying to replicate a video he posted on YouTube. This library stores boolean matrices (2d arrays) for displaying basic patterns in a small grid. This particular example displays the same grid on 3D space with a certain number of duplicates behind it (determined by length and Iterator). These are my problems:


1-  What is the syntax string for calling a file within my computer directory?

   readFromDirectory("XXX")

2- I can't make the shapes on every draw() command to suit my mouseX and mouseY rotation numbers established in mouseDragged(), I don't know why. It probably has to do with the reset thing that happens on every draw(), but I don't know how to bypass this.

3- I also can't seem to fill the "mat1" 2D array with random boolean values, because when I use it to display a matrix it only shows for true.


import processing.opengl.*;
import de.cappelnord.ppm.*;

int dim;
int size = 24;

Iterator it;

float drehI = 0.0;

PPMatrix m1;
PPMatrix m2;
PPMatrix m3;

PPMatrixList list;

boolean[][] mat1;
boolean[][] mat2;
boolean[][] mat3;

PPMatrix[] history;

final static int NUM = 6;

float rotx = PI/4;
float roty = PI/4;


void setup()
{
 dim = PublicPixelMatrix.DIM;
 size(1024, 576, OPENGL);
 frameRate(25);
 smooth();

 mat1 = new boolean[dim][dim];
 mat2 = new boolean[dim][dim];
 mat3 = new boolean[dim][dim];

 for(int i=0; i<dim; i++) {
   for(int j=0; j<dim; j++) {
     if (random(2) == 1) {
       boolean bool =  random(2) <= 0 ? false : true;
       mat1[j][i] = bool;
     }
   }
 }
 arrayCopy(mat1, mat2);
 arrayCopy(mat2, mat3);

 m1 = new PPMatrix(1249422542, mat1);
 m2 = new PPMatrix(1249422543, mat2);
 m3 = new PPMatrix(1249422544, mat3);

 list = new PPMatrixList();
 list.add(m1);
 list.add(m2);
 list.add(m3);
 //list = PublicPixelMatrix.readPPMatrixListFromURL("");  

 it = list.iterator();

 history = new PPMatrix[NUM];


}

void draw()
{   }

void mousePressed() {
 rotateX(rotx);
 if(it.hasNext())
 {
   background(0);
   noStroke();
   
   PPMatrix matrix = (PPMatrix) it.next();

   for(int i = history.length - 2; i >= 0; i--)
   {
     history[i+1] = history[i];
   }
   history[0] = matrix;

   pushMatrix();
   translate(width/2, height / 2 - ((dim * size) / 2));

   drehI  = drehI + 0.011;
   rotateX(rotx);
   rotateY(roty);    //rotateY( PI + (sin(drehI) * (PI/4)));
   translate(-((dim * size) / 2),0);
   
   for(int i = 0; i < history.length; i++)
   {
     if(history[i] != null)
     {
       pushMatrix();
       translate(0,0,i*-80 );

       float alpha = 255 - (((float) i / (float) history.length) * 220);
       
       for(int y = 0; y < dim; y++)
       {
         for(int x = 0; x < dim; x++)
         {  
           fill(0,history[i].get(x,y) ? 0 : 255,0, alpha);
           rect(x * size, y * size, size , size);
           
         }
       }  

       popMatrix();
     }  
   }
   popMatrix();  

   fill(255);
   // text(matrix.getFormattedDate(),20,34);
   // saveFrame("frame####.png");
 }      
}

void mouseDragged() {
 float rate = 0.01;
 rotx += (pmouseY-mouseY) * rate;
 roty += (mouseX-pmouseX) * rate;
}
Re: Three very specific questions
Reply #1 - Dec 24th, 2009, 11:19pm
 
1. http://processing.org/reference/open_.html ?
2. You are drawing within the mousePressed method?
3. random(2) generates floating point numbers from 0 to 2 (2 not included), you have to cast the random() to an int for your check to work, e.g.:
boolean randomBool = ((int)random(2))==1;
Page Index Toggle Pages: 1