2018-06-29 10:22:13 +00:00
|
|
|
---
|
|
|
|
language: "Processing"
|
|
|
|
filename: learnprocessing.pde
|
|
|
|
contributors:
|
|
|
|
- ["Phone Thant Ko", "http://github.com/phonethantko"]
|
|
|
|
---
|
2018-06-29 11:32:18 +00:00
|
|
|
## Introduction
|
|
|
|
|
2018-06-29 10:22:13 +00:00
|
|
|
Processing is a programming language for creation of digital arts and multimedia content, allowing non-programmers to
|
2018-06-29 10:29:16 +00:00
|
|
|
learn fundamentals of computer programming in a visual context.
|
|
|
|
While the language is based off on Java language,
|
|
|
|
its syntax has been largely influenced by both Java and Javascript syntaxes. [See more here](https://processing.org/reference/)
|
2018-06-29 10:22:13 +00:00
|
|
|
The language also comes with its official IDE to compile and run the scripts.
|
|
|
|
|
2018-06-29 11:32:18 +00:00
|
|
|
```processing
|
|
|
|
/* ---------
|
|
|
|
Comments
|
|
|
|
---------
|
|
|
|
*/
|
|
|
|
|
2018-06-29 10:22:13 +00:00
|
|
|
// Single-line comment starts with //
|
|
|
|
|
|
|
|
/*
|
2018-06-29 11:32:18 +00:00
|
|
|
Since Processing is based on Java,
|
|
|
|
the syntax for its comments are the same as Java (as you may have noticed above)!
|
|
|
|
Multi-line comments are wrapped as seen here.
|
2018-06-29 10:22:13 +00:00
|
|
|
*/
|
|
|
|
|
2018-06-29 11:32:18 +00:00
|
|
|
/* ---------------------------------------
|
|
|
|
Writing and Running Processing Programs
|
|
|
|
---------------------------------------
|
|
|
|
*/
|
|
|
|
|
2018-06-29 10:22:13 +00:00
|
|
|
// In Processing, your program's entry point is a function named setup() with a void return type.
|
2018-06-29 11:32:18 +00:00
|
|
|
// Note! The syntax looks strikingly similar to that of C++.
|
2018-06-29 10:22:13 +00:00
|
|
|
void setup() {
|
|
|
|
// This prints out the classic output "Hello World!" to the console when run.
|
2018-06-29 11:32:18 +00:00
|
|
|
println("Hello World!"); // Another language with a semi-column trap, ain't it?
|
2018-06-29 10:22:13 +00:00
|
|
|
}
|
|
|
|
|
2018-06-29 11:32:18 +00:00
|
|
|
// Normally, we put all the static codes inside the setup() method as the name suggests.
|
|
|
|
// It can range from setting the background colours, setting the canvas size.
|
|
|
|
// You will see more of them throughout this document.
|
|
|
|
|
|
|
|
// Now that we know how to write the working script and how to run it,
|
|
|
|
// we will proceed to explore what data types and collections are supported in Processing.
|
|
|
|
|
|
|
|
/* -----------------------
|
|
|
|
Datatypes & collections
|
|
|
|
------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
// According to Processing References, Processing supports 8 primitive datatypes as follows.
|
|
|
|
|
|
|
|
boolean booleanValue = true; // Boolean
|
|
|
|
byte byteValueOfA = 23; // Byte
|
|
|
|
char charValueOfA = 'A'; // Char
|
|
|
|
color colourValueOfWhiteM = color(255, 255, 255); // Colour (Specified using color() method)
|
|
|
|
color colourValueOfWhiteH = #FFFFFF; // Colour (Specified using hash value)
|
|
|
|
int intValue = 5; // Integer (Number without decimals)
|
|
|
|
long longValue = 2147483648L; // "L" is added to the number to mark it as a long
|
|
|
|
float floatValue = 1.12345; // Float (32-bit floating-point numbers)
|
|
|
|
double doubleValue = 1.12345D; // Double (64-bit floating-point numbers)
|
|
|
|
|
|
|
|
// NOTE!
|
|
|
|
// Although datatypes "long" and "double" work in the language,
|
|
|
|
// processing functions do not use these datatypes, therefore
|
|
|
|
// they need to be converted into "int" and "float" datatypes respectively,
|
|
|
|
// using (int) and (float) syntax before passing into a function.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-06-29 10:22:13 +00:00
|
|
|
```
|
2018-06-29 11:32:18 +00:00
|
|
|
Processing is easy to learn and is particularly useful to create multimedia contents (even in 3D) without
|
|
|
|
having to type a lot of codes. It is so simple that you can read through the code and get a rough idea of
|
|
|
|
the program flow.
|
|
|
|
However, that does not apply when you introduce external libraries, packages and even your own classes.
|
|
|
|
(Trust me! Processing projects can get really large)
|
|
|
|
|
|
|
|
## What's Next?
|
|
|
|
|
|
|
|
Here, I have compiled some useful resources:
|
|
|
|
|
|
|
|
- [Processing Website](http://processing.org)
|
|
|
|
- [Processing Sketches](http://openprocessing.org)
|