SlideShare ist ein Scribd-Unternehmen logo
1 von 1
Downloaden Sie, um offline zu lesen
The Joy of
Programming
Writing Beautiful Programs:                                                                                                       S.G. GANESH
ASCII Arts and Fractals—Part III
In this column, we’ll look at how to draw the Mandelbrot set fractal using ASCII characters.



I
    n most of the cases, writing fractal programs requires a
                                                                                                z.r = temp.r;
    good knowledge of mathematics. The Mandelbrot set is                                        z.i = temp.i;
    based on the theory and use of complex numbers. The
Mandelbrot set is a collection of complex numbers, which                                      // if square of z.r and z.i is more than 4,
                                                                             // then the point is outside the image
have two parts: real and imaginary. Usually, a complex                                        if((z.r * z.r + z.i * z.i) > 4) {
number is represented in the form, 'a + bi', where 'a' is the                                      outside = 1; break;
real part and 'b' is the imaginary part (the suffix 'i'                                       }
                                                                                         }
indicates that). A complex plane has real numbers in the x-                              // if the point is inside image, print ‘*’
axis and imaginary numbers in the y-axis.                                                printf(“%c”, outside ? ‘ ‘ : ‘*’);
    Given the complex numbers Z and C, the Mandelbrot                               }
                                                                                    printf(“n”); // move to next row
set is formed by the formula: Z = Z ** 2 + C. Here ** stands                    }
for square. C is the number we test to see if the number is                  }
inside or outside the set. We start Z from zero and keep
reassigning it as we change C, using this formula.                                When you run this program, you’ll get this output:
    Given a complex number a + bi, the formula for finding
the square of a complex number is: a**2 – b**2 + 2abi. So,                                               *
the real part is a**2 – b**2 and the imaginary part is 2*a*b.
                                                                                                   *
    With this background, here is the program to print the                                        ****
                                                                                                  ****
Mandelbrot set. The comments in the program explain the                                           ****
                                                                                                 ** *
programming steps required to find if a given number Z is                                     * **********
                                                                                              ******************
inside or outside the set.                                                                     *****************
                                                                                            * *****************
                                                                                             *******************
 struct complex { double r, i; } origin, z, c;                                              ***********************
                                                                                             *********************
                                                                                      * *** **********************
 int main() {                                                                         ******* **********************
                                                                                      ********* **********************
 // the incr value for c                                                              ********* **********************
    double incr = 0.05;                                                             ** ********* *********************
                                                                                  ************************************
    // image dimension is size * size characters                                    ** ********* *********************
    const int size = 60;                                                              ********* **********************
                                                                                      ********* **********************
 origin.r = -1.5; origin.i = -1.5;                                                    ******* **********************
                                                                                      * *** **********************
                                                                                             *********************
    for(int rows = 0; rows < size; rows++) {                                                ***********************
        // for each rwo, increase the value of c.i                                           *******************
                                                                                            * *****************
        c.i = origin.i + rows * incr;                                                          *****************
        for(int cols = 0; cols < size; cols++) {                                              ******************
                                                                                              * **********
             // for each row, increase the value for c.r                                         ** *
             c.r = origin.r + cols * incr;                                                        ****
                                                                                                  ****
                                                                                                  ****
             // initialize z to 0 and start again                                                  *
             z.r = 0; z.i = 0;
             // to check if the point is “outside”                                                *
             int outside = 0;
                                                                                  Quite interesting, isn’t it!
             // loop to check and set “outside”
             for(int i = 0; i < 100; i++) {
                  // calc z**2 + c
                  // z**2 = z.r**2 - z.i**2 + 2*z.r*z.i                      By: S.G. Ganesh is a research engineer in Siemens
                  complex temp;                                              (Corporate Technology). He has authored a book “Deep C”
                  temp.r = z.r * z.r - z.i * z.i + c.r;                      (ISBN 81-7656-501-6). You can reach him at
        temp.i = 2 * z.r * z.i + c.i;                                        sgganesh@gmail.com.


88     AUGUST 2007     |    LINUX FOR YOU          |   www.linuxforu.com



                                                                           CMYK

Weitere ähnliche Inhalte

Andere mochten auch (20)

Golf kurallari
Golf kurallariGolf kurallari
Golf kurallari
 
2003 - Promoting Youth Employment (A/58/229)
2003 - Promoting Youth Employment (A/58/229) 2003 - Promoting Youth Employment (A/58/229)
2003 - Promoting Youth Employment (A/58/229)
 
Lllllljeya
LllllljeyaLllllljeya
Lllllljeya
 
Opdracht 1
Opdracht 1Opdracht 1
Opdracht 1
 
Undersøgelse Af Teenagers Fritid
Undersøgelse Af Teenagers FritidUndersøgelse Af Teenagers Fritid
Undersøgelse Af Teenagers Fritid
 
Hiep Hiep
Hiep HiepHiep Hiep
Hiep Hiep
 
12 Jo P Dec 07
12 Jo P Dec 0712 Jo P Dec 07
12 Jo P Dec 07
 
Auto
AutoAuto
Auto
 
07 Jo P Jul 07
07 Jo P Jul 0707 Jo P Jul 07
07 Jo P Jul 07
 
Doc4
Doc4Doc4
Doc4
 
Card Pack Ad
Card Pack AdCard Pack Ad
Card Pack Ad
 
01 Jo P Jan 07
01 Jo P Jan 0701 Jo P Jan 07
01 Jo P Jan 07
 
Planeamiento Bimestral Xii
Planeamiento Bimestral XiiPlaneamiento Bimestral Xii
Planeamiento Bimestral Xii
 
Junio 2009
Junio 2009Junio 2009
Junio 2009
 
aJw Ailment Could Sideline Eating Champ
aJw Ailment Could Sideline Eating ChampaJw Ailment Could Sideline Eating Champ
aJw Ailment Could Sideline Eating Champ
 
Sabia Usted Que
Sabia Usted QueSabia Usted Que
Sabia Usted Que
 
Plains Wars
Plains WarsPlains Wars
Plains Wars
 
Tas1
Tas1Tas1
Tas1
 
In product growth hacking to increase revenue
In product growth hacking to increase revenueIn product growth hacking to increase revenue
In product growth hacking to increase revenue
 
HA Solutions for MySQL and MariaDB
HA Solutions for MySQL and MariaDBHA Solutions for MySQL and MariaDB
HA Solutions for MySQL and MariaDB
 

Ähnlich wie 09 Jo P Sep 07

c# Write an application that displays the following patterns separatel.docx
c# Write an application that displays the following patterns separatel.docxc# Write an application that displays the following patterns separatel.docx
c# Write an application that displays the following patterns separatel.docx
gilliandunce53776
 
#include deck.h .pdf
#include deck.h .pdf#include deck.h .pdf
#include deck.h .pdf
agarvalcollections16
 
(In java language)1. Use recursion in implementing the binarySearc.pdf
(In java language)1. Use recursion in implementing the binarySearc.pdf(In java language)1. Use recursion in implementing the binarySearc.pdf
(In java language)1. Use recursion in implementing the binarySearc.pdf
rbjain2007
 
MIS 4310-01 Final Take Home Exam (100 points) DUE Thursd.docx
MIS 4310-01 Final Take Home Exam (100 points) DUE  Thursd.docxMIS 4310-01 Final Take Home Exam (100 points) DUE  Thursd.docx
MIS 4310-01 Final Take Home Exam (100 points) DUE Thursd.docx
raju957290
 
Please do Part A, Ill be really gratefulThe main.c is the skeleto.pdf
Please do Part A, Ill be really gratefulThe main.c is the skeleto.pdfPlease do Part A, Ill be really gratefulThe main.c is the skeleto.pdf
Please do Part A, Ill be really gratefulThe main.c is the skeleto.pdf
aioils
 
Part I.pdf
Part I.pdfPart I.pdf
Part I.pdf
support58
 
PLEASE complete in java codes A program that pops open an .pdf
PLEASE complete in java codes   A program that pops open an .pdfPLEASE complete in java codes   A program that pops open an .pdf
PLEASE complete in java codes A program that pops open an .pdf
kitty811
 
DiceSimulatorProgram
DiceSimulatorProgramDiceSimulatorProgram
DiceSimulatorProgram
Amy Baxter
 
The Morse code (see Table 6.10 in book) is a common code that is use.pdf
The Morse code (see Table 6.10 in book) is a common code that is use.pdfThe Morse code (see Table 6.10 in book) is a common code that is use.pdf
The Morse code (see Table 6.10 in book) is a common code that is use.pdf
bhim1213
 
WHAT TO DOUpdate the comment boxes at the top of each function in.pdf
WHAT TO DOUpdate the comment boxes at the top of each function in.pdfWHAT TO DOUpdate the comment boxes at the top of each function in.pdf
WHAT TO DOUpdate the comment boxes at the top of each function in.pdf
adityavision1
 
Implementation of k-means clustering algorithm in C
Implementation of k-means clustering algorithm in CImplementation of k-means clustering algorithm in C
Implementation of k-means clustering algorithm in C
Kasun Ranga Wijeweera
 
Q1 Consider the below omp_trap1.c implantation, modify the code so t.pdf
Q1 Consider the below omp_trap1.c implantation, modify the code so t.pdfQ1 Consider the below omp_trap1.c implantation, modify the code so t.pdf
Q1 Consider the below omp_trap1.c implantation, modify the code so t.pdf
abdulrahamanbags
 
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
Adamq0DJonese
 

Ähnlich wie 09 Jo P Sep 07 (20)

Microsoft word java
Microsoft word   javaMicrosoft word   java
Microsoft word java
 
c# Write an application that displays the following patterns separatel.docx
c# Write an application that displays the following patterns separatel.docxc# Write an application that displays the following patterns separatel.docx
c# Write an application that displays the following patterns separatel.docx
 
Quiz using C++
Quiz using C++Quiz using C++
Quiz using C++
 
#include deck.h .pdf
#include deck.h .pdf#include deck.h .pdf
#include deck.h .pdf
 
(In java language)1. Use recursion in implementing the binarySearc.pdf
(In java language)1. Use recursion in implementing the binarySearc.pdf(In java language)1. Use recursion in implementing the binarySearc.pdf
(In java language)1. Use recursion in implementing the binarySearc.pdf
 
Java p1
Java p1Java p1
Java p1
 
MIS 4310-01 Final Take Home Exam (100 points) DUE Thursd.docx
MIS 4310-01 Final Take Home Exam (100 points) DUE  Thursd.docxMIS 4310-01 Final Take Home Exam (100 points) DUE  Thursd.docx
MIS 4310-01 Final Take Home Exam (100 points) DUE Thursd.docx
 
Please do Part A, Ill be really gratefulThe main.c is the skeleto.pdf
Please do Part A, Ill be really gratefulThe main.c is the skeleto.pdfPlease do Part A, Ill be really gratefulThe main.c is the skeleto.pdf
Please do Part A, Ill be really gratefulThe main.c is the skeleto.pdf
 
M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014
M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014
M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014
 
Part I.pdf
Part I.pdfPart I.pdf
Part I.pdf
 
PLEASE complete in java codes A program that pops open an .pdf
PLEASE complete in java codes   A program that pops open an .pdfPLEASE complete in java codes   A program that pops open an .pdf
PLEASE complete in java codes A program that pops open an .pdf
 
DiceSimulatorProgram
DiceSimulatorProgramDiceSimulatorProgram
DiceSimulatorProgram
 
The Morse code (see Table 6.10 in book) is a common code that is use.pdf
The Morse code (see Table 6.10 in book) is a common code that is use.pdfThe Morse code (see Table 6.10 in book) is a common code that is use.pdf
The Morse code (see Table 6.10 in book) is a common code that is use.pdf
 
WHAT TO DOUpdate the comment boxes at the top of each function in.pdf
WHAT TO DOUpdate the comment boxes at the top of each function in.pdfWHAT TO DOUpdate the comment boxes at the top of each function in.pdf
WHAT TO DOUpdate the comment boxes at the top of each function in.pdf
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
 
Implementation of k-means clustering algorithm in C
Implementation of k-means clustering algorithm in CImplementation of k-means clustering algorithm in C
Implementation of k-means clustering algorithm in C
 
Quick reference for sqoop
Quick reference for sqoopQuick reference for sqoop
Quick reference for sqoop
 
Q1 Consider the below omp_trap1.c implantation, modify the code so t.pdf
Q1 Consider the below omp_trap1.c implantation, modify the code so t.pdfQ1 Consider the below omp_trap1.c implantation, modify the code so t.pdf
Q1 Consider the below omp_trap1.c implantation, modify the code so t.pdf
 
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
 
Nesting of for loops using C++
Nesting of for loops using C++Nesting of for loops using C++
Nesting of for loops using C++
 

Mehr von Ganesh Samarthyam

Mehr von Ganesh Samarthyam (20)

Wonders of the Sea
Wonders of the SeaWonders of the Sea
Wonders of the Sea
 
Animals - for kids
Animals - for kids Animals - for kids
Animals - for kids
 
Applying Refactoring Tools in Practice
Applying Refactoring Tools in PracticeApplying Refactoring Tools in Practice
Applying Refactoring Tools in Practice
 
CFP - 1st Workshop on “AI Meets Blockchain”
CFP - 1st Workshop on “AI Meets Blockchain”CFP - 1st Workshop on “AI Meets Blockchain”
CFP - 1st Workshop on “AI Meets Blockchain”
 
Great Coding Skills Aren't Enough
Great Coding Skills Aren't EnoughGreat Coding Skills Aren't Enough
Great Coding Skills Aren't Enough
 
College Project - Java Disassembler - Description
College Project - Java Disassembler - DescriptionCollege Project - Java Disassembler - Description
College Project - Java Disassembler - Description
 
Coding Guidelines - Crafting Clean Code
Coding Guidelines - Crafting Clean CodeCoding Guidelines - Crafting Clean Code
Coding Guidelines - Crafting Clean Code
 
Design Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on ExamplesDesign Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on Examples
 
Bangalore Container Conference 2017 - Brief Presentation
Bangalore Container Conference 2017 - Brief PresentationBangalore Container Conference 2017 - Brief Presentation
Bangalore Container Conference 2017 - Brief Presentation
 
Bangalore Container Conference 2017 - Poster
Bangalore Container Conference 2017 - PosterBangalore Container Conference 2017 - Poster
Bangalore Container Conference 2017 - Poster
 
Software Design in Practice (with Java examples)
Software Design in Practice (with Java examples)Software Design in Practice (with Java examples)
Software Design in Practice (with Java examples)
 
OO Design and Design Patterns in C++
OO Design and Design Patterns in C++ OO Design and Design Patterns in C++
OO Design and Design Patterns in C++
 
Bangalore Container Conference 2017 - Sponsorship Deck
Bangalore Container Conference 2017 - Sponsorship DeckBangalore Container Conference 2017 - Sponsorship Deck
Bangalore Container Conference 2017 - Sponsorship Deck
 
Let's Go: Introduction to Google's Go Programming Language
Let's Go: Introduction to Google's Go Programming LanguageLet's Go: Introduction to Google's Go Programming Language
Let's Go: Introduction to Google's Go Programming Language
 
Google's Go Programming Language - Introduction
Google's Go Programming Language - Introduction Google's Go Programming Language - Introduction
Google's Go Programming Language - Introduction
 
Java Generics - Quiz Questions
Java Generics - Quiz QuestionsJava Generics - Quiz Questions
Java Generics - Quiz Questions
 
Java Generics - by Example
Java Generics - by ExampleJava Generics - by Example
Java Generics - by Example
 
Software Architecture - Quiz Questions
Software Architecture - Quiz QuestionsSoftware Architecture - Quiz Questions
Software Architecture - Quiz Questions
 
Docker by Example - Quiz
Docker by Example - QuizDocker by Example - Quiz
Docker by Example - Quiz
 
Core Java: Best practices and bytecodes quiz
Core Java: Best practices and bytecodes quizCore Java: Best practices and bytecodes quiz
Core Java: Best practices and bytecodes quiz
 

Kürzlich hochgeladen

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Kürzlich hochgeladen (20)

Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 

09 Jo P Sep 07

  • 1. The Joy of Programming Writing Beautiful Programs: S.G. GANESH ASCII Arts and Fractals—Part III In this column, we’ll look at how to draw the Mandelbrot set fractal using ASCII characters. I n most of the cases, writing fractal programs requires a z.r = temp.r; good knowledge of mathematics. The Mandelbrot set is z.i = temp.i; based on the theory and use of complex numbers. The Mandelbrot set is a collection of complex numbers, which // if square of z.r and z.i is more than 4, // then the point is outside the image have two parts: real and imaginary. Usually, a complex if((z.r * z.r + z.i * z.i) > 4) { number is represented in the form, 'a + bi', where 'a' is the outside = 1; break; real part and 'b' is the imaginary part (the suffix 'i' } } indicates that). A complex plane has real numbers in the x- // if the point is inside image, print ‘*’ axis and imaginary numbers in the y-axis. printf(“%c”, outside ? ‘ ‘ : ‘*’); Given the complex numbers Z and C, the Mandelbrot } printf(“n”); // move to next row set is formed by the formula: Z = Z ** 2 + C. Here ** stands } for square. C is the number we test to see if the number is } inside or outside the set. We start Z from zero and keep reassigning it as we change C, using this formula. When you run this program, you’ll get this output: Given a complex number a + bi, the formula for finding the square of a complex number is: a**2 – b**2 + 2abi. So, * the real part is a**2 – b**2 and the imaginary part is 2*a*b. * With this background, here is the program to print the **** **** Mandelbrot set. The comments in the program explain the **** ** * programming steps required to find if a given number Z is * ********** ****************** inside or outside the set. ***************** * ***************** ******************* struct complex { double r, i; } origin, z, c; *********************** ********************* * *** ********************** int main() { ******* ********************** ********* ********************** // the incr value for c ********* ********************** double incr = 0.05; ** ********* ********************* ************************************ // image dimension is size * size characters ** ********* ********************* const int size = 60; ********* ********************** ********* ********************** origin.r = -1.5; origin.i = -1.5; ******* ********************** * *** ********************** ********************* for(int rows = 0; rows < size; rows++) { *********************** // for each rwo, increase the value of c.i ******************* * ***************** c.i = origin.i + rows * incr; ***************** for(int cols = 0; cols < size; cols++) { ****************** * ********** // for each row, increase the value for c.r ** * c.r = origin.r + cols * incr; **** **** **** // initialize z to 0 and start again * z.r = 0; z.i = 0; // to check if the point is “outside” * int outside = 0; Quite interesting, isn’t it! // loop to check and set “outside” for(int i = 0; i < 100; i++) { // calc z**2 + c // z**2 = z.r**2 - z.i**2 + 2*z.r*z.i By: S.G. Ganesh is a research engineer in Siemens complex temp; (Corporate Technology). He has authored a book “Deep C” temp.r = z.r * z.r - z.i * z.i + c.r; (ISBN 81-7656-501-6). You can reach him at temp.i = 2 * z.r * z.i + c.i; sgganesh@gmail.com. 88 AUGUST 2007 | LINUX FOR YOU | www.linuxforu.com CMYK