Loading...
Logo
Processing Forum
martijnbac's Profile
2 Posts
7 Responses
0 Followers

Activity Trend

Last 30 days
Show:
Private Message
      Hello,

      I try to find a more compact way for creating a custom 'pixel' font (because I need to process a whole alphabet this way).

      When i select a character ( c='a') I want to loop the corresponding array with the for loop. Now I have a seperate rect for each character, because I don't know how to use the value of c as the name of the array (so I can say if value of c[i][j]{}).

      Is this possible?


      the 'problem' part:
      1.         if (c=='a') {
      2.           if (a[i][j]==1) {
      3.             rect(x+j*40, i*40, 20, 20);
      4.           }
      5.         }


      full code:

      1.     c = 'a';
      2.     
      3.     int[][] a = {  
      4.       {0,0,0,0,0}, 
      5.       {0,0,0,0,0}, 
      6.       {0,1,1,1,0}, 
      7.       {0,0,0,0,1}, 
      8.       {0,1,1,1,1}, 
      9.       {1,0,0,0,1}, 
      10.       {0,1,1,1,1}, 
      11.       {0,0,0,0,0}, 
      12.       {0,0,0,0,0}
      13.     };

      14.     int[][] b = {  
      15.       {1,0,0,0,0}, 
      16.       {1,0,0,0,0}, 
      17.       {1,1,1,1,0}, 
      18.       {1,0,0,0,1}, 
      19.       {1,0,0,0,1}, 
      20.       {1,0,0,0,1}, 
      21.       {1,1,1,1,0}, 
      22.       {0,0,0,0,0}, 
      23.       {0,0,0,0,0}
      24.     };

      25.     for (int i = 0; i < 9; i++) {
      26.       for (int j = 0; j < 5; j++) {

      27.         if (c=='a') {
      28.           if (a[i][j]==1) {
      29.             rect(x+j*40, i*40, 20, 20);
      30.           }
      31.         }
      32.         if (c=='b') {
      33.           if (b[i][j]==1) {
      34.             rect(x+j*40, i*40, 20, 20);
      35.           }
      36.         }

      37.       }
      38.     }
      Hello,

      I working on a simple program as a part of a sound-reactive installation. Every time the sound velocity is more than 5, a rectangle comes in on the right, and all other objects shift one place to the left. 

      The problem: the velocity is the width/height of the rectangles. Now it affects all objects, but I only want to assign the value to the newest, so all rectangles get their own size (and stay that size). Maybe there is something wrong with void show() and I tried things with an arraylist, but I'm afraid I'm a bit lost.

      This is a simplified example to make it more clear, in the real version the rectangles are characters (kind of sound-reactive newsticker).

      If anyone can point me in the right direction, that would be great :-)



      full code:
      1. import ddf.minim.*;
      2. Minim minim;
      3. AudioInput in;
      4. AudioRecorder recorder;

      5. Rectangle[] myRectangle;
      6. float[] vs = new float[1000];
      7. float vel;
      8. int count;
      9. int index;
      10. public float y; 
      11. private float v;
      12. String txt;
      13. void setup() {
      14.   size(1024, 400);
      15.   noStroke();
      16.   minim = new Minim(this);
      17.   in = minim.getLineIn(Minim.STEREO, 2048);

      18.   count = 50;
      19.   char[] allChars = new char[count];
      20.   myRectangle = new Rectangle[count];

      21.   for (int i = 0; i < count; i++) {
      22.     myRectangle[i] = new Rectangle();
      23.   }
      24. }

      25. void draw() {
      26.   y = in.left.get(2)*800;
      27.   scale(0.1);
      28.   background(255);
      29.   translate(0, 200);

      30.   if (y>5) {
      31.     show();
      32.   }

      33.   for (int i=0;i<count;i++) {
      34.     vel = y;
      35.     myRectangle[i].display();
      36.   }
      37. }

      38. void show() {
      39.   if (index<count) {
      40.     for (int i=0;i<index;i++) {
      41.       vel = y;
      42.       myRectangle[i].update();
      43.     }
      44.   }
      45.   index++;
      46. }

      class
      1. class Rectangle { 
      2.   float xpos;
      3.   Rectangle() {
      4.     xpos = width*10;
      5.   }  
      6.   void display() {
      7.     fill(0, 99, 220);
      8.     rectMode(CENTER);
      9.     rect(xpos+40, 0, vel, vel);
      10.   }
      11.   void update() {
      12.     int spacing = 300;
      13.     xpos = xpos - spacing;
      14.   }
      15. }