PDF How computers make books (meap v04): from graphics rendering, search algorithms, and functional

Page 1


HowComputersMakeBooks(MEAPV04):Fromgraphics rendering,searchalgorithms,andfunctional programmingtoindexingandtypesettingJohn

https://ebookmass.com/product/how-computers-make-booksmeap-v04-from-graphics-rendering-search-algorithms-andfunctional-programming-to-indexing-and-typesetting-john-

Instant digital products (PDF, ePub, MOBI) ready for you

Download now and discover formats that fit your needs...

Make Brilliant Work: From Picasso to Steve Jobs, How to Unlock Your Creativity and Succeed Rod Judkins

https://ebookmass.com/product/make-brilliant-work-from-picasso-tosteve-jobs-how-to-unlock-your-creativity-and-succeed-rod-judkins/

ebookmass.com

Health Professions and Academia-How to Begin Your Career (Jun 29, 2022)_(3030942228)_(Springer).pdf John Paul (J.P) Sánchez

https://ebookmass.com/product/health-professions-and-academia-how-tobegin-your-career-jun-29-2022_3030942228_springer-pdf-john-paul-j-psanchez/

ebookmass.com

Guide to Evaluation of Functional Ability: How Request, Interpet, and Apply

https://ebookmass.com/product/guide-to-evaluation-of-functionalability-how-request-interpet-and-apply/

ebookmass.com

East Asia, Latin America, and the Decolonization of Transpacific Studies 1st Edition

Chiara Olivieri

https://ebookmass.com/product/east-asia-latin-america-and-thedecolonization-of-transpacific-studies-1st-edition-chiara-olivieri/ ebookmass.com

The Project Manager's Guide to Mastering Agile: Principles and Practices for an Adaptive Approach, 2nd Edition

https://ebookmass.com/product/the-project-managers-guide-to-masteringagile-principles-and-practices-for-an-adaptive-approach-2nd-editioncharles-g-cobb/ ebookmass.com

Biological Science, Third Canadian Edition, 3rd edition

Scott Freeman Kim Quillin Lizabeth Allison Michael Black

Greg Podgorski Emily Taylor Jeff Carmichael Michael Harrington Joan C. Sharp

https://ebookmass.com/product/biological-science-third-canadianedition-3rd-edition-scott-freeman-kim-quillin-lizabeth-allisonmichael-black-greg-podgorski-emily-taylor-jeff-carmichael-michaelharrington-joan-c-sharp/ ebookmass.com

Strategic

Management: Concepts: Competitiveness and Globalization 12th Edition, (Ebook PDF)

https://ebookmass.com/product/strategic-management-conceptscompetitiveness-and-globalization-12th-edition-ebook-pdf/

ebookmass.com

Beyond Fintech: Bionic Banking Bernardo Nicoletti

https://ebookmass.com/product/beyond-fintech-bionic-banking-bernardonicoletti/

ebookmass.com

Disability in Practice: Attitudes, Policies, and Relationships

Adam Cureton

https://ebookmass.com/product/disability-in-practice-attitudespolicies-and-relationships-adam-cureton/

ebookmass.com

Employees’ Emotional Intelligence, Motivation & Productivity, and Organizational Excellence : A Future Trend in HRD 1st Edition

https://ebookmass.com/product/employees-emotional-intelligencemotivation-productivity-and-organizational-excellence-a-future-trendin-hrd-1st-edition-gagari-chakrabarti/

ebookmass.com

welcome

Thank you for purchasing the MEAP for HowComputersMakeBooks

This is not an ordinary textbook, or even an ordinary Manning book. Rather than teaching you about a particular technology, How Computers Make Books explains Computer Science through a series of interrelated sketches on the theme of book production. Whilst you won’t learn a new programming language or technology stack from this book, I hope you will learn a lot.

We’ll start right from the beginning, learning how to place dots of ink on the white page to make up the shapes of letters and numbers, learn about some of the history of printing and publishing, and see how the automation of computer programs can ease our workload. I hope you enjoy the journey.

Please be sure to post any questions, comments, or suggestions you have about the book in the liveBook discussion forum Your feedback is essential in developing the best book possible.

Whitington

1 A taste of book production

2 Putting marks on paper

3 Letter forms

4 Storing words

5 Looking and finding

6 Typing it in

7 Saving space

8 Doing sums

9 Grey areas 10 A typeface 11 Words to paragraphs

APPENDIXES

A Solutions

B Further reading

C Templates

A tasteofbookproduction

1

This chaptercovers

What thisbookisabout

Who thisbookisfor

Three littlepreviewstowhetyourappetite

Thisbookaimstogiveanintroductiontocomputersciencethroughaseriesofsketches highlightingaspectsofonecentraltheme:bookproduction.Ifyouarereadingaphysicalpaperbackcopyofthisbook,everythingfromthewriter’sthoughtsuptotheactof printingitwasdoneautomatically.IfyouarereadingthisbookasaneBook,ofcourse, thebookisstillinsidethecomputer.

Whatiscomputerscience?Isitjustprogramming?Isitreallyasciencelikephysics orchemistry,orisitjustabranchofmathematics?Orisitjustafancywayoftalking abouthowweusecomputers,andnotascienceatall?Wewilltrytoanswerthese questionsthroughtensketchesbasedaroundourtheme.

We’lllookatthescienceandmathematicsbehindeverythingfromfontstophotographs.Fromthetransmissionandstorageofdatatothelayoutofapage.From thelow-levelzeroesandonesofacomputer’smostbasicarithmetictotheinputand processingoftheworld’slanguages.Alongthewaywewilllearnaboutsomeoftheart andsciencebehindtypesettingandprintingfromtheearlycomputerera,andfrom thetimebeforecomputers.Ifthisappealstoyou,readon…

1.1 Whothisbookisfor,andwhatitisandisnot

Thisbookdoesnotpresupposeanythingbutgeneralknowledge.Itiswrittentobecomprehensibletoacuriousteenager,andinterestingtothoseofussailinggentlythrough middleage.Youmighthavenopriorinterestincomputerscience,ornotquiteknow whatitis–oryoumaybeaprofessionalorhobbyistprogrammerwhojustwishesto learnaboutbuildingelectronicdocuments.

Thisisnotatextbook.Itwillnotteachyouanewprogramminglanguageortechnology,andyoumayfinditdoesnotrelatetoyourprofessionalworkatall.Itshould, however,giveyouinsightintothewaysweusecomputerstoautomatehumanprocesses, howwemarshaldataandmathematicstodoourworkforus,andhowthepublishing industryusescomputerstobuildelectronicandphysicalbooks.

Thisbookisalittleunusual,butIhopethatwithanopenmindandasenseof curiosity,youmightfindthesameenjoymentinreadingitthatitsauthorfoundin writingit.Towhetyourappetite,let’slookatthreelittlepreviewsoflaterchapters.For each,we’llintroduceaproblem,andaskhowitmightbesolved.Youcanponderthese questionsbeforefindingouttheanswerslaterinthebook.

1.2Previews

Eachchapterinthisbookisalargelyself-containedexplorationofasingletopic–whilst wewillsometimesintroducewordsinanearlierchapterwhicharethenusedwithout explanationinalaterchapter,mostreaderscantakethechaptersinanyorder.Inthis section,wepreviewthreeofthechapters,givingyouatasteofwhatistocome.

Foreachofthesepreviews,we’llpresentaprobleminthefieldofpublishingandtry tothinkabouthowitmightbesolved.Howdowedrawlinesandcurvesonthegrid ofpixelsonourscreens?Howdoesthecomputerrepresentthelettersandformatting makingupthetextwewishtoprint?Howtoweprintsmoothtonedgreyscaleimages withonlyblackinkandwhitepaper?

1.2.1Pixels,linesandcurves

Whenwedrawapictureonapieceofpaperincrayonorpen,wechoosewhereto drawourlinesandshapes,andhowtofillthemin,andwesimplytranslatethatinto thecontinuousmovementofpenoverpaper.Thelinesaresmoothandunbroken. Whenweholdupourcameratotakeaphotographofalandscape,wearecapturing thereflectedlightofaworldfullofintricatedetail.Butwhenwewanttolookatsucha photographordrawingonacomputerortelevisionscreen,orwhenwewishtotransmit ittoanotherdeviceoranothercountry,wedonothavethecapacityfortheseinfinitelydetailedrepresentations.Wemustinsteadcreateagridofso-calledpixels(picture elements).Thesedays,suchpixelsarequitesmall,butmanyofuscanremembera timewhentheyweremuchlargerandblockier.Theprincipleisthesame,however: eachlineorcurveorfilling-inorphotographmustbeconvertedautomaticallyand painstakinglytogridsofcolouredblocks.Howdowedothis?

Figure1.1Linesofdifferingslope,representedusingpixels

Infigure1.1youcanseehowpatternsofpixelsforlinesofdifferingslopesappear. Doyourecognisetheseblockypatternsfromcomputerscreens–or,perhaps,from knitwearorembroidery?Figure1.2showshowwemightconvertafilledshape,inthis caseanampersandletterfromafont,intoapixelrepresentation.Firstusingblackand whiteonly,andthenshadesofgray.Canyouimaginehowthisprocessworks?

&Figure1.2Afilledshape,madeofjustblackandwhitepixels,andwithpixelsofvaryingshadesofgrey

Wemightalsothinkabouthowthisampersandshapewasformedinthefirstplace. Howdowerepresentthelinesandcurvesofeachletterofafont,andhowdoesthefont designerdrawtheminthefirstplace?Figure1.3showstheindividualcurvesandtheir endpointswhichmakeupthiscomplicatedshape.Suchpointsandcurvesmustbe designedmanuallyforeachofthehundredsofletters,numbersandsymbolsrequired –andagainforeachstylisticvariationofthefontsuchasboldoritalic.

Figure1.3Chainsofcurvesusedtodrawanampersand

Inchapters2and3,weaddressalltheseissues,andmore.

1.2.2 Markup

Whenwewritewithapenonpaper,formattingthedocumentiseasy.Ifwewantto makethetitlelarge,orunderlineit,ormakealistorputaboxaroundanimportant paragraph,wedoitnaturallyandeasily.Buthowdoweinstructacomputertodoit?In aword-processingprogramweusethemousetoselecttextandapplyastylelikebold oritalic.Butwhatisreallygoingoninsidethecomputer?Whatistheinternalrepresentationinamachinewhichcanonlyprocessnumbers,andnotthesehigher-level concepts?Howdowerepresentachangein typeface (font), typeshape, typethickness, orthe sizeofthe text?Let’slookatanexample:

SectionTitle

Thisisthe first paragraph,whichis important. Wecouldencodethesepiecesofformattingintheplaintext:

[!SectionTitle!

Thisisthe$first$paragraph,whichis*important*.]

Herewe’veused $ foritalic, * forbold, ! foratitle,and [ and ] toindicatethe paragraphshouldbeboxed.Buttherenowcomesaproblem.Whatdowedoifwe wishtousea $ or !,or [ or ] inthetextitself?Canyouthinkofasolution?Allwillbe revealedinchapter4.

1.2.3Greyareas

Figure1.4Woodblockprint.DerFormschneider (TheBlockcutter),1568.

Figure1.5Amezzotintprint“SunshineFallingon aDoor”,byDanishartistPeterIlsted(1861–1933)

Sometimes,weonlyhaveblackinkandwhitepaperavailable-eventodaysomenewspapersareinblackandwhite,someeBookreaderslikewise,andplentyofbookstoo,

including thisone.Inthepast,printingwithmultipleshadesofgraywassimplynotpossible.Evenbeforeprintingmachines,artwasreproducedusingprimitivetechniques suchasthewoodblockprint(figure1.4).Thisinvolvedcarvingtheimageintowood, dippingitininkandpressingitontopaper,likeachildwithhalfapotato.Forcenturies,artistsstruggledtorefinethistechniquefromoneinwhichshadesofgrayhad toberepresentedbythecarvingofsmalllinesorcross-hatchpatternsintothewood, intooneinwhichveryfineandconvincinggreyshadescouldbereliablyreproduced, asinthemezzotintoffigure1.5.

Wefacethesameproblemsintheageofmechanicalprinting.Figure1.6shows,at thetop,anidealizedgradientfromwhitetoblack,throughthegreys.Atthebottom isanapproximationproducedusingonlyblackinkandwhitepaperwhichmightbe suitableforprintingoncoarse,porouspaperlikenewsprint.Canyouworkouthow thispatternofdotsmighthavebeencalculated?

Wewilllookathistoricalandpresent-daygreyscaleimagereproductioninchapter9.

Summary

This bookintroducescomputersciencethroughtenlittlesketches,eachrelatedtothethemeofbookpublishing.

Wehavepreviewedsomeofthesesketchesinthischaptertostimulateyour imagination.

Read ontofindtheanswerstothequestionsposedinthischapter.

Figure1.6Agradientandits‘halftone’dots

This chaptercovers

2 Putting marksonpaper

Coordinates andunitsforplacingink onapageorpixelsonascreen

The physicalcharacteristicsofpaper, inkandcomputerscreens

Building linesandfillingshapes,using onlydots

Inthischapter,westartrightfromthebeginning:ablankpage,andsomemeansof placingmarksonit.Thismightbeblackinkonapieceofpaper,orpixelsonaphone, tablet,eBookreader,orcomputerscreen.Wewilllearnhowtochoosewheretoplace thesemarksonthepagetobuildlinesandfilledshapes.Thereby,wewillseehoweven complextextandgraphicsarecomposedofjusttheselittlemarks.

2.1Wherethingsgo

Inthisbook,weshallneedverylittleformalmathematics,butifweareconsideringthe arrangementoflettersandwordsandlinesandpicturesonthepage,weshallneeda wayofdiscussingtheideaofposition–thatistosay, where somethingis,ratherthan just what itis.Thankfully,ourpaperisflatandrectangular,sowecanusethesimple coordinateswelearnedinschool.Inotherwords,wejustmeasurehowfarweareabove thebottomleftcornerofthepage,andhowfartotheright.Wecanwritethisasapair

of numbers;forexample,thecoordinate(6,2)issixlengthsrightandtwolengthsup fromthebottom-leftofthepage.Itisconventiontouse x todenotetheacrosspartof thecoordinate,and y todenotetheuppart.Theseareknownas Cartesian coordinates, namedforfrenchmathematicianandphilosopherRenéDescartes(1596–1659)–the LatinformofhisnameisRenatusCartesius,whichisalittlecloserto“Cartesian”.The ideawasdiscoveredindependently,ataboutthesametime,byPierredeFermat(1607–1665).Figure2.1showsthecoordinate(6,2)drawnonagraph,withaxesfor x and y, andlittlemarksontheaxestomakeiteasiertojudgepositionbyeye.

Wecanassignunitsifwelike,suchascentimetresorinches,todefinewhatthese “lengths”are.Inpublishing,weliketousealittleunitcalleda point or pt,whichis1/72 ofaninch.Thisisconvenientbecauseitallowsustotalkmostlyusingwholenumbers (itiseasiertotalkabout450ptthanabout6.319inches).Weneedsuchsmallunits becausetheitemsonourpagearequitesmallandmustbecarefullypositioned(look atthewritingonthispage,andseehoweachtinylittleshaperepresentingacharacter issocarefullyplaced).Figure2.2showshowanA4page(whichisabout595ptswide andabout842ptstall)mightlook.

Chapter1

LoremIpsum

Loremipsumdolorsitamet,consectetueradipiscingelit.Utpuruselit,vestibulum ut,placeratac,adipiscingvitae,felis.Curabiturdictumgravidamauris.Namarcu libero,nonummyeget,consectetuerid,vulputatea,magna.Donecvehiculaaugue euneque.Pellentesquehabitantmorbitristiquesenectusetnetusetmalesuada famesacturpisegestas.Maurisutleo.Crasviverrametusrhoncussem.Nulla etlectusvestibulumurnafringillaultrices.Phaselluseutellussitamettortor gravidaplacerat.Integersapienest,iaculisin,pretiumquis,viverraac,nunc. Praesentegetsemvelleoultricesbibendum.Aeneanfaucibus.Morbidolornulla, malesuadaeu,pulvinarat,mollisac,nulla.Curabiturauctorsempernulla.Donec variusorciegetrisus.Duisnibhmi,congueeu,accumsaneleifend,sagittisquis, diam.Duisegetorcisitametorcidignissimrutrum. Namduiligula,fringillaa,euismodsodales,sollicitudinvel,wisi.Morbiauctor loremnonjusto.Namlacuslibero,pretiumat,lobortisvitae,ultricieset,tellus. Donecaliquet,tortorsedaccumsanbibendum,eratligulaaliquetmagna,vitae ornareodiometusami.Morbiacorcietnislhendreritmollis.Suspendisseut massa.Crasnecante.Pellentesqueanulla.Cumsociisnatoquepenatibuset magnisdisparturientmontes,nasceturridiculusmus.Aliquamtincidunturna. Nullaullamcorpervestibulumturpis.Pellentesquecursusluctusmauris. Nullamalesuadaporttitordiam.Donecfeliserat,conguenon,volutpatat, tincidunttristique,libero.Vivamusviverrafermentumfelis.Donecnonummy pellentesqueante.Phasellusadipiscingsemperelit.Proinfermentummassaac quam.Seddiamturpis,molestievitae,placerata,molestienec,leo.Maecenas lacinia.Namipsumligula,eleifendat,accumsannec,suscipita,ipsum.Morbi blanditligulafeugiatmagna.Nunceleifendconsequatlorem.Sedlacinianulla vitaeenim.Pellentesquetinciduntpurusvelmagna.Integernonenim.Praesent euismodnunceupurus.Donecbibendumquamintellus.Nullamcursuspulvinar lectus.Donecetmi.Namvulputatemetuseuenim.Vestibulumpellentesquefelis eumassa.

Figure2.2Apage,itscontents,anditsunits

Youcanseethatthechapterheading“Chapter1”beginsatabout(80,630).Notice thatthecoordinatesofthebottomleftofthepage(calledthe origin)are,ofcourse,

Figure2.1PlacingapointusingCartesiancoordinates

(0,0). Thechoiceofthebottomleftasouroriginissomewhatarbitrary–onecould makeanargumentthatthetopleftpoint,withverticalpositionsmeasureddownwards, isamoreappropriatechoice,atleastintheWestwherewereadtoptobottom.Of course,onecouldalsohavetheoriginatthetoprightorbottomright,withhorizontal positionsmeasuringleftward.

Weshallbeusingsuchcoordinatestodescribethepositionandshapeofeachpart ofeachletter,eachword,andeachparagraph,aswellasanydrawingsorphotographs tobeplacedonthepage.Wewillseehowlinescanbedrawnbetweencoordinates,and howtomaketheelegantcurveswhichformthelettersinatypeface(sometimescalled afont).

2.2Placingdots

Oncewehavedeterminedwhatshapeswewishtoputoneachpage,wemustconsider thefinalformofourdocument.Youmaybereadingthisasaphysicalpaperbackbook, printedandboundbyveryexpensiveequipment.Youmaybereadingitasanelectronic document(suchasaPDFfile)onyourcomputer,tablet,orsmartphone.Or,youmay bereadingitonsomesortofspecial-purposeeBookreader.Eachofthesescenarios hasdifferentcharacteristics.Everypageoftheprintedbookismadeupofhundredsof millionsoflittledots,eachofwhichmaybewhite(noink)orblack(ink).Wecannot typicallyseethedotswiththenakedeye.Thenumberofdotsinagivenspaceisknown asthe resolution (fromtheword“resolve”).Alowresolutionimageisonewhereitis easyfortheeyetoresolve(thatis,distinguish)theindividualdots.Ahighresolution imagehasdotssosmallandtightlypackedthatthenakedeyecannotdistinguishthem.

Ahighresolutionprinter,suchastheoneprintingthephysicalcopyofthisbook, mayhaveasmanyas600or1200dotsperinch(dpi);thatistosay,between600 × 600= 360,000and1200 × 1200=1,440,000dotspersquareinch.Thescreenofacomputer ortabletmayonlyhave100to300dpi,butitcandisplaymanyshadesofgreyand colours.Iftheresolutionistoolow,weseeblockyimages.Figure2.3showspartofa capitalletterAinblackandwhiteat60dpi,30dpi,and15dpi.

Wehaveusedsquaredotshere,suchasmaybeusedonamoderncomputerscreen (wecallthem pixels,whichisshortfor“pictureelements”).Forviewingapageona typicaltabletcomputer,wemighthaveonly2048 × 1536=5,193,728dotsonthewhole screen,buttheymaybecoloursorgreys,aswellasblackorwhite.Whenprintingabook likethis,wehavemanymoredots,butonlyblackink.Letussay,forexample,thatwe haveaUSLetterpage(8.5inchesby11inches)andweareprintingataresolutionof

Figure2.3Threedifferentresolutions

1200 dpi.Wehave1200 × 1200=1,440,000dotspersquareinch,sowehave1200 × 1200 × 8.5 × 11,or134,640,000dotsonthepage,eachofwhichmaybeblackorwhite.

Figure2.4showsphotographs,takenunderamicroscope,ofletteringasitappears inhighqualityprinting,andonthemuchlowerquality,cheapernewsprintusedfor thedailynewspaper.

Figure2.4Microscopepicturesofhighqualityprinting(upper)andnewsprint(lower)

Theupperrowshowshigh-resolutionprintingofletteringoncoatedpaper,suchas mightbeusedforaglossypamphlet,underamicroscopeat20xmagnification,and thesameat400xmagnification.ThelowerrowisstandardtextoftheLondonTimes printedonnewsprintat20xmagnificationandthesameat400xmagnification.

Thehomeorofficelaserprinterworksbyusingalasertopreparearollerinsuch awaythatapowderwilladhereonlytoareaswherethelaserhasbeenshone.The powder(calledtoner)isthentransferredfromtherollertopaper,andbondedtoitby heat.Figure2.5showsthattheparticlesoftonerbehaveratherdifferentlyfromink.

Figure2.5Microscopepicturesoflaser-printedtext

On theleftisawordprintedin1pt,2pt,4pt,6pt,and8pttextunderamicroscope, withmagnificationat20x.Ontheright,the2ptwordwithmagnificationat400x(a typefaceofagivensizeisroughlythatnumberofpointstall,say,foritscapitalletters.)

Allthesedotsformahugeamountofinformationwhichiscostlyanddifficultto manipulate.So,wewillnormallystoreourpagesinamorestructuredway–some paragraphs,whicharemadeofwords,whicharemadeofletters,whicharedrawnfrom sometypeface,whichisdefinedusinglinesandcurves.Thehundredsofmillionsof dotswhichwillfinallymakeupthepageonlyexisttemporarilyastheimageisprinted, orplacedontothescreen.(Theexception,ofcourse,iswhenweusephotographs aspartofourpage–thecolourofeachdotiscapturedbythecamera,andwemust maintainitinthatform.)Untilrecentlythestorage,transmission,andmanipulation ofhighresolutionphotographswasasignificantproblem.Thestorage,transmission, andmanipulationofhighresolutionvideostillis–imaginehowmanylittlecoloured dotsmakeupastillimage,thenmultiplyby25or50imagespersecondforthe2hours (7200seconds)afeaturefilmlasts.

2.3Makinglines

Wehavetalkedonlyaboutsingledots.However,weshallneedlines,curves,andfilled shapestobuildourpage.Supposethatwewishtodrawaline.Howcanweworkout whichdotstopaintblacktorepresenttheline?Horizontalandverticallinesseemeasy –wejustputinkoneachdotinthatroworcolumn,forthewholelengthoftheline.If wewantathickerline,wecaninkmultiplerowsorcolumnseithersideoftheoriginal line.Buttherearemanyusefullinesotherthanthehorizontalandverticalones.To begin,weshallneedawaytodefinealine.Wecanjustusetwocoordinates–thoseof thepointsateitherend.Forexample,Figure2.6showstheline(1,1)—(6,3).

Figure2.6Alinedefinedbythecoordinatesofitstwoend-points

Inmathematics,wewouldusuallyconsideralinetobeofinfinitelength,andsothis isreallyaline segment,butweshalljustcallitaline.Noticethatthislinecouldequally bedefinedas(6,3)—(1,1).

Asafirststrategy,letustrycolouringinonedotineachcolumnfromcolumn1to column6,wherethelineispresent.Figure2.7showstheresultofchoosingthedot whosecentreisclosesttothelineineachcase.

Figure2.7Approximatingalinewithsixdots

Admittedly,thisdoesnotlookmuchlikealine.Butifwechooseahigherresolutionforalineofthesameslope,andsodrawmoreandsmallerdots,weseeabetter approximation,asshowsinFigure2.8.

Figure2.8Approximatingalinewitheighteendots

Now,youmaywonderwhywechosetodrawonedotineachcolumninsteadofone dotineachrow.Forexample,insteadofputtingonedotineachofthecolumnsfrom column1tocolumn6,wemightputonedotineachoftherowsfromrow1torow3, againchoosingtheoneinthatrownearesttheactualline.Forthisshallowline,doing sowouldleadtothemostunpleasantresultshowninFigure2.9.

Figure2.9Thewrongapproach:onedotperrow

Ifthelineissteeperthan45°,theconverseistrue(drawitonpapertosee).So, wechoosetoputoneblackdotineachrowinsteadofineachcolumninthiscase. Horizontalandverticallinesaresimplyspecialcasesofthisgeneralmethod–forthe verticalcasewedrawonedotineachrow;forthehorizontalcaseonedotineach column.Forthelineatexactly45°,thetwomethods(rowandcolumn)producethe sameresult.Figure2.10illustratesthesortsofpatternsofdotsweseeforlinesofvarious slopesusingthisimprovedprocedure.

Figure2.10Linesofdifferingslope

Thisimageis100dotstallandwide.Theresultsarenotterriblygood,fortworeasons.First,atlowresolutions,theindividualdotsareclearlyvisible.Moreover,the densityofthelinesvaries.Ahorizontalorverticallineoflength100willhave100dots overitslength,butthe45° linehas100dotsoveralengthofabout141(thediagonal ofasquarewithsidesoflength100is √2 × 100), andsoitsdensityofdotsislower,and itappearslessdark.

Whenweareusingascreen,ratherthanpaper,todisplayourline,wecantake advantageoftheabilitytousemorethanjustblackandwhite.Andso,wecanuse varyingshadesofgrey:dotswhicharerightonthelineareverydarkgrey,dotswhich arejustclosearelightergrey.Figure2.11showsalinedrawninthismanner,atthree scales.

Figure2.11Usingshadesofgreyforsmootherlines

Wecanseethatthelineissmootherthanwouldotherwisebethecase.Ifyouare readingthisbookonanelectronicdevice,youmaybeabletoseethiseffectonthetext orimageswithamagnifyingglass.Figure2.12showsanotherexample,withamore complex,filledshape,whichmightbeusedtorepresentanampersandcharacter.

&Figure2.12Ashapefilledfirstwithblackandwhitedots,andthenwithdotsofdifferingshadesofgrey

On theleftisanidealisedhighresolutionshape.Inthemiddle,justblackandwhite atalowerresolution.Ontheright,preparedfordisplayonascreensupportinggreyas wellasblackandwhite,atthesamelowerresolution.Thisuseofgreysisknownas antialiasing,sincethejaggededgesinlowresolutionlinesareknownas aliasing.Thisterm originatedinthefieldofsignalprocessingandisusedtodescribeproblemsstemming fromlow-resolutionversionsofhigh-resolutionsignals.Figure2.13isaphotograph, takenunderamicroscope,ofsuchanantialiasedlineonamoderncomputerscreen.

Theleftimageismagnified20x;therightimage400x.Therectangularshapesyou canseeintheimagesaretheseparateRed,Green,andBluesub-pixels,whichamodern LCDmonitorusestobuildupallthedifferentcoloursandgreysitmayneed(the monitormakesapicturebyemittinglightandRed,Green,andBluearetheprimary coloursoflight.)

Whatmightareasonableminimumresolutionbe?Tosimplify,let’sreturntothe scenariowhereweonlyhaveblackandwhitedots–noantialiasing.Theresolution requiredtomakethepagelooksmoothdependsonthedistanceatwhichthetypical viewerseesit.Foracomputerscreen,thismightbetwentyinches.Forasmartphone, eightinches.Forabillboard,twentyorfiftyfeet(ifyouhaveneverwalkedrightupto abillboardandlookedattheprinting,doso–itissurprisinglycoarse.)Thelimitof thehumanopticalsystem’sabilitytodistinguishthecolourofadjacentdots,ortheir existenceorabsence,isthedensityoflightsensitivecellsontheretina.Atadistance of12inches,adensityof600dotsperinchontheprintedpagemayberequired.For abillboard,wemayonlyneed20or50dotsperinch.Onascreen,antialiasingallows ustousealowerresolutionthanwemightotherwiseneed.

2.4Buildingshapes

Wehaveseenhowtodrawlinesbetweenpoints,andsowecanbuildshapesbychainingtogethermultiplelines.Forexample,thelines(1,1)—(10,1),(10,1)—(10,10), (10,10)—(1,10),and(1,10)—(1,1)formasquare(youcandrawitonpaperifyou wish).Wemightdefinethismoreconciselyas(1,1)—(10,1)—(10,10)—(1,10)—(1,1). However,ifwewishtoproduceafilledshape(suchasaletterinaword)wewould havetomakeitupfromlotsoflittlehorizontallinesorlotsoflittleverticalones,to

Figure2.13Anantialisedlineunderamicroscopeat20xand400xmagnifications

make surethateverydotwewantedtobecoveredwascovered.Weshouldliketoautomatethisprocess,soastoavoidmanuallyspecifyingeachpartofthefilledsection.

Forexample,Figure2.14showsachild’spictureofahouse,madefromseverallines.

Noticethatwehavebuiltthreedifferentsetsofjoined-uplines:onefortheoutline ofthehouse,andtwomore,oneforeachwindow.Consideringthebottom-leftdotto beat(0,0),theyare,infact,thesesetsoflines:

forthehouseoutline

(1,1)—(1,10)—(9,18)—(13,14)—(13,16)—(14,16)—(14,13)—(17,10)—(17,1)— (11,1)—(11,5)—(7,5)—(7,1)—(1,1)

fortheleftwindow

(3,10)—(6,10)—(6,7)—(3,7)—(3,10)

fortherightwindow

(12,10)—(15,10)—(15,7)—(12,7)—(12,10)

Now,wecanproceedtodesignamethodtofilltheshape.Foreachrowoftheimage, webeginontheleft,andproceedrightwardpixel-by-pixel.Ifweencounterablackdot, weremember,andenterfillingmode.Infillingmode,wefilleverydotblack,untilwe hitanotherdotwhichwasalreadyblack–thenweleavefillingmode.Seeinganother already-blackdotputsusbackintofillingmode,andsoon.

Figure2.14Asimpleoutlinepicture,builtfromlines
Figure2.15Fillingindividuallines

Figure2.15shows twohighlightedlines.Inthefirst,weentertheshapeonceatthe sideoftheroof,fillacross,andthenexititattherighthandsideoftheroof.Inthe second,wefillasection,exittheshapewhenwehitthedoorframe,enteritagainat theotherdoorframe–fillingagain–andfinallyexitit.Ifwefollowthisprocedurefor thewholeimage,thehouseisfilledasexpected.TheresultisshowninFigure2.16.

Theimageontheleftshowsthenewdotsingrey;thatontherightthefinalimage.Noticethatthewindowsanddoordidnotcauseaproblemforourmethod.In thischapter,wehaveconverteda vector graphic(thelistofcoordinatesmakingupthe house)intoa raster graphic(asetofcoloursforeachdotonthescreenorpaper).

Inthischapter,wehavelookedattheverybasicsofhowtoconvertdescriptionsof shapesintopatternsofdotssuitableforaprinterorscreen.Wehavealsoexplored someofthephysicalcharacteristicsofscreens,paper,andink.Inthenextchapter,we willconsiderthemorecomplicatedshapesneededtodrawlettersandnumbers,which consistnotonlyofstraightlines,butalsocurves.

Summary

Everypageofabooksuchasthisoneismadeupofahugenumberoftiny blackinkmarksplacedontowhitepaper,orahugenumberofpixels,each chosentobewhiteorblackorgrey.

Tomakesuchapage,wehavetoconvertvectordescriptionsoftheshapes (lettersanddrawings)intorasterform.

There aremethodsforconvertinglinestorasterform,andforfillingshapes madefromsuchlines.

Figure2.16Thewholefilledhouse

Problems

Solutions onpage139. Gridsforyoutophotocopyorprintouthavebeenprovidedon page161.Alternatively,usegraphpaperordrawyourowngrids.

1 Givesequencesofcoordinateswhichmaybeusedtodrawthesesetsoflines.

2 Draw thesetwosequencesofcoordinatesonseparate20x20grids,withlines betweenthepoints.Whatdotheyshow?

(5,19)—(15,19)—(15,16)—(8,16)—(8,12)—(15,12)—(15,9)—(8,9)— (8,5)—(15,5)—(15,2)—(5,2)—(5,19)

(0,5)—(10,10)—(5,0)—(10,3)—(15,0)—(10,10)—(20,5)—(17,10)— (20,15)—(10,10)—(15,20)—(10,17)—(5,20)—(10,10)—(0,15)—(3,10)— (0,5)

3 Giventhefollowinglineson20x20grids,selectpixelstoapproximatethem.

4 On 20x20grids,choosepixelstofillintoapproximatethefollowingcharacters.Keeptheminproportiontooneanother.

3Letter forms

This chaptercovers

The mathematicsofcomputer-generated curves

Building letteroutlinesfromsuchcurves

Drawingfilledshapesfromtheseoutlines

Wehavelearnedhowtobuildshapesfromstraightlinesandhowtodrawthoselines ontoascreenbuiltfrompixelsorontopaperusingink.Ifweonlyeverdrewourshapes atonesize,wecouldjustuseenoughtinylittlestraightlinestobuildupanyshape, includingcurvedones.However,wemightliketodrawourshapesatdifferentsizes,or displaythemondeviceswithdifferentso-calledresolutions(theremaybe1200dotsper inchonacommercialprinter,forexample,butonly200dotsperinchonacomputer screen).Wedon’treallywanttostoreahundredlittlelinesandtheircoordinatesto describeacircle–weshouldjustliketosay“acircleofradius20ptatcoordinates(200, 300)”,forexample.Inthischapter,wewilllearnhowtoconvertdescriptionslikethis intothesetsofinkdotsorpixelsneededtomakeupanimageonpaperorscreen.

3.1Straightandcurvedlines

Considertheshapeswhichmakeupaletterofatypeface– Palatino,forexample,which isdescribedinChapter10.Atypefaceisacollectionoflittleshapes,oneforeachletter, whicharearrangedonthepageinlines.Wemustbeabletoscalethemtodifferent

sizes (large,forexample,forchapterheadings,orsmallerforfootnotes).Theymost oftencontaincurvesaswellasstraightlines.ConsidertheletterC,whichhascurved parts.Figure3.1showstheeffectofincreasingthesizeofaletterCdesignedusingonly lines.

lines Figure3.2AletterCcomposedofonlystraight linesandcirculararcs

Thestraightlinessurvivescalingintact,butthecurvesarespoiled.Almostassimple asdrawinglines(atleastonpaper)isdrawingcircles–wecandothiswithapairof compasses.Figure3.2showshowwecouldusethesesectionsofcircles(orarcs)to buildourletterCinstead.Thissufficesonlyforsimpleletterforms.Imaginetryingto drawcomplicatedcurves,suchastheampersandcharactershowninFigure3.3,using justapairofcompasses.

&Circulararcsdon’thelpmuchhere(noteverycurveispartofacircle).Wewould needdozensifnotahundredpiecesofcirclestoaccuratelyfollowtheshapeofthe letter.Beforecomputers,thesolutionwasasetof frenchcurves,whichareshapedpieces ofwood,rubber,orplasticwhosecontoursarecomposedofcurvesofvaryingtightness. Figure3.4showsatypicalsetoffrenchcurves.Thecurvesaremanipulatedbymoving androtatingthem,untilanappropriatecontourisfoundforpartofthedesiredshape. Sometimesthisisdonebystartingwithpointsthroughwhichthecurvemustpass, makingiteasiertolineuptheforms.Acomplexcurvewillbemadeupbyusingseveral differentpartsofthefrenchcurves,makingsurethatthejoinsbetweenthechosen sectionsaresmooth.

Figure3.1AletterCcomposedofonlystraight
Figure3.3Alettershaperequiringmanycurves

Figure3.4Frenchcurves

Thecurvesectionsusedandpointspassedthroughcanberecorded,sothatthe shapemaybereproduced.Suchcurvesarenolongerusedbydraughtsmen,whouse computersinstead,buttheyarestillusedby,forexample,dressmakers.Alarger,less tightlycurvedsetofshapeswereformerlyusedforthedesignofboathulls.Theyare knownasshipcurves.

3.2Computerisedcurves

Howmightweapplythesetechniquestocomputeriseddrawing?TwoFrenchmenin thecarindustry,PierreBézier(1910–1999)atRenaultandPauldeCasteljau(1930–2022)atCitroën,areresponsibleforthedevelopmentofakindofcurvewhichiseasy andpredictableforthedesignertoworkwith,canbeusedtodescribemanyuseful sortsofshapes,andisamenabletomanipulationanddisplaybycomputer.Theyare knownasBéziercurves.

Wehaveseenthatastraightlinemaybedefinedsimplybyitstwoend-points,for example(1,3)—(6,5).ABéziercurveisdefinedbyfourpoints:itstwoend-points, andtwootherpointscalled controlpoints,oneforeachend-point.Thesecontrolpoints, whichmaybepositionedanywhere,areusedtopullthecurveawayfromthestraight linebetweentheend-points.Thefurtherawaythecontrolpoints,themorethecurve deviatesfromthestraightlinebetweenitsend-points.Figure3.5exhibitsseveralBézier

curves.(Wehaveshownthecontrolpointslinkedtotheirrespectiveend-pointswith dottedlines.)

NotethataBéziercurvemaybendonewayortwo,andthatitmayalsobestraight. Thedesignercanmovethecontrolpointsinteractivelytobuildawiderangeofcurved lines.Ifyouhaveaccesstoaninteractivegraphicsprogramonyourcomputer,tryusing ittoplaywiththecontrolpointsofaBéziercurve.

Thecurveswehavemadearestilltoosimpletobuildacomplicatedshape,such asourampersand.Tomakesuchshapes,westitchtogetheranumberofsuchcurves, makingsurethatanend-pointofonecurvecoincideswithanend-pointofthenext, formingachain.Figure3.6showsasetofsuchchainsforourampersand.Thereare threechainsofcurves,whichwecall paths,intheampersand:oneforthemainpart andoneeachforthetwo“holes”.Thereare58curves,ofwhich5arestraightlines.

Figure3.5SeveralBéziercurvesandtheircontrolpoints
Figure3.6Béziercurvechainstodrawanampersandcharacter

Note thatseveralofthesecurvesjoinverysmoothlytooneanother.Thisisamatter ofgettingthecontrolpointsforbothcurvesintherightplace:ifthecontrol-point associatedwiththeend-pointofonecurveisarrangedat180°tothecontrolpoint associatedwiththeend-pointofthenext,thejoinwillbesmooth,withnochangein slopeatthatpoint.Otherwise,therewillbeadefinitecorner.Iftheend-pointsoftwo adjacentcurvesinthesequencedonotcoincideatall,therewillbeagap.(Wecall suchcurvesdiscontinuous.)Figure3.7givesexamplesofdiscontinuous,continuous, andsmoothcontinuousBéziercurvepairs.

Figure3.7Discontinuous(upper),continuous(lowerleft),andsmoothcontinuous(lowerright)pairsof Béziercurves.Noticethecontrolpointsinthesmoothcontinuouscaseareat180°tooneanother.

HowcanwedrawaBéziercurveonthescreenorprintitonpaper?Itseemsmuch morecomplicatedthanthestraightlineswehavealreadydrawn.Itturnsout,though, thatthereisasimpleway:werepeatedlysplitupthecurveintosmallerandsmaller sections,untileachoneisalmostasflatasaline.Then,wecandraweachofthoselittle linesusingthemethodwedevelopedinChapter2.Howdoweperformsuchasubdivision?Wecouldpickequally-spacedpointsalongthelengthofthecurve.However, thiswouldusetoomanylineswherethecurveisopen,andtoofewwhenthecurveis tight.

Analgorithm(method),devisedbyDeCasteljau,issimpleenoughtodoonpaper, andproducesasubdivisionofthecurvewhichisappropriatetothetightnessofeach part.Considerthecurvewithend-pointsAandDandcontrolpointsBandCshown atthetopleftofFigure3.8.

Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.