Using java.awt.Toolkit and javascript
in
Processing with Other Languages
•
1 year ago
Hello,
I'm really new to processing, so this may sound trivial. I have a sketch including java.awt.Toolkit. Even though I can export it as an application, when trying to export it as javascript (through version 2.0 of processing) in html, I can't make it play on any browser (I have checked that javascript is enabled, and also tried the "older" processing.js method with 1.5 version). It also won't work when exporting it as a java applet, and opening it in a browser. When taking away the part that has to do with the java.awt.Toolkit all work smoothly. Are there any limitations when using certain java packages with javascript? If so, how could I overcome this?
This is the code that I'm talking about (this is in a bigger sketch but works like this as well):
- //--------------------------------------------------------------
- import java.awt.Toolkit;
- String url = "https://fbcdn-sphotos-a.akamaihd.net/hphotos-ak-ash3/523162_218503838249084_165272370238898_350729_1214161092_n.jpg";
- Image temp;
- PImage ptemp, inicial;
- byte[] data;
- int dcnt[];
- void setup()
- {
- frameRate(60);
- data = loadBytes(url);
- inicial = corruptImage(0);
- ptemp = corruptImage(1);
- size(300, 300, P2D);
- noSmooth();
- }
- PImage corruptImage(int howMuch) {
- dcnt = new int[howMuch];
- for (int i=0;i<howMuch;i++) // 100 changes
- {
- int loc=(int)random(1000, data.length-1);
- data[loc]+=(byte)(((byte)random(10, 255)-data[loc])/20.0);
- dcnt[i] = loc;
- }
- try {
- temp = GetFromJPEG(data);
- }
- catch(Exception e) {
- }
- return new PImage(temp);
- }
- void draw() {
- if (frameCount%10==0) {
- data = loadBytes(url);
- }
- ptemp = corruptImage((int)(noise(frameCount/30.0)*12));
- image(ptemp, 0, 0);
- String matrix = "";
- for (int i =0 ; i < dcnt.length;i++) matrix += dcnt[i]+" | ";
- }
- Image GetFromJPEG(byte[] jpegBytes) {
- Image jpegImage = null;
- try {
- jpegImage = Toolkit.getDefaultToolkit().createImage(jpegBytes);
- }
- catch (Exception e) {
- println("Fuckkkkk: " + e.toString() + ": " + e.getMessage());
- }
- float waitTime = 0;
- while (jpegImage.getHeight (null) == -1) {
- delay(2); //
- waitTime += 0.025;
- }
- return jpegImage;
- }
Thank you!
George
1