曼德尔布罗特集合

June 22, 2021 · 程序 · 10749次阅读

计算机艺术是我一直关注的领域,国内外都有人在研究,它不仅是渲染的艺术,也是代码的艺术,同时也是数学的艺术。

曼德尔布罗特集合最经常被用来说明何为分形几何,它已成为分形几何的标志性图案,它可以帮助我们更好地理解我们周围不规则和粗糙的世界。它的名称就来源于“分形几何之父”伯努瓦-曼德尔布罗特。分形几何理论认为,许多领域(如物理学、生物学以及金融等)中的复杂现象,都可以以这种美丽的图案进行处理。今天用JS+Canvas来实现曼德尔布罗特集合的算法。传送门

HTML部分

<div id="canvas_wrapper" style="overflow:auto;"></div>

javascript部分

var $canvas,canvas,context;
draw();
function draw(){
    var w = 1024;
    var h = w;
    $canvas = $("<canvas>");
    $canvas.attr("id","canvas");
    $canvas.attr("width",w);
    $canvas.attr("height",h);
    $canvas.appendTo("#canvas_wrapper");
    canvas = $canvas[0];
    context = canvas.getContext("2d");
    var imageData = context.createImageData(canvas.width, canvas.height);
    var pixelData = imageData.data;
    for (var i = 0; i < canvas.height; i++) {
        for (var j = 0; j < canvas.width; j++) {
            var x = 0.0, y = 0.0, a = 0.0;
            for (var k = 0; k < 256; k++) {
                a = x * x - y * y + (i - (canvas.width * 2 / 3 + 50))/(canvas.width * 0.5);
                y = 2 * x * y + (j - (canvas.width * 0.5))/(canvas.width * 0.5);
                x = a;
                if (x * x + y * y > 4) {
                    break;
                }
            }

            var p = j * canvas.width + i;
            pixelData[4 * p + 0] = Math.log(k) * 47;
            pixelData[4 * p + 1] = Math.log(k) * 47;
            pixelData[4 * p + 2] = 128 - Math.log(k) * 23;
            pixelData[4 * p + 3] = 255;
        }
    }
    context.putImageData(imageData, 0, 0, 0, 0, canvas.width, canvas.height);
}

最终效果

喝杯水 ENJOY 1

javascriptcanvas

最后编辑于4年前

添加新评论

  1. 2025-09-17 00:11

    new zealandn online pokies au reviews, new bingo
    sites usa 2021 and best online slot new zealand, or milwausaee casino entertainment

    回复
  2. 2025-09-17 01:01

    https://t.me/s/ReYting_CaSIno_RUssiA

    回复
  3. 2025-10-02 04:08

    25 free spins casino new zealand, united statesn online
    pokies paysafe and free spins no deposit bonus codes
    canada, or best nz casino bonuses

    回复
  4. 2025-10-03 23:21

    united statesn casino nashua nh, fastest paying casino usa
    and echeck casinos united kingdom, or united kingdom online pokies paypal

    回复
  5. 2025-10-04 00:21

    https://t.me/s/z_official_1xbet

    回复
  6. 2025-10-04 02:39

    big pokie wins australia 2021, united statesn roulette wheel number order
    and free spins new usa, or montreal australia casino

    回复
  7. 2025-10-05 02:01

    新车上路,只带前10个人

    回复
  8. 2025-10-05 03:53

    Get free Blockchain Insurance globally!

    Get professional insurance of global importance from an insurer in Chelyabinsk, Russia.

    Without personal data, cookie and JS.

    We got access to the US market without compromising.

    More than 85 types of non-criminal insurance.

    Once a month, a document is created that can be shown to the regulatory authorities. We're taking over the negotiations.

    We insure risks such as:
    1. Arbitrary legislation
    2. Arbitrariness of the Central Bank
    3. Possible harm to other people

    Link (own hosting): http://78.29.53.57/freeinsurance/?s1=xrum

    http://78.29.53.57/freeinsurance/?s1=xrum

    By brand ChelyabinskMAN

    回复
  9. 2025-10-05 04:15

    https://t.me/s/a_official_1xbet

    回复
  10. 2025-10-06 21:25

    新盘 上车集合 留下 我要发发 立马进裙

    回复
  11. 2025-10-07 00:50

    crypto gambling usa, the united states casino video and is playing poker for money illegal usa, or online pokies
    australia wheres the gold

    回复
  12. 2025-10-07 10:16

    2025年10月新盘 做第一批吃螃蟹的人coinsrore.com
    新车新盘 嘎嘎稳 嘎嘎靠谱coinsrore.com
    新车首发,新的一年,只带想赚米的人coinsrore.com
    新盘 上车集合 留下 我要发发 立马进裙coinsrore.com
    做了几十年的项目 我总结了最好的一个盘(纯干货)coinsrore.com
    新车上路,只带前10个人coinsrore.com
    新盘首开 新盘首开 征召客户!!!coinsrore.com
    新项目准备上线,寻找志同道合的合作伙伴coinsrore.com
    新车即将上线 真正的项目,期待你的参与coinsrore.com
    新盘新项目,不再等待,现在就是最佳上车机会!coinsrore.com
    新盘新盘 这个月刚上新盘 新车第一个吃螃蟹!coinsrore.com

    回复
  13. 2025-10-07 19:58

    2025年10月新盘 做第一批吃螃蟹的人coinsrore.com
    新车新盘 嘎嘎稳 嘎嘎靠谱coinsrore.com
    新车首发,新的一年,只带想赚米的人coinsrore.com
    新盘 上车集合 留下 我要发发 立马进裙coinsrore.com
    做了几十年的项目 我总结了最好的一个盘(纯干货)coinsrore.com
    新车上路,只带前10个人coinsrore.com
    新盘首开 新盘首开 征召客户!!!coinsrore.com
    新项目准备上线,寻找志同道合 的合作伙伴coinsrore.com
    新车即将上线 真正的项目,期待你的参与coinsrore.com
    新盘新项目,不再等待,现在就是最佳上车机会!coinsrore.com
    新盘新盘 这个月刚上新盘 新车第一个吃螃蟹!coinsrore.com

    回复
  14. 2025-10-07 20:05

    poker stars sign up bonus uk, no deposit bonus codes casino usa and new zealandn online pokies minimum $5 deposit,
    or best uk casino offers

    回复
  15. Don Don
    2025-10-08 14:49

    online gambling sites in the usa, best winning online casino nz and free casino bonus no deposit
    required uk, or online live roulette casino usa

    回复
  16. 2025-10-08 18:44

    play online poker united states, united kingdom online play roulette and leo vegas casino nz, or gambling commission usa

    回复
  17. 2025-10-09 14:33

    best way to win united kingdom roulette, what slot machine
    are called in australia and australian gambling law, or remote
    gambling association uk

    回复
  18. 2025-10-09 17:25

    ausaa ca casino, casino online united states bc and casino chip
    values usa, or real online australian pokies

    回复
  19. 2025-10-10 01:03

    kostenlos wetten ohne einzahlung

    回复
  20. 2025-10-10 23:41

    sportwetten startguthaben ohne einzahlung

    回复
  21. 2025-10-11 03:24

    quote wetten dass

    回复
  22. 2025-10-11 18:38

    wetten mit bonus

    回复
  23. 2025-10-11 19:48

    esc buchmacher quoten

    回复
  24. Iva Iva
    2025-10-11 23:40

    brasilien deutschland wette

    回复
  25. 2025-10-12 09:08

    wettbüro

    回复
  26. 2025-10-12 11:41

    über tore wetten tipps

    回复
  27. 2025-10-12 16:39

    wette vorhersage wetten

    回复
  28. 2025-10-12 17:09

    sportwetten in österreich

    回复
  29. 2025-10-12 21:11

    hello

    回复
  30. 2025-10-12 21:57

    online wetten ohne verifizierung

    回复
avatar

朱益雷

有趣的灵魂万里挑一

10

文章数

1406

评论数

3

分类

热死辣

新鲜出炉の评论