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

Graphics Library

Started by KillaVanilla, 22 November 2012 - 02:27 PM
KillaVanilla #1
Posted 22 November 2012 - 03:27 PM
Hello all.

This API provides developers with functions to draw things on the screen.

Functions:
  • drawPoint(x,y,color) - Sets one pixel/character on the screen
  • drawLine(start, end, color) - Draws a line from the first pair of coordinates to the second pair of coordinates
  • drawRect(corner1, corner2, color, fill) - Draws a rectangle. Can be filled if needed.
  • drawCircle(midpoint, radius, color) - Draws a circle.
  • floodFill(startPoint, color) - Fills an area with a color.
  • writeText(text, start, color) - writes text starting from (start[1], start[2])
  • update() - Draws the contents of the internal buffer to screen.
  • resetSurface() - Resets the internal buffer.
  • resetScreen() - Clears the screen and changes the colors back to default.
Usage Notes:
  • Points are taken as tables. Example:
    
    myPoint = {5,9}
    
  • The color argument can actually be two things: a number (such as colors.red), or a table.
  • When a color argument is a number, it is assumed to be a constant from the colors API.
  • However, if it is a table, then it assumes that you're trying to write text to the screen.
  • When passing tables to the drawing functions, please ensure that the tables are in this format:
    
    {textColor, character}
    
  • You need to call update after drawing everything to screen, or else you won't see anything happen.
  • resetScreen is defined as such:
    
    function resetScreen()
    	term.setTextColor(colors.white)
    	term.setBackgroundColor(colors.black)
    	term.clear()
    	term.setCursorPos(1,1)
    end
    
  • Surfaces are meant to be used internally;
    drawPoint(1,1,colors.red)
    is equivalent to
    drawSurfaces[1][1][1] = colors.red
    , and
    drawPoint(1,1,{colors.red, "-"})
    is equivalent to
    drawSurfaces[2][1][1] = {colors.red, "-"}
    .
Downloads:
Graphics API on Pastebin

Graphics API Demo on Pastebin

or, alternatively:

For the API itself:

pastebin get vanFtbrA GraphicsAPI

and for the demo:

pastebin get b6KNBv7D demo
tommyroyall #2
Posted 26 November 2012 - 04:45 AM
Any documentation on it, such as for use of the surface, or packXY()?
KillaVanilla #3
Posted 28 November 2012 - 12:58 PM
Any documentation on it, such as for use of the surface, or packXY()?

I thought that I included docu— whoops

I'm going to write documentation now.
Also, the surface is meant to be used internally.
tommyroyall #4
Posted 29 November 2012 - 10:39 AM
Ok :)/>. In total, amazing man :D/>. Thanks.
KillaVanilla #5
Posted 29 November 2012 - 12:13 PM
I was going to write documentation, but then I realized that I had written documentation.
DrCeph #6
Posted 01 January 2013 - 09:15 PM
Hey mate,

If I try to send your demo to my external advanced monitor (4x wide, 3x high) using [monitor left demo], I get the following error on the monitor:
GraphicsAPI:12: index expected, got nil

if I just run the demo on the advanced computer itself, it all works correctly. Do you have any thoughts as to what the problem would be?

Cheers.