Skip to content

Instantly share code, notes, and snippets.

View dmoa's full-sized avatar

Stan Osipenko dmoa

View GitHub Profile
@dmoa
dmoa / class.lua
Created October 2, 2019 16:35
Lua Module for Classes
function class(def)
local class = {}
local parents = {}
local upv
local env = _G
local wraps
local function super(parent_class)
if not parent_class then
local self = {}
self.image = love.graphics.newImage("assets/imgs/ice.png")
self.reflectionImage = love.graphics.newImage("assets/imgs/iceReflection.png")
self.angle = 0
self.canvas = love.graphics.newCanvas()
local Player = {
image = love.graphics.newImage("assets/imgs/ice.png"),
reflectionImage = love.graphics.newImage("assets/imgs/iceReflection.png"),
angle = 0,
canvas = love.graphics.newCanvas(),
x = 75,
xv = 0,
function love.draw()
local canvas, x, y, width, height, rotation, scaleX, scaleY, offsetX, offsetY = Scene:getRender()
love.graphics.setShader(crtShader)
love.graphics.draw(canvas, x, y, width, height, rotation, scaleX, scaleY, offsetX, offsetY)
end
scene.getRender = function (self, drawArg)
love.graphics.setColor(1,1,1)
love.graphics.setCanvas({self.threeCanvas, depth=true})
love.graphics.clear(0,0,0,0)
crtShader = lg.newShader([[
extern float elapsed;
extern float colorI;
vec2 radialDistortion(vec2 coord, float dist) {
vec2 cc = coord - 0.5;
dist = dot(cc, cc) * dist + cos(elapsed * .3) * .01;
return (coord + cc * (1.0 + dist) * dist);
}
def lerp(a, b, t)
return a + (b - a) * t
end
@dmoa
dmoa / shader.frag
Created March 29, 2020 20:31
Attempt at lighting shader
#define M_PI 3.1415926535897932384626433832795
#define NUM_LIGHTS 32
struct Light {
vec2 position;
// color of the light
vec3 diffuse;
// power of the light
float power;
};
@dmoa
dmoa / sketch.js
Last active June 17, 2021 15:26
Polygon + Point Collision Detection
let polygon = [
[200, 100], [400, 130], [350, 300], [250, 300]
];
function setup() {
createCanvas(800, 800);
}
function draw() {
background(0);
@dmoa
dmoa / main.cpp
Created September 10, 2021 22:46
OpenGL Holy Grail
// This example loads an image and a shader that are used to draw the image.
#include <math.h>
#include <GL/glew.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_opengl.h>
#define print SDL_Log
@dmoa
dmoa / SDL_Setup.txt
Last active January 12, 2022 00:15
Setup SDL project without Visual Studio or CMake (Windows)
1. Download Compiler
2. Add Compiler to Path
3. Download SDL
4. Use SDL
$. Extras
1. Download compiler: