The CCG API is a graphics API for 2D transformations and shapes

Features
Spoiler
  • Stack API
  • 2D and 3D vector and matrix APIs
  • Quadrilaterals
  • Triangles
  • Points
  • Scaling
  • Rotating
  • Translating
  • Test program
  • Matrix stack
  • Choose between angle modes
  • Multiple graphics contexts

How to use
SpoilerGetting Started
SpoilerFirst you must start by loading the API

os.loadAPI("CCG/CCG")
Next create a context

myContext = CCG.createContext(originX, originY, xMin, yMin, xMax, yMax, mon)
originX and originY are the x and y coordinates on the monitor of the 0, 0 drawing coordinates.
xMin and yMin are the minimum drawing coordinates before clipping.
xMax and yMax are the maximum drawing coordinates before clipping.
mon is the monitor object.

For example

myContext = CCG.createContext(10, 10, -5, -5, 5, 5, term)
Would create an 11x11 context centered on 10, 10 on the main terminal and return it to the myContext variable

Context functions
Spoiler

myContext:loadIdentity()
Set the top matrix stack value to the identity matrix


myContext:pushMatrix()
Push the identity matrx to the top of the stack


myContext:pushMatrix(matrix)
Push a matrx to the top of the stack
matrix(Mat2) is the matrix to be pushed


myContext:popMatrix()
Pop a matrix from the matrix stack


myContext:vertex(x, y)
Add a vertex to the current vertex program
x(number) the x position of the vertex
y(number) the y position of the vertex


myContext:vertex(pos)
Add a vertex to the current vertex program
pos(Vec2) the position of the vertex


myContext:draw()
Draw the context to the screen


myContext:rotate(angle)
Rotate any subsequent vertices
angle(number) the angle in the selcted angle mode to rotate


myContext:translate(x, y)
Translate any subsequent vertices
x(number) the x distance to translate
y(number) the y distance to translate


myContext:translate(distance)
Translate any subsequent vertices
distance(Vec2) the distance to translate


myContext:scale(x, y)
Scale any subsequent vertices
x(number) the x factor to scale by
y(number) the y factor to scale by


myContext:scale(factor)
Scale any subsequent vertices
factor(Vec2) the factor to scale by


myContext:applyMatrix(matrix)
Multiply any subsequent vertices by a matrix
matrix(Mat2) the matrix to multipy by


myContext:setAngleMode(mode)
Set the angle mode for rotations
mode(boolean) defaults to DEGREES


myContext:setBackground(color)
Set the background color for pixels
color(number) defaults to BLACK


myContext:setForeground(color)
Set the text color for pixels
color(number) defaults to WHITE


myContext:setChar(char)
Set the character for pixels
char(string) defaults to space


myContext:setClearColor(color)
Sets the color to clear to
color(number) defaults to BLACK


myContext:pixelClear()
Clear the pixel table


myContext:matrixClear()
Clear the matrix stack


myContext:screenClear()
Clear the screen area to the clear color


myContext:begin(prog)
Finish the previous graphics program and begin a new one
prog(number) the program to begin


myContext:finish()
Equivalent to
myContext:begin(CCG.POINTS)

Constants
SpoilerDEGREES
The angle mode constant for degrees

RADIANS
The angle mode constant for radians

POINTS
This program directly turns vetices into pixels

TRIANGLES
This program creates triangle from every 3 vertices(additional vertices ignored)

QUADS
This program creates quadrilaterals from every 4 vertices(additional vertices ignored)

WHITE
ORANGE
MAGENTA
LIGHT_BLUE
YELLOW
LIME
PINK
GRAY
LIGHT_GRAY
CYAN
PURPLE
BLUE
BROWN
GREEN
RED
BLACK
The color constants(equivalent to the colors API)

Installation
SpoilerTo install the API type
pastebin run q82xTt4A
into the shell

To test that the install worked type
CCG/test
It should display a spinning multicolored rectangle