applet starting only once
in
Integration and Hardware
•
1 year ago
From a 3d sketch I can produce an applet without problems and when i call the index.html the browser displays it properly.
The problem is that if i call it a second time it results in a black screen.
I have tested it on various computers and with different browsers.
Then, if i close the browser and again call index.html, it works fine but again also only once.
Is this a known problem?
I'm using version 2.06a on WinXP with a Geforce GT9600.
Here is a sample sketch:
// 3D Array of objects
import peasy.*;
PeasyCam cam;
GridObject[][][] cellModel;
// Number of columns and rows in the grid
int cols = 4;
int rows = 4;
int staples = 4;
float rotAngle = 0.0;
float angleChange = 0.08;
float angleLimit = 64.0;
float percOpaque = 0.64;
int delta = 0;
long[][][] xyzPos;
void setup() {
size(680, 400, P3D);
//hint(DISABLE_DEPTH_SORT);
//translate(cols/2*100, rows/2*100, staples/2*100);
//translate(-cols*100, -rows*100, -staples*100);
cam = new PeasyCam(this, 640);
cam.setMinimumDistance(64);
cam.setMaximumDistance(1024);
xyzPos = new long[cols][rows][staples];
cellModel = new GridObject[cols][rows][staples];
for (int i = 0; i < cols; i++) {
for (int j = 0; j < rows; j++) {
for (int k = 0; k < rows; k++) {
if(random(1)<percOpaque) {
// Initialize each object
//cellModel[i][j][k] = new Grid(i*100+50, j*100+50, k*100+50);
cellModel[i][j][k] = new GridObject(i*100-(cols-1)*50, j*100-(rows-1)*50, k*100-(staples-1)*50);
xyzPos[i][j][k] = 1;
} else {
cellModel[i][j][k] = new GridObject(i*100-(cols-1)*50, j*100-(rows-1)*50, k*100-(staples-1)*50);
}
}
}
}
}
void draw() {
background(0);
// rect(0, 0, width, height);
// rect(-width/2, -height/2, width, height);
//set up different colored lights
pointLight(51, 102, 255, 500, 500, 640);
pointLight(200, 40, 60, -500, -500, -800);
pointLight(255, 255, 255, -500, 500, -100);
pointLight(255, 255, 255, 500, -500, -100);
//raise overall light in the scene
ambientLight(127, 127, 127);
if(rotAngle < angleLimit){
rotAngle += angleChange;
rotateX(radians(rotAngle*2));
rotateY(radians(rotAngle*8));
rotateZ(radians(rotAngle*4));
angleChange = angleChange*cos(radians(delta/8));
delta = delta + 1;
// angleChange = angleChange*0.9905;
}else {
rotateX(radians(angleLimit));
rotateY(radians(angleLimit));
}
//translate(-cols/2*100, -rows/2*100, -staples/2*100);
// rotateX(radians(64));
// rotateZ(radians(32));
// The counter variables i and j are also the column and row numbers and
// are used as arguments to the constructor for each object in the grid.
for (int i = 0; i < cols; i++) {
for (int j = 0; j < rows; j++) {
for (int k = 0; k < rows; k++) {
if (xyzPos[i][j][k] == 1) {
// Oscillate and display each object
cellModel[i][j][k].run();
} else {
cellModel[i][j][k].display_fillcubes();
// fill(255, 0, 0);
// box(64);
//println(cellModel[i][j][k]);
// grid[i][j].oscillate();
// grid[i][j].display();
}
}
}
}
}
with:
// A Grid object
class GridObject {
// A cell object knows about its location in the grid as well as its size with the variables x,y,w,h.
float x, y, z; // x,y location
float w, h; // width and height
float angle; // angle for oscillating brightness
float z_box;
int colorshift = (int)random(-32, 32);
int sizeshift = (int)random(-16, 32);
int translationshift = (int)random(-16, 16);
// Grid Constructor
GridObject(float tempX, float tempY, float tempZ) {
x = tempX;
y = tempY;
z = tempZ;
// angle = tempAngle;
// z_box = tempZ_box;
}
void run() {
// oscillate();
display();
}
// Oscillation means increase angle
/* void oscillate() {
angle += 0.032;
delta_z += 0.00032;
}*/
void display() {
noStroke();
// stroke(255);
pushMatrix();
// translate(x, y, z);
translate(x+translationshift, y+translationshift, z+translationshift);
// Color calculated using sine wave
// fill(216+127*sin(angle), 216+127*sin(angle), 8+127*sin(angle));
fill(32+colorshift, 32+colorshift, 122+colorshift);
// box(64+sizeshift, 64+sizeshift, 64+sizeshift);
box(64);
// box(20, 20, 16+8*cos((10-z_box)-delta_z));
popMatrix();
}
void display_fillcubes() {
noStroke();
// stroke(255);
pushMatrix();
translate(x, y, z);
// translate(x+translationshift, y+translationshift, z+translationshift);
fill(191, 64, 0, 127);
box(64+sizeshift, 64+sizeshift, 64+sizeshift);
// box(64);
popMatrix();
}
}
The problem is that if i call it a second time it results in a black screen.
I have tested it on various computers and with different browsers.
Then, if i close the browser and again call index.html, it works fine but again also only once.
Is this a known problem?
I'm using version 2.06a on WinXP with a Geforce GT9600.
Here is a sample sketch:
// 3D Array of objects
import peasy.*;
PeasyCam cam;
GridObject[][][] cellModel;
// Number of columns and rows in the grid
int cols = 4;
int rows = 4;
int staples = 4;
float rotAngle = 0.0;
float angleChange = 0.08;
float angleLimit = 64.0;
float percOpaque = 0.64;
int delta = 0;
long[][][] xyzPos;
void setup() {
size(680, 400, P3D);
//hint(DISABLE_DEPTH_SORT);
//translate(cols/2*100, rows/2*100, staples/2*100);
//translate(-cols*100, -rows*100, -staples*100);
cam = new PeasyCam(this, 640);
cam.setMinimumDistance(64);
cam.setMaximumDistance(1024);
xyzPos = new long[cols][rows][staples];
cellModel = new GridObject[cols][rows][staples];
for (int i = 0; i < cols; i++) {
for (int j = 0; j < rows; j++) {
for (int k = 0; k < rows; k++) {
if(random(1)<percOpaque) {
// Initialize each object
//cellModel[i][j][k] = new Grid(i*100+50, j*100+50, k*100+50);
cellModel[i][j][k] = new GridObject(i*100-(cols-1)*50, j*100-(rows-1)*50, k*100-(staples-1)*50);
xyzPos[i][j][k] = 1;
} else {
cellModel[i][j][k] = new GridObject(i*100-(cols-1)*50, j*100-(rows-1)*50, k*100-(staples-1)*50);
}
}
}
}
}
void draw() {
background(0);
// rect(0, 0, width, height);
// rect(-width/2, -height/2, width, height);
//set up different colored lights
pointLight(51, 102, 255, 500, 500, 640);
pointLight(200, 40, 60, -500, -500, -800);
pointLight(255, 255, 255, -500, 500, -100);
pointLight(255, 255, 255, 500, -500, -100);
//raise overall light in the scene
ambientLight(127, 127, 127);
if(rotAngle < angleLimit){
rotAngle += angleChange;
rotateX(radians(rotAngle*2));
rotateY(radians(rotAngle*8));
rotateZ(radians(rotAngle*4));
angleChange = angleChange*cos(radians(delta/8));
delta = delta + 1;
// angleChange = angleChange*0.9905;
}else {
rotateX(radians(angleLimit));
rotateY(radians(angleLimit));
}
//translate(-cols/2*100, -rows/2*100, -staples/2*100);
// rotateX(radians(64));
// rotateZ(radians(32));
// The counter variables i and j are also the column and row numbers and
// are used as arguments to the constructor for each object in the grid.
for (int i = 0; i < cols; i++) {
for (int j = 0; j < rows; j++) {
for (int k = 0; k < rows; k++) {
if (xyzPos[i][j][k] == 1) {
// Oscillate and display each object
cellModel[i][j][k].run();
} else {
cellModel[i][j][k].display_fillcubes();
// fill(255, 0, 0);
// box(64);
//println(cellModel[i][j][k]);
// grid[i][j].oscillate();
// grid[i][j].display();
}
}
}
}
}
with:
// A Grid object
class GridObject {
// A cell object knows about its location in the grid as well as its size with the variables x,y,w,h.
float x, y, z; // x,y location
float w, h; // width and height
float angle; // angle for oscillating brightness
float z_box;
int colorshift = (int)random(-32, 32);
int sizeshift = (int)random(-16, 32);
int translationshift = (int)random(-16, 16);
// Grid Constructor
GridObject(float tempX, float tempY, float tempZ) {
x = tempX;
y = tempY;
z = tempZ;
// angle = tempAngle;
// z_box = tempZ_box;
}
void run() {
// oscillate();
display();
}
// Oscillation means increase angle
/* void oscillate() {
angle += 0.032;
delta_z += 0.00032;
}*/
void display() {
noStroke();
// stroke(255);
pushMatrix();
// translate(x, y, z);
translate(x+translationshift, y+translationshift, z+translationshift);
// Color calculated using sine wave
// fill(216+127*sin(angle), 216+127*sin(angle), 8+127*sin(angle));
fill(32+colorshift, 32+colorshift, 122+colorshift);
// box(64+sizeshift, 64+sizeshift, 64+sizeshift);
box(64);
// box(20, 20, 16+8*cos((10-z_box)-delta_z));
popMatrix();
}
void display_fillcubes() {
noStroke();
// stroke(255);
pushMatrix();
translate(x, y, z);
// translate(x+translationshift, y+translationshift, z+translationshift);
fill(191, 64, 0, 127);
box(64+sizeshift, 64+sizeshift, 64+sizeshift);
// box(64);
popMatrix();
}
}
1