# Algorithms for Visual Design Using the Processing Language

ISBN: 978-0-470-37548-8
384 pages
May 2009

## Description

As the first book to share the necessary algorithms for creating code to experiment with design problems in the processing language, this book offers a series of generic procedures that can function as building blocks and encourages you to then use those building blocks to experiment, explore, and channel your thoughts, ideas, and principles into potential solutions. The book covers such topics as structured shapes, solid geometry, networking and databases, physical computing, image processing, graphic user interfaces, and more.
See More

## Table of Contents

Introduction xix

Chapter 1 Elements of the Language 1

1.1 Operands and Operations 2

1.1.1 Variable Types 2

1.1.2 Name Conventions 4

1.1.3 Arithmetic Operations 5

1.1.4 Logical and Relational Operations/Statements 7

1.1.5 Loops 8

1.1.6 Patterns of Numbers 10

1.2 Graphics Elements 12

1.2.1 Code Structure 12

1.2.2 Draw Commands 13

1.2.3 Geometrical Objects 13

1.2.4 Attributes 17

1.2.5 Fonts and Images 20

1.2.6 Examples 21

1.3 Interactivity 24

1.3.1 Drawing on the Screen 24

1.3.2 Mouse and Keyboard Events 26

1.4 Grouping of Code 28

1.4.1 Arrays 28

1.4.2 Procedures and Functions 30

1.4.4 Recursion 33

1.4.5 Importing Processing Classes 34

Summary 35

Exercises 35

Chapter 2 Points, Lines, and Shapes 41

2.1 Sine and Cosine Curves 42

2.2 Bezier Curve 47

2.3 Pointillist Images 48

2.4 Polygons 51

2.5 Equilateral Polygons 53

2.6 Responsive Polygons 54

2.7 Responsive Curve 56

Summary 57

Exercises 57

Chapter 3 The Structure of Shapes 63

3.1 Introduction to Class Structures 63

3.1.1 Defining a Class Called MyPoint 64

3.1.2 Adding Methods to a Class 66

3.2 Organization of Classes 68

3.2.1 Class MyPoint 70

3.2.2 Class MySegment 70

3.2.3 Class MyShape 71

3.3 Standard Transformations (move, rotate, scale) 74

3.4 Implementing Transformations 76

3.5 Creating Grids of Shapes 80

3.6 Class MyGroup 83

3.7 Selecting Objects 85

Summary 90

Exercises 91

Chapter 4 Basics of Graphical User Interfaces 93

4.1 Basic GUI (Buttons) 94

4.2 Choice, Label, and TextField 98

4.3 Arranging GUI Objects on the Screen 99

4.4 Selecting Points, Segments, Shapes, or Groups 102

4.5 Color Setup 104

4.6 Putting the GUI Elements in Their Own Window 106

4.7 Mouse Wheel Control 107

Summary 107

Exercises 108

Chapter 5 Image Processing 109

5.1 Displaying Images 110

5.2 Preset Image Filters 111

5.3 Bit Manipulation on Pixels 115

5.4 A Paint Brush Tool 118

5.5 Edge Detection 121

Summary 123

Exercises 123

Chapter 6 Motion 127

6.1 Animation Basics 127

6.2 Erratic Motion 131

6.3 Line Traces 133

6.4 Interactive Transformations 135

6.5 Double Buffering 138

6.6 Motion and Friction 140

6.7 Collision 143

6.8 Elastic Motion 145

Summary 149

Exercises 149

Notes 152

Chapter 7 Advanced Graphics Algorithms 153

7.1 Voronoi Tessellation 154

7.2 Stochastic Search 158

7.3 Fractals 162

7.4 Interpolation/Extrapolation 165

7.5 Cellular Automata 168

7.6 Evolutionary Algorithm 172

Summary 177

Exercises 178

Notes 180

Chapter 8 3-D Space 181

8.1 The Third Dimension 182

8.2 Defining 3D Objects 183

8.3 Projecting on the Screen 187

8.4 Perspective Projection 190

8.5 Three-Dimensional Graphics in Processing 192

8.6 3D Point Formations 199

8.6.1 Cubical Formations 199

8.6.2 Spherical Formations 201

8.6.3 Superquadrics 203

Summary 205

Exercises 206

Chapter 9 Solid Geometry 209

9.1 Class MyPoint 209

9.1.1 Class MyFace 211

9.1.2 Sets of Faces 214

9.1.3 Class MySolid 215

9.1.4 Face Visibility 220

9.2 Shading 223

9.2.1 Vectors 225

9.2.2 Normalization 226

9.2.3 Cross Product 227

9.2.4 Dot Product 228

9.2.5 MyVector Class 228

9.2.6 Color Tables 229

9.2.7 Array of Shades 230

9.2.8 Shade Calculation 231

9.2.9 Class MyGroup 234

9.2.10 Sorting Solids (Painter’s Algorithm) 238

9.3 3D User Interaction 240

9.3.1 Picking Objects in the Scene 241

9.3.2 Simulating Menu Bars 244

Summary 246

Exercises 246

Notes 247

Chapter 10 File Read/Write 249

10.1 File Formats 250

10.2 Basic Write/Read in Processing 250

10.2.1 Exporting PDF and DXF File Formats Using Processing Libraries 253

10.2.2 Native File Write 255

10.2.3 Native File Read 256

10.2.4 The DXF File Format 258

10.2.5 Writing DXF Files 259

10.2.6 Reading DXF Files 261

10.2.7 The VRML File Format 263

10.2.8 Writing VRML Files 265

10.2.9 Reading VRML Files 266

10.3 Client/Server Data Transfer 268

Summary 272

Exercises 272

Chapter 11 Physical Computing 275

11.1 Basics of Electrical Circuits 276

11.2 Arduino Microcontroller Board 278

11.3 Arduino Language 279

11.4 LED 282

11.5 Photocell 284

11.6 Pushbutton 287

11.7 Servo Motor 288

11.8 Sound 290

11.9 Differential Values 292

11.10 Responsive System: Photo-Sound 292

11.11 A Feedback System: Photo-Motor 294

Summary 296

Exercises 296

Appendix A Equations of Lines and Planes 301

Appendix B Answers to Exercises 307

Appendix C Further Readings 335

Index 339

See More

## Author Information

Kostas Terzidis is an associate professor at Harvard University's Graduate School of Design. He is an educator, designer, theorist, architect, and computer scientist. His professional work includes software development for Java media framework and Linux as a software engineer for AOL. Terzidis is also the author of three previous books.

See More

## Downloads

Download TitleSizeDownload
All sample code from book 2.11 MB Click to Download
Chapter 1 9.72 KB Click to Download
Chapter 2 6.37 KB Click to Download
Chapter 3 8.54 KB Click to Download
Chapter 4 22.39 KB Click to Download
Chapter 5 977.66 KB Click to Download
Chapter 6 494.79 KB Click to Download
Chapter 7 7.12 KB Click to Download
Chapter 8 7.84 KB Click to Download
Chapter 9 32.91 KB Click to Download
Chapter 10 81.16 KB Click to Download
Chapter 11 4.17 KB Click to Download
Appendix 498.27 KB Click to Download
See More