started on svg visualization
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
proc visualize_lisp_machine() -> void {
|
||||
const int padding = 30;
|
||||
const int margin = 20;
|
||||
|
||||
FILE *f = fopen("visualization.svg", "w");
|
||||
defer {
|
||||
fclose(f);
|
||||
};
|
||||
|
||||
if (f == NULL) {
|
||||
create_generic_error("The file for writing the visualization"
|
||||
"could not be opened for writing");
|
||||
return;
|
||||
}
|
||||
|
||||
int max_x = 0,
|
||||
max_y = 0,
|
||||
write_x = 0,
|
||||
write_y = 0;
|
||||
|
||||
proc draw_text = [&](const char* text) {
|
||||
int text_width = 12 * strlen(text);
|
||||
int text_height = 12;
|
||||
|
||||
if (write_x + text_width > max_x) max_x = write_x + text_width;
|
||||
if (write_y > max_y) max_y = write_y;
|
||||
|
||||
fprintf(f,
|
||||
" <text x='%d' y='%d' font-size='20' "
|
||||
"font-family='monospace'>\n"
|
||||
" %s"
|
||||
"\n </text>\n", write_x, write_y, text);
|
||||
|
||||
write_x += text_width;
|
||||
};
|
||||
|
||||
proc draw_header = [&](){
|
||||
write_y = 12;
|
||||
// draw_text("ASD");
|
||||
// write_x += margin;
|
||||
draw_text("doeun");
|
||||
|
||||
};
|
||||
|
||||
fprintf(f,
|
||||
"<?xml version='1.0' encoding='UTF-8'?>\n"
|
||||
"<svg xmlns='http://www.w3.org/2000/svg'\n"
|
||||
" version='1.1' baseProfile='full'\n"
|
||||
" viewBox='%06d %06d %06d %06d'"
|
||||
">\n\n", -padding, -padding, 0, 0);
|
||||
|
||||
draw_header();
|
||||
|
||||
fprintf(f, "\n\n</svg>");
|
||||
|
||||
// fill in the correct viewBox
|
||||
rewind(f);
|
||||
|
||||
fprintf(f,
|
||||
"<?xml version='1.0' encoding='UTF-8'?>\n"
|
||||
"<svg xmlns='http://www.w3.org/2000/svg'\n"
|
||||
" version='1.1' baseProfile='full'\n"
|
||||
" viewBox='%06d %06d %06d %06d'", -padding, -padding, max_x + 2*padding, max_y + 2*padding);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user