pdf generates black page
in
Core Library Questions
•
1 year ago
Hi,
I'm having a little difficulty creating a pdf. All I get is a white background.
One other thing, I've seen people upload code this this forum with lines numbered. How is that done?
Any help would be greatly appreciated.
Thanks,
I'm having a little difficulty creating a pdf. All I get is a white background.
One other thing, I've seen people upload code this this forum with lines numbered. How is that done?
Any help would be greatly appreciated.
Thanks,
- import processing.pdf.*; // Import PDF code
int cols = 5;
int rows = 10;
int xn0 = 1;
int yn0 = 1;
float y = 1, y1;
float h = 0.1;
float[][] myArray = new float[cols][rows]; // declares array
void setup() {
size(400, 400);
// size(400, 400, PDF, "Euler.pdf");
background(255);
fill(0);
populateArray();
readArray();
}
void draw() {
noLoop();
pushMatrix();
translate(width/2 + 52, height/2 + 55);
line(-100, 0, 100, 0);
line(0, 100, 0, -100);
scale(60);
strokeWeight(1/10);
line(-0.05, -1, 0.05, -1);
line(1, -0.05, 1, 0.05);
popMatrix();
text("(0,1)", width/2 + 22, height/2 - 5);
text("(1,0)", width/2 + 102, height/2 + 72
);
pushMatrix();
translate(width/2 + 52, height/2 + 55);
scale(60);
for (int j = 0; j < rows - 1; j++) {
stroke(0, 0, 255);
int i = 1;
line(myArray[i][j], -myArray[i+1][j], myArray[i][j+1], -myArray[i+1][j+1]);
ellipse(myArray[i][j], -myArray[i+1][j], 0.05, 0.05);
}
// Graph original function y(x)=(x^4 + 3)/4x
for (float x = 1.0; x < 2.5; x += 0.01) {
y = (pow(x, 4) + 3)/4*x;
stroke(255, 0, 0);
ellipse(x, -y, 0.01, 0.01);
// point(x, -y);
}
popMatrix();
}
void keyPressed() {
if (key == 'B' || key == 'b') {
beginRecord(PDF, "Euler.pdf");
}
else if (key == 'E' || key == 'e') {
endRecord();
exit();
}
}
void populateArray() {
for (int j = 0; j < rows; j++) {
for (int i = 0; i < cols; i++) {
if (j==0);
{
myArray[1][0] = xn0;
myArray[2][0] = yn0;
}
if (i==0) // first column
{
myArray[i][j] = j+1;
}
if ((i==1) && (j!=0)) // xn values, adds h to the previous xn value
{
myArray[i][j] = h + myArray[i][j-1];
}
if ((i==2) && (j!=0)) // yn values, previous yn value
{
myArray[i][j] = myArray[i+2][j-1];
}
if (i==3) // fn values, fn = (xn^3 - yn)/xn (this is the derivative dy/dx)
{
myArray[i][j] = (pow(myArray[i-2][j], 3) - myArray[i-1][j])/myArray[i-2][j];
}
if ((i==4)) // y_{n+1} values, yn+1 = yn + h*fn
{
myArray[i][j] = myArray[i-2][j] + h*myArray[i-1][j];
}
}
}
}
void readArray() { // reads the myArray and tabulates it
translate(-20, 20);
for (int i = 0; i < cols; i++) {
for (int j = 0; j < rows; j++) {
if (j==0);
{
text(myArray[i][j], ((i+1)*40), ((j+1)*20)+20);
}
}
}
stroke(0, 0, 0);
text("Euler method: dy/dx=(x^3-y)/x)", 40, -3);
text("n", 50, 15);
text("xn", 90, 15);
text("yn", 130, 15);
text("fn", 170, 15);
text("y_{n+1}", 200, 15);
line(40, 23, 247, 23);
line(80, 5, 80, (rows*20)+30);
}
1