Skip to main content

LOOK INSIDE: Computational Drawing

Page 35

is that each mark need not be a reinvention of a new mark type. Once a kind of mark is defined, many instances of that mark can be made without invention of new mark types. As a corollary, the definition of a mark is not the same as the creation of a mark. The outer layer—the “calling”—of functions is necessary to deploy the actions that have been articulated. Both conditional statements and loops allow functions and other operations to be performed based on a logical order. If you are fluent in English, you already implicitly understand how these constructs work. Similar logic is built into our spoken and written language. A conditional statement is an if-then argument: if a condition is true, then do something. A variant on the if-then statement is the if-then-else statement, which, in more verbose terms can be articulated as, if a condition is true, then do something—otherwise—do something else. In an if-then statement, the “do something” part can be any number of things, it could be one line of code calling one of your marking functions or multiple lines of code that do anything else. A “while” construct is shorthand for while a condition is true, do something. A very basic drawing algorithm might read something like: While the number of marks made so far is less than 100, “make a mark”.

Of course, make a mark, could be any one of your marking functions. Exercise 1.2 Draw from a function library Using nothing more than loops and conditional statements, call your marking functions from your library by writing in plain English. Then, make another drawing using a library made by someone else.

The algorithm just given as an example is simple enough to write out as a sentence. However, when the algorithms get even slightly more layered, with loops within loops and multiple functions within each conditional, it becomes necessary to organize the code a bit more. Different programming languages do this in different ways. This book does not adhere to the conventions of any one language. Instead, algorithms are written something called “pseudocode,” which uses plain English, but is structured like a programming language. Indentations are used to group code together in segments associated with each conditional or loop. For example, the example algorithm in pseudocode is:

35


Turn static files into dynamic content formats.

Create a flipbook