Presentation is loading. Please wait.

Presentation is loading. Please wait.

Review of ArT3 Programming Course David Meredith Aalborg University

Similar presentations


Presentation on theme: "Review of ArT3 Programming Course David Meredith Aalborg University"— Presentation transcript:

1 Review of ArT3 Programming Course David Meredith Aalborg University dave@create.aau.dk

2 Lecture 1: Introduction to Processing Drawing simple shapes point(x,y) line(x1,y1,x2,y2) rect(x,y,w,h) rectMode(CORNER|CENTER|CORNERS ) ellipse(x,y,w,h) ellipseMode(CORNER|CENTER|CORNE RS) Defining greyscale values – 0 = black, 255 = white stroke(n) (default is black) fill(n) (default is white) background(n) (default is grey) noStroke() noFill() Defining colours fill(r,g,b) stroke(r,g,b) background(r,g,b) Defining opacity (alpha) – 255 = completely opaque, 0 = completely transparent – Greyscale fill(n,a) background(n,a) stroke(n,a) – Colour fill(r,g,b,a) background(r,g,b,a) stroke(r,g,b,a) Defining line width strokeWeight(x) Defining drawing area size(x,y) Smoothing lines and edges smooth() Printing to console println(“a string”) Comments // comments rest of line /* comments region in between */ Program structure setup() and draw() Tracking mouse location mouseX and mouseY pmouseX and pmouseY Responding to mouse clicks and key presses void mousePressed() void keyPressed() Using Processing – Shift-Click Run to run full screen – Sketchbook – Publishing (Exporting) a sketch

3 Lecture 2: Variables and Conditionals Variables – Types int, byte, short, long double, float char boolean – Declaring variables int x; – Initializing variables int x = 2; – Global variables Defined outside setup() and draw() – Assigning values to variables x = 5; – System variables width, height, frameCount, frameRate, screen.width, screen.height, key, keyCode, mousePressed, mouseX, mouseY, pmouseX, pmouseY, mouseButton – Random numbers w = random(x,y) w = random(x) – Type-casting e.g., w = int(random(1,100)) Conditionals – Boolean expressions – Relational operators >, =, <=, ==, != – if (condition) {doThis();} – if (condition) {doThis();} else {doThat();} – if (condition1) {doThis();} else if (condition2) {doThat();} else {doTheOther();} – Logical operators &&, ||, ! – Bouncing ball programme

4 Lecture 3: Loops and Functions Loops – while(condition) { doThis(); change something; } – int x = constrain(value, min, max); – for (initialization; test; change something) { doThis(); } – Increment expressions i++, i--, i += 2, i -= 2 – Scope – Loops within loops Functions – Modularity and reusability – ReturnType functionName(ArgType1 arg1, ArgType2 arg2) { ReturnType r = something; doSomethingWithR(); return r; }

5 Lecture 4: Objects and Arrays Objects – Data and functions together – Instance variables and methods – Classes as templates for making objects – Dot notation for messages myCar.move(); int s = myCar.speed; – Writing a class class ClassName { int x; float y; ClassName(int x, float y) { this.x = x; this.y = y; } void display() { //Use x and y to show this object …. } } – Class definitions must appear outside of setup() or draw() – Putting a class in its own tab Arrays – Array is a list of boxes, all holding values of the same type – Declaring an array variable int[] arrayOfInts; – Creating an array int[] arrayOfInts = new int[10]; – Accessing an element in an array arrayOfInts[0] = 5; int x = arrayOfInts[0]; – Initializing all elements at once int[] intArray = {5,4,3,2,1}; – Initializing an array with a loop for (int i = 0; i < intArray.length; i++) intArray[i] = 2 * i; – Array functions shorten(), concat(), subset(), etc.


Download ppt "Review of ArT3 Programming Course David Meredith Aalborg University"

Similar presentations


Ads by Google