LoginSignup
0
0

More than 1 year has passed since last update.

plunkerでMandelbrot その2

Posted at

概要

plunkerでMandelbrotやってみた。

写真

image.png

サンプルコード

var ctx = document.getElementById('canvas').getContext('2d');
var KS = 500;
var RST = -3.1;
var RED = 0.9;
var IST = -1.85;
var IED = 1.85;
var DR = (RED - RST) / KS;
var DI = (IED - IST) / KS;

function map(n, v, omin, omax) {
    return n / (omax - omin) * v + v / 2;
};

for (CR = RST; CR <= RED; CR = CR + DR)
{
    for (CI = IST; CI <= IED; CI = CI + DI)
    {
        ZR = 0;
        ZI = 0;
        for (K = 1; K <= 8; K++)
        { 
            if (K == 1) ctx.fillStyle = 'rgb(255, 255, 25)';
            if (K == 2) ctx.fillStyle = 'rgb(255, 25, 255)';
            if (K == 3) ctx.fillStyle = 'rgb(25, 255, 255)';
            if (K == 4) ctx.fillStyle = 'rgb(25, 25, 255)';
            if (K == 5) ctx.fillStyle = 'rgb(25, 255, 25)';
            if (K == 6) ctx.fillStyle = 'rgb(55, 55, 55)';
            if (K == 7) ctx.fillStyle = 'rgb(55, 55, 255)';
            if (K == 8) ctx.fillStyle = 'rgb(255, 55, 255)';
            R = ZR * ZR - ZI * ZI + CR;
            I = 2 * ZR * ZI + CI;
            if ((R * R + I * I) > 4)
            { 
                var x = map(CR, KS, RST, RED);
                var y = map(CI, KS, IST, IED);
                ctx.fillRect(x, y, 1, 1);
                K = 9;
            }
            ZR = R;
            ZI = I;
        }
    }
}






成果物

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0