programming_fundamentals_with_processing:ch02-getting-going.html
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
programming_fundamentals_with_processing:ch02-getting-going.html [2017/07/26 15:20] – created mithat | programming_fundamentals_with_processing:ch02-getting-going.html [2017/07/26 17:44] (current) – [The console] mithat | ||
---|---|---|---|
Line 7: | Line 7: | ||
==== Source code ==== | ==== Source code ==== | ||
- | A computer program' | + | In programming, |
- | )) The source code you write is stored in files called **source code files**--sometimes shortened to simply **sources** or **code**. Thus, source code files are text files made up of sets of instructions written in a particular programming language that express what you'd like the program to do. | + | )) The source code you write is stored in files called **source code files**---sometimes shortened to simply **sources** or **code**. Thus, source code files are text files made up of sets of instructions written in a particular programming language that express what you'd like the program to do. |
==== Entry points ==== | ==== Entry points ==== | ||
- | Some languages start executing a program at the first bit of program text that is in the program' | + | Some languages start executing a program at the first bit of program text that is in the program' |
=== Processing without an entry point === | === Processing without an entry point === | ||
- | Below is one of the simplest Processing programs you can write. When executed, it will print an important message about cranberries. | + | Below is one of the simplest Processing programs you can write. When executed, it will print an important message about cranberries.((Yes, this text output goes against the visual intent of Processing! Don't worry, we'll get to visual stuff shortly.)) |
- | **program '' | + | <file |
- | + | ||
- | <code java> | + | |
println(" | println(" | ||
- | </code> | + | </file> |
- | This is an example of a program written in what Processing calls its Basic Mode. In Basic Mode, the program' | + | |
- | **program | + | This is an example of a program |
- | <code java> | + | Here's a program with two statements: |
+ | |||
+ | <file java cranberries_and_more.pde> | ||
println(" | println(" | ||
println(" | println(" | ||
- | </code> | + | </file> |
- | Processing' | + | |
+ | Processing' | ||
=== Processing with an entry point === | === Processing with an entry point === | ||
- | Processing will automatically switch to Continuous Mode when you define at least one function in your program. (This is why you are not allowed to define functions in Basic Mode.) In Continuous Mode, Processing will look for a definition of a function called **'' | + | Processing will automatically switch to Continuous Mode when you define at least one function in your program. (This is why you are not allowed to define functions in Basic Mode.) In Continuous Mode, Processing will look for a definition of a function called **'' |
- | **program '' | + | <file java cranberries_continuous_mode.pde> |
- | + | ||
- | <code java> | + | |
void setup() { | void setup() { | ||
println(" | println(" | ||
} | } | ||
- | </code> | + | </file> |
This program consists of a definition of the '' | This program consists of a definition of the '' | ||
Line 50: | Line 49: | ||
<code java> | <code java> | ||
void setup() { | void setup() { | ||
- | | ||
} | } | ||
</ | </ | ||
+ | |||
The code that is written between the pair of curly braces is called the **body** of the '' | The code that is written between the pair of curly braces is called the **body** of the '' | ||
Line 60: | Line 59: | ||
void setup() { | void setup() { | ||
</ | </ | ||
- | and/or after the matching | + | and/or after the matching |
- | + | ||
- | <code java> | + | |
- | } | + | |
- | </ | + | |
the program will actually start at the first statement in the '' | the program will actually start at the first statement in the '' | ||
Line 70: | Line 65: | ||
void setup() { | void setup() { | ||
</ | </ | ||
+ | |||
==== Program statements ==== | ==== Program statements ==== | ||
Line 92: | Line 88: | ||
</ | </ | ||
- | ---- | ||
+ | <WRAP center round box 80%> | ||
=== Geek break: Why semicolons? === | === Geek break: Why semicolons? === | ||
If a statement is the programming equivalent of a sentence, why are semicolons used to mark the end of statements rather than periods? | If a statement is the programming equivalent of a sentence, why are semicolons used to mark the end of statements rather than periods? | ||
- | The biggest reason for this is that the language on which Processing is based, Java, uses semicolons to mark the end of statements. But why does Java do this? Because the language on which a lot of Java syntax is based, C++, also uses semicolons. Why does C++ do this? Because ..., you get the idea. The language ALGOL, whose development began in the late 1950' | + | The biggest reason for this is that the language on which Processing is based, Java, uses semicolons to mark the end of statements. But why does Java do this? Because the language on which a lot of Java syntax is based, C++, also uses semicolons. Why does C++ do this? Because ... , you get the idea. The language ALGOL, whose development began in the late 1950' |
- | One of the things that makes the semicolon well-suited to marking the end of statements is that the semicolon has little semantic value otherwise. A period is commonly used with floating point numbers (e.g., 3.14159, 22.5, 98.6) and so marking the end of program statements with a period would mean that whatever tries to understand the code would have to do additional work to figure out whether the dot means "end of statement" | + | One of the things that makes the semicolon well-suited to marking the end of statements is that the semicolon has little semantic value otherwise. A period is commonly used with floating point numbers (e.g., 3.14159, 22.5, 98.6) and so marking the end of program statements with a period would mean that whatever tries to understand the code you're written |
)) | )) | ||
- | You might now be asking why you need to mark the end of a statement all. Isn't it obvious that the statement ends at the end of the line? Some languages actually do this. There are advantages and disadvantages either way, which you might gain an appreciation for when we cover the subject of whitespace. The debate over which is indeed " | + | You might now be asking why you need to mark the end of a statement all. Isn't it obvious that the statement ends at the end of the line? Some languages actually do this. There are advantages and disadvantages either way, which you might gain an appreciation for when we cover the subject of //whitespace//. The debate over which is indeed " |
+ | </ | ||
- | ---- | ||
==== Comments ==== | ==== Comments ==== | ||
Line 133: | Line 129: | ||
Sending text messages to the console can be accomplished with two predefined Processing functions: '' | Sending text messages to the console can be accomplished with two predefined Processing functions: '' | ||
- | **program '' | + | <file java cranberries.pde> |
- | + | ||
- | <code java> | + | |
void setup() { | void setup() { | ||
println(" | println(" | ||
} | } | ||
- | </code> | + | </file> |
The above code consists of a definition of the '' | The above code consists of a definition of the '' | ||
Line 145: | Line 140: | ||
Cranberries are high in antioxidants. | Cranberries are high in antioxidants. | ||
</ | </ | ||
+ | |||
Notice the double quotation marks around the text. These are important. They tell '' | Notice the double quotation marks around the text. These are important. They tell '' | ||
Line 161: | Line 157: | ||
} | } | ||
</ | </ | ||
+ | |||
produces the following console output: | produces the following console output: | ||
Line 166: | Line 163: | ||
Cranberries are high in antioxidants. | Cranberries are high in antioxidants. | ||
</ | </ | ||
+ | |||
Using '' | Using '' | ||
Line 176: | Line 174: | ||
} | } | ||
</ | </ | ||
- | will outputs: | + | |
+ | will output: | ||
< | < | ||
Line 184: | Line 183: | ||
antioxidants. | antioxidants. | ||
</ | </ | ||
+ | |||
=== Outputting numbers and calculations === | === Outputting numbers and calculations === | ||
Line 219: | Line 219: | ||
</ | </ | ||
- | ---- | + | <WRAP center round box 80%> |
=== Geek break: What about input? === | === Geek break: What about input? === | ||
Line 228: | Line 227: | ||
Because text-based input is as involved as it is in Processing, we will avoid it in this text. We will, however, work with some of the interaction features that Processing makes very easy when we cover //event handling//. | Because text-based input is as involved as it is in Processing, we will avoid it in this text. We will, however, work with some of the interaction features that Processing makes very easy when we cover //event handling//. | ||
+ | </ | ||
- | ---- | ||
==== The canvas ==== | ==== The canvas ==== |
programming_fundamentals_with_processing/ch02-getting-going.html.1501082421.txt.gz · Last modified: 2017/07/26 15:20 by mithat