Ors
Custom User Title
I think I need a thread for my projects in case I'll do them as much as I've planned to do. (Extremely unlikely) I was a little bored and wanted to do some stuff with Lua.
I recently tried some graphical things with OpenGL, and I thought why not drawing triangles and stuff in Lua as well. I haven't also seen easy RGB colors in SRB2's Lua before. Here are two things I'd like to show in action: A function that draws triangles, and a function that converts RGB-values to SRB2's Palette.
This is what the drawing function looks like:
And here's the result:
I recently tried some graphical things with OpenGL, and I thought why not drawing triangles and stuff in Lua as well. I haven't also seen easy RGB colors in SRB2's Lua before. Here are two things I'd like to show in action: A function that draws triangles, and a function that converts RGB-values to SRB2's Palette.
This is what the drawing function looks like:
Code:
//The main Drawing function
local function DrawScene(v, p)
// Setting up points for a triangle
local p1 = vec2(100 + cos(20000000*leveltime)*100/FRACUNIT, 0)
local p2 = vec2(160, 50+sin(15000000*leveltime)*50/FRACUNIT)
local p3 = vec2(50+sin(10000000*leveltime)*50/FRACUNIT, 160)
// RGB color for the triangle
local r = sin(20000000*leveltime)
local g = sin(-20000000*leveltime)
local b = sin(20000000*leveltime)
// Draw the triangle (point1, point2, point3, color, drawer)
DrawTriangle2D(p1, p2, p3, ColorToPalette(vec3(r, g, b)), v)
// Draw the gradient color thing pixel by pixel
// Demonstrating the function that converts RGB values to palette colors
for i = 0, 31
for j = 0, 31
r = i*FRACUNIT/32
g = j*FRACUNIT/32
b = FixedMul(r,g)
v.drawFill(100+i, 50+j, 1, 1, ColorToPalette(vec3(r, g, b)))
end
end
end
And here's the result:
Last edited: