Last active
April 13, 2022 07:44
-
-
Save ogrew/d0b9f76a3e89f6b96df89aff55c2dc80 to your computer and use it in GitHub Desktop.
シェルピンスキーのギャスケット
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let W = 1200; | |
let H = 1200; | |
function setup() { | |
createCanvas(W, H); | |
background(255); | |
smooth(); | |
noLoop(); | |
noStroke(); | |
pixelDensity(12); | |
} | |
function draw() { | |
fill(0); | |
sierpinski_tri(W/2, 50, H, 12); | |
} | |
function sierpinski_tri(x, y, len, depth) { | |
var x1 = x + len*sin(PI/6); | |
var x2 = x - len*sin(PI/6); | |
var yy = y + len*cos(PI/6); | |
fill(0); | |
triangle(x, y, x1, yy, x2, yy); | |
depth -= 1; | |
if(depth > 0) { | |
fill(255); | |
triangle(x, y, x1, yy, x2, yy); | |
var ll = len / 2; | |
sierpinski_tri(x, y, ll, depth); | |
sierpinski_tri(x+ll*sin(PI/6), y+ll*cos(PI/6), ll, depth); | |
sierpinski_tri(x-ll*sin(PI/6), y+ll*cos(PI/6), ll, depth); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment