Skip to content

Instantly share code, notes, and snippets.

View kashimAstro's full-sized avatar
🔒
busy

Dario Longobardi kashimAstro

🔒
busy
View GitHub Profile
@kashimAstro
kashimAstro / kalman_filter.h
Created March 1, 2016 20:46
kalman filter IMU / MPU6050
//https://en.wikipedia.org/wiki/Kalman_filter#Example_application.2C_technical
class Kalman {
public:
Kalman() {
Q_angle = 0.001;
Q_bias = 0.003;
R_measure = 0.03;
angle = 0;
bias = 0;
@kashimAstro
kashimAstro / NoiseDithering.glsl
Last active March 4, 2016 19:39
Generated Noise pattern for dithering
vec2 rand(vec2 coord, vec2 uv, float noiseamount, bool noise) {
float noiseX = ((fract(1.0-coord.s*(uv.x/2.0))*0.25)+(fract(coord.t*(uv.y/2.0))*0.75))*2.0-1.0;
float noiseY = ((fract(1.0-coord.s*(uv.x/2.0))*0.75)+(fract(coord.t*(uv.y/2.0))*0.25))*2.0-1.0;
if (noise) {
noiseX = clamp(fract(sin(dot(coord ,vec2(12.9898,78.233))) * 43758.5453),0.0,1.0)*2.0-1.0;
noiseY = clamp(fract(sin(dot(coord ,vec2(12.9898,78.233)*2.0)) * 43758.5453),0.0,1.0)*2.0-1.0;
}
return vec2(noiseX,noiseY)*noiseamount;
}
@kashimAstro
kashimAstro / i2cUDPMPU6050.py
Last active February 20, 2016 11:36
i2c UDP Demon Read MPU6050 data and write socket [ USAGE: python i2cUDPMPU6050.py '127.0.0.1' 5005 1 'N' ]
#!/usr/bin/python
import smbus
import math
import socket
import sys
import time
if len(sys.argv) < 4:
sys.exit('Usage: %s IPADDRESS PORT ID_BUS_I2C' % sys.argv[0])
@kashimAstro
kashimAstro / i2cRaspberryGPIO.h
Last active June 2, 2022 12:06
i2c Multiple Byte read and write c++
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/i2c-dev.h>
class i2cReadWrite {
public:
int file_i2c;
unsigned char buffer[60];
int length=2;
@kashimAstro
kashimAstro / pseudocode
Created February 19, 2016 15:42
pseudocode floyd steinberg
per ogni y dall'alto in basso
per ogni x da sinistra a destra
vecchio_pixel := pixel[x][y]
nuovo_pixel := trova_il_colore_della_tavolozza_più_vicino(vecchio_pixel)
pixel[x][y] := nuovo_pixel
quant_errore := vecchio_pixel - nuovo_pixel
pixel[x+1][y] := pixel[x+1][y] + 7/16 * quant_errore
pixel[x-1][y+1] := pixel[x-1][y+1] + 3/16 * quant_errore
pixel[x][y+1] := pixel[x][y+1] + 5/16 * quant_errore
pixel[x+1][y+1] := pixel[x+1][y+1] + 1/16 * quant_errore
@kashimAstro
kashimAstro / floydSteinberg.h
Created February 19, 2016 15:33
C++ Floyd-Steinberg 24bit RGB color
unsigned char * floydSteinberg(unsigned char * source, int w, int h){
unsigned char * newSource;
for(int i=0; i<(h*3); i++){
for(int j=0; j<w; j++) {
int ci = i*w+j;
int cc = source[ci];
int rc = (cc<128?0:255);
int err = cc-rc;
source[ci] = rc;
if(j+1<w) source[ci+1] += (err*7)>>4;