Hi There,
Earlier I made a Quine in Processing, that is code that prints it’s source code without any input.
It works, it prints to the canvas what I can see in the text editor.
I am wondering if anyone can see any further optimizations that I could be making?
My java/processing knowledge isn’t exactly vast so I’m keen for any input!
I’ve based my Processing sketch on this java example: Github Java Quine Example
My Code is as below:
//Quine
//Thomas Day 19/7/21
//Processing 3.5.4
import processing.svg.*;
PFont font;
char R = 82; char o = 111; char m = 109; char a = 97; char n = 110; char S = 83;
char dot = 46; char s = 115; char v = 118; char g = 103;
void setup() {
size(891, 1260);
noLoop();
String RomanS = new StringBuilder().append(R).append(o).append(m).append(a).append(n).append(S).toString();
font = createFont(RomanS, 12);
}
void draw() {
String file = new StringBuilder().append(S).append(dot).append(s).append(v).append(g).toString();
beginRecord(SVG, file);
char quote = 34;
String[] string = {
"//Quine",
"//Thomas Day 19/7/21",
"//Processing 3.5.4",
"",
"import processing.svg.*;",
"PFont font;",
"",
"char R = 82; char o = 111; char m = 109; char a = 97; char n = 110; char S = 83;",
"char dot = 46; char s = 115; char v = 118; char g = 103;",
"",
"void setup() {",
" size(594, 840);",
" noLoop();",
"String RomanS = new StringBuilder().append(R).append(o).append(m).append(a).append(n).append(S).toString();",
" font = createFont(RomanS, 12);",
"}",
"",
"void draw() {",
" String file = new StringBuilder().append(S).append(dot).append(s).append(v).append(g).toString();",
" beginRecord(SVG, file);",
" char quote = 34;",
" String[] string = {",
" };",
"",
"fill(0);",
" for (int i=0; i<22; i++)",
" text(string[i], 50, i*font.getSize() + font.getSize() + i*2);",
" for (int i=0; i<string.length; i++)",
" text(quote + string[i] + quote + ',', 50, 22*font.getSize() + i*font.getSize() + font.getSize() + 22*2 + i*2);",
" for (int i=22; i<string.length; i++)",
" text(string[i], 50, string.length*font.getSize() + i*font.getSize() + font.getSize() + string.length*2 + i*2);",
" endRecord();",
"}",
};
fill(0);
for (int i=0; i<22; i++)
text(string[i], 50, i*font.getSize() + font.getSize() + i*2);
for (int i=0; i<string.length; i++)
text(quote + string[i] + quote + ',', 50+font.getSize(), 22*font.getSize() + i*font.getSize() + font.getSize() + 22*2 + i*2);
for (int i=22; i<string.length; i++)
text(string[i], 50, string.length*font.getSize() + i*font.getSize() + font.getSize() + string.length*2 + i*2);
endRecord();
}