SlideShare uma empresa Scribd logo
1 de 1
Baixar para ler 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

Mais conteúdo relacionado

Destaque (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
 

Semelhante a 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
 
(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
 
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 .pdfkitty811
 
DiceSimulatorProgram
DiceSimulatorProgramDiceSimulatorProgram
DiceSimulatorProgramAmy 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.pdfbhim1213
 
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.pdfadityavision1
 
Computer graphics
Computer graphicsComputer graphics
Computer graphicssnelkoli
 
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
 
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.pdfabdulrahamanbags
 
-- 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.docxAdamq0DJonese
 
Nesting of for loops using C++
Nesting of for loops using C++Nesting of for loops using C++
Nesting of for loops using C++prashant_sainii
 

Semelhante a 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++
 

Mais de 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
 

Mais de 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
 

Último

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
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 AutomationSafe Software
 
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...Drew Madelung
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
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 Processorsdebabhi2
 
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 slidevu2urc
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
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 2024The Digital Insurer
 
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...Miguel Araújo
 
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.pptxHampshireHUG
 
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...Martijn de Jong
 

Último (20)

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
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
 
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...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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
 
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
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
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
 
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...
 
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
 
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...
 

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