review of art3 programming course david meredith aalborg university [email protected]

5
Review of ArT3 Programming Course David Meredith Aalborg University [email protected]

Upload: leslie-ellis

Post on 02-Jan-2016

214 views

Category:

Documents


2 download

TRANSCRIPT

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

Review of ArT3 Programming Course

David MeredithAalborg University

[email protected]

Page 2: Review of ArT3 Programming Course David Meredith Aalborg University dave@create.aau.dk

Lecture 1: Introduction to Processing

• Drawing simple shapespoint(x,y)line(x1,y1,x2,y2)rect(x,y,w,h)rectMode(CORNER|CENTER|

CORNERS)ellipse(x,y,w,h)ellipseMode(CORNER|CENTER|

CORNERS)

• Defining greyscale values – 0 = black, 255 = whitestroke(n) (default is black)fill(n) (default is white)background(n) (default is grey)noStroke()noFill()

• Defining coloursfill(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)

– Colourfill(r,g,b,a)background(r,g,b,a)stroke(r,g,b,a)

• Defining line widthstrokeWeight(x)

• Defining drawing areasize(x,y)

• Smoothing lines and edgessmooth()

• Printing to consoleprintln(“a string”)

• Comments// comments rest of line/* comments region in between */

• Program structuresetup() and draw()

• Tracking mouse locationmouseX and mouseYpmouseX 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

Page 3: Review of ArT3 Programming Course David Meredith Aalborg University dave@create.aau.dk

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

Page 4: Review of ArT3 Programming Course David Meredith Aalborg University dave@create.aau.dk

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;

}

Page 5: Review of ArT3 Programming Course David Meredith Aalborg University dave@create.aau.dk

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.