Processing: A Programming Handbook for Visual Designers and Artists

  • View
    219

  • Download
    1

Embed Size (px)

DESCRIPTION

 

Text of Processing: A Programming Handbook for Visual Designers and Artists

  • Processing:a programming handbook for visual designers and artists

    Casey ReasBen Fry

    The MIT PressCambridge, MassachusettsLondon, England

    Reas_00_i-xxvi.indd Sec1:iiiReas_00_i-xxvi.indd Sec1:iii 5/16/07 9:53:05 AM5/16/07 9:53:05 AM

  • 2007 Massachusetts Institute of Technology

    All rights reserved. No part of this book may be reproduced in any form by any electronic or mechanical means (including photocopying, recording, or information storage and retrieval) without permission in writing from the publisher.

    MIT Press books may be purchased at special quantity discounts for business or sales promotional use. For information, please email special_sales@mitpress.mit.edu or write to Special Sales Department, The MIT Press, 55 Hayward Street, Cambridge, MA 02142.

    Printed and bound in the United States of America.

    Library of Congress Cataloging-in-Publication Data

    Reas, Casey. Processing : a programming handbook for visual designers and artists / Casey Reas & Ben Fry ; foreword by John Maeda. p. cm. Includes bibliographical references and index. ISBN 978-0-262-18262-1 (hardcover : alk. paper) 1. Computer programming. 2. Computer graphicsComputer programs. 3. Digital artComputer programs. 4. ArtData processing. 5. Art and technology. I. Fry, Ben. II. Title.

    QA76.6.R4138 2007005.1dc22 2006034768

    10 9 8 7 6 5 4 3 2 1

    Reas_00_i-xxvi.indd Sec1:ivReas_00_i-xxvi.indd Sec1:iv 5/16/07 9:53:06 AM5/16/07 9:53:06 AM

  • 29 34 45 57 67 72

    91 99 113 121 131 141

    192 204 208 221 225 233

    247 289 297 307 320 324

    336 344 352 354 359 409

    447 451 472 493 530 551

    84

    189

    244

    331

    415

    535

    Reas_00_i-xxvi.indd Sec1:viReas_00_i-xxvi.indd Sec1:vi 5/16/07 9:53:06 AM5/16/07 9:53:06 AM

  • vii

    Foreword Preface

    Processing . . . Using Processing

    Structure 1: Code Elements Shape 1: Coordinates, Primitives Data 1: Variables Math 1: Arithmetic, Functions Control 1: Decisions Control 2: Repetition Shape 2: Vertices Math 2: Curves Color 1: Color by Numbers Image 1: Display, Tint Data 2: Text Data 3: Conversion, Objects Typography 1: Display Math 3: Trigonometry Math 4: Random Transform 1: Translate, Matrices Transform 2: Rotate, Scale Development 1: Sketching, Techniques Synthesis 1: Form and Code Interviews 1: Print

    Structure 2: Continuous Structure 3: Functions Shape 3: Parameters, Recursion Input 1: Mouse I Drawing 1: Static Forms Input 2: Keyboard Input 3: Events Input 4: Mouse II Input 5: Time, Date Development 2: Iteration, Debugging Synthesis 2: Input and Response Interviews 2: Software, Web

    Motion 1: Lines, Curves Motion 2: Machine, Organism Data 4: Arrays Image 2: Animation Image 3: Pixels Typography 2: Motion Typography 3: Response Color 2: Components Image 4: Filter, Blend, Copy, Mask Image 5: Image Processing Output 1: Images Synthesis 3: Motion and Arrays Interviews 3: Animation, Video

    Structure 4: Objects I Drawing 2: Kinetic Forms Output 2: File Export Input 6: File Import Input 7: Interface Structure 5: Objects II Simulate 1: Biology Simulate 2: Physics Synthesis 4: Structure, Interface Interviews 4: Performance, Installation

    Extension 1: Continuing . . . Extension 2: 3D Extension 3: Vision Extension 4: Network Extension 5: Sound Extension 6: Print Extension 7: Mobile Extension 8: Electronics

    Appendixes Related Media Glossary Code Index Index

    Contents

    xixxxi

    1

    9

    17

    23

    37

    43

    51

    61

    69

    79

    85

    95

    101

    105

    111

    117

    127

    133

    137

    145

    149

    155

    173

    181

    197

    205

    217

    223

    229

    237

    245

    251

    255

    261

    279

    291

    301

    315

    321

    327

    333

    337

    347

    355

    367

    371

    377

    395

    413

    421

    427

    435

    453

    461

    477

    495

    501

    519

    525

    547

    563

    579

    603

    617

    633

    661

    693

    699

    703

    705

    Reas_00_i-xxvi.indd Sec1:viiReas_00_i-xxvi.indd Sec1:vii 5/16/07 9:53:09 AM5/16/07 9:53:09 AM

  • viii

    88 342 55 65 305 220

    98 319 323 351 353 359

    225 232 240 247 444 44

    124 129 288 296 29 32

    202 470 488 184 190 407

    141 113 329 335 530 535

    415

    207

    83

    75

    455

    551

    Reas_00_i-xxvi.indd Sec1:viiiReas_00_i-xxvi.indd Sec1:viii 5/16/07 9:53:10 AM5/16/07 9:53:10 AM

  • ix

    Foreword Preface

    Processing . . . Using Processing

    Color 1: Color by Numbers Color 2: Components Control 1: Decisions Control 2: Repetition Data 1: Variables Data 2: Text Data 3: Conversion, Objects Data 4: Arrays Development 1: Sketching, Techniques Development 2: Iteration, Debugging Drawing 1: Static Forms Drawing 2: Kinetic Forms Image 1: Display, Tint Image 2: Animation Image 3: Pixels Image 4: Filter, Blend, Copy, Mask Image 5: Image Processing Input 1: Mouse I Input 2: Keyboard Input 3: Events Input 4: Mouse II Input 5: Time, Date Input 6: File Import Input 7: Interface Math 1: Arithmetic, Functions Math 2: Curves Math 3: Trigonometry Math 4: Random Motion 1: Lines, Curves Motion 2: Machine, Organism Output 1: Images Output 2: File Export

    Shape 1: Coordinates, Primitives Shape 2: Vertices Shape 3: Parameters, Recursion Simulate 1: Biology Simulate 2: Physics Structure 1: Code Elements Structure 2: Continuous Structure 3: Functions Structure 4: Objects I Structure 5: Objects II Synthesis 1: Form and Code Synthesis 2: Input and Response Synthesis 3: Motion and Arrays Synthesis 4: Structure, Interface Transform 1: Translate, Matrices Transform 2: Rotate, Scale Typography 1: Display Typography 2: Motion Typography 3: Response

    Interviews 1: Print Interviews 2: Software, Web Interviews 3: Animation, Video Interviews 4: Performance, Installation

    Extension 1: Continuing . . . Extension 2: 3D Extension 3: Vision Extension 4: Network Extension 5: Sound Extension 6: Print Extension 7: Mobile Extension 8: Electronics

    Appendixes Related Media Glossary Code Index Index

    Contents by category

    xixxxi

    1

    9

    85

    337

    51

    61

    37

    101

    105

    301

    145

    251

    217

    413

    95

    315

    321

    347

    355

    205

    223

    229

    237

    245

    427

    435

    43

    79

    117

    127

    279

    291

    367

    421

    23

    69

    197

    461

    477

    17

    173

    181

    395

    453

    149

    255

    371

    495

    133

    137

    111

    327

    333

    155

    261

    377

    501

    519

    525

    547

    563

    579

    603

    617

    633

    661

    693

    699

    703

    705

    Reas_00_i-xxvi.indd Sec1:ixReas_00_i-xxvi.indd Sec1:ix 5/18/07 9:44:32 AM5/18/07 9:44:32 AM

  • x

    29 30 44 55 63 70

    88 97 113 124 128 137

    186 200 206 219 225 231

    246 281 293 306 316 322

    334 340 349 353 406

    441 458 464 484 530 535

    83

    174

    239

    329

    414

    551

    356

    Reas_00_i-xxvi.indd Sec1:xReas_00_i-xxvi.indd Sec1:x 5/16/07 9:53:14 AM5/16/07 9:53:14 AM

  • xi

    Foreword by John Maeda

    Preface Contents How to read this book Caseys introduction Bens introduction Acknowledgments

    Processing . . . Software Literacy Open Education Network Context

    Using Processing Download, Install Environment Export Example walk-through Reference

    Structure 1: Code Elements Comments //, /* */

    Functions Expressions, Statements ;, ,

    Case sensitivity Whitespace Console print(), println()

    Extended contents

    Shape 1: Coordinates, Primitives Coordinates size()

    Primitive shapes point(), line(),

    triangle(), quad(), rect(),

    ellipse(), bezier()

    Drawing order Gray values background(), fill(),stroke(),

    noFill(), noStroke()

    Drawing attributes smooth(), noSmooth(),

    strokeWeight(), strokeCap(),

    strokeJoin()

    Drawing modes ellipseMode(), rectMode()

    Data 1: Variables Data types int, float, boolean,

    true, false

    Variables =

    Processing variables width, height

    Math 1: Arithmetic, Functions Arithmetic +, -, *, /, %

    Operator precedence, Grouping ()

    Shortcuts ++, --, +=, -=, *=, /=, - Constraining numbers ceil(), floor(), round(), min(), max()

    xix

    xxixxi

    xxiixxiiixxivxxv

    1

    1

    3

    4

    4

    6

    7

    9

    9

    9

    10

    11

    16

    17

    17

    18

    18

    20

    20

    20

    23

    23

    25

    31

    31

    33

    34

    37

    37

    38

    40

    43

    43

    47

    48

    49

    Reas_00_i-xxvi.indd Sec1:xiReas_00_i-xxvi.indd Sec1:xi 5/16/07 9:53:17 AM5/16/07 9:53:17 AM

  • xii

    Control 1: Decisions Relational expressions >, =,

  • xiii

    Transform 1: Translate, Matrices Translation translate()

    Controlling transformations pushMatrix(), popMatrix()

    Transform 2: Rotate, Scale Rotation, Scaling rotate(), scale()

    Combining transformations New coordinates

    Development 1: Sketching,