File:Mandelbrot set - Stripe Average Coloring.png
From Wikimedia Commons, the free media repository
Jump to navigation
Jump to search
Size of this preview: 600 × 600 pixels. Other resolutions: 240 × 240 pixels | 480 × 480 pixels | 768 × 768 pixels | 1,024 × 1,024 pixels | 2,000 × 2,000 pixels.
Original file (2,000 × 2,000 pixels, file size: 2.18 MB, MIME type: image/png)
File information
Structured data
Captions
Summary
[edit]DescriptionMandelbrot set - Stripe Average Coloring.png |
English: Mandelbrot set - Stripe Average Coloring |
Date | |
Source | Made with code and help by Alex Simes and Syntopia |
Author | Adam majewski |
Other versions |
|
Licensing
[edit]I, the copyright holder of this work, hereby publish it under the following license:
This file is licensed under the Creative Commons Attribution-Share Alike 4.0 International license.
- You are free:
- to share – to copy, distribute and transmit the work
- to remix – to adapt the work
- Under the following conditions:
- attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
- share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.
Processing source code
[edit]// http://www.fractalforums.com/general-discussion/stripe-average-coloring/
// code by asimes
float xmin = -2.5;
float ymin = -2.0;
float wh = 4;
float stripes = 5.0;
int maxIterations = 1000;
void setup() {
size(10000, 10000, P2D);
}
void draw() {
loadPixels();
float xmax = xmin+wh;
float ymax = ymin+wh;
float dx = (xmax-xmin)/width;
float dy = (ymax-ymin)/height;
float x = xmin;
for (int i = 0; i < width; i++) {
float y = ymin;
for (int j = 0; j < height; j++) {
float zr = x;
float zi = y;
float lastzr = x;
float lastzi = y;
float orbitCount = 0;
int n = 0;
while (n < maxIterations) {
float zrr = zr*zr;
float zii = zi*zi;
float twori = 2*zr*zi;
zr = zrr-zii+x;
zi = twori+y;
if (zrr+zii > 10000) break;
orbitCount += 0.5+0.5*sin(stripes*atan2(zi, zr));
lastzr = zr;
lastzi = zi;
n++;
}
if (n == maxIterations) pixels[i+j*width] = 0;
else {
float lastOrbit = 0.5+0.5*sin(stripes*atan2(lastzi, lastzr));
float smallCount = orbitCount-lastOrbit;
orbitCount /= n;
smallCount /= n-1;
float frac = -1+log(2.0*log(10000))/log(2)-log(0.5*log(lastzr*lastzr+lastzi*lastzi))/log(2);
float mix = frac*orbitCount+(1-frac)*smallCount;
float orbitColor = mix*255;
pixels[i+j*width] = color(orbitColor);
}
y += dy;
}
x += dx;
}
updatePixels();
noLoop();
}
void mousePressed(){
save("a10000.png");
}
Downsizing with Image Magic:
convert a10000.png -resize 2000x2000 a2000.png
C source code
[edit]/*
c program: console, 1-file
samm.c
samm = Stripe Average Method
with :
- skipping first (i_skip+1) points from average
- linear interpolation
https://en.wikibooks.org/wiki/Fractals/Iterations_in_the_complex_plane/stripeAC
--------------------------------
1. draws Mandelbrot set for complex quadratic polynomial
Fc(z)=z*z +c
using samm = Stripe Average Method
-------------------------------
2. technique of creating ppm file is based on the code of Claudio Rocchini
http://en.wikipedia.org/wiki/Image:Color_complex_plot.jpg
create 24 bit color graphic file , portable pixmap file = PPM
see http://en.wikipedia.org/wiki/Portable_pixmap
to see the file use external application ( graphic viewer)
-----
it is example for :
https://www.math.univ-toulouse.fr/~cheritat/wiki-draw/index.php/Mandelbrot_set
-------------
compile :
gcc samm.c -lm -Wall
./a.out
-------- git --------
cd existing_folder
git init
git remote add origin [email protected]:adammajewski/mandelbrot_wiki_ACh.git
git add samm.c
git commit -m "samm + linear interpolation "
git push -u origin master
*/
#include <stdio.h>
#include <math.h> // M_LN2;
#include <complex.h> // https://stackoverflow.com/questions/6418807/how-to-work-with-complex-numbers-in-c
#define M_PI 3.14159265358979323846 /* pi */
/* screen ( integer) coordinate */
int iX,iY;
const int iXmax = 1200;
const int iYmax = 1000;
/* world ( double) coordinate = parameter plane*/
double Cx,Cy;
const double CxMin=-2.5;
const double CxMax=1.5;
const double CyMin=-5.0/3.0;
const double CyMax= 5.0/3.0;
/* */
double PixelWidth; //=(CxMax-CxMin)/iXmax;
double PixelHeight; // =(CyMax-CyMin)/iYmax;
/* color component ( R or G or B) is coded from 0 to 255 */
/* it is 24 bit color RGB file */
const int MaxColorComponentValue=255;
FILE * fp;
char *filename="samm_i.ppm"; // https://commons.wikimedia.org/wiki/File:Mandelbrot_set_-_Stripe_Average_Coloring.png
char *comment="# ";/* comment should start with # */
static unsigned char color[3]; // 24-bit rgb color
unsigned char s = 5; // stripe density
const int IterationMax=1000; // N in wiki
int i_skip = 1; // exclude (i_skip+1) elements from average
/* bail-out value for the bailout test for exaping points
radius of circle centered ad the origin, exterior of such circle is a target set */
const double EscapeRadius=10000; // = ER big !!!!
double lnER; // ln(ER)
double complex give_c(int iX, int iY){
double Cx,Cy;
Cy=CyMin + iY*PixelHeight;
if (fabs(Cy)< PixelHeight/2) Cy=0.0; /* Main antenna */
Cx=CxMin + iX*PixelWidth;
return Cx+Cy*I;
}
// the addend function
// input : complex number z
// output : double number t
double Give_t(double complex z){
return 0.5+0.5*sin(s*carg(z));
}
/*
input :
- complex number
- intege
output = average
*/
double Give_Arg(double complex C , int iMax)
{
int i=0; // iteration
double complex Z= 0.0; // initial value for iteration Z0
double A = 0.0; // A(n)
double prevA = 0.0; // A(n-1)
double R; // =radius = cabs(Z)
double d; // smooth iteration count
// iteration = computing the orbit
for(i=0;i<iMax;i++)
{
Z=Z*Z+C; // https://en.wikibooks.org/wiki/Fractals/Iterations_in_the_complex_plane/qpolynomials
if (i>i_skip) A += Give_t(Z); //
R = cabs(Z);
if(R > EscapeRadius) break; // exterior of M set
prevA = A; // save value for interpolation
} // for(i=0
if (i == iMax)
A = -1.0; // interior
else { // exterior
// computing interpolated average
A /= (i - i_skip) ; // A(n)
prevA /= (i - i_skip - 1) ; // A(n-1)
// smooth iteration count
d = i + 1 + log(lnER/log(R))/M_LN2;
d = d - (int)d; // only fractional part = interpolation coefficient
// linear interpolation
A = d*A + (1.0-d)*prevA;
}
return A;
}
/*
input = complex number
output
- color array as Formal parameters
- int = return code
*/
int compute_color(complex double c, unsigned char color[3]){
double arg;
unsigned char b;
// compute
arg = Give_Arg( c, IterationMax);
//
if (arg < 0.0)
{ /* interior of Mandelbrot set = inside_color = */
color[0]=191; //
color[1]=191;
color[2]=191;
}
else // exterior of Mandelbrot set = CPM
{
// gray gradient
b = (unsigned char) (255 - 255*arg );
color[0]= b; /* Red*/
color[1]= b; /* Green */
color[2]= b; /* Blue */
};
return 0;
}
void setup(){
//
PixelWidth=(CxMax-CxMin)/iXmax;
PixelHeight=(CyMax-CyMin)/iYmax;
lnER = log(EscapeRadius); // ln(ER)
/*create new file,give it a name and open it in binary mode */
fp= fopen(filename,"wb"); /* b - binary mode */
/*write ASCII header to the file*/
fprintf(fp,"P6\n %s\n %d\n %d\n %d\n",comment,iXmax,iYmax,MaxColorComponentValue);
}
void info(){
double distortion;
// widt/height
double PixelsAspectRatio = (double)iXmax/iYmax; // https://en.wikipedia.org/wiki/Aspect_ratio_(image)
double WorldAspectRatio = (CxMax-CxMin)/(CyMax-CyMin);
printf("PixelsAspectRatio = %.16f \n", PixelsAspectRatio );
printf("WorldAspectRatio = %.16f \n", WorldAspectRatio );
distortion = PixelsAspectRatio - WorldAspectRatio;
printf("distortion = %.16f ( it should be zero !)\n", distortion );
printf("\n");
printf("bailut value = Escape Radius = %.0f \n", EscapeRadius);
printf("IterationMax = %d \n", IterationMax);
printf("i_skip = %d = number of skipped elements ( including t0 )= %d \n", i_skip, i_skip+1);
// file
printf("file %s saved. It is called .... in A Cheritat wiki\n", filename);
}
void close(){
fclose(fp);
info();
}
// ************************************* main *************************
int main()
{
complex double c;
setup();
printf(" render = compute and write image data bytes to the file \n");
for(iY=0;iY<iYmax;iY++)
for(iX=0;iX<iXmax;iX++)
{ // compute pixel coordinate
c = give_c(iX, iY);
/* compute pixel color (24 bit = 3 bytes) */
compute_color(c,color);
/*write color to the file*/
fwrite(color,1,3,fp);
}
close();
return 0;
}
New code with DEM/M
/*
c program: console, 1-file
samm.c
algorithms:
- escape time
- DEM/M = distance estimation
- SAC/M = SAM/M
samm = Stripe Average Method =
Stripe Average coloring = sac
with :
- skipping first (i_skip+1) points from average
- linear interpolation
https://en.wikibooks.org/wiki/Fractals/Iterations_in_the_complex_plane/stripeAC
--------------------------------
1. draws Mandelbrot set for complex quadratic polynomial
Fc(z)=z*z +c
using samm = Stripe Average Method/Coloring
-------------------------------
2. technique of creating ppm file is based on the code of Claudio Rocchini
http://en.wikipedia.org/wiki/Image:Color_complex_plot.jpg
create 24 bit color graphic file , portable pixmap file = PPM
see http://en.wikipedia.org/wiki/Portable_pixmap
to see the file use external application ( graphic viewer)
-----
it is example for :
https://www.math.univ-toulouse.fr/~cheritat/wiki-draw/index.php/Mandelbrot_set
-------------
compile :
gcc samm.c -lm -Wall
./a.out
convert samm.ppm -resize 800x800 samm.png
-------- git --------
cd existing_folder
git init
git remote add origin [email protected]:adammajewski/mandelbrot_wiki_ACh.git
git add samm.c
git commit -m "samm + linear interpolation "
git push -u origin master
*/
#include <stdio.h>
#include <math.h>
#include <complex.h> // https://stackoverflow.com/questions/6418807/how-to-work-with-complex-numbers-in-c
#include <omp.h> //OpenM
#define M_PI 3.14159265358979323846 /* pi */
/* screen ( integer) coordinate */
int iX,iY;
const int iXmax = 8000;
const int iYmax = 8000;
/* world ( double) coordinate = parameter plane*/
double Cx,Cy;
// c = -0.355298979690605 +1.178016112830515 i period = 0
// c = 0.213487557597331 +0.604701020309395 i period = 0
const double CxMin=-2.25;
const double CxMax=0.75;
const double CyMin=1.5;
const double CyMax= -1.5;
/* */
double PixelWidth; //=(CxMax-CxMin)/iXmax;
double PixelHeight; // =(CyMax-CyMin)/iYmax;
/* color component ( R or G or B) is coded from 0 to 255 */
/* it is 24 bit color RGB file */
const int MaxColorComponentValue=255;
FILE * fp;
char *filename="samm.ppm"; // https://commons.wikimedia.org/wiki/File:Mandelbrot_set_-_Stripe_Average_Coloring.png
char *comment="# ";/* comment should start with # */
static unsigned char color[3]; // 24-bit rgb color
unsigned char s = 7; // stripe density
const int IterationMax=2500; // N in wiki
int i_skip = 2; // exclude (i_skip+1) elements from average
/* bail-out value for the bailout test for exaping points
radius of circle centered ad the origin, exterior of such circle is a target set */
const double EscapeRadius=1000000; // = ER big !!!!
double lnER; // ln(ER)
double complex give_c(int iX, int iY){
double Cx,Cy;
Cy=CyMax - iY*PixelHeight;
//if (fabs(Cy)< PixelHeight/3.0) Cy=0.0; /* Main antenna */
Cx=CxMin + iX*PixelWidth;
return Cx+Cy*I;
}
// the addend function
// input : complex number z
// output : double number t
double Give_t(double complex z){
return 0.5+0.5*sin(s*carg(z));
}
/*
input :
- complex number
- intege
output = average or other estimators, like distance or interior
*/
double Give_Arg(double complex C , int iMax)
{
int i=0; // iteration
double complex Z= 0.0; // initial value for iteration Z0
double A = 0.0; // A(n)
double prevA = 0.0; // A(n-1)
double R; // =radius = cabs(Z)
double d; // smooth iteration count
double complex dC = 0; // derivative
double de; // = 2 * z * log(cabs(z)) / dc;
// iteration = computing the orbit
for(i=0;i<iMax;i++)
{
dC = 2 * Z * dC + 1;
Z=Z*Z+C; // https://en.wikibooks.org/wiki/Fractals/Iterations_in_the_complex_plane/qpolynomials
if (i>i_skip) A += Give_t(Z); //
R = cabs(Z);
if(R > EscapeRadius) break; // exterior of M set
prevA = A; // save value for interpolation
} // for(i=0
if (i == iMax)
A = -1.0; // interior
else { // exterior
de = 2 * R * log(R) / cabs(dC);
if (de < PixelWidth) A = FP_ZERO; // boundary
else {
// computing interpolated average
A /= (i - i_skip) ; // A(n)
prevA /= (i - i_skip - 1) ; // A(n-1)
// smooth iteration count
d = i + 1 + log(lnER/log(R))/M_LN2;
d = d - (int)d; // only fractional part = interpolation coefficient
// linear interpolation
A = d*A + (1.0-d)*prevA;
}
}
return A;
}
/*
input = complex number
output
- color array as Formal parameters
- int = return code
*/
int compute_color(complex double c, unsigned char color[3]){
double arg;
unsigned char b;
// compute
arg = Give_Arg( c, IterationMax);
//
if (arg < 0.0)
/* interior of Mandelbrot set = inside_color = */
b = 0;
else // exterior of Mandelbrot set = CPM
{
if (arg == FP_ZERO) b= 255; // boundary
else b = (unsigned char) (255 - 255*arg );
};
// gray gradient
color[0]= b; /* Red*/
color[1]= b; /* Green */
color[2]= b; /* Blue */
return 0;
}
void setup(){
//
PixelWidth=(CxMax-CxMin)/iXmax;
PixelHeight=(CyMax-CyMin)/iYmax;
lnER = log(EscapeRadius); // ln(ER)
/*create new file,give it a name and open it in binary mode */
fp= fopen(filename,"wb"); /* b - binary mode */
/*write ASCII header to the file*/
fprintf(fp,"P6\n %s\n %d\n %d\n %d\n",comment,iXmax,iYmax,MaxColorComponentValue);
}
void info(){
double distortion;
// widt/height
double PixelsAspectRatio = (double)iXmax/iYmax; // https://en.wikipedia.org/wiki/Aspect_ratio_(image)
double WorldAspectRatio = (CxMax-CxMin)/(CyMax-CyMin);
printf("PixelsAspectRatio = %.16f \n", PixelsAspectRatio );
printf("WorldAspectRatio = %.16f \n", WorldAspectRatio );
distortion = PixelsAspectRatio - WorldAspectRatio;
printf("distortion = %.16f ( it should be zero !)\n", distortion );
printf("\n");
printf("bailut value = Escape Radius = %.0f \n", EscapeRadius);
printf("IterationMax = %d \n", IterationMax);
printf("i_skip = %d = number of skipped elements ( including t0 )= %d \n", i_skip, i_skip+1);
// file
printf("file %s saved. It is called .... in A Cheritat wiki\n", filename);
}
void close(){
fclose(fp);
info();
}
// ************************************* main *************************
int main()
{
complex double c;
setup();
printf(" render = compute and write image data bytes to the file \n");
//#pragma omp parallel for schedule(static) private(iY, iX, c, color)
for(iY=0;iY<iYmax;iY++)
for(iX=0;iX<iXmax;iX++)
{ // compute pixel coordinate
c = give_c(iX, iY);
/* compute pixel color (24 bit = 3 bytes) */
compute_color(c,color);
/*write color to the file*/
fwrite(color,1,3,fp);
}
close();
return 0;
}
File history
Click on a date/time to view the file as it appeared at that time.
Date/Time | Thumbnail | Dimensions | User | Comment | |
---|---|---|---|---|---|
current | 15:39, 26 September 2017 | 2,000 × 2,000 (2.18 MB) | Soul windsurfer (talk | contribs) | smaller size, 8000 is loading slow | |
15:36, 26 September 2017 | 8,000 × 8,000 (19.25 MB) | Soul windsurfer (talk | contribs) | better image, + DEM | ||
15:21, 20 September 2017 | 2,000 × 2,000 (1.1 MB) | Soul windsurfer (talk | contribs) | User created page with UploadWizard |
You cannot overwrite this file.
File usage on Commons
The following 3 pages use this file:
File usage on other wikis
The following other wikis use this file:
- Usage on en.wikibooks.org
- Usage on pl.wikibooks.org
Metadata
This file contains additional information such as Exif metadata which may have been added by the digital camera, scanner, or software program used to create or digitize it. If the file has been modified from its original state, some details such as the timestamp may not fully reflect those of the original file. The timestamp is only as accurate as the clock in the camera, and it may be completely wrong.
PNG file comment | |
---|---|
File change date and time | 15:37, 26 September 2017 |