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.
Page Index Toggle Pages: 1
scale a pixel (Read 878 times)
scale a pixel
Apr 7th, 2010, 3:22pm
 
Hello,
I created a 15x15 matrix writing pixels one by one with set() - I want to scale my pixels on my screen..means to make them bigger in dimensions so they are more visible..please help..
Any hint highly appreciated.
Re: scale a pixel
Reply #1 - Apr 7th, 2010, 11:28pm
 
you can create an new image using get
http://processing.org/reference/get_.html
and then just redraw it and scale it.
http://processing.org/reference/image_.html

Re: scale a pixel
Reply #2 - Apr 8th, 2010, 1:02am
 
Use rect() where you use set(), with proper spacing of course.
Re: scale a pixel
Reply #3 - Apr 8th, 2010, 3:20am
 
thanks for the nice replies,  I just added the rect() in the code that creates my image from serial data but it doesn't seem to update. My code with set() works fine...can u help me debug?thanks a lot in advance..
Code:
import processing.serial.*;
Serial port;
int x=0;
int y=0;
int i=0;  

void setup(){
    size(200,200);

    port = new Serial(this,Serial.list()[1], 9600);
}

void draw() {
    delay(500);
    while (port.available() > 0) {
     
      int inByteRED = port.read();
      println(inByteRED);
      delay(500);
      int inByteGREEN = port.read();
      println(inByteGREEN);
      delay(500);
      int inByteBLUE = port.read();
      println(inByteBLUE);
      delay(500);
     
      color c = color(inByteRED, inByteGREEN, inByteBLUE);
     
      set(x, y, c);
     
      fill(c);
      rect(30, 20, 55, 55)
;
     
      x ++;
     
      if (x > 14) {x = 0; y++;}
      if (y == 15) {noLoop();}      
     
   }
}




Re: scale a pixel
Reply #4 - Apr 8th, 2010, 3:27am
 
cant test your code, but you have to add the x and y to your rect.

something like that.

rect(x*rectSize,y*rectSize,rectSize,rectSize);
Re: scale a pixel
Reply #5 - Apr 8th, 2010, 3:55am
 
Hello,
thanks a lot for the answer..
I add the x,y to the rect() but no result...while set() works fine.Below is the code which is supposed to draw 5x5 rectangles...When I place it outside of (port.available() > 0) {} function the rect is drawn once but the color and the rect do not update...any idea?thanks a lot..

Code:
import processing.serial.*;
Serial port;
int x=0;
int y=0;
int i=0;  

void setup(){
    size(200,200);

    port = new Serial(this,Serial.list()[1], 9600);
}

void draw() {
    delay(500);
    while (port.available() > 0) {
     
      int inByteRED = port.read();
      println(inByteRED);
      delay(500);
      int inByteGREEN = port.read();
      println(inByteGREEN);
      delay(500);
      int inByteBLUE = port.read();
      println(inByteBLUE);
      delay(500);
     
      color c = color(inByteRED, inByteGREEN, inByteBLUE);
     
      set(x, y, c);
     
      fill(c);
     rect(x, y, 5, 5);

      x+=5;
     
      if (x > 14*5) {x = 0; y+=5;}
      if (y == 15*5) {noLoop();}      
     
   }
}



Re: scale a pixel
Reply #6 - Apr 8th, 2010, 4:12am
 
the code above WORKS fine!!thanks!!
but I have to minimize and reopen my window to see the new pixels that are coming from the array..that 's why I couldn't see anything before..
I miss an update function somewhere..any ideas?
thanks in advance
Re: scale a pixel
Reply #7 - Apr 8th, 2010, 4:52am
 
Don't loop inside draw(), use draw() as a loop, since it is called repeatedly.
If you do several updates in the same draw() call, you will only see the last one.
Page Index Toggle Pages: 1