[Library] AsciiCanvas

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
Linkpy
Party member
Posts: 102
Joined: Fri Aug 29, 2014 6:05 pm
Location: France
Contact:

[Library] AsciiCanvas

Post by Linkpy »

Hellooooo.

WARNING : Don't use this current version for serious project ! This is currently not optimized !

So, what is it ? This library allow you to create canvas of text. Yes, of text. Each canvas are subdivided in "slot", which contain a character, an attribute, a foreground color and a background color. This library allow you to have console-like graphics for your game, but it allow you to have fine graphics too (images, lines, etc) !

All the source code are documented.

There is a little example :

Code: Select all

-- Include the library.
AC = require "AsciiCanvas"


function love.load ()

	love.graphics.setBackgroundColor (128, 128, 128)

	-- Create a new canvas.
	canvas = AC.AsciiCanvas:new (80, 24)
	
	-- Render it to a Love2D canvas.
	canvas:renderToCanvas ()
	
	-- Fill an area of the canvas.
	canvas:fill (5, 5, 25, 10, " ", {255, 0, 0}, {0, 200, 0})
	
	-- Add a character.
	canvas:put (5, 5, "+")
	canvas:put (30, 15, "+")
	
	-- Add a string.
	canvas:putString (11, 11, "Huehuehue ! :D")
	
	-- Render to the canvas.
	canvas:render ()
	
end


function love.draw ()

	-- Get the size in pixel of the canvas.
	local cw, ch = canvas:getSizeInPixel ()
	-- Center the canvas.
	local w, h = love.window.getDimensions ()
	local x, y = w/2 - cw/2, h/2 - ch/2

	-- Draw the canvas to the screen.
	love.graphics.draw (canvas:target(), x, y)

end
And, there is the result :
Image

Links : Some notes :
  • It's preferred to use the canvas render mode, because it's more optimized than the direct render mode. For explanation : In this mode, the renderer render all the canvas only when it's needed (when it's created or cleared), and after this first draw on the Love2D canvas, the canvas will only render change : if you change one slot, and then call the render function, the renderer will only render the modified slot, and not all the canvas again.
  • In canvas render mode, you shouldn't draw on the Love2D canvas. You can get some funny results :crazy:
  • You can use it freely, even for commercial game. But you need to credit my name and my library ( "This game use AsciiCanvas made by Linkpy" Place this somewhere. I know you can do it ! ).
Future changes :
  • Whole rewrite : using C structures for reduce memory usage.
  • Optimizing drawing : using SpriteBatch for minimizing love.graphics.draw calls.
Changelog :

Code: Select all

--  15/07/2015 :
--    Added the "AsciiImage" class. Allowing user to save and to load AsciiImage.
Last edited by Linkpy on Wed Jul 15, 2015 5:17 pm, edited 1 time in total.
Founder of NeoShadow Studio. Currently working on the project "Sirami".
github / linkpy
User avatar
Linkpy
Party member
Posts: 102
Joined: Fri Aug 29, 2014 6:05 pm
Location: France
Contact:

Re: [Library] AsciiCanvas

Post by Linkpy »

So. A little update. I added the github link, and other little things.
Founder of NeoShadow Studio. Currently working on the project "Sirami".
github / linkpy
multivoxmuse
Prole
Posts: 1
Joined: Sat May 04, 2024 3:36 pm

Re: [Library] AsciiCanvas

Post by multivoxmuse »

Do you still have the source code? I want to do the exact same kind of thing
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest