This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
sonic_overlord25's profile picture

Custom Characters on Screen

Started by sonic_overlord25, 19 November 2016 - 06:47 AM
sonic_overlord25 #1
Posted 19 November 2016 - 07:47 AM
Back when I was working on a science project of mine, I utilized an Arduino microcontroller and a 16x2 LCD display. The Arduino allowed me to program in my own custom characters to be displayed on the LCD. Here's how it worked:

Since the LCD is 16x2 characters, we have a total of 32 "squares" in which characters can be printed on. Each square has a ratio of pixels that it can display. I believe each square has a 5x7 ratio of pixels. Anyhow, I was actually able to program the Arduino to target specific pixels in each square with a binary sequence, in which a 1 equaled an ON pixel, and a 0 equaled an OFF pixel. By setting some pixels ON and others OFF, I was able to create my own custom characters. Since it appears CC uses a Consolas font scheme (look it up if you don't know what I'm referring to. Also, Notepad uses Consolas as its default font.), it should be relatively easy to implement. One pro to this implementation would be custom designs, and more creative GUIs.

I apologize if I butchered this idea I have, I'm not quite awake at the moment. Here are some links that show what I'm talking about.

Arduino Custom Characters
https://www.arduino....ystalCreateChar

Here is a pic of Emoji Characters on a 16x2 LCD
http://www.engineers...3%20%282%29.jpg

Anyhow, one could create a library of custom characters and we could recreate the ASCII character table. Feel free to comment your opinions. I'd love to hear what you all think about this.
Admicos #2
Posted 19 November 2016 - 09:18 AM
Since it appears CC uses a Consolas font scheme
I don't know exactly what you are referring to (Monospace fonts? Or the Consolas font itself?) but CC uses whatever font your texture pack will give it, and by default it's the minecraft font.


But other than that, you can kinda do it with this snippet.
Edited on 19 November 2016 - 08:21 AM
sonic_overlord25 #3
Posted 19 November 2016 - 08:57 PM
Monospace was what I was trying to say, it just wasn't coming to me when I was writing that earlier today. Consolas was the only thing I could think of.

I didn't even see that post you linked. Otherwise, I wouldn't have posted. Thanks for the code snippet.

Otherwise though, having a standard CC library for that would be kinda nice.
Bomb Bloke #4
Posted 20 November 2016 - 01:46 AM
As of CC 1.76, CC no longer uses the Minecraft font file, and instead uses its own. This can still be overridden by a resource pack (eg), but regular texture packs won't touch it.

sonic_overlord, the teletext drawing characters (128 - 159, introduced by the same update) are pretty much for the purpose of which you're thinking. They're not as dynamic as I'm sure you'd like, but they're significantly less taxing on server bandwidth. Probably the easiest way to get started with them is through BLittle.
HaddockDev #5
Posted 26 November 2016 - 02:47 AM
Well, from what I've heard CC renders pixel by pixel, so it shouldn't be hard to implement.
You could do this:
local happy = {
0,0,0,0,0,
1,0,0,1,0,
0,0,0,0,0,
1,0,0,1,0,
0,1,1,0,0,
0,0,0,0,0,
}
--use some sort of term function, like
term.writeCustomChar(happy)
Then, on client side for rendering (Java):
int[][] cChar = new int[5][6]{};
int yOffset;
for(int x = 0; x <= 6; x++){
  if(x >= 6){x=0;yOffset++;}
  //draw the pixel using a function like:
  drawPixel(cursorX,cursorY,x,yOffset,backgroundColor,textColor,1); //1 so it "turns on" the pixel
}
Which, could work and could make a revolution for GUI's, because you could overlap text and things.
Edited on 26 November 2016 - 01:47 AM
Anavrins #6
Posted 26 November 2016 - 03:30 AM
As Bomb-Bloke just said, characters are rendered from a font texture.

The main reason why we aren't doing this is due to network overhead.
Since you would have to send an additional 4 bytes of data per screen pixels.

Right now (I'm assuming) each pixels use two bytes, one for the 8bits ascii character and two nibbles for text and bg colors, which totals to (51*19)*2 = 1938 bytes being sent for drawing the screen.
With your method, we would need 4 bytes and two nibbles to define a pixel, which would add up to 4845 bytes.

Might be worth trying, but more bytes being sent usually means more lag, every bytes you can save counts on a large server.
Edited on 26 November 2016 - 08:32 AM
sonic_overlord25 #7
Posted 27 November 2016 - 08:07 PM
I definitely see what you guys are saying. I suppose though, with the stuff you all have shown me, it should be relatively easy to create a program that could go about this in a similar manner. Thank you also for showing me how to go about this also.

I do apologize it took me so long to write back, I couldn't remember my password.
Edited on 27 November 2016 - 07:08 PM