Skip to content

Instantly share code, notes, and snippets.

View JustinSDK's full-sized avatar
👨‍👩‍👧
Working from home

Justin Lin JustinSDK

👨‍👩‍👧
Working from home
View GitHub Profile
@JustinSDK
JustinSDK / FoliageScroll.java
Last active June 23, 2022 07:26
FoliageScroll
// refactor from https://openprocessing.org/sketch/1491377
import java.util.*;
final int maxSpirals = 500;
final float angleMax = 4 * PI;
final float angleStep = 0.1;
final float minR = 8;
final float distScale = 1.5;
class PoissonSampling {
constructor(width, height, r, start, k = 30) {
this.r = r;
this.k = k;
this.w = r / sqrt(2);
let rows = floor(height / this.w);
let columns = floor(width / this.w);
this.grid = [];
@JustinSDK
JustinSDK / poisson-trees.js
Last active June 14, 2022 02:57
Poisson Trees
class PoissonSampling {
constructor(width, height, r, start, k = 30) {
this.r = r;
this.k = k;
this.w = r / sqrt(2);
let rows = floor(height / this.w);
let columns = floor(width / this.w);
@JustinSDK
JustinSDK / poisson-disc-sampling.js
Last active June 14, 2022 02:51
Poisson Disc Sampling
// Poisson Disc Sampling
// https://www.youtube.com/watch?v=flQgnCUxHlw
class PoissonSampling {
constructor(width, height, r, start, k = 30) {
this.r = r;
this.k = k;
this.w = r / sqrt(2);
let rows = floor(height / this.w);
@JustinSDK
JustinSDK / circle_packing.js
Last active September 8, 2022 03:11
circle packing
const n_start = 200;
let circles = [];
function setup() {
createCanvas(640, 480);
noFill();
strokeWeight(1.5);
stroke(5);
@JustinSDK
JustinSDK / differential_line_growth.js
Last active September 7, 2022 07:39
Differential line growth with p5.js
// Differential line growth with p5.js
// refactored from http://www.codeplastic.com/2017/07/22/differential-line-growth-with-processing/
const maxNodeNumbers = 400;
const nodesStart = 15;
const rayStart = 15;
let diffLine;
function setup() {
createCanvas(300, 300);
@JustinSDK
JustinSDK / Map.go
Last active April 22, 2022 07:52
Go 介面:Map 實現
package main
import "fmt"
type Indicable interface {
Len() int
Idx(i int) any
}
type AnySlice []any
@JustinSDK
JustinSDK / Map.go
Created March 24, 2022 03:09
Go 泛型:Map 實現
package main
import "fmt"
func Map[T any](arr []T, fn func(T) T) []T {
newArr := make([]T, len(arr))
for i := 0; i < len(arr); i++ {
newArr[i] = fn(arr[i])
}
return newArr
@JustinSDK
JustinSDK / AlgebraicType.java
Last active October 13, 2021 02:43
代數資料型態:子型態多型+模式比對
package cc.openhome;
import java.util.Arrays;
sealed interface List permits Nil, Cons {
default Integer head() { return null; }
default List tail() { return null; }
default Integer sum() {
return switch(this) {
@JustinSDK
JustinSDK / AlgebraicType.java
Last active October 13, 2021 02:43
代數資料型態:子型態多型
package ;
import java.util.Arrays;
sealed interface List permits Nil, Cons {
default Integer head() { return null; }
default List tail() { return null; }
Integer sum();
}