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 › keyPressed failure
Page Index Toggle Pages: 1
keyPressed failure? (Read 668 times)
keyPressed failure?
Dec 2nd, 2006, 11:02pm
 
hi there,
i've got a question aboute processing. when i use this code below, i can only increase the cubesize with 's' but don't decrease it with 'd'.

does anyone find the failure?
thanks in advance
b_we

//code
int cubeperline = 5;
int cubesize = 10;
int cubeabstand = cubesize+cubesize/2;
int r = 75;
int g = 150;
int b = 225;
int a = 100;


void setup() {
 size(800, 400, P3D);
 frameRate(30);
 }

void draw() {
 if (keyPressed) {
   if (key == 'd') {
     cubesize -= 0.01;
     }
   if (key == 's') {
     cubesize += 0.01;
     }
 }
 background(0);
 lights();
 stroke(255,255,255,15);
 fill(r,g,b,a);
 translate(mouseX,mouseY,0);
 for(int z = 0; z < cubeperline; z++) {
   for(int y = 0; y < cubeperline; y++) {
     for(int x = 0; x < cubeperline; x++) {
       translate(cubeabstand,0,0);
       box(cubesize);
       }
       translate(-cubeabstand*cubeperline,0,0);
       translate(0,cubeabstand,0);
     }
     translate(0,-cubeabstand*cubeperline,0);
     translate(0,0,cubeabstand);
   }
}
   
Re: keyPressed failure?
Reply #1 - Dec 3rd, 2006, 1:16am
 
Hi,

Here is the workaround :

Quote:
float cubesize = 10;  
float cubeabstand = cubesize+cubesize/2;

Quote:
if (keyPressed) {
   if (key == 's') {
cubesize = cubesize+0.05;
   }
   if(key == 'd') {
cubesize = cubesize-0.05;
}
 }


You can also modify the cubeperline value by adding this in draw() following the previous code:

Quote:
if (keyPressed) {
   if (key == 'e') {
cubeperline = cubeperline+1;
   }
   if(key == 'x') {
cubeperline = cubeperline-1;
}
 }
Re: keyPressed failure?
Reply #2 - Dec 3rd, 2006, 5:54pm
 
thanks jaylfk,

works fine Smiley
Page Index Toggle Pages: 1