Created
October 6, 2021 07:16
-
-
Save sblendorio/3dc6444b6708997d73d173f904a59d52 to your computer and use it in GitHub Desktop.
Block PETSCII Graphics for BBS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package eu.sblendorio.bbs.demo; | |
import eu.sblendorio.bbs.core.AsciiThread; | |
import eu.sblendorio.bbs.core.Hidden; | |
import eu.sblendorio.bbs.core.PetsciiThread; | |
@Hidden // THIS CLASS IS ONLY FOR EXPERIMENTS | |
public class GardaconBlockExperiment extends AsciiThread { | |
int[][] matrix = { | |
{1,1,1,1,1,1,1,1,1}, | |
{1,0,1,0,1,0,0,0,1}, | |
{1,0,1,0,0,1,0,0,1}, | |
{1,0,1,0,0,0,1,0,1}, | |
{1,1,1,1,1,1,1,1,1} | |
}; | |
public static int roundUp(int num, int divisor) { | |
return (num + divisor - 1) / divisor; | |
} | |
@Override | |
public void doLoop() throws Exception { | |
cls(); | |
int[][] output = new int[roundUp(matrix.length, 2)][roundUp(matrix[0].length, 2)]; | |
for (int y=0; y<matrix.length; ++y) | |
for (int x=0; x<matrix[y].length; ++x) | |
if (matrix[y][x] != 0) plotMidres(output, x, y); | |
renderMidres(output); | |
readKey(); | |
} | |
void plotMidres(int[][] output, int x, int y) { | |
int[] pow = {1, 2, 4, 8}; | |
int macrox = x / 2; | |
int macroy = y / 2; | |
int microx = 1 - (x % 2); | |
int microy = 1 - (y % 2); | |
output[macroy][macrox] |= pow[microx + 2*microy]; | |
} | |
void renderMidres(int[][] output) { | |
int[] decode = { | |
32, 172, 187, 162, | |
188, 9161, 9191, 9190, | |
190, 191, 161, 188, | |
9162, 9187, 9172, 9032 | |
}; | |
boolean reverse = false; | |
for (int y=0; y<output.length; ++y) { | |
for (int x=0; x<output[y].length; ++x) { | |
int chr = decode[output[y][x]]; | |
if (chr >= 9000) { | |
if (!reverse) write(18); | |
reverse = true; | |
write(chr-9000); | |
} else { | |
if (reverse) write(146); | |
reverse = false; | |
write(chr); | |
} | |
} | |
println(); | |
reverse = false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment