Skip to content

Instantly share code, notes, and snippets.

View runewake2's full-sized avatar

Sam Wronski runewake2

View GitHub Profile
public static int Compare<TCompare>(TCompare first, TCompare second) where TCompare : IComparable
{
return first.CompareTo(second);
}
@runewake2
runewake2 / FallingBox.cs
Created November 6, 2016 02:14
An excerpt from the World of Zero Physics Playground. A 2D controller to handle boxes accurately falling into precise holes.
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(Rigidbody2D))]
public class FallingBox : MonoBehaviour {
public float width = 1;
private new Rigidbody2D rigidbody;
private RaycastHit2D hit;
public Transform origin;
@runewake2
runewake2 / PhilosophersWithOrderAlteration
Created December 23, 2016 04:01
Solution to the Dining Philosophers problem - Solves the deadlock problem by alternating the order the philosophers select their chopsticks.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace DiningPhilosophers
{
class Program
@runewake2
runewake2 / DynamicProgrammingChangeProblem.cs
Created January 24, 2017 05:15
Solution to dynamic programming problem of creating optimal change with least number of coins. Solution includes greedy and dynamic problems as well as comparisons between them.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
// The change problem :D
namespace DynamicProgramming
{
using System;
namespace CSharp7PatternMatching
{
// Built for World of Zero: https://youtu.be/PQucU3VFiBA
class Program
{
static void Main(string[] args)
{
for (int i = 1; i < 100; ++i)
@runewake2
runewake2 / GenericObjectPool.cs
Created March 1, 2017 06:23
Unity 3D Generic Object Pool for pooling a set object.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// Creates a cached object pool for reduced memory thrashing.
// Developed as a part of World of Zero, an interactive programming YouTube channel: youtube.com/worldofzerodevelopment
public class GenericObjectPool : MonoBehaviour
{
public int count;
public GameObject prefab;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/*
* Construct a bridge as a tracked object moves across it.
* Created as a part of World of Zero
* See it in action here: https://youtu.be/GaQBLD7bGCM
*/
public class BridgeBuilder : MonoBehaviour
@runewake2
runewake2 / TriplanarTesselatedShader.shader
Created April 2, 2017 19:33
Initial pass at a triplanar tesselated shader as created in this video: https://youtu.be/KCKN44-dMOY
// Upgrade NOTE: replaced '_World2Object' with 'unity_WorldToObject'
Shader "Custom/TriPlanarTesselatedShader" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Glossiness ("Smoothness", Range(0,1)) = 0.5
_Metallic ("Metallic", Range(0,1)) = 0.0
_Displacement("Displacement", Range(0, 1.0)) = 0.3
_EdgeLength("Edge length", Range(2,50)) = 5
@runewake2
runewake2 / GrassPhysics.cs
Created July 6, 2017 22:46
Grass Physics.CS class from Simulating Grass Physics and Trampling in Compute Shaders video: https://youtu.be/gF1LZNOUb9w
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GrassPhysics : MonoBehaviour
{
[HideInInspector] public ComputeShader calculationEngine;
public Texture2D initialInput;
public Texture2D springynessMap;
@runewake2
runewake2 / FancyBoxShader.shader
Created July 13, 2017 05:28
Shader code from Transformation Matrices Shader video on World of Zero
// Shader developed for the Transformation Matrices Shader video on World of Zero.
// https://www.youtube.com/watch?v=VzhxginBhdc
// Developed for Boxes/Cubes but should work anywhere
Shader "Custom/FancyBoxShader" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Glossiness ("Smoothness", Range(0,1)) = 0.5
_Metallic ("Metallic", Range(0,1)) = 0.0
_OriginOffset ("Offset", Float) = 0.0