Posted 26 April 2015 - 09:59 PM
The CCG API is a graphics API for 2D transformations and shapes
Features
How to use
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
Context functions
matrix(Mat2) is the matrix to be pushed
x(number) the x position of the vertex
y(number) the y position of the vertex
pos(Vec2) the position of the vertex
angle(number) the angle in the selcted angle mode to rotate
x(number) the x distance to translate
y(number) the y distance to translate
distance(Vec2) the distance to translate
x(number) the x factor to scale by
y(number) the y factor to scale by
factor(Vec2) the factor to scale by
matrix(Mat2) the matrix to multipy by
mode(boolean) defaults to DEGREES
color(number) defaults to BLACK
color(number) defaults to WHITE
char(string) defaults to space
color(number) defaults to BLACK
prog(number) the program to begin
Constants
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
To test that the install worked type
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
Spoiler
Getting StartedSpoiler
First 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 variableContext 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 stackmatrix(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 programx(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 programpos(Vec2) the position of the vertex
myContext:draw()
Draw the context to the screen
myContext:rotate(angle)
Rotate any subsequent verticesangle(number) the angle in the selcted angle mode to rotate
myContext:translate(x, y)
Translate any subsequent verticesx(number) the x distance to translate
y(number) the y distance to translate
myContext:translate(distance)
Translate any subsequent verticesdistance(Vec2) the distance to translate
myContext:scale(x, y)
Scale any subsequent verticesx(number) the x factor to scale by
y(number) the y factor to scale by
myContext:scale(factor)
Scale any subsequent verticesfactor(Vec2) the factor to scale by
myContext:applyMatrix(matrix)
Multiply any subsequent vertices by a matrixmatrix(Mat2) the matrix to multipy by
myContext:setAngleMode(mode)
Set the angle mode for rotationsmode(boolean) defaults to DEGREES
myContext:setBackground(color)
Set the background color for pixelscolor(number) defaults to BLACK
myContext:setForeground(color)
Set the text color for pixelscolor(number) defaults to WHITE
myContext:setChar(char)
Set the character for pixelschar(string) defaults to space
myContext:setClearColor(color)
Sets the color to clear tocolor(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 oneprog(number) the program to begin
myContext:finish()
Equivalent to myContext:begin(CCG.POINTS)
Constants
Spoiler
DEGREESThe 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
Spoiler
To install the API typepastebin run q82xTt4A
into the shellTo test that the install worked type
CCG/test
It should display a spinning multicolored rectangleEdited on 26 April 2015 - 08:20 PM