^-^
fullscreen BufferedReader reader;
String line, c, str;
int count, w, pixelSize;
boolean read;
void setup(){
background(0);
reader = createReader("SelfPrintingSketch2.pde");
read = true;
pixelSize = 15;
str = "";
while(read){
try{
line = reader.readLine();
} catch (IOException e){
e.printStackTrace();
line = null;
}
if (line == null){
read = false;
} else {
for(int x = 0; x < line.length(); x++){
c = String.valueOf(line.charAt(x));
count++;
}
str = str + line;
}
}
w = nearestSquare(count);
size(w * pixelSize, w * pixelSize);
for(int i = 0; i < str.length(); i++){
fill(String.valueOf(str.charAt(i)).hashCode());
rect(pixelSize*(i % w), pixelSize*(i / w) , pixelSize, pixelSize);
}
}
int nearestSquare(int n){
int i = 2;
while(i*i < n){
i++;
}
return i;
}
First attempt at writing a sketch that prints itself out as an image. bit of a kludgy mess. have to copy the pde file into data folder before posting, which is annoying.
doesn't seem to work consistently either, sometimes it just won't display. and there was something funny going on with the size of the sketch on import. works fine when run locally within processing...