山辺氏によるフラクタル描画

山辺氏によるフラクタル描画



fractal.js
Copied!
/* This visualization is inspired by Jared Tarbell's "Emotion Fractal" http://levitated.net/daily/levEmotionFractal.html */

var cell_min_size = 4;
var cell_scales = [1,4,8,16,24,32];
var cell_aspects = [1,2,3,4,5,6];
var corners = [0,1,2,3];
var challenge_limit = 100;
var cells = [];
var count = 0;

function setup() {
createCanvas(501, 501);
background(255);
strokeWeight(1);
stroke(120);
smooth();
noFill();
//frameRate(60);
fillSpace(0,0,width-1,height-1);
}

function draw() {
cells[count-1].display();
count--;
if(count === 0){
noLoop();
}
}

function fillSpace(x, y, w, h){
var cell;
var corner;
var lx, ly, lw, lh, sx, sy, sw, sh;
for(var i = challenge_limit; 0<i; i--){
cell = new Cell();
cell.w = cell_min_size * random(cell_scales);
cell.h = cell.w * random(cell_aspects);
if( cell.w <= w && cell.h <=h){
corner = random(corners);
switch(corner){
case 0://left top
cell.x = x;
cell.y = y;
lx = x + cell.w;
ly = y;
sx = x;
sy = y+cell.h;
break;
case 1://right top
cell.x = x + w - cell.w;
cell.y = y;
lx = x;
ly = y;
sx = x + w - cell.w;
sy = y + cell.h;
break;
case 2://right bottom
cell.x = x + w - cell.w;
cell.y = y + h - cell.h;
lx = x;
ly = y;
sx = x + w - cell.w;
sy = y;
break;
case 3://left bottom
cell.x = x;
cell.y = y + h - cell.h;
lx = x + cell.w;
ly = y;
sx = x;
sy =y;
break;
}
lw = w - cell.w;
lh = h;
sw = cell.w;
sh = h - cell.h;
fillSpace(lx, ly, lw, lh);
fillSpace(sx, sy, sw, sh);
//cell.display();
cells.push(cell);
count = cells.length;
break;
}
}
}

function Cell(){
this.x = 0;
this.y = 0;
this.w = 0;
this.h =0;
this.display = function(){
rect(this.x, this.y, this.w, this.h);
}
}

#Generative_Art #フラクタル
Powered by Helpfeel