Skip to content

Instantly share code, notes, and snippets.

View ritobanrc's full-sized avatar

Ritoban Roy-Chowdhury ritobanrc

View GitHub Profile
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
<summary>
A two-way dictionary. Can get T1 given T2 or T2 given T1.
</summary>
public class BidirectionalDictionary<T1, T2> : Dictionary<T1, T2>
@ritobanrc
ritobanrc / Singleton.cs
Created March 13, 2018 01:20
A class that can be inherited from for singletons in Unity.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Utility
{
public abstract class Singleton<T> : MonoBehaviour where T : MonoBehaviour
{
public static T Instance
{
@ritobanrc
ritobanrc / Timer.cs
Last active March 13, 2018 01:23
A Timer class in Unity. Requires my Singleton class.
/* Timer.cs
(c) 2017 Ritoban Roy-Chowdhury. All rights reserved
*/
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Timer
@ritobanrc
ritobanrc / Util.cs
Created March 13, 2018 01:24
Several utility functions, for C# and Unity
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace Utility
{
static class Util
{
#include <stdio.h>
int main()
{
// printf() displays the string inside quotation
printf("Hello, World!");
return 0;
}
@ritobanrc
ritobanrc / kmeans.py
Created June 8, 2019 23:13
A simple program which applies KMeans to the pixels of an image, finding the most prominent colors.
#!/usr/bin/python3
import requests
from PIL import Image
from io import BytesIO
import matplotlib.pyplot as plt
import matplotlib.animation as anim
import matplotlib as mpl
import numpy as np
width = height = 800
@ritobanrc
ritobanrc / main.py
Created June 8, 2019 23:15
A failure of a fluid simulation. I'll get back to this, but it'll be in an actual repo.
from vispy import app, gloo, io
import numpy as np
from scipy.spatial.distance import pdist, squareform
REFLECT_MATRIX_X = np.array([[1, 0],
[0, -1]])
REFLECT_MATRIX_Y = np.array([[-1, 0],
[0, 1]])
IDEAL_GAS_CONST = 5 # J/Kmol
REST_DENSITY = 0.8 # Experimentally determined
@ritobanrc
ritobanrc / mandelbrot.glsl
Created June 8, 2019 23:29
Some cool shaders I wrote, along with the html files to render them in a WebGL canvas
#ifdef GL_ES
precision mediump float;
#endif
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
const float iterations = 100.0;
@ritobanrc
ritobanrc / Stack.py
Last active May 13, 2020 02:02
An L system parser and implementation in Turtle, also several rules to generate common fractals
class Stack:
def __init__(self):
self.items = []
def isEmpty(self):
return self.items == []
def push(self, item):
self.items.append(item)
@ritobanrc
ritobanrc / hidato.py
Created June 8, 2019 23:49
Hidato Puzzle Solver using DFS (see: https://en.wikipedia.org/wiki/Hidato)
# -*- coding: utf-8 -*-
"""
Created on Wed Jan 10 08:43:47 2018
@title: Hidato Puzzle Solver
@author: Ritoban
"""
import csv
import numpy as np