This is a file from the Wikimedia Commons

File:Cpmj.png

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Original file(1,000 × 1,000 pixels, file size: 44 KB, MIME type: image/png)

Summary

Description
English: Potential of filled-in Julia set
Polski: Potencjał zbioru Julia
Date
Source Own work
Author Adam majewski

Long description

Method of drawing :

  • escape time (function GiveLastIteration)
  • potential (function jlogphi)

Code is formatted with Emacs

Compare with

Licensing

I, the copyright holder of this work, hereby publish it under the following licenses:
w:en:Creative Commons
attribution share alike
This file is licensed under the Creative Commons Attribution-Share Alike 3.0 Unported 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.
GNU head Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled GNU Free Documentation License.
You may select the license of your choice.

C src code

See also:


/* 
  c console program
  Adam Majewski 
   fraktal.republika.pl 
   1. draws  for Fc(z)=z*z +c
  -------------------------------         
   2. technic of creating ppm file is  based on the code of Claudio Rocchini
   http://en.wikipedia.org/wiki/Image:Color_complex_plot.jpg
   create 8 bit color ( gray scale ) graphic file ,  portable pixmap file = PGM  (P5)
   see http://en.wikipedia.org/wiki/Portable_pixmap
   to see the file use external application ( graphic viewer)
   ---------------------------------
   http://fraktal.republika.pl/cpp_argphi.html

*/
 
#include <stdio.h>

// this function is based on cpp function   
// in the file mandelXXsrc.zip .
// from program mandel by Wolf Jung
// http://www.mndynamics.com/indexp.html

int GiveLastIteration(double Zx, double Zy,double Cx ,double Cy , int iter_max,  double bailout2)
{
  // z= x+ y*i   
  long double x ,y ;
  //
  long double  u,  v;
  int iter; // iteration
 
  iter=0;//there was no iteration
 
  y =Zy; 
  x =Zx; 
  u = x*x ; 
  v = y*y;
  if ( u + v > bailout2 ) return  iter;  // point is in target set =no need to iterate 
  //
  do
    {
      // Fc(z)= z*z +c
      y = 2 * x * y + Cy;
      x = u - v + Cx; 
      u = x*x; 
      v = y*y;
      iter+=1;     
    } 
  while (( u + v <= bailout2 ) && iter<iter_max) ;
  return iter;
 
}





/* this function is based on function by W Jung */

double jlogphi(double zx0, double zy0, double cx, double cy)
{ 
  int j; 
  double 
    zx=zx0,
    zy=zy0,
    s = 0.5, 
    zx2=zx*zx,
    zy2=zy*zy,
    t;
  //
  for (j = 1; j < 400; j++)
    { s *= 0.5; 
      zy = 2 * zx * zy + cy;
      zx = zx2 - zy2 + cx; 
      zx2 = zx*zx; 
      zy2 = zy*zy;
      t = fabs(zx2 + zy2); // abs(z)
      if ( t > 1e24) break; 
    } 
  return s*log2(t);  // log(zn)* 2^(-n)
}//jlogphi



int main()
{
  const double Cx=-0.12,Cy=0.665;
        
       
  /* screen ( integer) coordinate */
  int iX,iY;
  const int iXmax = 1000, iXmin=0; 
  const int iYmax = 1000, iYmin=0;
  int iWidth=iXmax-iXmin+1,
    iHeight=iYmax-iYmin+1,
    /* number of bytes = number of pixels of image * number of bytes of color */
    iLength=iWidth*iHeight*1,/* 1 bytes of color  */
    index; /* of array */
       
  /* world ( double) coordinate = parameter plane*/
  const double length=2.0;
  const double ZxMin=-length;
  const double ZxMax=length;
  const double ZyMin=-length;
  const double ZyMax=length;
  /* */
  double PixelWidth=(ZxMax-ZxMin)/iXmax;
  double PixelHeight=(ZyMax-ZyMin)/iYmax;
  /* color component ( R or G or B) is coded from 0 to 255 */
  /* it is 8 bit color RGB file */
  const int MaxColorComponentValue=255; 
  FILE * fp;
  char *filename="p__10.pgm";
  char *comment="# Cx=-0.12, Cy=0.665; EscapeRadius=3 IterationMax=4000;";/* comment should start with # */
       
  /* Z=Zx+Zy*i  ;   Z0 = 0 */
  double Zx, Zy;
  double Zx2, Zy2; /* Zx2=Zx*Zx;  Zy2=Zy*Zy  */
  /*  */
  double potential,temp;
  int Level, PreviousLevel;
  int LastIteration;
  const int IterationMax=4000;
  /* bail-out value , radius of circle ;  */
  const double EscapeRadius=3;
  double ER2=EscapeRadius*EscapeRadius;
  /* dynamic 1D array for 8-bit color values */    
  unsigned char *array;
  unsigned char color;
  /*-------------------------------------------------------------------*/
  array = malloc( iLength * sizeof(unsigned char) );
  if (array == NULL)
    {
      fprintf(stderr,"Could not allocate memory");
      getchar();
      return 1;
    }
  else 
    {   fprintf(stderr,"I'm working. Please wait (:-))\n ");
      /* fill the data array with white points */       
      for(index=0;index<iLength-1;++index) array[index]=255;
    }
  /* ---------------------------------------------------------------*/
  for(iY=0;iY<iYmax;iY++)
    {
      for(iX=0;iX<iXmax;iX++)
	{         /* compute Zx and Zy for each point */
	  Zy=ZyMin + iY*PixelHeight;
	  if (fabs(Zy)< PixelHeight/2) Zy=0.0; /*  */
	  Zx=ZxMin + iX*PixelWidth;
	  //
	  LastIteration=GiveLastIteration(Zx, Zy, Cx , Cy , IterationMax, ER2);
	  if (LastIteration!=IterationMax)
	    /*   */
	    {    potential=jlogphi(Zx, Zy,Cx,Cy);// GivePotential(Zx, Zy,Cx,Cy,ER2,IterationMax );
	      // printf(" potential= %f\n",potential);
	      temp=255*potential;
	      if (temp>255) 
		color=255;
	      else color= temp; 
	      array[((iYmax-iY-1)*iXmax+iX)]= color ;
	    }
	}
    }
        
  /* write the whole data array to ppm file in one step */      
  /*create new file,give it a name and open it in binary mode  */
  fp= fopen(filename,"wb"); /* b -  binary mode */
  if (fp == NULL){ fprintf(stderr,"file error"); }
  else
    {
      /*write ASCII header to the file*/
      fprintf(fp,"P5\n %s\n %d\n %d\n %d\n",comment,iXmax,iYmax,MaxColorComponentValue);
      /*write image data bytes to the file*/
      fwrite(array,iLength ,1,fp);
      fclose(fp);
      fprintf(stderr,"OK : file  "); fprintf(stderr,filename); fprintf(stderr,"  saved.\nDone !!!");
      getchar();
    }
  free(array);
       
  getchar();
  return 0;
}

Captions

Add a one-line explanation of what this file represents

Items portrayed in this file

depicts

24 October 2009

image/png

8fc2c3b253677b4ef1af70815e105f4ef7635f98

45,334 byte

1,000 pixel

1,000 pixel

File history

Click on a date/time to view the file as it appeared at that time.

Date/TimeThumbnailDimensionsUserComment
current17:54, 3 August 2023Thumbnail for version as of 17:54, 3 August 20231,000 × 1,000 (44 KB)Obscure2020Optimized with OxiPNG and ZopfliPNG.
15:46, 24 October 2009Thumbnail for version as of 15:46, 24 October 20091,000 × 1,000 (70 KB)Soul windsurfer{{Information |Description={{en|1=Potential of filled-in Julia set }} {{pl|1=Potencjał zbioru Julia}} |Source={{own}} |Author=Adam majewski |Date=24.10.2009 |Permission= |other_versions= }}

The following page uses this file:

Global file usage

The following other wikis use this file: