Created
July 25, 2013 16:03
-
-
Save YukiSakamoto/6081222 to your computer and use it in GitHub Desktop.
Mandelbrot set by C language.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <math.h> | |
const int times = 200; | |
const double x_max = 1; | |
const double x_min =-2; | |
const double y_max = 1; | |
const double y_min =-1; | |
const double dx = 0.02; | |
const double dy = 0.02; | |
/* If mandelbrot() function returns zero, that inidicates divergence. */ | |
int mandelbrot(double c_x, double c_y, int n) | |
{ | |
double x_n = 0; | |
double y_n = 0; | |
double x_n_1; | |
double y_n_1; | |
int i; | |
for(i = 0; i < n; i++) { | |
x_n_1 = pow(x_n, 2) - pow(y_n, 2) + c_x; | |
y_n_1 = 2 * x_n * y_n + c_y; | |
if ( pow(x_n_1, 2) + pow(y_n_1, 2) > 4.0 ){ | |
return n; | |
} else { | |
x_n = x_n_1; | |
y_n = y_n_1; | |
} | |
} | |
return 0; | |
} | |
int main(void) | |
{ | |
double x; | |
double y; | |
int x_length = (x_max - x_min) / dx; | |
for(y = y_max; y > y_min; y -= dy) { | |
for(x = x_min; x < x_max; x += dx) { | |
putchar(mandelbrot(x, y, 300) == 0 ? '*' : ' '); | |
} | |
putchar('\n'); | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
times = 200; | |
x_max = 1; | |
x_min =-2; | |
y_max = 1; | |
y_min =-1; | |
dx = 0.02; | |
dy = 0.02; | |
* | |
** | |
* | |
******* | |
********* | |
********* | |
********* | |
********** | |
********** | |
********* | |
******* | |
***** | |
************* | |
* ******************* * | |
* * ************************* | |
*** **************************** * | |
**** ******************************* **** | |
************************************* ***** | |
***************************************** | |
****************************************** | |
****************************************** | |
******************************************* | |
** ********************************************* | |
************************************************ | |
*********************************************** | |
************************************************* | |
************************************************** * | |
******************************************************* | |
*************************************************** * | |
***************************************************** | |
* ****************************************************** | |
* * ***************************************************** | |
*** ********* ******************************************************* | |
************* ******************************************************** | |
**************** ******************************************************* | |
******************* ******************************************************* | |
* ******************* ******************************************************* | |
********************* ******************************************************** | |
********************** ******************************************************** | |
*********************** ******************************************************** | |
*********************** ******************************************************* | |
******************************************************************************* | |
**** ******************************************************************************* | |
*********************************************************************************** | |
** * *********************************************************************************** | |
*********************************************************************************** | |
**** ******************************************************************************* | |
******************************************************************************* | |
*********************** ******************************************************* | |
*********************** ******************************************************** | |
********************** ******************************************************** | |
********************* ******************************************************** | |
* ******************* ******************************************************* | |
******************* ******************************************************* | |
**************** ******************************************************* | |
************* ******************************************************** | |
*** ********* ******************************************************* | |
* * ***************************************************** | |
* ****************************************************** | |
***************************************************** | |
*************************************************** * | |
******************************************************* | |
************************************************** * | |
************************************************* | |
*********************************************** | |
************************************************ | |
** ********************************************* | |
******************************************* | |
****************************************** | |
****************************************** | |
***************************************** | |
************************************* ***** | |
**** ******************************* **** | |
*** **************************** * | |
* * ************************* | |
* ******************* * | |
************* | |
***** | |
******* | |
********* | |
********** | |
********** | |
********* | |
********* | |
********* | |
******* | |
* | |
** | |
* | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment