I'm coding a game where I'd like there to be a limit on how long you can hold a key down. If you press it for any more than say 1 second, you lose a point and it goes back to the "off" state until you release the key and press it again. Any suggestions on how to do this? I'd really rather not use keyReleased(); because it would screw up the timing of the user input (it's a rhythm-based game).
I found this code by rbrauer that cleverly gets around the repeat rate issue, but I can't get my head around how I'd work a timer into it
boolean state, pstate;
void setup() {}
void draw() {
state = false;
state = keyPressed;
if(state != pstate) println(state); //only react if there's been a change
pstate = state; //flip it so the starting state is the current state
I'm interested in actually writing Processing sketches on my Galaxy Tab 10.1 (I have a Bluetooth keyboard for it which should make that easier). Everything I've come across this morning is about writing programs to run on the tablet, but nothing has said whether there's a Processing IDE app written for Android. Anyone have experience with this?
3rd day into Processing (and OOP coding at all), and pretty excited about it. I ran into an issue that a bunch of searching hasn't helped. I currently have a bunch of ellipses being drawn randomly, and I'm trying to attach a random number of randomly sized arc segments to each ellipse. I was able to get one arc per circle, but I'd like to get more (all arcs per ellipse should be the same stroke thickness, but random start and stop points). What's the best way to do this?
Here's what I have so far. Thanks in advance for any insight :)
//declare variables globally
int circNum = (int) random(10, 30); //Declare the number of Circles globally
//declare arrays globally
int[]ArrayCirSiz = new int[circNum]; //Array for random size of Circs
int[]ArrayCirStr = new int[circNum]; //Array for random stroke weight of Circs
int[]ArrayArcNum = new int[circNum]; //Array for random ArcSegs per Circ
int[]ArrayArcBeg = new int[circNum]; //Array for when each ArcSeg starts --- May have to be 2D
int[]ArrayArcEnd = new int[circNum]; //Array for when each ArcSeg ends --- May have to be 2D
int[]ArrayArcStr = new int[circNum]; //Array for ranom stroke weight of all ArcSegs per Circ
//everything in setup runs once, so randoms are all generated here, otherwise they loop.
void setup() {
size (500, 500); //set the canvas size
// circNum = (int) random(15, 30); //set the number of circles to a random number, once.
//loop that populates all the random numbers
for (int i = 0; i < circNum; i++) {
ArrayCirSiz[i] = (int) random(width/3, width);
ArrayCirStr[i] = (int) random(1, 2);
ArrayArcNum[i] = (int) random(1, 3);
ArrayArcBeg[i] = (int) random(1, 360);
ArrayArcEnd[i] = (int) random(5, 360);
ArrayArcStr[i] = (int) random(2, 4);
}
}
void draw() {
//constant values that affect everything in the scene