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 › drawing only a single square
Page Index Toggle Pages: 1
drawing only a single square (Read 373 times)
drawing only a single square
Aug 2nd, 2008, 6:53pm
 
float xpos;
float ypos;
float rectW;
float rectH;
float cl;
float R;
float G;
float B;


import promidi.*;

MidiIO midiIO;

void setup(){
 size(640, 480);
 smooth();
 background(0);
 
 //get an instance of MidiIO
 midiIO = MidiIO.getInstance(this);
 println("printPorts of midiIO");
 
 //print a list of all available devices
 midiIO.printDevices();
 
 //open the first midi channel of the first device
 midiIO.openInput(0,0);
 midiIO.openInput(1,0);
 frameRate(30);

 

}

void draw(){
 moveBox();
}

void noteOn(Note note, int device, int channel){
 
 if (note.getPitch() ==0) {
   R = random(255);
   G = random(255);
   B = random(255);
 
 }
        println(note.getPitch());

}

void moveBox() {
  color cl = color(R, G, B);
 fill(cl);

 if (rectW < 20){
  rectW = 20;
 }else if (rectH <20){
  rectH=20;
 }
 
 
rect(xpos, ypos, rectW, rectH);
}

void controllerIn(Controller controller, int device, int channel){
 if (controller.getNumber() == 4){
  xpos = controller.getValue() * 5;
 } else if (controller.getNumber() == 5){
  ypos = controller.getValue() *4;
 }
 else if(controller.getNumber() ==6){
  rectW = controller.getValue() *2;
 }else if (controller.getNumber() ==7){
 rectH = controller.getValue() *2;
 }
 
 
 println(controller.getValue());
}




Everytime i change a value it draws a new square on top of the old one.  I just want a single square to move around the screen.  How would i go about doing this?  Help please. thanks.
Re: drawing only a single square
Reply #1 - Aug 2nd, 2008, 7:09pm
 
Just put "background(0);" at the beginning of your draw loop to clear the screen each frame.
Re: drawing only a single square
Reply #2 - Aug 2nd, 2008, 9:44pm
 
thanks! Also when i hit a note to change color it changes the color but when i release a note the color changes again.  How would i stop that?
Page Index Toggle Pages: 1