Skip to content

Instantly share code, notes, and snippets.

@ogrew
Last active April 18, 2022 02:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ogrew/bbe6e4468127cfe75b3b1fa9d1e2abce to your computer and use it in GitHub Desktop.
Save ogrew/bbe6e4468127cfe75b3b1fa9d1e2abce to your computer and use it in GitHub Desktop.
ジュリア集合を描く
let gridScale = 2.1;
let border = 2.7;
let maxCount = 150;
function getRealPart(x) {
let rp = -1/2 + 1.0 * x / width;
let s = height / width;
return rp * gridScale/s;
}
function getImaginaryPart(y) {
let ip = 1/2 - 1.0 * y / height;
return ip * gridScale;
}
function drawJuliaSet(ca, cb) {
for (let y = 0; y <= height; y++)
{
for(let x = 0; x <= width; x++)
{
// z = a + bi
let a = getRealPart(x);
let b = getImaginaryPart(y);
let count = 0;
while(dist(a,b,0,0) < border && count < maxCount)
{
// z -> z + c
let a_tmp = a*a - b*b + ca;
let b_tmp = 2*a*b + cb;
a = a_tmp;
b = b_tmp;
count++;
}
// 2 Color
let color = dist(a,b,0,0) < border ? 10.0 : 220.0;
stroke(color);
point(x,y);
}
}
}
function setup() {
createCanvas(1200, 800);
noLoop();
}
function draw() {
background(220);
// offset c
let ca = -0.6778;
let cb = 0.3245;
drawJuliaSet(ca, cb);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment