Skip to content

Instantly share code, notes, and snippets.

View Eclmist's full-sized avatar

Samuel Huang Eclmist

View GitHub Profile
@Eclmist
Eclmist / BasicImageEffect.cs
Created November 17, 2018 11:59
Basic Image Effect Script
/*
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
@Eclmist
Eclmist / Procedural_Heart.js
Last active August 18, 2019 08:01
Generates a colorful heart in source academy
// Minified, token reduced:
function procedural_heart()
{
function f(u,v){const r=0.15/(math_pow(0.5-u,2)+math_pow(0.75-(v+math_sqrt(math_abs(u-0.5)+0.1)*0.5),2)+0.01);return color(square,r,r-v*r,u*r);}
function i(x,y,acc){return x>=150?acc:i(x+1,y,beside_frac(x/(x+1),acc,f(x/150,y/150)));}
function j(y,acc){return y>=150?acc:j(y+1,stack_frac(y/(y+1),acc,i(0,y,blank)));}
return j(0,blank);
}
// Full source code that actually have a chance of making sense
@Eclmist
Eclmist / source_rt.js
Last active September 4, 2019 16:31
Simple raytracing in Source Academy
// IMPORTANT: increase the code execution time limit up to 20000 milliseconds. This may take some time to render.
function raytracer() {
// Resolution
const res = parse_int(prompt("Choose resolution (recommended: 200)"), 10);
const sample = parse_int(prompt("Anti-aliasing (MSAA) number of samples (1 - 8)"), 10);
const roughness = parse_int(prompt("Surface roughness (0 - 100)"), 10) / 100;
const col = [0.5, 0.5, 0.6]; // r, g, b
const skycol = [0.5, 0.7, 1.0];