Skip to content

Instantly share code, notes, and snippets.

View native-m's full-sized avatar

Fiann Thur (Native-M) native-m

View GitHub Profile
@native-m
native-m / lazy_delete.h
Last active May 16, 2019 17:03
use this if you are lazy to delete multiple pointers
#ifndef LAZY_DELETE_H
#define LAZY_DELETE_H
template <class Delete>
void deleteAll(Delete del)
{
delete del;
}
template <class Delete, class... Deletes>
Declaration
____________
// variable
a: int; // <var-id>: <type-id>;
b: int = 15; // <var-id>: <type-id> = <expr>;
// constant variable (must be initialized first)
let ca: int = 15; // let <var-id>: <type-id> = <expr>;
@native-m
native-m / lexer.cpp
Created May 3, 2019 10:59
i made a f-ing lexical analyzer
#include <iostream>
#include <string>
#include <vector>
enum TokenType
{
TK_PLUS, // the token can be addition operator or negation operator
TK_MIN, // the token can be subtraction operator or negation operator
TK_ASTERISK, // the token can be multiplication operator or pointer dereferece
TK_SLASH,
@native-m
native-m / Buf0.glsl
Created February 19, 2019 06:11
another glitch
float rand(vec2 c)
{
return fract(sin(dot(c.xy ,vec2(12.9898,78.233))) * 43758.5453);
}
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
vec2 uv = fragCoord/iResolution.xy;
float t = floor(iTime * 60.0) / 60.0;
fragColor = vec4(rand(sin(uv) + t));
@native-m
native-m / FastMath.h
Last active September 10, 2018 06:58
Fast math functions approximation
// License under: WTFPL 1.0
// WARNING: I haven't checked the approximation error yet.
#ifndef __FASTMATH_H__
#define __FASTMATH_H__
#define _USE_MATH_DEFINES
#include <math.h>
inline double fast_fmod(double x, double y)
{
@native-m
native-m / sin.c
Created September 7, 2018 19:23
My sin function
double fast_sin(double x)
{
return x *
(x * x * (x * x *
(x * x * (x * x *
(x * x * (x * x *
1.6059043837e-10 - 2.5052108385e-8)
+ 0.0000027557319224) - 0.000198412698413)
+ 0.00833333333333) - 0.166666666667) + (double)1.0);
}
@native-m
native-m / glitch.glsl
Last active September 4, 2018 08:22
Glitch with block noise (fractal noise)
float rand(vec2 p)
{
float t = floor(iTime * 10.);
return fract(sin(dot(p, vec2(t * 12.9898, t * 78.233))) * 43758.5453);
}
float noise(vec2 uv, float blockiness)
{
vec2 lv = fract(uv);
vec2 id = floor(uv);
@native-m
native-m / loss.asm
Created July 29, 2018 15:13
Loss in x86 assembly
; I don't know why i made this
; nasm -f elf *.asm; ld -dynamic-linker /lib/ld-linux.so.2 -m elf_i386 -s -o fuckyou -lc *.o
extern printf
extern exit
section .data
str1 times 23 db 0
section .text
global _start
@native-m
native-m / fractalnoise.glsl
Last active July 20, 2018 00:28
🅱ractal 🅱ois 👌
float rand(vec2 p)
{
return fract(sin(dot(p, vec2(34.8313, 90.1394))) * 9813.91);
}
float noise(vec2 p)
{
vec2 f = fract(p);
vec2 i = floor(p);
@native-m
native-m / waterdisp.glsl
Last active July 19, 2018 09:36
Water Displacement (ShaderToy)
// Water displacement (MIT License)
// Native-M
float rand(vec2 p)
{
return fract(sin(dot(p, vec2(93.9898, 60.1414))) * 43758.5453);
}
float noise(vec2 uv, float blockiness)
{