graphics lecture

29
Creative Programming – workshop 02 Mathias Funk (ID DI), Fall 2012 1

Upload: nic

Post on 28-Jan-2016

228 views

Category:

Documents


0 download

DESCRIPTION

Lecture on graphics for processing

TRANSCRIPT

Page 1: Graphics Lecture

Creative Programming – workshop 02

Mathias Funk (ID DI), Fall 2012

1

Page 2: Graphics Lecture

What we do today

ShapesColors +

Coordinates

Transforming shapes

Animating shapes

2

Page 3: Graphics Lecture

3

Page 4: Graphics Lecture

Shapes

4

Page 5: Graphics Lecture

First running sketch

5

Page 6: Graphics Lecture

Coordinate system

size(200, 200);(0,0)

(200,200)

(50,150)

y

x

6

Page 7: Graphics Lecture

Shapes

• Triangle

• Quad

• Rectangle

• Ellipse

triangle(x1, y1, x2, y2, x3, y3);

rect(x, y, width, height);

ellipse(x, y, width, height);

quad(x1, y1, x2, y2, x3, y3, x4, y4);

7

Page 8: Graphics Lecture

Rectangle Drawing Mode

• rectMode(CORNER);

• rectMode(CORNERS);

• rectMode(CENTER);

• rectMode(RADIUS);

8

Page 9: Graphics Lecture

Ellipse Drawing Mode

• ellipseMode(CORNER);

• ellipseMode(CORNERS);

• ellipseMode(CENTER);

• ellipseMode(RADIUS);

9

Page 10: Graphics Lecture

Colors

10

Page 11: Graphics Lecture

How colors work in Processing

• Color rendering in Processing works in the additive color model: RGB

• fill (<RED>, <GREEN>, <BLUE>); // all values from 0 - 255 possible

• fill(255, 0, 0); // pure red

• fill(0, 0, 130); // dark blue

• How to get yellow?

• When all values are same you will get grayscale colors (or white or black).

• “fill(120)” is a shortcut for “fill(120, 120, 120)”

11

Page 12: Graphics Lecture

Colors...

12

Page 13: Graphics Lecture

Colors, really

13

Page 14: Graphics Lecture

Outline aka Border aka Stroke

noStroke(); stroke(0,255,0);

14

Page 15: Graphics Lecture

Smoothing aka Anti-Aliasing

smooth(); noSmooth();

15

Page 16: Graphics Lecture

Transforming shapes

16

Page 17: Graphics Lecture

Transformations?

translate

scale

rotate

17

Page 18: Graphics Lecture

Translate

18

Page 19: Graphics Lecture

Scale

19

Page 20: Graphics Lecture

Rotate

Hint: rotate(radians(30));

20

Page 21: Graphics Lecture

Transformation UNDO

21

Page 22: Graphics Lecture

Polygon shapes

22

Page 23: Graphics Lecture

23

Page 24: Graphics Lecture

Dynamics – animating shapes

24

Page 25: Graphics Lecture

void setup( ) {size(200, 200);

}

void draw( ) {// erase backgroundbackground(0);// draw some stuff// ...

}

just once on start up

every frame,this happens

by the way: every frame starts without any transformations

25

Page 26: Graphics Lecture

// declare variable and set start valueint x = 0;

void draw( ) {// erase backgroundbackground(0);// add 1 to variablex = x + 1;// draw a rectangle of 20 by 20 pixelsrect(x, x, 20, 20);

}

void setup( ) {size(400, 400);

}

just once on start up

every framethis happens

26

Page 27: Graphics Lecture

Exercises

• Rotate a rectangle around the center of the window

• Rotate two rectangles around each other

• Bounce a rectangle off the screen’s borders

• Bounce a rectangle ... and change the color on every bounce

• Grow a rectangle and fade it out

27

Page 28: Graphics Lecture

Books

Must-have

Getting Started with Processing, by By Casey Reas, Ben Fry e-Book and hard copy available from O'Reilly

Recommended-to-have

Learning Processing: A Beginner's Guide to Programming Images, Animation, and InteractionDaniel Shiffman.Published August 2008, Morgan Kaufmann. 450 pages. Paperback.Available from LUCID, or from Amazon

Programming Interactivity: A Designer's Guide to Processing, Arduino, and openFrameworks (Paperback) by Joshua Noble (Author). Very good one, covers many topics in Competency II. Available from LUCID. Also see http://programminginteractivity.com

Processing: Creative Coding and Computational Art (Foundation)Ira Greenberg (Foreword by Keith Peters).Published 28 May 2007, Friends of Ed. 840 pages. Hardcover.Available from LUCID

Making Things Talk: Practical Methods for Connecting Physical ObjectsTom Igoe.Published 28 September 2007, O'Reilly. 428 pages. Paperback.Available from LUCID

28

Page 29: Graphics Lecture

More help...

http://wiki.id.tue.nl/creapro/

29