Trying to Visualize a BarCode Image
in
Programming Questions
•
1 year ago
Hi. I've got a .xtx file with a column of numbers ranging from 0-4. I'm trying to visualize this data like a barcode image, with each line stroke corresponding to the value in the .txt file. So, for example, a value of 0 would be blank, a value of 1 would be a thin line, a value of 2 a thicker line, etc. But the code doesn't work. I'm using code such as:
String lines[] = loadStrings("batcode.txt"); // to access the column of data in the file
for(int j=1; j<70; j++){ // to index through the 70 rows of data
data = int(split(lines[0], ',' )); // creating an integer variable called data for each row of data
strokeWeight(data[j]); // assigning the variable to each line's stroke
line (50+j*10,100,50+j*10,300); // and then drawing the lines vertically and spaced equally across the screen
When I run it I get a blank gray screen and an error message that says:
The file "batcode.txt" is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.
Exception in thread "Animation Thread" java.lang.NullPointerException
at Batcode.draw(Batcode.java:59)
at processing.core.PApplet.handleDraw(PApplet.java:1631)
at processing.core.PApplet.run(PApplet.java:1530)
at java.lang.Thread.run(Thread.java:680)
Here's the code in its entirety: Any idea what I'm doing wrong? Thanks!!!!!
int[] data;
void setup() {
size(1280,800);
PFont font;
font = loadFont("CenturyGothic-20.vlw");
textFont(font);
}
String lines[] = loadStrings("batcode.txt");
void draw() {
background (r240,235,235);
for(int j=1; j<70; j++){
//for(int j=0; j<data.length; j++){ // I thought perhaps I could use this instead of specifying 70 rows but wasn't sure and kept it out.
data = int(split(lines[0], ',' ));
stroke(0,0,0);
strokeWeight(data[j]);
line (50+j*10,100,50+j*10,300);
}
}
String lines[] = loadStrings("batcode.txt"); // to access the column of data in the file
for(int j=1; j<70; j++){ // to index through the 70 rows of data
data = int(split(lines[0], ',' )); // creating an integer variable called data for each row of data
strokeWeight(data[j]); // assigning the variable to each line's stroke
line (50+j*10,100,50+j*10,300); // and then drawing the lines vertically and spaced equally across the screen
When I run it I get a blank gray screen and an error message that says:
The file "batcode.txt" is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.
Exception in thread "Animation Thread" java.lang.NullPointerException
at Batcode.draw(Batcode.java:59)
at processing.core.PApplet.handleDraw(PApplet.java:1631)
at processing.core.PApplet.run(PApplet.java:1530)
at java.lang.Thread.run(Thread.java:680)
Here's the code in its entirety: Any idea what I'm doing wrong? Thanks!!!!!
int[] data;
void setup() {
size(1280,800);
PFont font;
font = loadFont("CenturyGothic-20.vlw");
textFont(font);
}
String lines[] = loadStrings("batcode.txt");
void draw() {
background (r240,235,235);
for(int j=1; j<70; j++){
//for(int j=0; j<data.length; j++){ // I thought perhaps I could use this instead of specifying 70 rows but wasn't sure and kept it out.
data = int(split(lines[0], ',' ));
stroke(0,0,0);
strokeWeight(data[j]);
line (50+j*10,100,50+j*10,300);
}
}
1