Problem with applet
in
Integration and Hardware
•
2 years ago
Hello!
I have some code in Processing, when I press "Play" everything works like it should, but when I try to export an applet or application it shows white screen and nothing more. Do you know how to solve such a problem?
Here is the code:
void setup() {
size(1200, 600, P2D);
frameRate(30);
background(255, 248, 236);
castle = loadImage("castle.gif");
//img = loadImage("cannon.png");
//image(img, 5, height - img.height);
rectMode(CORNER);
ellipseMode(CENTER);
PFont font;
font = loadFont("a.vlw");
textFont(font);
fill(0);
stroke(0);
line(185 + 70 * 5, 0, 185 + 70 * 5, 40);
image(castle, 560, height - 100);
rect(560, height - 5, 80, 5);
text(castleLife, 575, 500);
ellipse(0, height, 16, 16);
}
//PImage img;
PImage castle;
float castleLife = 15;
int lowT = 650;
int highT = 740;
int g = 0;
int d =0;
int force = 0;
float angle = 90.0;
int hits = 0;
void draw() {
fill(0);
stroke(0);
//image(img, 5, height - img.height);
float x = mouseX;
float y = height - mouseY;
angle = (y / (x + y)) * 90;
writeDegree(angle);
if (mousePressed) {
fill(0);
stroke(0);
rect(185, 0, force * 5, 40);
force += 1;
if (force >= 71) {
force = 0;
fill(255, 248, 236);
stroke(255, 248, 236);
rect(185, 0, 349, 40);
}
}
else
{
force = 0 ;
fill(255, 248, 236);
stroke(255, 248, 236);
rect(185, 0, 150, 40);
}
}
void writeDegree(float deg) {
fill(255, 248, 236);
stroke(255, 248, 236);
rect(0, 0, 185, 50);
fill(0);
String f = str(deg);
text(f, 0, 40);
}
boolean finished = false;
float degfrad(float deg) {
return deg / 180 * PI;
}
void mouseReleased() {
hits += 1;
float attackSpeed;
fill(255, 248, 236);
stroke(255, 248, 236);
rect(0, 0, width, height);
fill(0);
stroke(0);
line(185 + 70 * 5, 0, 185 + 70 * 5, 40);
image(castle, 560, height - 100);
rect(560, height - 5, 80, 5);
int xa = 30;
int ya = 100;
float f = force;
force = 0;
float a = angle;
int times = 0;
rect(120, 0, 150, 20);
float A = 1000.0;
float speed = f / 40;
float g = 0.981;
float t = 0.0;
float x = 0.0;
float y = 0.0;
float forceX = speed * cos(degfrad(a));
float forceY = speed * sin(degfrad(a));
colorMode(HSB);
float h;
int l;
boolean bye = false;
while (true) {
t+= 0.00001;
x += forceX;
y += forceY;
forceY -= (g * t);
h = forceY;
if (forceY < 0) {
h = -forceY;
}
l = int(255-180-((forceX + h) * 25));
if (l < 0) {
fill(0, 0, 0);
stroke(0, 0, 0);
}
else {
fill(l, 240, 127);
stroke(l, 240, 127);
}
ellipse(x, height - y, 4, 4);
if (2*forceY <= g * t) {
times = int(t * 100000);
break;
}
}
for (int d =0;d<=times;d += 1) {
t+= 0.00001;
x += forceX;
y += forceY;
forceY -= (g * t);
h = forceY;
if (forceY < 0) {
h = -forceY;
}
l = int(255-180-((forceX + h) * 25));
if (l < 0) {
fill(0, 0, 0);
stroke(0, 0, 0);
}
else {
fill(l, 240, 127);
stroke(l, 240, 127);
}
ellipse(x, height - y, 4, 4);
}
colorMode(RGB);
attackSpeed = h + forceX;
fill(0);
stroke(0);
forceX = 0;
if (int(x)>=lowT&&int(x)<=highT) {
text("COOL! - distance: " + x + ", force - "+ f/70*100 + " %, " + angle + " degrees, attack speed : " + attackSpeed, 20, 80);
fill(255, 248, 236);
stroke(255, 248, 236);
castleLife -= attackSpeed;
rect(560, 465, 80, 35);
fill(0);
stroke(0);
if (castleLife <= 0) {
PFont winFont = loadFont("b.vlw");
textFont(winFont);
text("Great! You passed the game by "+ hits + " hits!", 20, 200);
winFont = loadFont("a.vlw");
textFont(winFont);
text("(Press Esc to exit)", 550, 300);
}
}
else {
text("Try Again! - distance: " + x + ", force - "+ f/70*100 + " %, " + angle + " degrees, attack speed : " + attackSpeed, 0, 80);
}
text(castleLife, 575, 500);
}
Thank you in advance!
I have some code in Processing, when I press "Play" everything works like it should, but when I try to export an applet or application it shows white screen and nothing more. Do you know how to solve such a problem?
Here is the code:
void setup() {
size(1200, 600, P2D);
frameRate(30);
background(255, 248, 236);
castle = loadImage("castle.gif");
//img = loadImage("cannon.png");
//image(img, 5, height - img.height);
rectMode(CORNER);
ellipseMode(CENTER);
PFont font;
font = loadFont("a.vlw");
textFont(font);
fill(0);
stroke(0);
line(185 + 70 * 5, 0, 185 + 70 * 5, 40);
image(castle, 560, height - 100);
rect(560, height - 5, 80, 5);
text(castleLife, 575, 500);
ellipse(0, height, 16, 16);
}
//PImage img;
PImage castle;
float castleLife = 15;
int lowT = 650;
int highT = 740;
int g = 0;
int d =0;
int force = 0;
float angle = 90.0;
int hits = 0;
void draw() {
fill(0);
stroke(0);
//image(img, 5, height - img.height);
float x = mouseX;
float y = height - mouseY;
angle = (y / (x + y)) * 90;
writeDegree(angle);
if (mousePressed) {
fill(0);
stroke(0);
rect(185, 0, force * 5, 40);
force += 1;
if (force >= 71) {
force = 0;
fill(255, 248, 236);
stroke(255, 248, 236);
rect(185, 0, 349, 40);
}
}
else
{
force = 0 ;
fill(255, 248, 236);
stroke(255, 248, 236);
rect(185, 0, 150, 40);
}
}
void writeDegree(float deg) {
fill(255, 248, 236);
stroke(255, 248, 236);
rect(0, 0, 185, 50);
fill(0);
String f = str(deg);
text(f, 0, 40);
}
boolean finished = false;
float degfrad(float deg) {
return deg / 180 * PI;
}
void mouseReleased() {
hits += 1;
float attackSpeed;
fill(255, 248, 236);
stroke(255, 248, 236);
rect(0, 0, width, height);
fill(0);
stroke(0);
line(185 + 70 * 5, 0, 185 + 70 * 5, 40);
image(castle, 560, height - 100);
rect(560, height - 5, 80, 5);
int xa = 30;
int ya = 100;
float f = force;
force = 0;
float a = angle;
int times = 0;
rect(120, 0, 150, 20);
float A = 1000.0;
float speed = f / 40;
float g = 0.981;
float t = 0.0;
float x = 0.0;
float y = 0.0;
float forceX = speed * cos(degfrad(a));
float forceY = speed * sin(degfrad(a));
colorMode(HSB);
float h;
int l;
boolean bye = false;
while (true) {
t+= 0.00001;
x += forceX;
y += forceY;
forceY -= (g * t);
h = forceY;
if (forceY < 0) {
h = -forceY;
}
l = int(255-180-((forceX + h) * 25));
if (l < 0) {
fill(0, 0, 0);
stroke(0, 0, 0);
}
else {
fill(l, 240, 127);
stroke(l, 240, 127);
}
ellipse(x, height - y, 4, 4);
if (2*forceY <= g * t) {
times = int(t * 100000);
break;
}
}
for (int d =0;d<=times;d += 1) {
t+= 0.00001;
x += forceX;
y += forceY;
forceY -= (g * t);
h = forceY;
if (forceY < 0) {
h = -forceY;
}
l = int(255-180-((forceX + h) * 25));
if (l < 0) {
fill(0, 0, 0);
stroke(0, 0, 0);
}
else {
fill(l, 240, 127);
stroke(l, 240, 127);
}
ellipse(x, height - y, 4, 4);
}
colorMode(RGB);
attackSpeed = h + forceX;
fill(0);
stroke(0);
forceX = 0;
if (int(x)>=lowT&&int(x)<=highT) {
text("COOL! - distance: " + x + ", force - "+ f/70*100 + " %, " + angle + " degrees, attack speed : " + attackSpeed, 20, 80);
fill(255, 248, 236);
stroke(255, 248, 236);
castleLife -= attackSpeed;
rect(560, 465, 80, 35);
fill(0);
stroke(0);
if (castleLife <= 0) {
PFont winFont = loadFont("b.vlw");
textFont(winFont);
text("Great! You passed the game by "+ hits + " hits!", 20, 200);
winFont = loadFont("a.vlw");
textFont(winFont);
text("(Press Esc to exit)", 550, 300);
}
}
else {
text("Try Again! - distance: " + x + ", force - "+ f/70*100 + " %, " + angle + " degrees, attack speed : " + attackSpeed, 0, 80);
}
text(castleLife, 575, 500);
}
Thank you in advance!
1