标签: mandelbrot

代码高尔夫:Mandelbrot套装

代码高尔夫的常用规则.这是python中的一个实现作为示例

from PIL import Image

im = Image.new("RGB", (300,300))
for i in xrange(300):
    print "i = ",i
    for j in xrange(300):
        x0 = float( 4.0*float(i-150)/300.0 -1.0)
        y0 = float( 4.0*float(j-150)/300.0 +0.0)
        x=0.0
        y=0.0
        iteration = 0
        max_iteration = 1000
        while (x*x + y*y <= 4.0 and iteration < max_iteration):
            xtemp = x*x - y*y + x0
            y = 2.0*x*y+y0
            x = xtemp
            iteration += 1
        if iteration == max_iteration:
            value = 255 
        else:
            value = iteration*10 % 255
        print value …
Run Code Online (Sandbox Code Playgroud)

code-golf fractals mandelbrot rosetta-stone

40
推荐指数
13
解决办法
3810
查看次数

Mandelbrot Set渲染的平滑光谱

我目前正在编写一个程序来生成真正巨大的(65536x65536像素及以上)Mandelbrot图像,我想设计一种能够正义的光谱和着色方案.在维基百科特色的Mandelbrot图像似乎是一个很好的例子,调色板尤其是如何保持在序列中的所有缩放级别变化.不过,我不确定它是在旋转调色板还是做其他一些技巧来实现这一点.

我熟悉mandelbrot集的平滑着色算法,所以我可以避免使用条带,但我仍然需要一种方法来为此算法的输出值指定颜色.

我正在生成的图像是金字塔形的(例如,一系列图像,每个图像的尺寸都是前一个图像的一半),所以我可以使用某种旋转调色板,只要调色板之间的变化即可缩放级别不是太明显.

algorithm colors fractals mandelbrot

30
推荐指数
4
解决办法
3万
查看次数

哪个颜色渐变用于维基百科中的mandelbrot?

在维基百科的Mandelbrot页面上,有很多美丽的Mandelbrot图像.

细节Mandelbrot

我也刚刚实现了自己的mandelbrot算法.给定n是用于计算每个像素的迭代次数,我将它们从黑色到绿色非常简单地着色(使用C++和Qt 5.0):

QColor mapping(Qt::white);
if (n <= MAX_ITERATIONS){
    double quotient = (double) n / (double) MAX_ITERATIONS;
    double color = _clamp(0.f, 1.f, quotient);
    if (quotient > 0.5) {
        // Close to the mandelbrot set the color changes from green to white
        mapping.setRgbF(color, 1.f, color);
    }
    else {
        // Far away it changes from black to green
        mapping.setRgbF(0.f, color, 0.f);
    }
}
return mapping;
Run Code Online (Sandbox Code Playgroud)

我的结果看起来像这样:

在此输入图像描述

我已经非常喜欢它,但维基百科中的图像使用了哪种颜色渐变?如何使用给定n的迭代计算该梯度?

(这个问题与平滑无关.)

c++ qt gradient colors mandelbrot

21
推荐指数
2
解决办法
2万
查看次数

Mandelbrot在Common Lisp中设置实现

我一直致力于用几种不同的语言实现Mandelbrot Set.我有一个C++,C#,Java和Python的工作实现,但Common Lisp实现有一些我无法弄清楚的错误.它生成集合,但在管道中的某个地方集合变形.我已经测试并且几乎可以肯定地知道文件I/O CLO不是问题 - 它不太可能但是可能,我已经非常彻底地测试了它.

请注意,这些实现的目的是将它们相互比较 - 所以我试图保持代码实现尽可能相似,以便它们具有可比性.

Mandelbrot集(这里由Python实现生成):

http://www.freeimagehosting.net/uploads/65cb71a873.png http://www.freeimagehosting.net/uploads/65cb71a873.png"Mandelbrot Set(由Python生成)"

但我的Common Lisp程序生成了这个:

http://www.freeimagehosting.net/uploads/50bf29bcc9.png http://www.freeimagehosting.net/uploads/50bf29bcc9.png"Common Lisp版本的扭曲Mandelbrot集"

Clisp和SBCL中的错误相同.

码:

Common Lisp:

(defun mandelbrot (real cplx num_iter)
   (if (> (+ (* real real) (* cplx cplx)) 4)
      1
      (let ((tmpreal real) (tmpcplx cplx) (i 1))
         (loop
            (setq tmpcplx (+ (* (* tmpreal tmpcplx) 2) cplx))
            (setq tmpreal (+ (- (* tmpreal tmpreal) (* tmpcplx tmpcplx))
               real))
            (setq i (+ i 1))
            (cond
               ((> (+ (* tmpreal …
Run Code Online (Sandbox Code Playgroud)

common-lisp set mandelbrot

11
推荐指数
2
解决办法
1703
查看次数

Lua挑战:你能改进mandelbrot实现的性能吗?

状态:到目前为止,最佳答案的程序在原始程序的33%的时间内执行!但可能还有其他方法可以优化它.


Lua目前是最快的脚本语言,但Lua在针对C/C++的一些基准测试中得分非常糟糕.

其中之一是mandelbrot测试(Generate Mandelbrot设置便携式位图文件N = 16,000),其中得分可怕1:109(多核)或1:28(单核)

由于Delta的速度非常大,因此这是优化的理想选择.此外,我确信那些知道Mike Pall是谁的人可能认为不可能进一步优化这一点,但这显然是错误的.任何做过优化的人都知道总是可以做得更好.此外我通过一些调整设法获得了一些额外的性能,所以我知道它可能:)

-- The Computer Language Shootout
-- http://shootout.alioth.debian.org/
-- contributed by Mike Pall

local width = tonumber(arg and arg[1]) or 100
local height, wscale = width, 2/width
local m, limit2 = 50, 4.0
local write, char = io.write, string.char

write("P4\n", width, " ", height, "\n")

for y=0,height-1 do
  local Ci = 2*y / height - 1
  for xb=0,width-1,8 do
    local bits = 0
    local xbb = xb+7
    for x=xb,xbb < width and …
Run Code Online (Sandbox Code Playgroud)

optimization lua mandelbrot

10
推荐指数
1
解决办法
3735
查看次数

使C#mandelbrot绘图更有效率

首先,我知道这个问题听起来好像我没有搜索,但我做了很多.

我为C#编写了一个小的Mandelbrot绘图代码,它基本上是一个带有PictureBox的窗体,我在其上绘制了Mandelbrot集.

我的问题是,它是非常慢的.如果没有深度变焦,它可以很好地工作并且移动并且变焦非常平滑,每次绘制只需不到一秒钟,但是一旦我开始放大一点并到达需要更多计算的地方,它就变得非常慢.

在其他Mandelbrot应用程序上,我的计算机在我的应用程序中工作得慢得多的地方确实很好,所以我猜我可以做很多事情来提高速度.

我做了以下事情来优化它:

  • 我没有在位图对象上使用SetPixel GetPixel方法,而是使用LockBits方法直接写入内存,这使得事情变得更快.

  • 我没有使用复数对象(我自己创建的类,而不是内置的类),而是使用2个变量re和im模拟复数.这样做可以减少乘法,因为在计算过程中对实部和虚部进行平方是一些事情,所以我只需将方块保存在变量中并重复使用结果而无需重新计算.

  • 我使用4个线程绘制Mandelbrot,每个线程执行不同的图像四分之一,它们都同时工作.据我所知,这意味着我的CPU将使用其4个核心来绘制图像.

  • 我使用Escape Time算法,据我所知最快?

这是我如何在像素之间移动并计算,它被注释掉,所以我希望它是可以理解的:

        //Pixel by pixel loop:
        for (int r = rRes; r < wTo; r++)
        {
            for (int i = iRes; i < hTo; i++)
            {

                //These calculations are to determine what complex number corresponds to the (r,i) pixel.
                double re = (r - (w/2))*step + zeroX ;
                double im = (i - (h/2))*step - zeroY;

                //Create the Z complex number
                double zRe = 0;
                double zIm = 0;

                //Variables …
Run Code Online (Sandbox Code Playgroud)

c# optimization gpu fractals mandelbrot

9
推荐指数
2
解决办法
5189
查看次数

优化快速乘法但缓慢添加:FMA和doubledouble

当我第一次使用Haswell处理器时,我尝试使用FMA来确定Mandelbrot集.主要算法是这样的:

intn = 0;
for(int32_t i=0; i<maxiter; i++) {
    floatn x2 = square(x), y2 = square(y); //square(x) = x*x
    floatn r2 = x2 + y2;
    booln mask = r2<cut; //booln is in the float domain non integer domain
    if(!horizontal_or(mask)) break; //_mm256_testz_pd(mask)
    n -= mask
    floatn t = x*y; mul2(t); //mul2(t): t*=2
    x = x2 - y2 + cx;
    y = t + cy;
}
Run Code Online (Sandbox Code Playgroud)

这确定n像素是否在Mandelbrot集中.因此对于双浮点,它运行超过4个像素(floatn = __m256d,intn = __m256i).这需要4个SIMD浮点乘法和4个SIMD浮点加法.

然后我修改了这个就像这样使用FMA

intn n = 0; …
Run Code Online (Sandbox Code Playgroud)

floating-point x86 assembly mandelbrot fma

9
推荐指数
1
解决办法
944
查看次数

为什么龟可以点亮像素?

我创建Mandelbrot集的程序有一个错误:每当笔改变颜色时,每隔42个像素就会变亮.这是一个非常巧合的mandelbug(是的,我刚刚学过这个术语),因为它对于"边缘"附近的许多像素是不一致的(它实际上可能在它应该是的颜色和最后一个颜色之间模糊,或者接下来,像素应该是),但它总是在那之后的第42个像素,直到下一个颜色变化.我使用的是OSX 10.6.8,PYTHON 2.7.当我在学校写这个程序时,它完美地工作(Windows),然后我把它发送给自己,并且更多地工作(大多只是制作样本大小,因此图像更大),然后运行它,我得到了这个错误.编辑:我的坏,我忘了提到这只发生在我的Mandelbrot程序,我在家里的其他几个海龟程序都很好.

截图的一部分(这样你就不必在程序运行时永远等待,看看我在说什么):

从我家的第一个版本:

我的意思是,是什么?

从当前版本(侧面):

请注意:此图片是侧面的

下面是代码:

import turtle
import math
turtle.speed(0)
def benoit(onelen):
    turtle.left(90)
    for x in range(-2*onelen, onelen):
        turtle.up()
        turtle.goto(x, int(-1.5*onelen)-1)
        turtle.down()
        for y in range(int(-1.5*onelen)-1, int(1.5*onelen)-1):
            z = complex(0,0)
            c = complex(x*1.0/onelen,y*1.0/onelen)
            for k in range(20):
                z = z*z+c
                if abs(z) > 2:
                    g = .2 + .8*(20-k)/20
                    break
                if k == 19:
                    g = 0
            turtle.pencolor(0,g,0)
            turtle.forward(1)
benoit(250)
x = raw_input("Press Enter to Exityadayadayada")
Run Code Online (Sandbox Code Playgroud)

编辑:DSM建议修复,他喜欢这个bug.但是,我没有编辑Python源代码的经验,所有下划线都让我感到紧张.有人能告诉我具体编辑和/或如何编辑?

python turtle-graphics mandelbrot

7
推荐指数
1
解决办法
1333
查看次数

改进了我的Mandelbrot设置代码

我在C中有以下Mandelbrot设置代码.我正在进行计算并为最终的分形图像创建.ppm文件.关键是我的分形图像是颠倒的,这意味着它旋转了90度.您可以通过执行我的代码来检查它:./ mandel> test.ppm

另一方面,我也想改变颜色.我想实现这个分形图像:

在此输入图像描述

我的最后一个问题是我的代码没有检查我的代码的运行时间.我也有这部分的代码,但是当代码执行完成时,它不会打印运行时间.如果有人可以对我的代码进行适当的更改并帮助我实现这个分形图像,并显示已用时间,我会很高兴.

#include <math.h>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>

void color(int red, int green, int blue)
{
    fputc((char)red, stdout);
    fputc((char)green, stdout);
    fputc((char)blue, stdout);
}

int main(int argc, char *argv[])
{
    int w = 600, h = 400, x, y; 
    //each iteration, it calculates: newz = oldz*oldz + p, where p is the current pixel, and oldz stars at the origin
    double pr, pi;                   //real and imaginary part of the pixel p
    double newRe, newIm, oldRe, oldIm; …
Run Code Online (Sandbox Code Playgroud)

c colors set fractals mandelbrot

7
推荐指数
1
解决办法
1万
查看次数

在曼德尔布罗集中实现平滑着色

我正在尝试使用 HSV 值和 PIL 库为 MandelBrot 着色。

即使多次尝试摆弄 HSV 值,我也无法达到预期的效果。

这是我目前拥有的

当前.png

这是想要的效果

所需.png

这是我正在尝试的代码,如果您可以添加一些提示来优化下面的代码以更快地计算集合,这也可能是有益的,我是 python 新手

from PIL import Image
import random
import math
from decimal import Decimal


# Size of the Image Canvas
HEIGHT = 500

ZOOM = 0.0
Y_PAN = 0.0


# Range of the Complex Plane
MIN_X = -2.0 + ZOOM
MAX_X = 2.0 - ZOOM


MAX_Y = 2.0 + Y_PAN - ZOOM
MIN_Y = -2.0 + Y_PAN + ZOOM

DATA = []


def map_to_scale_d(x, in_min, in_max, out_min, …
Run Code Online (Sandbox Code Playgroud)

python fractals mandelbrot python-3.x

7
推荐指数
1
解决办法
1180
查看次数