Jump to content




[CC 1.76] Pixel Canvas API


8 replies to this topic

#1 oli414

  • Members
  • 29 posts
  • LocationThe Netherlands

Posted 12 December 2015 - 10:51 PM

Hey folks, as you may know from my previous post I really enjoy the new characters, especially the pixel characters.

To make it easier to use these characters in an effective way I've created this simple to use API:
http://pastebin.com/TFFJwxvp

It contains two classes, the character class and the canvas class.
Character Class (Please note that this class isn't really ment to be used outside of the API):
textColor :: color :: The foreground color
backgroundColor :: color :: The background color
pixelMode :: bool :: true if the character is made out of seperate pixels
pixel :: bool[2][3] :: a two dimensionay array, each element represents a pixel. A character consist out of 2 by 3 pixels
character :: char :: the actual character
invert :: bool :: wether or not the text- and backgroundcolor are switched around (required for some pixel combinations)

create() :: returns a new character object
update() :: sets the "character" and "invert" member based on the values in the "pixel" member array
draw() :: writes the character (or pixels) with the right text and background color

Canvas Class:
x :: number :: x position of the canvas on the terminal
y :: number :: y position of the canvas on the terminal
character :: Character[<canvasWidth>][<canvasHeight>] :: an two-dimensional array containing all the characters

create() :: returns a new canvas object.
setSize() :: set the size of the canvas. Clears all the characters.
setPixel(number x, number y, bool value) :: set a pixel within the canvas. Please note that these positions are in pixels and not in character row/columns. For example, to set the right most pixel the X would have to be twice the canvas width. The lowest pixel would be three times the canvas height (each pixel consist out of 2x3 pixels).
setCharacter(number x, number y, char char) :: set a character on the canvas.
draw() :: draws the canvas to the screen.

Example:
local canvas = Canvas.create()
for i=1,20 do
  canvas:setPixel(i, i, true)
  canvas:setPixel(28 - i, i + 4, true)
  canvas:setPixel(26 - i, i + 2, true)
  canvas:setPixel(8, i + 8, true)
  canvas:setPixel(i + 8, 28, true)
end
canvas:draw()
term.setCursorPos(1, 18)
which would draw:
Posted Image


And that's it, hope you like it :-)

-Oli414

Edited by oli414, 12 December 2015 - 11:08 PM.


#2 Quartz101

  • Members
  • 141 posts
  • Location/dev/nvme0n1

Posted 12 December 2015 - 11:37 PM

I just noticed... with these pixels... HIGHER RES?!?!!?!?!?!!?!?!?

#3 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 12 December 2015 - 11:54 PM

Yes, about six times. There's a catch, though: You can only use two colours within every 2x3 pixel block! Even so, that's a big step up. :)

#4 Creator

    Mad Dash Victor

  • Members
  • 2,168 posts
  • LocationYou will never find me, muhahahahahaha

Posted 12 December 2015 - 11:58 PM

How?

#5 oli414

  • Members
  • 29 posts
  • LocationThe Netherlands

Posted 13 December 2015 - 12:25 AM

^ Which reminds me of the MCI graphic mode on the Commodore 64 where only 4 colors could be used per 8*8 cell (As seen in this great video)

It adds a whole lot of new possiblities. Especially for the OS makers.
However, it will require some great API to make it easy to use (which this isn't). Can't wait to see what people will come up with.

#6 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 13 December 2015 - 01:17 AM

You've got a good start here, yourself. How about some vector-plotting functions? :)

View PostCreator, on 12 December 2015 - 11:58 PM, said:

How?

If you divide a character up into six squares - in a 2x3 shape - and say each square can either be "on" or "off", you get 2^6 = 64 possibilities.

Characters 128 - 159 of CC 1.76's new character set represent exactly half of these. Inverting your text/background colours gives you the other half. You can hence use these characters to plot out images using effectively six times the resolution previously possible - for example, a 51x19 display becomes 102x57. Oh, and these new "pixels" are actually square, too.

However, since every group of six "pixels" is actually just a regular character, colour depth is the price you pay for the extra display resolution: you can't use six colours per character (one per pixel), you can only use two.

#7 oli414

  • Members
  • 29 posts
  • LocationThe Netherlands

Posted 13 December 2015 - 10:57 AM

So I was thinking about the color limitations last night, and I came up with a solution where it's possible to have as many colors as you want with a smaller resolution than the original character size. If you make the pixels 2x2 each character would hold 1 and a half pixel. Meaning there are only two colors ever needed per character.

If I have the time I'd like to spend some on a graphics render API with several overlay-modes taking care of the limited color problem.

Can't wait to see what others come up with with these new characters. The possibilities are endless.

#8 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 13 December 2015 - 11:06 AM

View Postoli414, on 13 December 2015 - 10:57 AM, said:

So I was thinking about the color limitations last night, and I came up with a solution where it's possible to have as many colors as you want with a smaller resolution than the original character size. If you make the pixels 2x2 each character would hold 1 and a half pixel. Meaning there are only two colors ever needed per character.

That's pretty clever - no increase in screen width, but a 50% increase in height, with no loss of colour depth. A 51x19 screen becomes something like 51x28.5.

One thing I noticed is that the colour bleed along the left of the CC display is especially annoying when these characters are used.

#9 oli414

  • Members
  • 29 posts
  • LocationThe Netherlands

Posted 13 December 2015 - 11:11 AM

View PostBomb Bloke, on 13 December 2015 - 11:06 AM, said:

One thing I noticed is that the colour bleed along the left of the CC display is especially annoying when these characters are used.

Yeah it is, took me a while to realise it was even there, at first I thought the characters contained 9 pixels because of that.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users