Hi
Trying to display PGraphics buffer as ascii characters.
The method is to render things to a PGraphics buffer, then iterate through the pixels manually and map them to ascii characters. It works fine when the PGraphics render is set to the default 2D one. However P3D (and P2D) make it very slow. I’m assuming it’s related to the GPU being involved.
Below code will run fine. If you change the ‘createGraphics’ line to use P3D it will be too slow. Is there any way around this?
Thanks!
int sw = 1000;
int sh = 800;
int bw = 70;
int bh = bw;
float r = 0;
PGraphics pg;
String chars = " ..o**OX@@";
float factor;
void setup() {
size(1000, 1000, P3D);
//pixelDensity(2);
//pg = createGraphics(bw, bh, P3D);
pg = createGraphics(bw, bh);
factor = sw/bw;
}
void draw() {
background(0);
drawText();
textSize(15);
//image(pg, sw/2, sh/2);
translate(0,0);
for (int i = 0; i < bh*2; i ++) {
for (int j = 0; j < bw*2; j++) {
float p = brightness(pg.get(j, i));
float q = p/255*9;
//String chars = "..oo**OO@@";
char l = chars.charAt(int(q));
//print(factor);
//text(i, j*factor, i*factor);
text(l, j*factor, i*factor);
}
}
}
void drawText() {
pg.beginDraw();
pg.background(65);
//pg.circle(0, 0, 10);
pg.textSize(30);
String time = "11:07";
time = hour() + ":" + minute();
float tw = pg.textWidth(time);
float th = pg.textAscent();
pg.translate(bw/2, bh/2);
//pg.rotateY(radians(r));
pg.rotate(radians(r));
pg.text(time, -tw/2, th/4);
r += 0.3;
pg.endDraw();
pg.filter(BLUR,1);
}