|
Author |
Topic: Java mode keypressed bug (Read 300 times) |
|
Jaymann Guest
|
Java mode keypressed bug
« on: Dec 11th, 2003, 10:56pm » |
|
Hi there, I've been using Processing for about a week and I absolutely love it. Thanks to everybody for their efforts. Here's my first contribution: I think I found a strange bug, but since it affects "Java Mode" which I understand is not yet fully operational I don't know if I should post this. In case not, please excuse me. The bug: I got a code that works perfect in active mode, but when extended it to java mode with the appropriate "public class MyDemo extends BApplet" header fails to handle the keypressed events correctly and crashes after a while. The code below in active mode. All that is required to extended it to java mode is commenting out the first and last line (I know this is obvious, sorry). //public class loMio extends BApplet { int boxWidth = 500; int boxHeight = 200; BImage a; boolean onetime = true; int[] bPixels = new int[boxWidth*boxHeight]; int[] aPixels; int direction = 1; boolean displayFreezed = false; float signal; //textWrapper tW; void setup() { size(boxWidth,boxHeight); stroke(255); a = loadImage("scircnoise4.jpg"); aPixels = new int[a.width*a.height]; for(int i=0; i<a.width*a.height; i++) { aPixels[i] = a.pixels[i]; } println("Applet Setup!"); } // Keyboard event handlers for DEBUGGING purposes void keyPressed() {FreezeOn("<Learn all about my my giant-sized mother and father!>");} void keyReleased() {FreezeOff();} //low-level pixel lighting - ref: note on blending at http://www.proce55ing.net/reference/technotes/index.html color lightenPix(color pix) { int alfa = 153; int r1=(pix&0x0000FF); int g1=(pix&0x00FF00); int b1=(pix&0xFF0000); //int r3=(((alfa*(r1-0x0000FF)) >>8 )+0x0000FF)&0x0000FF; int r3=(((alfa*(r1-0x0000FF)) >>8 )+0x0000FF)&0x0000FF; int g3=(((alfa*(g1-0x00FF00)) >>8 )+0x00FF00)&0x00FF00; int b3=(((alfa*(b1-0xFF0000)) >>8 )+0xFF0000)&0xFF0000; return (r3)|(g3)|(b3); } synchronized void FreezeOn(String caption) { println("Start freezing: "+ caption); if (!displayFreezed) { // first time displayFreezed = true; for (int i=0; i<width*height; i++) { pixels[i]=lightenPix(pixels[i]); } } } synchronized void FreezeOff() { displayFreezed = false; } synchronized void paintBox() { for (int i=0; i<width*height; i++) { pixels[i] = aPixels[int((a.width*int(signal))+(i%a.width))]; } } void loop() { if (signal > a.height-1 || signal < 0) { direction = direction * -1; } if(mousePressed) { signal = abs(mouseY%a.height); } if (!displayFreezed) { paintBox(); signal += (0.15*direction); } } } // public class loMio extends BApplet There actually there is a linefeed after the last line (due to a documented bug). All it does is freeze and blend to white the screen when a key is pressed. Can you please help me on this one? Jaymann
|
|
|
|
Jaymann Guest
|
Re: Java mode keypressed bug
« Reply #1 on: Dec 11th, 2003, 11:04pm » |
|
Forgot about my configuration details: Sw: Win XP Home Edition SP1 Sun Java VM 1.4.1_01-b01 Processing 0067 Alpha Hw: Dell Inspiron 8200 512 Mb RAM thanks
|
|
|
|
|