100% found this document useful (2 votes)
63 views

Download Programming 101: Learn to Code Using the Processing Programming Language, 2nd Edition Jeanine Meyer ebook All Chapters PDF

Programming

Uploaded by

hilityive
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
63 views

Download Programming 101: Learn to Code Using the Processing Programming Language, 2nd Edition Jeanine Meyer ebook All Chapters PDF

Programming

Uploaded by

hilityive
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 65

Download Full Version ebook - Visit ebookmeta.

com

Programming 101: Learn to Code Using the


Processing Programming Language, 2nd Edition
Jeanine Meyer

https://ebookmeta.com/product/programming-101-learn-to-code-
using-the-processing-programming-language-2nd-edition-
jeanine-meyer/

OR CLICK HERE

DOWLOAD NOW

Discover More Ebook - Explore Now at ebookmeta.com


Instant digital products (PDF, ePub, MOBI) ready for you
Download now and discover formats that fit your needs...

Start reading on any device today!

The Essential Guide to HTML5: Using Games to Learn HTML5


and JavaScript 3rd Edition Jeanine Meyer

https://ebookmeta.com/product/the-essential-guide-to-html5-using-
games-to-learn-html5-and-javascript-3rd-edition-jeanine-meyer/

ebookmeta.com

C Programming Learn to Code 1st Edition Sisir Kumar Jena

https://ebookmeta.com/product/c-programming-learn-to-code-1st-edition-
sisir-kumar-jena/

ebookmeta.com

Programming for Absolute Beginners: Using the JavaScript


Programming Language 1st Edition Jonathan Bartlett

https://ebookmeta.com/product/programming-for-absolute-beginners-
using-the-javascript-programming-language-1st-edition-jonathan-
bartlett/
ebookmeta.com

Air B D Books One Three AirB D 1 3 Olivia Joy

https://ebookmeta.com/product/air-b-d-books-one-three-
airb-d-1-3-olivia-joy/

ebookmeta.com
Principles and Practice of Modern Chromatographics Methods
2nd Edition Kevin Robards

https://ebookmeta.com/product/principles-and-practice-of-modern-
chromatographics-methods-2nd-edition-kevin-robards/

ebookmeta.com

Networks of Stone Sculpture and Society in Archaic and


Classical Athens Cultural Interactions Studies in the
Relationship between the Arts Helle Hochscheid
https://ebookmeta.com/product/networks-of-stone-sculpture-and-society-
in-archaic-and-classical-athens-cultural-interactions-studies-in-the-
relationship-between-the-arts-helle-hochscheid/
ebookmeta.com

Additions to three minor works: i. The spiritual venality


or taxæ of the Church of Rome, ii. The venal indulgences
of the Church of Rome, iii. The Index of prohibited books
of Gregory xvi. 1st Edition Joseph Mendham.
https://ebookmeta.com/product/additions-to-three-minor-works-i-the-
spiritual-venality-or-taxa%c2%a6-of-the-church-of-rome-ii-the-venal-
indulgences-of-the-church-of-rome-iii-the-index-of-prohibited-books-
of-gregory-xvi-1st-e/
ebookmeta.com

New Frontiers in Environmental Toxicology 1st Edition Tanu


Jindal

https://ebookmeta.com/product/new-frontiers-in-environmental-
toxicology-1st-edition-tanu-jindal/

ebookmeta.com

Decision Sciences for COVID-19 1st Edition Said Ali Hassan

https://ebookmeta.com/product/decision-sciences-for-covid-19-1st-
edition-said-ali-hassan/

ebookmeta.com
Okinawan Women s Stories of Migration From War Brides to
Issei 1st Edition Johanna O. Zulueta

https://ebookmeta.com/product/okinawan-women-s-stories-of-migration-
from-war-brides-to-issei-1st-edition-johanna-o-zulueta/

ebookmeta.com
Programming 101
Learn to Code with the Processing
Language Using a Visual Approach
Second Edition

Jeanine Meyer
Programming 101: Learn to Code with the Processing Language Using a Visual
Approach
Jeanine Meyer
Mt Kisco, NY, USA

ISBN-13 (pbk): 978-1-4842-8193-2 ISBN-13 (electronic): 978-1-4842-8194-9


https://doi.org/10.1007/978-1-4842-8194-9

Copyright © 2022 by Jeanine Meyer


This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the
material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation,
broadcasting, reproduction on microfilms or in any other physical way, and transmission or information
storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now
known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with
every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an
editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the
trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not
identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to
proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication,
neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or
omissions that may be made. The publisher makes no warranty, express or implied, with respect to the
material contained herein.
Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: James Robinson-Prior
Development Editor: James Markham
Coordinating Editor: Jessica Vakili
Distributed to the book trade worldwide by Springer Science+Business Media New York, 1 NY Plaza,
New York, NY 10004. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail [email protected], or
visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is
Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware
corporation.
For information on translations, please e-mail [email protected]; for reprint,
paperback, or audio rights, please e-mail [email protected].
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and
licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales
web page at http://www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available to readers
on the Github repository: https://github.com/Apress/Programming-101. For more detailed information,
please visit http://www.apress.com/source-­code.
Printed on acid-free paper
To my family, who inspire and teach me.
Table of Contents
About the Author�����������������������������������������������������������������������������������������������������xv

About the Technical Reviewer�������������������������������������������������������������������������������xvii


Acknowledgments��������������������������������������������������������������������������������������������������xix

Introduction������������������������������������������������������������������������������������������������������������xxi

Chapter 1: Basics����������������������������������������������������������������������������������������������������� 1
Abstract����������������������������������������������������������������������������������������������������������������������������������������� 1
Programming Concepts���������������������������������������������������������������������������������������������������������������� 3
Programming Languages and Natural Languages������������������������������������������������������������������ 3
Values and Variables��������������������������������������������������������������������������������������������������������������� 3
Functions��������������������������������������������������������������������������������������������������������������������������������� 5
Specifying Positions and Angles���������������������������������������������������������������������������������������������� 6
Colors�������������������������������������������������������������������������������������������������������������������������������������� 7
Development Environment������������������������������������������������������������������������������������������������������ 7
Role of Planning���������������������������������������������������������������������������������������������������������������������� 8
Under the Covers�������������������������������������������������������������������������������������������������������������������������� 8
Processing Programming Features����������������������������������������������������������������������������������������������� 9
Processing Development Environment������������������������������������������������������������������������������������ 9
Functions������������������������������������������������������������������������������������������������������������������������������� 11
Angles������������������������������������������������������������������������������������������������������������������������������������ 12
Implementing Hello, World���������������������������������������������������������������������������������������������������������� 14
Implementing the Daddy Logo���������������������������������������������������������������������������������������������������� 22
Planning��������������������������������������������������������������������������������������������������������������������������������� 22
Daddy Logo Program������������������������������������������������������������������������������������������������������������� 25

v
Table of Contents

Things to Look Up����������������������������������������������������������������������������������������������������������������������� 29


How to Make This Your Own������������������������������������������������������������������������������������������������������� 29
What You Learned����������������������������������������������������������������������������������������������������������������������� 30
What’s Next��������������������������������������������������������������������������������������������������������������������������������� 31

Chapter 2: Interactions������������������������������������������������������������������������������������������� 33
Abstract��������������������������������������������������������������������������������������������������������������������������������������� 33
Note��������������������������������������������������������������������������������������������������������������������������������������� 33
Programming Concepts�������������������������������������������������������������������������������������������������������������� 35
Events������������������������������������������������������������������������������������������������������������������������������������ 35
Randomness�������������������������������������������������������������������������������������������������������������������������� 36
Displaying Images from Files������������������������������������������������������������������������������������������������ 36
Calculations, Including Built-in Functions����������������������������������������������������������������������������� 36
Looping���������������������������������������������������������������������������������������������������������������������������������� 37
Processing Programming Features��������������������������������������������������������������������������������������������� 37
Note��������������������������������������������������������������������������������������������������������������������������������������� 38
Under the Covers������������������������������������������������������������������������������������������������������������������������ 41
Polygon Sketch Operation Overview������������������������������������������������������������������������������������������� 42
Implementing the Polygon Sketch���������������������������������������������������������������������������������������������� 44
Planning��������������������������������������������������������������������������������������������������������������������������������� 44
Polygon Sketch Program������������������������������������������������������������������������������������������������������� 47
Coin-Toss Sketch Operation Overview���������������������������������������������������������������������������������������� 49
Implementing the Coin-Toss Sketch������������������������������������������������������������������������������������������� 52
Planning��������������������������������������������������������������������������������������������������������������������������������� 52
Things to Look Up����������������������������������������������������������������������������������������������������������������������� 56
How to Make This Your Own������������������������������������������������������������������������������������������������������� 56
What You Learned����������������������������������������������������������������������������������������������������������������������� 57
What’s Next��������������������������������������������������������������������������������������������������������������������������������� 58

vi
Table of Contents

Chapter 3: Animation Using Arrays and Parallel Structures����������������������������������� 59


Abstract��������������������������������������������������������������������������������������������������������������������������������������� 59
More on the Sketches����������������������������������������������������������������������������������������������������������������� 59
Programming Concepts�������������������������������������������������������������������������������������������������������������� 64
Animation������������������������������������������������������������������������������������������������������������������������������ 65
Logical Operations����������������������������������������������������������������������������������������������������������������� 65
Arrays������������������������������������������������������������������������������������������������������������������������������������ 65
Parallel Structures����������������������������������������������������������������������������������������������������������������� 66
Compound Statements���������������������������������������������������������������������������������������������������������� 66
Pseudorandom Processing���������������������������������������������������������������������������������������������������� 66
Processing Programming Features��������������������������������������������������������������������������������������������� 67
Caution���������������������������������������������������������������������������������������������������������������������������������������� 67
Implementing a Bouncing Ball���������������������������������������������������������������������������������������������������� 71
Planning��������������������������������������������������������������������������������������������������������������������������������� 71
Program��������������������������������������������������������������������������������������������������������������������������������� 72
Implementing a Set of Three Bouncing Balls������������������������������������������������������������������������������ 74
Planning��������������������������������������������������������������������������������������������������������������������������������� 74
Program��������������������������������������������������������������������������������������������������������������������������������� 74
Implementing Pentagon Bouncing���������������������������������������������������������������������������������������������� 76
Planning��������������������������������������������������������������������������������������������������������������������������������� 76
Implementing Bouncing Polygons����������������������������������������������������������������������������������������������� 78
Planning��������������������������������������������������������������������������������������������������������������������������������� 79
Program��������������������������������������������������������������������������������������������������������������������������������� 79
Under the Covers������������������������������������������������������������������������������������������������������������������������ 82
Things to Look Up����������������������������������������������������������������������������������������������������������������������� 82
How to Make This Your Own������������������������������������������������������������������������������������������������������� 83
What You Learned����������������������������������������������������������������������������������������������������������������������� 83
What’s Next��������������������������������������������������������������������������������������������������������������������������������� 84

vii
Table of Contents

Chapter 4: Classes�������������������������������������������������������������������������������������������������� 85
Abstract��������������������������������������������������������������������������������������������������������������������������������������� 85
Programming Concepts�������������������������������������������������������������������������������������������������������������� 86
Classes���������������������������������������������������������������������������������������������������������������������������������������� 86
Phases of Operations������������������������������������������������������������������������������������������������������������� 87
Tolerance or Margin��������������������������������������������������������������������������������������������������������������� 88
Processing Programming Features��������������������������������������������������������������������������������������������� 88
Classes���������������������������������������������������������������������������������������������������������������������������������� 88
Definition of Images, Rectangles, and Ellipses���������������������������������������������������������������������� 90
Dynamic Arrays��������������������������������������������������������������������������������������������������������������������� 90
Tolerance and OK-So-Far Coding������������������������������������������������������������������������������������������ 92
Bouncing Objects Overview�������������������������������������������������������������������������������������������������������� 92
Implementing the Bouncing Objects������������������������������������������������������������������������������������������� 94
Planning��������������������������������������������������������������������������������������������������������������������������������� 94
Program��������������������������������������������������������������������������������������������������������������������������������� 96
Make Path and Travel Path Overview���������������������������������������������������������������������������������������� 100
Implementing the Make Path and Travel Path�������������������������������������������������������������������������� 103
Planning������������������������������������������������������������������������������������������������������������������������������� 104
Program������������������������������������������������������������������������������������������������������������������������������� 105
Jigsaw Overview����������������������������������������������������������������������������������������������������������������������� 109
Implementing the Jigsaw��������������������������������������������������������������������������������������������������������� 111
Planning������������������������������������������������������������������������������������������������������������������������������� 111
Program������������������������������������������������������������������������������������������������������������������������������� 114
Under the Covers���������������������������������������������������������������������������������������������������������������������� 125
Things to Look Up��������������������������������������������������������������������������������������������������������������������� 126
How to Make This Your Own����������������������������������������������������������������������������������������������������� 126
What You Learned��������������������������������������������������������������������������������������������������������������������� 127
What’s Next������������������������������������������������������������������������������������������������������������������������������� 127

viii
Table of Contents

Chapter 5: More Interactions�������������������������������������������������������������������������������� 129


Abstract������������������������������������������������������������������������������������������������������������������������������������� 129
More on the Sketches��������������������������������������������������������������������������������������������������������������� 129
Programming Concepts������������������������������������������������������������������������������������������������������������ 130
Ballistic Motion�������������������������������������������������������������������������������������������������������������������� 130
Character (char) Data Type vs. String Data Type����������������������������������������������������������������� 131
Use of Files�������������������������������������������������������������������������������������������������������������������������� 131
Case Statement������������������������������������������������������������������������������������������������������������������� 131
Elapsed Time����������������������������������������������������������������������������������������������������������������������� 131
Regular Expressions������������������������������������������������������������������������������������������������������������ 132
Processing Programming Features������������������������������������������������������������������������������������������� 132
The char Data Type�������������������������������������������������������������������������������������������������������������� 132
The keyPressed Function, key, and keyCode����������������������������������������������������������������������� 133
Table Files���������������������������������������������������������������������������������������������������������������������������� 133
The Switch Statement��������������������������������������������������������������������������������������������������������� 133
The millis and Other Time Functions����������������������������������������������������������������������������������� 135
The match Function for Regular Expressions���������������������������������������������������������������������� 136
ArrayList������������������������������������������������������������������������������������������������������������������������������ 136
Under the Covers���������������������������������������������������������������������������������������������������������������������� 136
Slingshot Operation Overview��������������������������������������������������������������������������������������������������� 138
Implementing the Slingshot Sketch������������������������������������������������������������������������������������������ 139
Planning������������������������������������������������������������������������������������������������������������������������������� 139
Programming the Slingshot Sketch������������������������������������������������������������������������������������� 142
Snake Operation Overview�������������������������������������������������������������������������������������������������������� 151
Implementing the Snake Sketch����������������������������������������������������������������������������������������������� 153
Planning������������������������������������������������������������������������������������������������������������������������������� 154
Programming the Snake Sketch������������������������������������������������������������������������������������������ 155
Image Test Operation Overview������������������������������������������������������������������������������������������� 163
Implementing the Image Test���������������������������������������������������������������������������������������������� 166

ix
Table of Contents

Things to Look Up��������������������������������������������������������������������������������������������������������������������� 171


How to Make This Your Own����������������������������������������������������������������������������������������������������� 171
What You Learned��������������������������������������������������������������������������������������������������������������������� 172
What’s Next������������������������������������������������������������������������������������������������������������������������������� 172

Chapter 6: Images and Graphics�������������������������������������������������������������������������� 173


Abstract������������������������������������������������������������������������������������������������������������������������������������� 173
More on the Sketches��������������������������������������������������������������������������������������������������������������� 174
Programming Concepts������������������������������������������������������������������������������������������������������������ 176
Images As Arrays of Pixels�������������������������������������������������������������������������������������������������� 177
Case Statement������������������������������������������������������������������������������������������������������������������� 177
Pixel Processing������������������������������������������������������������������������������������������������������������������ 177
The beginShape and endShape Vertex Functions��������������������������������������������������������������� 178
Changing the Coordinate System���������������������������������������������������������������������������������������� 178
Hue-Saturation-Brightness Color Mode������������������������������������������������������������������������������ 179
Changing Image Sketch Overview��������������������������������������������������������������������������������������� 179
Implementing the Image Transformations�������������������������������������������������������������������������������� 187
Planning������������������������������������������������������������������������������������������������������������������������������� 187
Programming the Image Sketch����������������������������������������������������������������������������������������������� 188
Origami Flower Graphic Overview�������������������������������������������������������������������������������������������� 191
Planning������������������������������������������������������������������������������������������������������������������������������� 191
Implementing the Origami Flower Sketch�������������������������������������������������������������������������������� 192
Programming the Origami Flower��������������������������������������������������������������������������������������������� 194
Programming the Hexagon with HSB Color Mode�������������������������������������������������������������������� 197
Under the Covers���������������������������������������������������������������������������������������������������������������������� 203
Things to Look Up��������������������������������������������������������������������������������������������������������������������� 204
How to Make This Your Own����������������������������������������������������������������������������������������������������� 205
What You Learned��������������������������������������������������������������������������������������������������������������������� 206
What’s Next������������������������������������������������������������������������������������������������������������������������������� 206

x
Table of Contents

Chapter 7: Using Files for Making a Holiday Card������������������������������������������������ 207


Abstract������������������������������������������������������������������������������������������������������������������������������������� 207
Programming Concepts������������������������������������������������������������������������������������������������������������ 208
Files������������������������������������������������������������������������������������������������������������������������������������� 208
Libraries������������������������������������������������������������������������������������������������������������������������������ 209
Fonts������������������������������������������������������������������������������������������������������������������������������������ 209
Callbacks����������������������������������������������������������������������������������������������������������������������������� 210
Feedback to Users��������������������������������������������������������������������������������������������������������������� 210
Processing Programming Features������������������������������������������������������������������������������������������� 210
Use of the Sound Library����������������������������������������������������������������������������������������������������� 210
Making and Saving an Image of the Current Window��������������������������������������������������������� 211
Use of Java Input/Output Library����������������������������������������������������������������������������������������� 212
Subclasses�������������������������������������������������������������������������������������������������������������������������� 213
Show Fonts Sketch Operation Overview����������������������������������������������������������������������������������� 214
Implementing the Show Fonts Sketch�������������������������������������������������������������������������������������� 216
Programming the Show Fonts Sketch��������������������������������������������������������������������������������� 217
Make Card Sketch Operation Overview������������������������������������������������������������������������������������ 218
Implementing the Make Card Sketch���������������������������������������������������������������������������������������� 223
Planning������������������������������������������������������������������������������������������������������������������������������� 223
Programming the Make Card Sketch����������������������������������������������������������������������������������� 225
Under the Covers���������������������������������������������������������������������������������������������������������������������� 231
Things to Look Up��������������������������������������������������������������������������������������������������������������������� 232
How to Make This Your Own����������������������������������������������������������������������������������������������������� 232
What You Learned��������������������������������������������������������������������������������������������������������������������� 232
What’s Next������������������������������������������������������������������������������������������������������������������������������� 233

Chapter 8: Combining Videos, Images, and Graphics������������������������������������������� 235


Abstract������������������������������������������������������������������������������������������������������������������������������������� 235
Programming Concepts������������������������������������������������������������������������������������������������������������ 235
Video������������������������������������������������������������������������������������������������������������������������������������ 236
Copying a Video������������������������������������������������������������������������������������������������������������������� 236

xi
Table of Contents

Processing Programming Features������������������������������������������������������������������������������������������� 236


Video������������������������������������������������������������������������������������������������������������������������������������ 237
Classes and Subclasses������������������������������������������������������������������������������������������������������ 238
Under the Covers���������������������������������������������������������������������������������������������������������������������� 238
Family Collage Operation Overview������������������������������������������������������������������������������������������ 239
Implementing the Family Collage Sketch��������������������������������������������������������������������������������� 242
Planning������������������������������������������������������������������������������������������������������������������������������� 242
Programming the Family Collage Sketch���������������������������������������������������������������������������� 243
Things to Look Up��������������������������������������������������������������������������������������������������������������������� 252
How to Make This Your Own����������������������������������������������������������������������������������������������������� 252
What You Learned��������������������������������������������������������������������������������������������������������������������� 257
What’s Next������������������������������������������������������������������������������������������������������������������������������� 257

Chapter 9: Word Guessing Game�������������������������������������������������������������������������� 259


Abstract������������������������������������������������������������������������������������������������������������������������������������� 259
More on the Sketches��������������������������������������������������������������������������������������������������������������� 259
Programming Concepts������������������������������������������������������������������������������������������������������������ 262
Implementing an Existing Application��������������������������������������������������������������������������������� 262
Testing and Scaling Up�������������������������������������������������������������������������������������������������������� 262
Displaying the State of the Game���������������������������������������������������������������������������������������������� 263
Displaying Text�������������������������������������������������������������������������������������������������������������������������� 264
Processing Programming Features������������������������������������������������������������������������������������������� 264
Note������������������������������������������������������������������������������������������������������������������������������������� 265
Operation Overview������������������������������������������������������������������������������������������������������������������� 266
Implementing the Word Game Sketches����������������������������������������������������������������������������������� 270
Planning������������������������������������������������������������������������������������������������������������������������������� 270
Programming the Word Game Sketches������������������������������������������������������������������������������ 272
Things to Look Up��������������������������������������������������������������������������������������������������������������������� 286
How to Make This Your Own����������������������������������������������������������������������������������������������������� 287
What You Learned��������������������������������������������������������������������������������������������������������������������� 287
What’s Next������������������������������������������������������������������������������������������������������������������������������� 288

xii
Table of Contents

Chapter 10: 3D������������������������������������������������������������������������������������������������������ 289


Abstract������������������������������������������������������������������������������������������������������������������������������������� 289
Programming Concepts������������������������������������������������������������������������������������������������������������ 292
Processing Programming Features������������������������������������������������������������������������������������������� 293
Under the Covers���������������������������������������������������������������������������������������������������������������������� 303
Rolling Ball at Alhambra Operation Overview��������������������������������������������������������������������������� 303
Implementing the Rolling Ball at Alhambra������������������������������������������������������������������������������� 304
Planning������������������������������������������������������������������������������������������������������������������������������� 304
Programming the Rolling Ball at Alhambra������������������������������������������������������������������������� 305
Rotating Cube Operation Overview������������������������������������������������������������������������������������������� 310
Implementing the Rotating Cube���������������������������������������������������������������������������������������������� 310
Planning������������������������������������������������������������������������������������������������������������������������������� 310
Programming the Rotating Cube����������������������������������������������������������������������������������������� 312
Things to Look Up��������������������������������������������������������������������������������������������������������������������� 318
How to Make This Your Own����������������������������������������������������������������������������������������������������� 319
What You Learned��������������������������������������������������������������������������������������������������������������������� 321
What’s Next������������������������������������������������������������������������������������������������������������������������������� 321

Appendix A: Introduction to p5.js������������������������������������������������������������������������� 323


Getting Started Using p5.js������������������������������������������������������������������������������������������������������� 323
Overview of Examples�������������������������������������������������������������������������������������������������������������� 325
Implementing Daddy Logo�������������������������������������������������������������������������������������������������������� 327
Implementing Fearless Girls vs. the Bull����������������������������������������������������������������������������������� 331
Implementing Rainbow Helix���������������������������������������������������������������������������������������������������� 336
W
 hat’s Next������������������������������������������������������������������������������������������������������������������������������� 341

Index��������������������������������������������������������������������������������������������������������������������� 343

xiii
About the Author
Jeanine Meyer is Professor Emerita at Purchase College/
SUNY. Before Purchase, she taught at Pace University and
prior to that was a manager and research staff member
at IBM Research in robotics and manufacturing. She also
worked as a research consultant at IBM for educational grant
programs.
She was moved to create this book because of a general
wish to make programming less mysterious and more
appealing while featuring the challenges. She enjoys
spending time with favorite pictures and video clips as well as producing programs. The
chance for a new edition provided a reason to explore p5.js, tools for using JavaScript
with features from Processing.
She is the author of five books and coauthor of five more on topics ranging from
educational uses of multimedia, programming, databases, number theory, and origami.
She earned a PhD in computer science at the Courant Institute at New York University,
an MA in mathematics at Columbia, and an SB (the college used the Latin form) in
mathematics from the University of Chicago. Recently, she has given lectures, in-­person
and remotely, connecting origami, mathematics, and computer science as well as the
use and misuse of math in the news. She is a member of Phi Beta Kappa, Sigma Xi, the
Association for Women in Science, and the Association for Computing Machinery.
Jeanine is trying but remains a beginner at Spanish and piano.

xv
About the Technical Reviewer
Joseph McKay is an associate professor of new media. He primarily teaches new
directions in virtual space, programming for visual artists, intro to physical computing,
hacking the everyday, senior seminar, and web development.
Joe’s work is focused on interactive art games. He makes games that have their roots
in fine art but are also fun and easy to play. He is currently working on a VR art game
with innovative locomotion.

xvii
Acknowledgments
Much appreciation to the subjects of the illustrations in this book, starting with my father
(Joseph) and including my mother (Esther), Aviva, Grant, Liam, and especially Annika.
Thanks to my children, Aviva and Daniel, for the photography, video, and computer
graphics work.
My students, teaching assistants, and colleagues always provide ideas, stimulation,
feedback, and advice. Thanks especially to Irina Shablinsky for her efforts in teaching me
Processing and how to teach Processing and introducing me to Takashi Mukoda. Thanks
to David Jameson, whose comments and concerns made me produce the “Under the
Covers” section for each chapter.
Thanks to the crew at Apress/Springer Nature, including for the second edition
James Robinson-Prior, Jessica Vakili, Dulcy Nirmala, Krishnan Sathyamurthy, and others
I do not know by name. Much appreciation to the past technical reviewers, Massimo
Nardone and Takashi Mukoda, and the technical reviewer for this edition, Joe McKay,
who brought his considerable talent and experience to the task.

xix
Introduction
Processing is a programming language built on top of another programming language
called Java. To quote from the https://processing.org page, “Processing is a flexible
software sketchbook and a language for learning how to code within the context of the
visual arts.” The term for a program in Processing is sketch. However, Processing can be
used to create applications that are far more than static sketches. You can use Processing
to create dynamic, interactive programs. It is a great tool for learning programming.
Though Processing was created for visual artists, it serves a broad population of
people. In particular, at Purchase College/SUNY, Processing has been an excellent first
computer programming language for our computer science/mathematics majors and
minors. It also serves students across the college, who take our CS I course to satisfy
one of the general education requirements. This experience has been reported in other
places. Processing and this text also are appropriate for self-study.
The ten chapters in this book share a common design and structure. My goal is to
introduce you to programming, focusing on the Processing language. In each chapter, I
explain general programming concepts and specific Processing features through the use
of one or more specific examples. The code and files such as image files are combined
as zip files and available at https://github.com/Apress/Programming-­101. I hope the
examples are entertaining; the goal, however, is not for you to learn the specific examples
but instead understand the concepts and features. The way to learn programming is to
make these examples “your own” and to go on to do a lot of programming.
The introduction to each chapter starts with a brief description of the concepts
and programming features used and the examples; then you need to be patient while
I provide background. Each chapter includes a discussion of general “Programming
Concepts” prior to plunging into the details. These are not limited to the Processing
language but are present in most programming languages. Presenting the concepts in a
general way might help you if you are coming to this book knowing another language or
you hope to move on to another language someday.
Next, I describe the “Processing Programming Features” that are used to realize
those concepts and produce the examples. This section will have actual code in it and
maybe short examples. This is a spiral approach, going from the general to the specific.

xxi
Introduction

A section called “Under the Covers” describes what Processing is doing for us behind
the scenes and the relationship between Processing and Java. This section appears
in different places in each chapter. It might be of more interest for readers who know
something or want to know something about Java, but I urge everyone to give it at least a
quick scan.
I then provide an overview of each example, with screenshots showing the operation
of the program. Please note that in some cases, I have modified the programs to obtain
the screenshots. I then go on to describe the implementation of the example, which
contains a “Planning” and a “Program” section. The “Planning” section is where I
describe my thought process. Programs do not spring into existence—at least for me—
not like Mozart composing a symphony, which was said to emerge all at once from his
mind. It is an iterative process for most of us. This section contains a table indicating the
relationship of the functions. The “Program” section includes a table with one column
for code and another column with an explanation of that line of code. These tables are
long and are not meant to be read as poetry or fine literature. Instead, skip around. Use
the function relationship table. If you download the code and try it out, you can use this
section to improve your understanding of the program. The most critical step is to make
changes, and I provide suggestions in the “How to Make This Your Own” section. This
set of sections is repeated for each example.
A section titled “Things to Look Up” will contain a list of Processing features related to
the ones described in the chapter. Processing is a large language, and it is growing. I can
show you only a small subset of the features, and each feature is used in one way, perhaps
using default values. You can and should consult other references to learn more. You
can look things up in multiple ways. For example, you can go to the website at https://
processing.org/reference/ and just keep that open. Alternatively, if you want to look up
how to draw a rectangle in Processing, it can be efficient to enter “processing.org rectangle”
into Google (or another search engine) or the address field of browsers such as Chrome to
retrieve a list of possible sites. It is best to use “processing.org” because “processing” is a
common English word. You can try “Processing rectangle,” but you will need to skip over
some sites that have nothing to do with the Processing language.
Remember that the goal of this book is not to teach you how to make my examples,
from peanut-shaped bald men to my versions of certain games to rotating 3D cubes with
photos of my grandchild, but to help you understand how to make your own programs!
Make small changes and then large changes. Make your own programs! Chapters will
close with two more sections: a brief review, “What You Learned,” and “What’s Next.”

xxii
Introduction

The book also has an Appendix describing what is called p5.js. This is a way to
produce programs for the Web by providing a Processing Library to use with JavaScript.
The Processing organization also supplies an online editor.
You are welcome to look at the chapters in any order, but later examples do depend
on an understanding of concepts introduced earlier. Moreover, because one of the
main techniques of programming is to reuse code, there are many instances of later
examples copying parts of earlier examples. Do not be concerned: the tables in the
“Implementation” section contain complete programs. It is beneficial for your learning
process to recognize the repetition.
Please do take a pause in reading to explore, experiment, and, I repeat, make your
own programs. Learning how to program is critical for understanding how we function
in today’s world and the requirements and challenges of devising algorithms using logic
and data. Learning to program might help you get a job. However, the main thing that
drives me, and I hope will drive you, is that it is fun.

Enjoy,
Jeanine

xxiii
CHAPTER 1

Basics
Abstract
The goal of this chapter is to get you started. The programming example will be a static
drawing of two cartoonish figures, as shown in Figure 1-1. Be aware that the examples
in subsequent chapters will increase in complexity, as we will be producing programs
that are highly interactive and, possibly, involving random effects, reading files, and
exhibiting behavior based on various conditions.

1
© Jeanine Meyer 2022
J. Meyer, Programming 101, https://doi.org/10.1007/978-1-4842-8194-9_1
Chapter 1 Basics

Figure 1-1. Fat and skinny Daddy logos

The Daddy logo is a version of a drawing my father would make, often as his
signature on a letter or note or artwork. I hope that you will design or recall a drawing
or symbol that has meaning to you and makes you happy the same way this cartoonish
peanut-shaped, bald guy makes me.
We will need to do some work to start us off and get to the point that the coding
is clear, but it is not too difficult. The traditional first task in using any programming
language is to get the program to display the phrase “Hello, world.” This works well in
demonstrating several important concepts, including what happens if the programmer
makes certain types of errors. Because of the features built into Processing, you can
produce a pretty fancy version of “Hello, world.”
Be patient with me and with yourself. At the end of the chapter, you will be able to
implement your own Daddy logo.

2
Chapter 1 Basics

Programming Concepts
This section, included in each chapter, is to provide a general introduction to concepts.
I begin with comparing and contrasting programming languages with natural languages.

Programming Languages and Natural Languages


Programming languages have some similarities with natural languages, but they
also have significant differences. Programming languages are defined by rules just
as a natural language’s grammar defines what is proper English, Spanish, or other
language. A program contains statements of different types just as we find in English
(or Spanish, etc.), and there also are ways to construct compound statements.
Statements in programming languages contain terms and expressions involving terms.
In programming languages, programmers often come up with our own names for
things. The names must follow certain rules, but these are not unduly restrictive. This
is a difference from natural languages, in which we mainly use the official words of the
language, whereas in programming, we are extending the language all the time.
A more significant difference between programming languages and natural
languages is that the rules must be obeyed at all times when using programming
languages! Consider that we all frequently utter grammatically incorrect statements
when we speak and yet generally are understood. This is not the situation in
programming. The good news in the case of Processing, and certain other languages, is
that the Processing system generally indicates where an error occurs. The development
environments for Processing and other computer languages are themselves computer
programs, and they do not exhibit any impatience while we fix errors and try the
program again. I will give some examples of statements, right after I introduce the
concept of values and variables.

Values and Variables


Programming involves containers or buckets where we can store specific types of things
(values). These kinds (types) of things are called data types. The following are some
examples of data:

Int           integer (e.g., 10)


float         decimal value (e.g., 5.3)

3
Chapter 1 Basics

Boolean       logical values (e.g., true/false)


Char          single character (e.g., 'a')
String        a string of characters (e.g., "hello world")

String should start with a capitalized “S”. The B in Boolean can be upper or
lowercase. The data type is named for George Boole, an English mathematician credited
with originating symbolic algebra.
Our programs can include literal values such as 5, 100.345, and “Hello” in the
code. In addition, a feature in all programming languages is what is termed variables.
A variable is a construct for associating a name of our choosing with a value. We can
initialize the variable, change it, and use it in an expression; that is, the value associated,
often termed in the variable, can vary, that is, change. Using variables makes our
programs less mysterious. Moreover, we can define one variable in terms of another,
making relationships explicit and preventing certain errors. In Processing, Java, and
some, but not all, programming languages, variables need to be declared, or set up
before use. One characteristic of variables is termed scope, which indicates what code
has access (e.g., global variables vs. local variables), but that is best explained later.
The following are examples of Processing statements. Explanation is given in
comments and later.

int classSize; // this declares, that is, sets up classSize to


                // be a variable.
classSize = 21; //assigns the value 21 to the variable classSize.
classSize = classSize + 5; //takes whatever is the current value held in
               // the variable classSize
               // and adds 5 to it and resets classSize to the new value
float score = 0; //declares the variable score AND
                 // assigns it a value. This is called initialization.
if (score == 0) {
      text("You did not score anything.", 100,100);
      text("Try again.", 100,300);
}

The // indicates that the rest of the line is a comment, meaning that Processing
ignores it. It is intended for readers of the code, including you, to make things clear. You
also can use the delimiters /* and */ for long comments.

4
Chapter 1 Basics

Note
My examples, because they are surrounded by explanations, tend not to have as many
comments as I would use outside of teaching and writing books.
There are rules for variable and function names in all programming languages.
Generally, they must start with a letter, uppercase or lowercase, and cannot contain
spaces. The most important guidance for naming is that the names should have meaning
for you. The programming language will accept single character names or names with no
apparent meaning, but these will not be helpful when you are trying to recall what you
were trying to do. So-called camel casing, as in classSize, can be helpful.
A single equal sign (=) means assignment and is used in what are called, naturally
enough, assignment statements and initialization statements. The statement

classSize = classSize + 5;

will seem less illogical if you read it as

classSize is assigned or gets the total of the current value of


classSize plus 5.

A double equal sign (==) is a comparison operator and often appears in an if


statement. Think of it as like < or <=.
The if statement is an example of a compound statement. The expression score ==
0 is interpreted as a comparison. If the value of the variable score is equal to zero, then
the statement within the brackets is executed. If the value of score is greater than zero
or less than zero, nothing happens. Again, you will see many more statements in the
context of examples.

Functions
Programming work in any language is structured into units. One important way of
structuring code comes with different names: function, procedure, subroutine, method.
These are ways of packaging one or more statements into one unit. You will read about
functions in the “Processing Programming Features” section and methods in the “Under
the Covers” section. Briefly, functions are defined, and functions are invoked. I can give you
directions , perhaps orally, perhaps by text, to my house, which is analogous to defining a
function. At that point, I am not directing you to come to my house. At some later time, I can
direct you to go to my house, and this is analogous to invoking the function.

5
Chapter 1 Basics

Programs can be considerably shorter as well as easier to modify through the use of
functions and variables, so understanding both of these concepts is important. You do
not need to accept this or understand this right now. It will be demonstrated later by my
sketch for displaying two Daddy logos that takes just one statement more than displaying
the Daddy logo just once.

Specifying Positions and Angles


Displaying drawings and images and text on the screen requires a coordinate system.
The coordinate system used by most computer languages and many graphical tools
is similar to what we learned (but might or might not remember) from high school
geometry, with one big difference. Horizontal positions, sometimes called x positions,
are specified starting from the left. Vertical positions, sometimes called y, are specified
starting from the top of the screen. Figure 1-2 shows the coordinate system with a small
circle at the 100, 200 location.

Figure 1-2. Coordinate system

If you say to yourself “This is upside down,” then I know you understood. Another
important point is that the unit is very small, so if your code positions something at
100, 200 and later at 101, 201, you probably will not detect the difference. Your intuition
regarding this will improve with experience.

6
Chapter 1 Basics

Note
As a teaser, Processing has facilities for 3D as well as 2D. We get to 3D in later chapters.
In this chapter, my Daddy logo has a smile made by specifying an arc of an ellipse. To
produce the arc, I need to write code to indicate a starting angle and an ending angle of
the arc. The system used in most computer languages is not the standard one in which
a right angle is 90 degrees, a U-turn is a 180, and snowboarders do 1800s. (I am writing
this during the Olympics, and yes, snowboarders did tricks measuring 1800 and bigger.)
It might be upsetting to realize this, but the notion of degrees with a circle consisting of
360 degrees was invented by people. I typically offer my students extra credit to identify
where and when this happened. Instead, in most programming languages, we use a
measure called radians. Think of wrapping a circle with lengths equal to one radius. How
many lengths will this take? You know the answer: It is not a whole number, it is 2 times
π, where π is an irrational number often approximated by 3.14159. In our programming,
we will use the built-in values TWO_PI, PI, HALF_PI, and QUARTER_PI. You will see
radians in use, so be patient.

Colors
There are different ways to specify colors in computer languages and computer
applications, and Processing supports more than one. In this text, we stick with
grayscale and RGB (red/green/blue). Because of how these values are stored, the range
of grayscale is from 0 (black) to 255 (white), and the values for redness, greenness,
and blueness are specified by a number from 0 to 255. This approach is used in many
applications. If you want to use a certain color that you see in a photo, you can open the
image file in Adobe Photoshop or the online Pixlr or some other graphics tool and use
the eye drop on the pixel (picture element) you want, and an information window will
tell you the RGB value. See also the mention of the Color Selector in the “Things to Look
Up” section.

Development Environment
Programmers need to prepare programs and test programs. We also need to save our
work to come back to it another time. We might need to send the program to someone
else. Processing has what is termed an integrated development environment, the
Processing Development Environment (PDE), which provides a way to prepare and

7
Chapter 1 Basics

make changes to a program as well as test it and save it. To give you a different example,
Hypertext Markup Language (HTML) documents containing JavaScript are prepared and
saved using a text editor, such as Sublime. The resulting files are opened (and run) using
a browser, such as Chrome. In the Appendix, I will show you how to use an editor for
p5.js, which is a version of JavaScript incorporating Processing features.

Role of Planning
I close this first “Programming Concepts” section by noting that preparing programs
such as a Processing sketch generally involves planning and design. It might be best to
step away from the keyboard. Some of the plans might need to be modified when you get
to writing the code, but it is best to have plans!

Under the Covers


As I indicated earlier, Processing is a language built on Java. This means that the
Processing code you write is Java code that the development environment puts into a
larger Java program prepared for handling Processing sketches. In Java, there are no
functions, but, instead, what are termed methods. I will introduce methods for our use in
Processing in Chapter 4.
The PDE (Processing Development Environment) makes use of libraries, collections
of methods holding the built-in functions of Processing, such as functions to draw a
rectangle.
In the big Java program, there are calls to functions that we write, or, to put it more
accurately, we code the body of the function. For example, all Processing sketches
contain a function called setup, the purpose of which is to do what the name implies.
It nearly always includes a statement that defines the width and height of the window,
for example. The big Java program invokes the setup program once at the start of the
sketch. Similarly, we can write the body of a function named draw. The Java program
invokes this function over and over, the frequency defined by the frame rate, which can
be reset by assigning a value to the built-in variable frameRate. This enables us to build
applications producing animations and responding to events such as a user clicking the
mouse button. There are many other functions for which we, the programmers, specify
the response to an event, for example, keyPressed or mouseClick.

8
Chapter 1 Basics

The Java program also defines default settings. Processing and other computer
languages and many computer applications provide powerful features. If we needed to
specify each aspect of each feature before anything happens, it would be tremendously
burdensome. It is important to be aware that certain things can be adjusted, though, as
you will see in our very first example later, with the discussion on default values for font,
text size, fill color, and stroke color.
The design and capabilities of Processing provide us a way to get started creating and
implementing our ideas quickly.

Processing Programming Features


In this section, I explain the concepts focusing on Processing features. There will be
small coding examples to prepare for the larger (although not too large) examples
covered later in the chapter.
To use Processing, you need to go to the processing.org website and follow the
directions to download and install Processing on your computer.

Processing Development Environment


To describe the PDE in abstract terms is too difficult, so let’s get started. Once you have
downloaded and installed Processing, open it. At the top of the PDE window, you will see
the Processing File toolbar.
Click File, which will open a drop-down menu. Select New. The toolbar will change
to hold more options. A window that looks like Figure 1-3 will appear on your screen.
The number after sketch_ will be different than what you see here. I believe in saving
early, and often so, at this point, you can think about where you want to save your
Processing work in terms of the file system on your computer. I leave that to you. You
also should give some thought to what you will name each sketch. I suggest the name
first0 for this one. Click File, then select Save As…, and proceed with a file name and a
location in the usual way for your operating system.

9
Chapter 1 Basics

Figure 1-3. Window for new sketch

Using Save As… in the PDE produces a folder, in this case named first0, which
contains a file named first0.pde. The examples explored in future chapters will
consist of folders containing additional items. For example, a Processing sketch named
myFamily that makes use of an image file aviva.jpg and an image file daniel.jpg will
be a folder named myFamily containing a file named myFamily.pde and a folder named
data that contains the two files aviva.jpg and daniel.jpg. The relationship of these
files is shown in Figure 1-4.

10
Chapter 1 Basics

Figure 1-4. Typical file structure for a sketch

Functions
Processing uses the term function for grouping together one or more statements into
something that can be invoked (called). Functions are defined with header statements
and then the body, a sequence of statements, contained within brackets. You will see
in this chapter and every chapter definitions for the setup function, a function that
Processing expects the programmer to supply. The header is

void setup()

The term void indicates that this function does not produce or return a value. The
opening and closing parentheses with nothing between them indicate that this function
does not expect any parameters.
The Daddy logo example includes a function called daddy that does the work of
drawing the cartoon. Its header is

void daddy(int x, int y, int w, int h)

The parameters are the things between the parentheses. The parameter list is the
place for the programmer to give names and specify the data type. This means that when
I wrote the code to invoke daddy, which is necessary because daddy was something I
made up, not anything Processing expects, Processing will check that the values cited in
the call are the correct type.
I feel obliged to show you an example of a function that does produce a value, a
standard one supplied in many textbooks.

11
Another Random Document on
Scribd Without Any Related Topics
unicorn, etc. When cells with raphides and mucilage are mounted in
a mixture of alcohol, glycerine, and water, the mucilage first swells
and finally disappears.

STORAGE CAVITIES

Particular attention should be given to storage cavities


whenever they occur in plants, for the reason that they are usually
filled with storage products, and for the added reason that storage
cavities are not common to all plants. Storage cavities occur in roots,
stems, leaves, flowers, fruits, and seeds.

C RY S TA L C AV I T I E S

Characteristic crystal cavities occur in many plants. Such a


cavity containing a bundle of raphides is shown in the cross-section
of skunk cabbage leaf (Plate 67).

S E C R E T I O N C AV I T I E S

In white pine bark there are a great number of secretion cavities


which are partially or completely filled with oleoresin. In the cross-
sections of white pine bark the secretion cavities are very
conspicuous, and they vary greatly in size. This variation is due, first,
to the age of the cavity, the more recently formed cavities being
smaller; and secondly, to the nature of the section, which will be
longer in longitudinal section, which will be through the length of the
secretion cavity, and shorter on transverse section. Such a section
shows the width of the secretion cavity.
Characteristic mucilage cavities occur in sassafras root, stem
bark, elm bark (Plate 66, Fig. 1), marshmallow root, etc. These
cavities form a conspicuous feature of the cross-section of these
plants. The presence or absence of mucilage cavities in a bark
should be carefully noted.
LAT E X C AV I T I E S

The latex tube cavities are characteristic in the plants in which


they occur. These cavities as explained under latex tubes are very
irregular in outline.

PLATE 67
Cross-Section of Skunk-cabbage Leaf
(Symplocarpus fœtidus,
[L.] Nutt.)

1. Crystal cavity.
2. Bundle of raphides.

O I L C AV I TY
Canella alba contains an oil cavity resembling in form the
mucilage cavity of elm bark.
Secretion cavities occur in most of the umbelliferous fruits. For
each fruit there is a more or less constant number of cavities. Anise
has twenty or more, fennel usually has six cavities, and parsley has
six cavities.
In poison hemlock fruits there are no secretion cavities. In certain
cases, however, the number of secretion cavities can be made to
vary. This was proved by the author in the case of celery seed. He
found that cultivated celery seed, from which stalks are grown,
contains six oil cavities (Plate 122, Fig. 2), while wild celery seed
(Plate 102, Fig. 1), grown for its medicinal value, always contains
more than six cavities. Most of the wild celery seeds contain twelve
cavities.
Many leaves contain cavities for storing secreted products. Such
storage cavities occur in fragrant goldenrod, buchu, thyme, savary,
etc.
The leaves in which such cavities occur are designated as pellucid-
punctate leaves. Such leaves will, when held between the eye and
the source of light, exhibit numerous rounded translucent spots, or
storage cavities.

G LA N D U LA R H A I R S

The glandular hair of peppermint (Plate 60, Fig. 3) and other


mints consists of eight secretion cells, arranged around a central
cavity and an outer wall which is free from the secretion cells. This
outer wall becomes greatly distended when the secretion cells are
active, and the space between the secretion cells and the wall serves
as the storage place for the oil. When the mints are collected and
dried, the oil remains in the storage cavity for a long time.

S TO N E C E L L S
The stone cells of the different cinnamons (Plate 65, Fig. 1) store
starch grains; these grains often completely fill the stone cells.
The yellow stone cells of calumba root (Plate 65, Fig. 2) usually
contain four prisms of calcium oxalate, which may be nearly uniform
or very unequal in size.

B AS T F I B R E S

The bast fibres of the different rubus species (Plate 65, Fig. 7)
contain starch. The medullary rays of quassia (Plate 107, Fig. 2)
contain starch; while the medullary rays of canella alba contain
rosette crystals. In a cross-section of canella alba (Plate 81, Fig. 3)
the crystals form parallel radiating lines which, upon closer
examination, are seen to be medullary rays, in each cell of which a
crystal usually occurs.
The epidermal and hypodermal cells of leaves serve as
water-storage tissue. These cells usually appear empty in a section.
The barks of many plants—i.e., quebracho, witch-hazel, cascara,
frangula, the leaves of senna and coca, and the root of licorice—
contain numerous crystals. These crystals occur in special storage
cells—crystal cells (Plate 65, Fig. 6)—which usually form a
completely enveloping layer around the bast fibres. These cells are
usually the smallest cells of the plant in which they occur, and with
but few exceptions each cell contains but a single crystal.
The epidermal cells of senna leaves and the epidermal cells of
mustard are filled with mucilage; the walls even consist of mucilage.
Such cells are always diagnostic in powders.

STORAGE WALLS

Storage walls (Plates 68 and 69) occur in colchicum seed, saw


palmetto seed, areca nut, nux vomica, and Saint Ignatius’s bean. In
each of these seeds the walls are strongly and characteristically
thickened and pitted. In no two plants are they alike, and in each
plant they are important diagnostic characters.
Storage cell walls consist of reserve cellulose, a form of cellulose
which is rendered soluble by ferments, and utilized as food during
the growth of the seed. Reserve cellulose is hard, bony, and of a
waxy lustre when dry. Upon boiling in water the walls swell and
become soft.
The structure of the reserve cellulose varies greatly in the different
seeds in which it occurs in the thickness of the walls and in the
number and character of the pores.
PLATE 68
Reserve Cellulose

1. Saw palmetto (Serenoa serrulata,


[Michaux] Hook., f.).
2. Areca nut (Areca catechu, L.).
3. Colchicum seed (Colchicum
autumnale, L.).
3-A. Porous side wall.
3-B. Cell cavity above the side wall.
PLATE 69
Reserve Cellulose

1. Endosperm of nux vomica (Strychnos


nux vomica, L.).
2. Endosperm of St. Ignatia bean
(Strychnos ignatii, Berg.).
CHAP TER IX
CELL CONTENTS

The cell contents of the plant are divided into two groups: first,
organic cell contents; and secondly, inorganic cell contents.
The organic cell contents include plastids, starch grains,
mucilage, inulin, sugar, hesperidin, alkaloids, glucocides, tannin,
resin, and oils.

CHLOROPHYLL

The chloroplasts of the higher plants are green, and they vary
somewhat in size, but they have a similar structure and form.
Chloroplasts are mostly oval in longitudinal view and rounded in
cross-section view. Each chlorophyll grain has an extremely thin
outer wall, which encloses the protoplasmic substance, the green
granules, a green pigment (chlorophyll), and a yellow pigment
(xanthophyll). Frequently the wall includes starch, oil drops, and
protein crystals.
Chloroplasts are arranged either in a regular peripheral manner
along the walls, or they are diffused throughout the protoplast.
The palisade cells of most leaves are packed with chlorophyll
grains. In the mesophyll cells the chlorophyll grains are not so
numerous, and they are arranged peripherally around the innermost
part of the wall.
Chloroplasts multiply by fission—that is, each chloroplast divides
into two equal halves, each of which develops into a normal
chloroplast.
Chlorophyll occurs in the palisade, spongy parenchyma, and guard
cells of the leaf; in the collenchyma and parenchyma of the cortex of
the stems of herbs and of young woody stems, and, under certain
conditions, in rhizomes and roots exposed to light. Almost without
exception young seeds and fruits have chlorophyll.
In powdered leaves, stems, etc., the chlorophyll grains occur in
the cells as greenish, more or less structureless masses. Yet cells
with chlorophyll are readily distinguished from cells with other cell
contents. In witch-hazel leaf the chlorophyll grains appear brownish
in color. Powdered leaves and herbs are readily distinguished from
bark, wood, root, and flower powders.
Leaves and the stems of herbs are of a bright-green color. With
the exception of the guard cells, the chloroplasts occur one or more
layers below the epidermis; but, owing to the translucent nature of
the outer walls of these cells, the outer cells of leaves and stems
appear green.
Wild cherry, sweet birch, and, in fact, most trees with smooth
barks have chloroplasts in several of the outer layers of the cortical
parenchyma. When the thin outer bark is removed from these
plants, the underlying layers are seen to be of a bright-green color.

LEUCOPLASTIDS

Leucoplastids, or colorless plastids, occur in the underground


portions of the plant; they may, when these organs in which they
occur are exposed to light, change to chloroplastids.
Leucoplasts are the builders of starch grains. They take the
chemical substance starch and build or mould it into starch grains,
storage starch, or reserve starch.
Other characteristic chromoplasts found in plants are yellow and
red. Yellow chromoplasts occur in carrot root and nasturtium flower
petals. Red plastids occur in the ripe fruit of capsicum.

STARCH GRAINS
The chemical substance starch (C₆H₁₀O₅) is formed in
chloroplasts. The starch thus formed is removed from the
chloroplasts to other parts of the plant because it is the function of
the chloroplasts to manufacture and not to store starch.
The starch formed by the chloroplasts is acted upon by a ferment
which adds one molecule of water to C₆H₁₀O₅, thus forming sugar
C₆H₁₂O₆. This sugar is readily soluble in the cell sap, and is
conducted to all parts of the plant. The sugar not utilized in cell
metabolism is stored away in the form of reserve starch or starch
grains by colorless plastids or amyloplasts.
The amyloplasts change the sugar into starch by extracting a
molecule of water. This structureless material (starch) is then formed
by the amyloplast into starch grains having a definite and
characteristic form and structure.
Starch grams vary greatly in different species of plants, owing
probably to the variation of the chemical composition, density, etc.,
of the protoplast, and to the environmental conditions under which
the plant is growing.

OCCURRENCE

Starch grains are simple, compound, or aggregate. Simple


starch grains may occur as isolated grains (Plates 70, 71, and 72),
or they may be associated as in cardamon seed, white pepper,
cubeb, and grains of paradise, where the simple grains stick together
in masses, having the outline of the cells in which they occur. These
masses are known as aggregate starch.
Aggregate starch (Plate 76) varies greatly in size, form, and in
the nature of the starch grains forming the aggregations.
Compound starch grains may be composed of two or more
parts, and they are designated as 2, 3, 4, 5, etc., compound (Plate
75).
The parts of a compound grain may be of equal size (Plate 75, Fig.
4), or they may be of unequal size (Plate 75, Fig. 2).
In most powders large numbers of the parts of the compound
grains become separated. The part in contact with other grains
shows plane surfaces, while the external part of the grain has a
curved surface. There will be one plane and one curved surface if
the grain is a half of a two-compound grain; two plane and one
curved surface if the grain is a part of a three-compound grain, etc.
The simple starch grains forming the aggregations become
separated during the milling process and occur singly, so that in the
drugs cited above the starch grains are solitary and aggregate.
Many plants contain both simple and compound starch grains
(Plate 74, Fig. 3).
In some forms—e.g., belladonna root (Plate 75, Fig. 2) the
compound grains are more numerous; while in sanguinaria the
simple grains are more numerous, etc.

OUTLINE

The outline of starch grains is made up of (1) rounded, (2)


angled, and (3) rounded and angled surfaces.
Starch grains with rounded surfaces may be either spherical, as in
Plate 74, Fig. 3, or oblong or elongated, as in Plate 71, Fig. 1.
Other starches with rounded surfaces are shown on Plates 72 and
73.
Angled outlined grains are common to cardamon seed, white
pepper, cubebs, grains of paradise (Plate 76, Fig. 4), and to corn
(Plate 70, Fig. 3).
The outlines of all compound grains are made up partly of plane
and partly of curved surfaces.

SIZE
The size (greatest diameter) of starch varies greatly even in the
same species, but for each plant there is a normal variation.
In spherical starch grains the size of the individual grains is
invariable, but in elongated starch grains and in parts of compound
grains the size will vary according to the part of the grain measured.
In zedoary starch (Plate 71, Fig. 4), for instance, the size will vary
according to whether the end, side, or surface of the starch grain is
in focus.
The parts of compound grains often vary greatly in size. Such a
variation is shown in Plate 75, Fig. 2.

HILUM

The hilum is the starting-point of the starch grain or the first part
of the grain laid down by the amyloplast. The hilum will be central if
formed in the middle of the amyloplast, and excentral if formed near
the surface of the amyloplast. It has been shown that the developing
starch grain with eccentric hilum usually extends the wall of the
amyloplast if it does not actually break through the wall. Starch
grains with excentral hilums are therefore longer than broad.
PLATE 70
Starch

1. Calabar bean (Physostigma


venenosum, Balfour).
2. Marshmallow root (Althæa officinalis,
L.).
3. Field corn (Zea mays, L.).
PLATE 71
Starch

1. Galanga root (Alpinia officinarum,


Hance). 2. Kola nut (Cola vera, [K.]
Schum.). 3. Geranium rhizome
(Geranium maculatum L.). 4. Zedoary
root (Curcuma zedoaria, Rosc.). 4-A.
Surface view of starch grain. 4-B. Side
view of starch grain. 4-C. End view of
starch grain.

In central hilum starch grains the grain is laid down around the
hilum in the form of concentric layers. These layers are of variable
density. The dense layers are formed when plenty of sugar is
available, and the less dense layers are formed when little sugar is
available. The unequal density of the different layers gives the
striated appearance characteristic of so many starch grains.
In eccentric hilum starch grains the starch will be deposited in
layers which are outside of and successively farther from the hilum.
The term hilum has come to have a broader meaning than
formerly. Hilum includes at the present time not only the starting-
point of the starch grain, but the fissures which form in the grain
upon drying. In all cases these fissures originate in the starting-
point, hilum, and in some cases extend for some distance from it.
The hilum, when excentral, may occur in the broad end of the grain,
galanga, and geranium (Plate 71, Figs, 1 and 3), or in the narrow
end of the grain, zedoary (Plate 71, Fig. 4).

N AT U R E O F T H E H I L U M

The hilum, whether central or excentral, may be rounded (Plate


75, Fig. 1); or simple cleft, which may be straight (Plate 71, Fig. 1);
or curved cleft (Plate 71, Fig. 2); or the hilum may be a multiple cleft
(Plate 74, Fig. 3).
In studying starches use cold water as the mounting medium,
because in cold water the form and structure are best shown, and
because there is no chemical action on the starch. On the other
hand, the form and structure will vary considerably if the starch is
mounted in hot water or in solutions of alkalies or acids. The hilum
appears colorless when in sharp focus, and black when out of focus.
Starch grains, when boiled with water, swell up and finally
disintegrate to form starch paste.
Starch paste turns blue upon the addition of a few drops of weak
Lugol solution. Upon heating, this blue solution is decolorized, but
the color reappears upon cooling. If a strong solution of Lugol is
used in testing, the color will be bluish black.
PLATE 72
Starch

1. Orris root (Iris florentinia L.).


2. Stillingia root (Stillingia sylvatica, L.).
3. Calumba root (Jateorhiza palmata,
[Lam.] Miers.).
PLATE 73
Starch

1. Male fern (Dryopteris marginalis, [L.] A.


Gray).
2. African ginger (Zingiber officinalis, Rosc.).
3. Yellow dock (Rumex crispus, L.).
4. Pleurisy root (Asclepias tuberosa, L.).
PLATE 74
Starch

1. Kava-kava (Piper methysticum, Forst.,


f.).
2. Pokeroot (Phytolacca americana, L.).
3. Rhubarb (Rheum officinale, Baill.).
PLATE 75
Starch Grains

1. Bryonia (Bryonia alba, L.).


2. Belladonna root (Atropa belladonna,
L.).
3. Valerian root (Valeriana officinalis, L.).
4. Colchicum root (Colchicum autumnale,
L.).
PLATE 76
Starch Masses

1. Aggregate starch of cardamon seed


(Elettaria cardamomum, Maton).
2. Aggregate starch of white pepper
(Piper nigrum, L.).
3. Aggregate starch of cubebs (Piper
cubeba, L., f.).
4. Aggregate starch of grains of paradise
(Amomum melegueta, Rosc.).

INULIN

Inulin is the reserve carbohydrate material found in the plants of


the composite family.
The medicinal plants containing inulin are dandelion, chicory,
elecampane, pyrethrum, and burdock. Plate 77, Figs, 1 and 2 show
masses of inulin in dandelion and pyrethrum.
In these plants the inulin occurs in the form of irregular,
structureless, grayish-white masses (Plate 77). In powdered drugs
inulin occurs either in the parenchyma cell or as irregular isolated
fragments of variable size and form. Inulin is structureless and the
inulin from one plant cannot be distinguished microscopically from
the inulin of another plant. For this reason inulin has little or no
diagnostic value. The presence or absence of inulin should always be
noted, however, in examining powdered drugs, because only a few
drugs contain inulin.
When cold water is added to a powder containing inulin it
dissolves. Solution will take place more quickly, however, in hot
water. Inulin occurs in the living plant in the form of cell sap. If fresh
sections of the plant are placed in alcohol or glycerine, the inulin
precipitates in the form of crystals.

MUCILAGE

Mucilage is of common occurrence in medicinal plants.


Characteristic mucilage cavities filled with mucilage occur in
sassafras stem (Plate 66, Fig. 2), in elm bark (Plate 66, Fig. 1), in
althea root, in the outer layer of mustard seed, and in the stem of
cactus grandiflorus. In addition, mucilage is found associated with
raphides in the crystal cells of sarsaparilla, squill, false unicorn, and
polygonatum.
When drugs containing mucilage are added to alcohol, glycerine,
and water mixture, the mucilage swells slightly and becomes
distinctly striated, but it will not dissolve for a long time. Refer to
Plate 79, Fig. 6.
Mucilage, when associated with raphides, swells and rapidly
dissolves when added to alcohol, glycerine, and water mixture. The
mucilage is, therefore, different from the mucilage found in mucilage
cavities, because it is more readily soluble.

PLATE 77
Inulin (Inula helenium, L.)
1. Inulin in the parenchyma cells of
dandelion root.
2. Inulin from Roman pyrethrum root
(Anacyclus pyrethrum, [L.] D. C.).

In coarse-powdered bark and other mucilage containing drugs the


mucilage masses are mostly spherical or oval in outline (Plate 66,
Figs. 2 and 3) the form being similar to the cavity in which the mass
occurs.
Acacia, tragacanth, and India gum consist of the dried
mucilaginous excretions.
HESPERIDIN

Hesperidin occurs in the epidermal cells of short and long buchu.


It is particularly characteristic in the epidermal cells of the dried
leaves of short buchu. In these leaves the hesperidin occurs in
masses which resemble rosette crystals (Plate 54, Fig. 1).
Hesperidin is insoluble in glycerine, alcohol, and water, but it
dissolves in alkali hydroxides, forming a yellowish solution.

VOLATILE OILS

Volatile oils occur in cinnamon stem bark, sassafras root bark,


flowers of cloves, and in the fruits of allspice, anise, fennel, caraway,
coriander, and cumin.
In none of these cases is the volatile oil diagnostic, but its
presence must always be determined.
When a powdered drug containing a volatile oil is placed in
alcohol, glycerine, and water mixture the volatile oil contained in the
tissues will accumulate at the broken end of the cells in the form of
rounded globules, while the volatile oil adhering to the surface of the
fragments will dissolve in the mixture and float in the solution near
the under side of the cover glass. Volatile oil is of little importance in
histological work.

TANNIN

Tannin masses are usually red or reddish brown. Tannin occurs in


cork cells, medullary rays of white pine bark (Plate 48, Fig. B), stone
cells, and in special tannin sacs.
The stone cells of hemlock and tamarac bark and the medullary
rays of white pine and hemlock bark contain tannin.
Tannin associated with prisms occurs in tannin sacs in white pine
and tamarac bark. These sacs are frequently several millimeters in
length and contain a great number of crystals surrounded by tannin.
Deposits of tannin are colored bluish black with a solution of ferric
chloride.

ALEURONE GRAINS

Aleurone grains are small granules of variable structure, size,


and form, and they are composed of reserve proteins. They occur in
celery, fennel, coriander, and anise, fruits, in sesame, sunflower,
curcas, castor oil, croton oil, bitter almond, and other oil seeds.
In many of the seeds the aleurone grains completely fill the cells
of the endosperm, embryo, and perisperm. In wheat, rye, barley,
oats, and corn the aleurone grains occur only in the outer layer or
layers of the endosperm, the remaining layers in these cases being
filled with starch.
In powdered drugs the aleurone grains occur in parenchyma cells
or free in the field.

STRUCTURE OF ALEURONE GRAINS

Aleurone grains are very variable in structure. The simplest grains


consist of an undifferentiated mass of proteid substance surrounded
by a thin outer membrane. In other grains the proteid substance
encloses one or more rounded denser proteid bodies known as
globoids. In other grains a crystalloid—crystal-like proteid substance
—is present in addition to the globoid. In some grains are crystals of
calcium oxalate, which may occur as prisms or as rosettes. All the
different parts, however, do not occur in any one grain. In castor-oil
seed (Plate 77a, Fig. 8) are shown the membrane (A), the ground
mass (B), the crystalloid (C), and the globoid (D).

FORM OF ALEURONE GRAINS

Much attention has been given to the study of the special parts of
the aleurone grains, but one of the most important diagnostic
characters has been overlooked, namely, that of comparative form.
For the purposes of comparing the forms of different grains, they
should be mounted in a medium in which the grain and its various
parts are insoluble. Oil of cedar is such a medium. The variation in
form and size of the aleurone grains when mounted in oil of cedar is
shown in Plate 77a.

DESCRIPTION OF ALEURONE GRAINS

The aleurone grains of curcas (Plate 77a, Fig. 1) vary in form from
circular to lens-shaped, and each grain contains one or more
globoids. The globoids are larger when they occur singly. In
sunflower seed (Plate 77a, Fig. 2) the grains vary from reniform to
oval, and one or more globoids are present; many occur in the
center of the grain.
The aleurone grains of flaxseed (Plate 77a, Fig. 3) resemble in
form those of sunflower seed, but the grains are uniformly larger
and some of the grains contain as many as five globoids.
In bitter almond (Plate 77a, Fig. 4) the aleurone grains are mostly
circular, but a few are nearly lens-shaped. A few of the large,
rounded grains contain as many as nine globoids; in such cases one
of the globoids is likely to be larger than the others. The aleurone
grains of croton-oil seed (Plate 77a, Fig. 5) are circular in outline,
variable in form, and each grain contains from one to seven
globoids.
In sesame seed (Plate 77a, Fig. 6) the typical grain is angled in
outline and the large globoid occurs in the narrow or constricted
end.
The aleurone grains of castor-oil seed (Plate 77a, Fig. 7) resemble
those of sesame seed, but they are much larger, and many of the
grains contain three large globoids. When these grains are mounted
in sodium-phosphate solution, the crystalloid becomes visible.

T E S TS F O R A L E U R O N E G R A I N S
Aleurone grains are colored yellow with nitric acid and red with
Millon’s reagent.
The proteid substance of the mass of the grain, of the globoid,
and of the crystalloid, reacts differently with different reagents and
dyes.
The ground substance and the crystalloids are soluble in dilute
alkali, while the globoids are insoluble in dilute alkali.
The ground substance and crystalloids are soluble in sodium
phosphate, while the globoids are insoluble in sodium phosphate.
Calcium oxalate is insoluble in alkali and acetic acid, but it
dissolves in hydrochloric acid.
PLATE 77a
Aleurone Grains

1. Curcas (Jatropha curcas, L.).


2. Sunflower seed (Helianthus annuus, L.).
3. Flaxseed (Linum usitatissimum, L.).
4. Bitter almond (Prunus amygdalus, amara,
D.C.).
5. Croton-oil seed (Croton tiglium, L.).
6. Sesame seed (Sesamum indicum, L.).
7 and 8. Castor-oil seed (Ricinus communis,
L.).

CRYSTALS

Calcium oxalate crystals form one of the most important inorganic


cell contents found in plants, because of the permanency of the
crystals, and because the forms common to a given species are
invariable. By means of calcium oxalate crystals it is possible to
distinguish between different species. In butternut root bark, for
instance, only rosette crystals are found, while in black walnut root
bark—a common substitute for butternut bark—both prisms and
rosettes occur. This is only one of the many examples which could
be cited.
These crystals, for purposes of study, will be grouped into four
principal classes, depending upon form and not upon crystal system.
These classes are micro-crystals, raphides, rosettes, and solitary
crystals.

M I C R O - C RY S TA L S

Micro-crystals are the smallest of all the crystals. Under the high
power of the microscope they appear as a V, a Y, an X, and as a T.
They are, therefore, three- or four-angled (Plate 78). The thicker
portions of these crystals are the parts usually seen, but when a
close observation of the crystals is made the thin portions of the
crystal connecting the thicker parts may also be observed. Micro-
crystals should be studied with the diaphragm of the microscope
nearly closed and with the high-power objective in position. While
observing the micro-crystals, raise and lower the objective by the
fine adjustment in order to bring out the structure of the crystal
more clearly. Micro-crystals occur in parenchyma cells of belladonna,
scopola, stramonium, and bittersweet leaves; in belladonna, in
horse-nettle root, in scopola rhizome, in bittersweet stems, and in
yellow and red cinchona bark, etc.
The crystals in each of the above parts of the plant are similar in
form, the only observed variation being that of size. Their presence
or absence should always be noted when studying powders.

RAPHIDES

Raphides, which are usually seen in longitudinal view, resemble


double-pointed needles. They are circular in cross-section, and the
largest diameter is at the centre, from which they taper gradually
toward either end to a sharp point.

PLATE 78
Micro-Crystals

1. Horse-nettle root (Solanum carolinense,


L.).
2. Scopola rhizome (Scopolia carniolica,
Jacq.).
3. Belladonna root (Atropa belladonna, L.).
4. Bittersweet stem (Solanum dulcamara,
L.).
5. Scopola leaf (Scopola carniolica, Jacq.).
6. Tobacco leaf (Nicotiana tabacum, L.).
7. Belladonna leaf (Atropa belladonna, L.).
Raphides occur in bundles, as in false unicorn root (Plate 79, Figs.
6, A, B, and C), rarely as solitary crystals.
In ipecac root the crystals are usually solitary. In sarsaparilla root,
squill, etc., the raphides occur both in clusters, part of bundle, or in
bundles, and as solitary crystals.
In most drugs the crystals are entire; but in squills, where the
raphides are very large, they are broken. In phytolacca (Plate 79,
Fig. 1) and in hydrangea the raphides are usually broken, owing to
the fact that these drugs contain large quantities of fibres which
break them up into fragments when the drug is milled.
There is the greatest possible variation in the size of raphides in
the same and in different drugs, but the larger forms are constant in
the same species.
Raphides are deposited in parenchyma cells and in special
raphides sacs. These crystals are always surrounded with mucilage.

R O S E TT E C RY S TA L S

Rosette crystals are compound crystals composed of an


aggregation of small crystals arranged in a radiating manner around
a central core. This core appears nearly black, and the whole mass is
nearly spherical. The free ends of the crystals are sharp-pointed or
blunt.
Characteristic rosette crystals occur in frangula bark, spikenard
root, wahoo stem, root bark, rhubarb, etc. (Plate 80, Figs. 1, 2, 3, 4,
5, and 6).
These crystals are very variable in size. This variation is illustrated
by the crystals of Plate 80.
Usually there is a variation in size of the crystals occurring in a
given plant, but for each plant there is a more or less uniform
variation. For instance, the largest rosette crystal occurring in wahoo
root bark (Plate 80, Fig. 5) is smaller than the largest crystal
occurring in rhubarb (Plate 80, Fig. 6), etc.

You might also like