![Page 1: Programming with Visual Output Crowd Simulation … · Programming with Visual Output Processing, Java, ... Processing examples explained Exercise ... Once software programs got a](https://reader030.vdocuments.site/reader030/viewer/2022021622/5b9b290e09d3f21b2f8cbd9b/html5/thumbnails/1.jpg)
Programming with Visual OutputProcessing, Java, Elementary Tricks
05.10.2015
Crowd Simulation [email protected]@arch.ethz.ch
![Page 2: Programming with Visual Output Crowd Simulation … · Programming with Visual Output Processing, Java, ... Processing examples explained Exercise ... Once software programs got a](https://reader030.vdocuments.site/reader030/viewer/2022021622/5b9b290e09d3f21b2f8cbd9b/html5/thumbnails/2.jpg)
Programming Visual Output
Java syntax: repetition / whole picture
Processing examples explained
Exercise
Crowd Simulation | 05.10.2015
![Page 3: Programming with Visual Output Crowd Simulation … · Programming with Visual Output Processing, Java, ... Processing examples explained Exercise ... Once software programs got a](https://reader030.vdocuments.site/reader030/viewer/2022021622/5b9b290e09d3f21b2f8cbd9b/html5/thumbnails/3.jpg)
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/_keywords.html
Java Syntax(Key)words vs punctuation
Crowd Simulation | 05.10.2015
punctuation characters cannot be changed
words can
exception:
keywords (for, if, int, return, ...)
and all other built-in data types:
int, double, ...
![Page 4: Programming with Visual Output Crowd Simulation … · Programming with Visual Output Processing, Java, ... Processing examples explained Exercise ... Once software programs got a](https://reader030.vdocuments.site/reader030/viewer/2022021622/5b9b290e09d3f21b2f8cbd9b/html5/thumbnails/4.jpg)
Java Syntax
Block {…}
bracket characters
Parameters(…)List[…]
Punctuation Characters
Crowd Simulation | 05.10.2015
/* comment */assignment
// commentcondition==
!=>
<
>=
<=
=
class
for loop
while loop
if / else conditions
function (also called "method")
calculation+
- /
* %
++
--
+=
-=
*=
/=
logic
&&
||
initializing an array using a for-loop to fill it with values
explain code with comments print the array
statements ;
int a = 1; using operators
![Page 5: Programming with Visual Output Crowd Simulation … · Programming with Visual Output Processing, Java, ... Processing examples explained Exercise ... Once software programs got a](https://reader030.vdocuments.site/reader030/viewer/2022021622/5b9b290e09d3f21b2f8cbd9b/html5/thumbnails/5.jpg)
Java SyntaxPunctuation Characters (Pro)
Crowd Simulation | 05.10.2015
short cut in for loops using :
:
for special data types the if/else if /else block can be replaced with a switch statement,
(old concept from C language )
goto statements = very, very old concept (not supported anymore in Java) goto = jump to another position in code
Once software programs got a bit more complex in the 70/80ies, code with "goto" statements turned out to be not understandable anymore.
Such code was called "spaghetti code" - too complex to follow. Therefore computer scientists invented first functions (C)
and later the concept of object oriented programming (C++)
additional information
![Page 6: Programming with Visual Output Crowd Simulation … · Programming with Visual Output Processing, Java, ... Processing examples explained Exercise ... Once software programs got a](https://reader030.vdocuments.site/reader030/viewer/2022021622/5b9b290e09d3f21b2f8cbd9b/html5/thumbnails/6.jpg)
Functionsin Java called methods
Crowd Simulation | 05.10.2015
return (result can be assigned to a variable)
return type (type of the returned value)
![Page 7: Programming with Visual Output Crowd Simulation … · Programming with Visual Output Processing, Java, ... Processing examples explained Exercise ... Once software programs got a](https://reader030.vdocuments.site/reader030/viewer/2022021622/5b9b290e09d3f21b2f8cbd9b/html5/thumbnails/7.jpg)
Java Syntax(Key)words / Syntax Coloring
Crowd Simulation | 05.10.2015
punctuation characters cannot be changed
words can
exception:
keywords (for, if, int, return, ...)
and all other built-in data types:
int, double, ...
method name
parameter declaration
same method name same parameter declaration = error
same method name different parameter declaration
![Page 8: Programming with Visual Output Crowd Simulation … · Programming with Visual Output Processing, Java, ... Processing examples explained Exercise ... Once software programs got a](https://reader030.vdocuments.site/reader030/viewer/2022021622/5b9b290e09d3f21b2f8cbd9b/html5/thumbnails/8.jpg)
this makes our code more readable
objects are being created by creating an instance of a class
Objects / ClassesDefine your own data types
Crowd Simulation | 05.10.2015
![Page 9: Programming with Visual Output Crowd Simulation … · Programming with Visual Output Processing, Java, ... Processing examples explained Exercise ... Once software programs got a](https://reader030.vdocuments.site/reader030/viewer/2022021622/5b9b290e09d3f21b2f8cbd9b/html5/thumbnails/9.jpg)
Casting
Crowd Simulation | 05.10.2015
Convert from one type to anotherif possible
![Page 10: Programming with Visual Output Crowd Simulation … · Programming with Visual Output Processing, Java, ... Processing examples explained Exercise ... Once software programs got a](https://reader030.vdocuments.site/reader030/viewer/2022021622/5b9b290e09d3f21b2f8cbd9b/html5/thumbnails/10.jpg)
Processing
Crowd Simulation | 05.10.2015
Examples & Sources (for Eclipse)
![Page 11: Programming with Visual Output Crowd Simulation … · Programming with Visual Output Processing, Java, ... Processing examples explained Exercise ... Once software programs got a](https://reader030.vdocuments.site/reader030/viewer/2022021622/5b9b290e09d3f21b2f8cbd9b/html5/thumbnails/11.jpg)
Processing
Crowd Simulation | 05.10.2015
Examples 1: Arrayhttps://processing.org/examples/array.html
![Page 12: Programming with Visual Output Crowd Simulation … · Programming with Visual Output Processing, Java, ... Processing examples explained Exercise ... Once software programs got a](https://reader030.vdocuments.site/reader030/viewer/2022021622/5b9b290e09d3f21b2f8cbd9b/html5/thumbnails/12.jpg)
Crowd Simulation | 05.10.2015
ProcessingExamples 2: Array2Dhttps://processing.org/examples/array2d.html
![Page 13: Programming with Visual Output Crowd Simulation … · Programming with Visual Output Processing, Java, ... Processing examples explained Exercise ... Once software programs got a](https://reader030.vdocuments.site/reader030/viewer/2022021622/5b9b290e09d3f21b2f8cbd9b/html5/thumbnails/13.jpg)
Crowd Simulation | 05.10.2015
ProcessingExamples 3: Particles
![Page 14: Programming with Visual Output Crowd Simulation … · Programming with Visual Output Processing, Java, ... Processing examples explained Exercise ... Once software programs got a](https://reader030.vdocuments.site/reader030/viewer/2022021622/5b9b290e09d3f21b2f8cbd9b/html5/thumbnails/14.jpg)
Home Task
a) Modify the Array2D example. Make the black hole follow the mouse.
b) Create a Processing Applet in which at least 3 different geometric forms are moving. (If we find out the code was copied from the internet ⇢ 0 pts)
Due 25.10.2015,send to [email protected]
Crowd Simulation | 05.10.2015