SlideShare a Scribd company logo
The Joy of
Programming
Writing Beautiful Programs:
ASCII Arts and Fractals—Part I                                                                                                S.G. GANESH




Computer programs can be written for aesthetic purposes also. This column gives an introduction to
the basics of computer art using C, and is meant for students and novice programmers.



M
         ost of us associate C, or any other programming                    $ gcc tmp/hello.c ; ./a.out
         language for that matter, with serious coding.
         However, programs can also be written just for fun                 @    @    @ @ @   @           @        @ @ @ @
                                                                            @    @    @       @           @        @     @
or aesthetic purposes—like drawing interesting patterns or
                                                                            @ @ @ @   @ @ @   @           @        @     @
pictures.
                                                                            @    @    @       @           @        @     @
    ASCII art refers to drawing pictures using only ASCII
                                                                            @    @    @ @ @   @ @ @       @ @ @    @ @ @ @
code. (ASCII is the most widely used character-encoding
scheme for computers, and is based on letters of the
                                                                               What the program does is very simple. The




                                                                                                                                        GUEST COLUMN
English alphabet.) Much of ASCII art can be generated by
                                                                           “HELLO” character is encoded with hexadecimal
computer programs. To give you an introduction to the
                                                                           characters in the h array. It is a two-dimensional,
concept, I’ve written a small program that prints “HELLO”
                                                                           5 x 5 array, with each character to represent a bit
using the ‘@’ character:
                                                                           pattern of four bits each.
                                                                               The bit-mask array m has hex characters to
 int main() {
                                                                           represent the bits (fourth, third, second and first
     // encode the “Hello” string as hex numbers
     char h[5][5] = { { 0x9, 0xE, 0x8, 0x8, 0xF },
                                                                           bits) set so that they can be used to check with
                                     { 0x9, 0x8, 0x8, 0x8, 0x9 },          the bit-pattern in the character.
                                     { 0xF, 0xE, 0x8, 0x8, 0x9 },              We have to print five rows, bit-patterns for
                                     { 0x9, 0x8, 0x8, 0x8, 0x9 },          five characters (one each for the letters in
                                     { 0x9, 0xE, 0xE, 0xE, 0xF } };        “HELLO”) and four bits read the bit-pattern using
                                                                           the mask. The three nested loops do exactly that.
     // mask for reading the characters                                        This is a simple, straightforward program. If
     char m[4] = { 0x08, 0x04, 0x02, 0x01 };                               you go through it, I’m sure you can easily
                                                                           decipher the logic. The basic idea in this program
     int i = 0, j = 0, k = 0;
                                                                           is to use a multi-dimensional array to represent
                                                                           the bit-pattern and a mask array to decode it. In
     // for five rows with five characters each,
     // decode the hex numbers using the mask and print @
                                                                           this way, you can ‘programmatically’ represent
     do { // for five rows                                                 complicated ASCII art, and print it using simple
            j = 0;                                                         logic.
            do { // for five chars                                             You may have already used the banner command that
                     k = 0;                                                prints posters in large letters. Maybe you would want to
                     do {   // for four points                             find out how it works?
                              (h[i][j] & m[k]) ? printf(“ @”):                 In next month’s column, we’ll take a different approach
                                printf(“   “);                             and do something little more complex. We’ll draw
                     } while(++k < 4);
                                                                           ‘Sierpinksi triangle fractal’ using just a few lines of code
          } while(++j < 5);
                                                                           and simple logic using recursion/iteration.
          printf(“n”);
     } while(++i < 5);
 }                                                                          S.G. Ganesh is an engineer in Hewlett-Packard’s C++
                                                                            compiler team. He is also a member of the ANSI/ISO C++
   When you execute the program, you’ll see the following                   Standardization committee (JTC1/SC22/WG21).You can
“HELLO” banner on your screen:                                              reach him at sgganesh@gmail.com



                                                                                 www.linuxforu.com    |       LINUX FOR YOU   |   JULY 2007   87


                                                                    CMYK

More Related Content

What's hot

Teaching F#
Teaching F#Teaching F#
Teaching F#
Tomas Petricek
 
Pointers
 Pointers Pointers
Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++
Sikder Tahsin Al-Amin
 
Pointers_c
Pointers_cPointers_c
Pointers_c
ahmed safwat
 
Input output functions
Input output functionsInput output functions
Input output functionshyderali123
 
detailed information about Pointers in c language
detailed information about Pointers in c languagedetailed information about Pointers in c language
detailed information about Pointers in c language
gourav kottawar
 
Nand2 tetris 1and2
Nand2 tetris 1and2Nand2 tetris 1and2
Nand2 tetris 1and2
Shuya Osaki
 
Pointers
PointersPointers
Pointers
NabishaAK
 
Introduction to programming - class 11
Introduction to programming - class 11Introduction to programming - class 11
Introduction to programming - class 11
Paul Brebner
 
Introduction to c++
Introduction to c++Introduction to c++
Introduction to c++
somu rajesh
 

What's hot (10)

Teaching F#
Teaching F#Teaching F#
Teaching F#
 
Pointers
 Pointers Pointers
Pointers
 
Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++
 
Pointers_c
Pointers_cPointers_c
Pointers_c
 
Input output functions
Input output functionsInput output functions
Input output functions
 
detailed information about Pointers in c language
detailed information about Pointers in c languagedetailed information about Pointers in c language
detailed information about Pointers in c language
 
Nand2 tetris 1and2
Nand2 tetris 1and2Nand2 tetris 1and2
Nand2 tetris 1and2
 
Pointers
PointersPointers
Pointers
 
Introduction to programming - class 11
Introduction to programming - class 11Introduction to programming - class 11
Introduction to programming - class 11
 
Introduction to c++
Introduction to c++Introduction to c++
Introduction to c++
 

Similar to 07 Jo P Jul 07

Computer Graphics Concepts
Computer Graphics ConceptsComputer Graphics Concepts
Computer Graphics Concepts
SHAKOOR AB
 
Learn Creative Coding: Begin Programming with the Processing Language
Learn Creative Coding: Begin Programming with the Processing LanguageLearn Creative Coding: Begin Programming with the Processing Language
Learn Creative Coding: Begin Programming with the Processing Language
shelfrog
 
Learn Creative Coding: Begin Programming with the Processing Language
Learn Creative Coding: Begin Programming with the Processing LanguageLearn Creative Coding: Begin Programming with the Processing Language
Learn Creative Coding: Begin Programming with the Processing Language
W M Harris
 
Encrypted message transmitter on public network
Encrypted message transmitter on public networkEncrypted message transmitter on public network
Encrypted message transmitter on public network
Rowshina Nikzad
 
Console I/o & basics of array and strings.pptx
Console I/o & basics of array and strings.pptxConsole I/o & basics of array and strings.pptx
Console I/o & basics of array and strings.pptx
PRASENJITMORE2
 
C standard library functions
C standard library functionsC standard library functions
C standard library functions
Vaishnavee Sharma
 
A01
A01A01
A01
lksoo
 
CS150 Assignment 7 Cryptography Date assigned Monday.docx
CS150 Assignment 7 Cryptography  Date assigned Monday.docxCS150 Assignment 7 Cryptography  Date assigned Monday.docx
CS150 Assignment 7 Cryptography Date assigned Monday.docx
faithxdunce63732
 
1 ECE 175 Computer Programming for Engineering Applica.docx
1  ECE 175 Computer Programming for Engineering Applica.docx1  ECE 175 Computer Programming for Engineering Applica.docx
1 ECE 175 Computer Programming for Engineering Applica.docx
oswald1horne84988
 
Scala Sjug 09
Scala Sjug 09Scala Sjug 09
Scala Sjug 09
Michael Neale
 
Template Haskell
Template HaskellTemplate Haskell
Template Haskell
Sergey Stretovich
 
Is Haskell an acceptable Perl?
Is Haskell an acceptable Perl?Is Haskell an acceptable Perl?
Is Haskell an acceptable Perl?
osfameron
 
COm1407: Character & Strings
COm1407: Character & StringsCOm1407: Character & Strings
COm1407: Character & Strings
Hemantha Kulathilake
 
A Simple 3D Graphics Engine Written in Python and Allegro
A Simple 3D Graphics Engine Written in Python and AllegroA Simple 3D Graphics Engine Written in Python and Allegro
A Simple 3D Graphics Engine Written in Python and Allegro
snowfarthing
 
Applets - lev' 2
Applets - lev' 2Applets - lev' 2
Applets - lev' 2
Rakesh T
 

Similar to 07 Jo P Jul 07 (20)

08 Jo P Aug 07
08 Jo P Aug 0708 Jo P Aug 07
08 Jo P Aug 07
 
14 Jo P Feb 08
14 Jo P Feb 0814 Jo P Feb 08
14 Jo P Feb 08
 
01 Jo P Jan 07
01 Jo P Jan 0701 Jo P Jan 07
01 Jo P Jan 07
 
Computer Graphics Concepts
Computer Graphics ConceptsComputer Graphics Concepts
Computer Graphics Concepts
 
Learn Creative Coding: Begin Programming with the Processing Language
Learn Creative Coding: Begin Programming with the Processing LanguageLearn Creative Coding: Begin Programming with the Processing Language
Learn Creative Coding: Begin Programming with the Processing Language
 
Learn Creative Coding: Begin Programming with the Processing Language
Learn Creative Coding: Begin Programming with the Processing LanguageLearn Creative Coding: Begin Programming with the Processing Language
Learn Creative Coding: Begin Programming with the Processing Language
 
03 Jo P Mar 07
03 Jo P Mar 0703 Jo P Mar 07
03 Jo P Mar 07
 
Encrypted message transmitter on public network
Encrypted message transmitter on public networkEncrypted message transmitter on public network
Encrypted message transmitter on public network
 
C Programming
C ProgrammingC Programming
C Programming
 
Console I/o & basics of array and strings.pptx
Console I/o & basics of array and strings.pptxConsole I/o & basics of array and strings.pptx
Console I/o & basics of array and strings.pptx
 
C standard library functions
C standard library functionsC standard library functions
C standard library functions
 
A01
A01A01
A01
 
CS150 Assignment 7 Cryptography Date assigned Monday.docx
CS150 Assignment 7 Cryptography  Date assigned Monday.docxCS150 Assignment 7 Cryptography  Date assigned Monday.docx
CS150 Assignment 7 Cryptography Date assigned Monday.docx
 
1 ECE 175 Computer Programming for Engineering Applica.docx
1  ECE 175 Computer Programming for Engineering Applica.docx1  ECE 175 Computer Programming for Engineering Applica.docx
1 ECE 175 Computer Programming for Engineering Applica.docx
 
Scala Sjug 09
Scala Sjug 09Scala Sjug 09
Scala Sjug 09
 
Template Haskell
Template HaskellTemplate Haskell
Template Haskell
 
Is Haskell an acceptable Perl?
Is Haskell an acceptable Perl?Is Haskell an acceptable Perl?
Is Haskell an acceptable Perl?
 
COm1407: Character & Strings
COm1407: Character & StringsCOm1407: Character & Strings
COm1407: Character & Strings
 
A Simple 3D Graphics Engine Written in Python and Allegro
A Simple 3D Graphics Engine Written in Python and AllegroA Simple 3D Graphics Engine Written in Python and Allegro
A Simple 3D Graphics Engine Written in Python and Allegro
 
Applets - lev' 2
Applets - lev' 2Applets - lev' 2
Applets - lev' 2
 

More from Ganesh Samarthyam

Wonders of the Sea
Wonders of the SeaWonders of the Sea
Wonders of the Sea
Ganesh Samarthyam
 
Animals - for kids
Animals - for kids Animals - for kids
Animals - for kids
Ganesh Samarthyam
 
Applying Refactoring Tools in Practice
Applying Refactoring Tools in PracticeApplying Refactoring Tools in Practice
Applying Refactoring Tools in Practice
Ganesh 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 Enough
Ganesh Samarthyam
 
College Project - Java Disassembler - Description
College Project - Java Disassembler - DescriptionCollege Project - Java Disassembler - Description
College Project - Java Disassembler - Description
Ganesh Samarthyam
 
Coding Guidelines - Crafting Clean Code
Coding Guidelines - Crafting Clean CodeCoding Guidelines - Crafting Clean Code
Coding Guidelines - Crafting Clean Code
Ganesh 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 Examples
Ganesh Samarthyam
 
Bangalore Container Conference 2017 - Brief Presentation
Bangalore Container Conference 2017 - Brief PresentationBangalore Container Conference 2017 - Brief Presentation
Bangalore Container Conference 2017 - Brief Presentation
Ganesh Samarthyam
 
Bangalore Container Conference 2017 - Poster
Bangalore Container Conference 2017 - PosterBangalore Container Conference 2017 - Poster
Bangalore Container Conference 2017 - Poster
Ganesh 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 Deck
Ganesh 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 Language
Ganesh 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 Questions
Ganesh Samarthyam
 
Java Generics - by Example
Java Generics - by ExampleJava Generics - by Example
Java Generics - by Example
Ganesh Samarthyam
 
Software Architecture - Quiz Questions
Software Architecture - Quiz QuestionsSoftware Architecture - Quiz Questions
Software Architecture - Quiz Questions
Ganesh Samarthyam
 
Docker by Example - Quiz
Docker by Example - QuizDocker by Example - Quiz
Docker by Example - Quiz
Ganesh 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 quiz
Ganesh 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

AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 

Recently uploaded (20)

AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 

07 Jo P Jul 07

  • 1. The Joy of Programming Writing Beautiful Programs: ASCII Arts and Fractals—Part I S.G. GANESH Computer programs can be written for aesthetic purposes also. This column gives an introduction to the basics of computer art using C, and is meant for students and novice programmers. M ost of us associate C, or any other programming $ gcc tmp/hello.c ; ./a.out language for that matter, with serious coding. However, programs can also be written just for fun @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ or aesthetic purposes—like drawing interesting patterns or @ @ @ @ @ @ @ @ @ @ @ pictures. @ @ @ @ @ @ @ ASCII art refers to drawing pictures using only ASCII @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ code. (ASCII is the most widely used character-encoding scheme for computers, and is based on letters of the What the program does is very simple. The GUEST COLUMN English alphabet.) Much of ASCII art can be generated by “HELLO” character is encoded with hexadecimal computer programs. To give you an introduction to the characters in the h array. It is a two-dimensional, concept, I’ve written a small program that prints “HELLO” 5 x 5 array, with each character to represent a bit using the ‘@’ character: pattern of four bits each. The bit-mask array m has hex characters to int main() { represent the bits (fourth, third, second and first // encode the “Hello” string as hex numbers char h[5][5] = { { 0x9, 0xE, 0x8, 0x8, 0xF }, bits) set so that they can be used to check with { 0x9, 0x8, 0x8, 0x8, 0x9 }, the bit-pattern in the character. { 0xF, 0xE, 0x8, 0x8, 0x9 }, We have to print five rows, bit-patterns for { 0x9, 0x8, 0x8, 0x8, 0x9 }, five characters (one each for the letters in { 0x9, 0xE, 0xE, 0xE, 0xF } }; “HELLO”) and four bits read the bit-pattern using the mask. The three nested loops do exactly that. // mask for reading the characters This is a simple, straightforward program. If char m[4] = { 0x08, 0x04, 0x02, 0x01 }; you go through it, I’m sure you can easily decipher the logic. The basic idea in this program int i = 0, j = 0, k = 0; is to use a multi-dimensional array to represent the bit-pattern and a mask array to decode it. In // for five rows with five characters each, // decode the hex numbers using the mask and print @ this way, you can ‘programmatically’ represent do { // for five rows complicated ASCII art, and print it using simple j = 0; logic. do { // for five chars You may have already used the banner command that k = 0; prints posters in large letters. Maybe you would want to do { // for four points find out how it works? (h[i][j] & m[k]) ? printf(“ @”): In next month’s column, we’ll take a different approach printf(“ “); and do something little more complex. We’ll draw } while(++k < 4); ‘Sierpinksi triangle fractal’ using just a few lines of code } while(++j < 5); and simple logic using recursion/iteration. printf(“n”); } while(++i < 5); } S.G. Ganesh is an engineer in Hewlett-Packard’s C++ compiler team. He is also a member of the ANSI/ISO C++ When you execute the program, you’ll see the following Standardization committee (JTC1/SC22/WG21).You can “HELLO” banner on your screen: reach him at sgganesh@gmail.com www.linuxforu.com | LINUX FOR YOU | JULY 2007 87 CMYK