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 › OK...had a thought.
Page Index Toggle Pages: 1
OK...had a thought. (Read 782 times)
OK...had a thought.
Feb 14th, 2007, 1:11am
 
I just had a thought for a project, actually its my final project. And was wondering if this was possible.

I want to use each keypress on a keyboard to create an output graphic that lasts maybe 3 seconds. For instance pressing a key would create a sphere maybe coloured for example.

Then having the spheres or graphics laid out in a grid of 54 (7x7 and the remainder).

If anyone could start me off that would be great.

Thanks in advance,

Jason
Re: OK...had a thought.
Reply #1 - Feb 14th, 2007, 5:52pm
 
Ive started to make the grid (not sure if this is long winded)

void setup() {
 size (430, 430);
}

void draw () {

 //first line
 
 rect(25, 25, 50, 50);
 rect(80, 25, 50, 50);
 rect(135, 25, 50, 50);
 rect(190, 25, 50, 50);
 rect(245, 25, 50, 50);
 rect(300, 25, 50, 50);
 rect(355, 25, 50, 50);
 
 //second line
 
 rect(25, 80, 50, 50);
 rect(80, 80, 50, 50);
 rect(135, 80, 50, 50);
 rect(190, 80, 50, 50);
 rect(245, 80, 50, 50);
 rect(300, 80, 50, 50);
 rect(355, 80, 50, 50);
 
 //third line
 
 rect(25, 135, 50, 50);
 rect(80, 135, 50, 50);
 rect(135, 135, 50, 50);
 rect(190, 135, 50, 50);
 rect(245, 135, 50, 50);
 rect(300, 135, 50, 50);
 rect(355, 135, 50, 50);
 
 //fourth line
 
 rect(25, 190, 50, 50);
 rect(80, 190, 50, 50);
 rect(135, 190, 50, 50);
 rect(190, 190, 50, 50);
 rect(245, 190, 50, 50);
 rect(300, 190, 50, 50);
 rect(355, 190, 50, 50);
 
 //fifth line
 
 rect(25, 245, 50, 50);
 rect(80, 245, 50, 50);
 rect(135, 245, 50, 50);
 rect(190, 245, 50, 50);
 rect(245, 245, 50, 50);
 rect(300, 245, 50, 50);
 rect(355, 245, 50, 50);
 
 //sixth line
 
 rect(25, 300, 50, 50);
 rect(80, 300, 50, 50);
 rect(135, 300, 50, 50);
 rect(190, 300, 50, 50);
 rect(245, 300, 50, 50);
 rect(300, 300, 50, 50);
 rect(355, 300, 50, 50);
 
 //seventh line
 
 rect(25, 355, 50, 50);
 rect(80, 355, 50, 50);
 rect(135, 355, 50, 50);
 rect(190, 355, 50, 50);
 rect(245, 355, 50, 50);
 rect(300, 355, 50, 50);
 rect(355, 355, 50, 50);
 
}

Then I tried implementing the 'key' code to change each of the blocks a different colour with a corresponding 'key' but didn't manage to do it.

void setup() {
 size (430, 430);
}

void draw () {

 //first line

if (keyPressed) {
 if (key == 'b' || key == 'B') {
   fill (0);
 }
} else {
 fill (255);
}
 rect(25, 25, 50, 50);
}

I can only do the first one and not sure how to go about doing the rest. I have a feeling that its quite simple but I can't find any examples on how to do it. Can anyone help?
Re: OK...had a thought.
Reply #2 - Feb 14th, 2007, 6:43pm
 
Hi Jason-

Try starting with this example project, which is somewhat close to your idea:

 http://processing.org/learning/examples/keyboardfunctions.html

Putting your logic into the keyPressed() method as done in this example should simplify the coding quite a bit.

-Matt
Re: OK...had a thought.
Reply #3 - Feb 14th, 2007, 6:50pm
 
mhuyck wrote on Feb 14th, 2007, 6:43pm:
Hi Jason-

Try starting with this example project, which is somewhat close to your idea:

 http://processing.org/learning/examples/keyboardfunctions.html

Putting your logic into the keyPressed() method as done in this example should simplify the coding quite a bit.

-Matt


Thanks Matt will look into it now!... Upon looking at it... I have literally no idea where to start looking =S will have a go and if I can't get anywhere I shall post again.

Jason
Page Index Toggle Pages: 1