SlideShare a Scribd company logo
1 of 1
Download to read offline
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

More Related Content

Viewers also liked (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
 

Similar to 09 Jo P Sep 07

Microsoft word java
Microsoft word   javaMicrosoft word   java
Microsoft word javaRavi Purohit
 
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.docxgilliandunce53776
 
Please answer in C! I provided my current code, my code is current.pdf
Please answer in C! I provided my current code, my code is current.pdfPlease answer in C! I provided my current code, my code is current.pdf
Please answer in C! I provided my current code, my code is current.pdfsupport58
 
(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.pdfrbjain2007
 
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.docxraju957290
 
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.pdfaioils
 
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 2014Supriya Radhakrishna
 
#include stdafx.h needed Libraries #include&lt;fstream&.pdf
#include stdafx.h needed Libraries  #include&lt;fstream&.pdf#include stdafx.h needed Libraries  #include&lt;fstream&.pdf
#include stdafx.h needed Libraries #include&lt;fstream&.pdfANGELMARKETINGJAIPUR
 
DiceSimulatorProgram
DiceSimulatorProgramDiceSimulatorProgram
DiceSimulatorProgramAmy Baxter
 
Please... I need help with this....Lanuage C++ (Beginner level).pdf
Please... I need help with this....Lanuage C++ (Beginner level).pdfPlease... I need help with this....Lanuage C++ (Beginner level).pdf
Please... I need help with this....Lanuage C++ (Beginner level).pdfarhamgarmentsdelhi
 
Computer graphics
Computer graphicsComputer graphics
Computer graphicssnelkoli
 
4. Magic SquaresOne interesting application of two-dimensional arr.pdf
4. Magic SquaresOne interesting application of two-dimensional arr.pdf4. Magic SquaresOne interesting application of two-dimensional arr.pdf
4. Magic SquaresOne interesting application of two-dimensional arr.pdfformaxekochi
 
1) Ask the user to input a character- You will draw your right triangl.docx
1) Ask the user to input a character- You will draw your right triangl.docx1) Ask the user to input a character- You will draw your right triangl.docx
1) Ask the user to input a character- You will draw your right triangl.docxdeant5
 
-- Program name- Midterm2 -- -- Description- This program reads a loca.docx
-- Program name- Midterm2 -- -- Description- This program reads a loca.docx-- Program name- Midterm2 -- -- Description- This program reads a loca.docx
-- Program name- Midterm2 -- -- Description- This program reads a loca.docxAdamq0DJonese
 
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 CKasun Ranga Wijeweera
 
parameterized constructorPlnArrayPlnA.pdf
parameterized constructorPlnArrayPlnA.pdfparameterized constructorPlnArrayPlnA.pdf
parameterized constructorPlnArrayPlnA.pdfpreetajain
 

Similar to 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
 
Please answer in C! I provided my current code, my code is current.pdf
Please answer in C! I provided my current code, my code is current.pdfPlease answer in C! I provided my current code, my code is current.pdf
Please answer in C! I provided my current code, my code is current.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
 
#include stdafx.h needed Libraries #include&lt;fstream&.pdf
#include stdafx.h needed Libraries  #include&lt;fstream&.pdf#include stdafx.h needed Libraries  #include&lt;fstream&.pdf
#include stdafx.h needed Libraries #include&lt;fstream&.pdf
 
DiceSimulatorProgram
DiceSimulatorProgramDiceSimulatorProgram
DiceSimulatorProgram
 
Please... I need help with this....Lanuage C++ (Beginner level).pdf
Please... I need help with this....Lanuage C++ (Beginner level).pdfPlease... I need help with this....Lanuage C++ (Beginner level).pdf
Please... I need help with this....Lanuage C++ (Beginner level).pdf
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
 
4. Magic SquaresOne interesting application of two-dimensional arr.pdf
4. Magic SquaresOne interesting application of two-dimensional arr.pdf4. Magic SquaresOne interesting application of two-dimensional arr.pdf
4. Magic SquaresOne interesting application of two-dimensional arr.pdf
 
1) Ask the user to input a character- You will draw your right triangl.docx
1) Ask the user to input a character- You will draw your right triangl.docx1) Ask the user to input a character- You will draw your right triangl.docx
1) Ask the user to input a character- You will draw your right triangl.docx
 
-- Program name- Midterm2 -- -- Description- This program reads a loca.docx
-- Program name- Midterm2 -- -- Description- This program reads a loca.docx-- Program name- Midterm2 -- -- Description- This program reads a loca.docx
-- Program name- Midterm2 -- -- Description- This program reads a loca.docx
 
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
 
parameterized constructorPlnArrayPlnA.pdf
parameterized constructorPlnArrayPlnA.pdfparameterized constructorPlnArrayPlnA.pdf
parameterized constructorPlnArrayPlnA.pdf
 

More from Ganesh Samarthyam

Applying Refactoring Tools in Practice
Applying Refactoring Tools in PracticeApplying Refactoring Tools in Practice
Applying Refactoring Tools in PracticeGanesh Samarthyam
 
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”Ganesh Samarthyam
 
Great Coding Skills Aren't Enough
Great Coding Skills Aren't EnoughGreat Coding Skills Aren't Enough
Great Coding Skills Aren't EnoughGanesh Samarthyam
 
College Project - Java Disassembler - Description
College Project - Java Disassembler - DescriptionCollege Project - Java Disassembler - Description
College Project - Java Disassembler - DescriptionGanesh Samarthyam
 
Coding Guidelines - Crafting Clean Code
Coding Guidelines - Crafting Clean CodeCoding Guidelines - Crafting Clean Code
Coding Guidelines - Crafting Clean CodeGanesh Samarthyam
 
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 ExamplesGanesh Samarthyam
 
Bangalore Container Conference 2017 - Brief Presentation
Bangalore Container Conference 2017 - Brief PresentationBangalore Container Conference 2017 - Brief Presentation
Bangalore Container Conference 2017 - Brief PresentationGanesh Samarthyam
 
Bangalore Container Conference 2017 - Poster
Bangalore Container Conference 2017 - PosterBangalore Container Conference 2017 - Poster
Bangalore Container Conference 2017 - PosterGanesh Samarthyam
 
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)Ganesh Samarthyam
 
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++ Ganesh Samarthyam
 
Bangalore Container Conference 2017 - Sponsorship Deck
Bangalore Container Conference 2017 - Sponsorship DeckBangalore Container Conference 2017 - Sponsorship Deck
Bangalore Container Conference 2017 - Sponsorship DeckGanesh Samarthyam
 
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 LanguageGanesh Samarthyam
 
Google's Go Programming Language - Introduction
Google's Go Programming Language - Introduction Google's Go Programming Language - Introduction
Google's Go Programming Language - Introduction Ganesh Samarthyam
 
Java Generics - Quiz Questions
Java Generics - Quiz QuestionsJava Generics - Quiz Questions
Java Generics - Quiz QuestionsGanesh Samarthyam
 
Software Architecture - Quiz Questions
Software Architecture - Quiz QuestionsSoftware Architecture - Quiz Questions
Software Architecture - Quiz QuestionsGanesh Samarthyam
 
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 quizGanesh Samarthyam
 

More from 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
 

Recently uploaded

UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UbiTrack UK
 
9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding TeamAdam Moalla
 
Empowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintEmpowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintMahmoud Rabie
 
UiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPathCommunity
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostMatt Ray
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024SkyPlanner
 
Cybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxCybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxGDSC PJATK
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfDianaGray10
 
Linked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesLinked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesDavid Newbury
 
How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?IES VE
 
Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsSeth Reyes
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IES VE
 
NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopBachir Benyammi
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Websitedgelyza
 
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsIgniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsSafe Software
 
Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024D Cloud Solutions
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemAsko Soukka
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureEric D. Schabell
 
Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Commit University
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1DianaGray10
 

Recently uploaded (20)

UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
 
9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team
 
Empowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintEmpowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership Blueprint
 
UiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation Developers
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024
 
Cybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxCybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptx
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
 
Linked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesLinked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond Ontologies
 
How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?
 
Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and Hazards
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
 
NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 Workshop
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Website
 
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsIgniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
 
Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystem
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability Adventure
 
Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
 

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