58
hacker 101/102 code4lib 2010 preconference Asheville, NC, USA 2010-02-21

Hacker 101/102 - Introduction to Programming w/Processing

Embed Size (px)

DESCRIPTION

Basic introduction to programming concepts using Processing. Developed for code4lib 2010 conference preconf "Hacker 101/102".

Citation preview

Page 1: Hacker 101/102 - Introduction to Programming w/Processing

hacker101/102

code4lib 2010 preconferenceAsheville, NC, USA 2010-02-21

Page 2: Hacker 101/102 - Introduction to Programming w/Processing

i. intro

why are we here?

Page 3: Hacker 101/102 - Introduction to Programming w/Processing

learn to hack?

Page 4: Hacker 101/102 - Introduction to Programming w/Processing

...not exactly

Page 5: Hacker 101/102 - Introduction to Programming w/Processing

we work in librariesso we can

help people

Page 6: Hacker 101/102 - Introduction to Programming w/Processing

we hack to help ourselves

help others

Page 7: Hacker 101/102 - Introduction to Programming w/Processing

what’s a good hacker?

Page 8: Hacker 101/102 - Introduction to Programming w/Processing

languages?standards?

jargon?math?logic?

frameworks?

Page 9: Hacker 101/102 - Introduction to Programming w/Processing

nope!

Page 10: Hacker 101/102 - Introduction to Programming w/Processing

a good hackerknows

when to ask for help

Page 11: Hacker 101/102 - Introduction to Programming w/Processing

a good hackerknows

how to ask for help

Page 12: Hacker 101/102 - Introduction to Programming w/Processing

a good hackerknows how

to help other hackers

Page 13: Hacker 101/102 - Introduction to Programming w/Processing

a good hackerknows other hackers

to ask for help

Page 14: Hacker 101/102 - Introduction to Programming w/Processing

when to askhow to ask

how to answerwhom to ask

Page 15: Hacker 101/102 - Introduction to Programming w/Processing

i’m herebecause i want

to be able to ask you

Page 16: Hacker 101/102 - Introduction to Programming w/Processing

when to ask?

Page 17: Hacker 101/102 - Introduction to Programming w/Processing

thirty minute rule

Page 18: Hacker 101/102 - Introduction to Programming w/Processing

for today:three minute rule

Page 19: Hacker 101/102 - Introduction to Programming w/Processing

how to ask?see “How to ask

questions the smart way”

Page 20: Hacker 101/102 - Introduction to Programming w/Processing

we’ll get startedtogether

Page 21: Hacker 101/102 - Introduction to Programming w/Processing

basics in Processingregexes in JavaScript

glue it together in Python

Page 22: Hacker 101/102 - Introduction to Programming w/Processing

explore on your own

Page 23: Hacker 101/102 - Introduction to Programming w/Processing

get comfortableasking for help

Page 24: Hacker 101/102 - Introduction to Programming w/Processing

ii. the basics

Processing

Page 25: Hacker 101/102 - Introduction to Programming w/Processing

canvas, grid, points

Page 26: Hacker 101/102 - Introduction to Programming w/Processing

200

400

300200

Page 27: Hacker 101/102 - Introduction to Programming w/Processing

lines, rects, ellipses

Page 28: Hacker 101/102 - Introduction to Programming w/Processing

start

end

Page 29: Hacker 101/102 - Introduction to Programming w/Processing

syntax, functions, errors

Page 30: Hacker 101/102 - Introduction to Programming w/Processing

don’t be afraidto break stuff

Page 31: Hacker 101/102 - Introduction to Programming w/Processing

variables, loops

Page 32: Hacker 101/102 - Introduction to Programming w/Processing

test

initial value

type “integer”

increment

repeatingactions

Page 33: Hacker 101/102 - Introduction to Programming w/Processing

every lang has loops

• for (a=blah, a<foo, a=a+bar) {...}

• for each (foo in blah) {...}

• for i in range(20): ...

• while (foo != bar) do {...}

• next, continue, break

Page 34: Hacker 101/102 - Introduction to Programming w/Processing

more variables, loops

Page 35: Hacker 101/102 - Introduction to Programming w/Processing

even more variables, loops

Page 36: Hacker 101/102 - Introduction to Programming w/Processing

explore on your own

Page 37: Hacker 101/102 - Introduction to Programming w/Processing

iii. functions, objects,the main loop

Page 38: Hacker 101/102 - Introduction to Programming w/Processing

why functions?

Page 39: Hacker 101/102 - Introduction to Programming w/Processing

setup, draw, void

Page 40: Hacker 101/102 - Introduction to Programming w/Processing

function structure

RETURN_TYPE FUNCTION_NAME ([var a, ...]) {...statements...}

Page 41: Hacker 101/102 - Introduction to Programming w/Processing

setup, draw

•void: returns nothing (into the void!)

•setup: prep stuff

•draw: the “animation loop” or “main”

Page 42: Hacker 101/102 - Introduction to Programming w/Processing

different kinds of “main”

• Processing: draw() is like an animation “cell”

• in a GUI: the user feedback loop

• command-line app: parse args, then main()

• web app: the user feedback loop

Page 43: Hacker 101/102 - Introduction to Programming w/Processing

setup, draw, void

Page 44: Hacker 101/102 - Introduction to Programming w/Processing

we canwrite this better

Page 45: Hacker 101/102 - Introduction to Programming w/Processing

setup, draw, void

Page 46: Hacker 101/102 - Introduction to Programming w/Processing

see the problem?

Page 47: Hacker 101/102 - Introduction to Programming w/Processing

setup, draw, void

Page 48: Hacker 101/102 - Introduction to Programming w/Processing

DRYDon’t Repeat Yourself

Page 49: Hacker 101/102 - Introduction to Programming w/Processing

a littlebetter

Page 50: Hacker 101/102 - Introduction to Programming w/Processing

moretask

specific

Page 51: Hacker 101/102 - Introduction to Programming w/Processing

adddelay(10);

Page 52: Hacker 101/102 - Introduction to Programming w/Processing

nowtry this

initialization

no loop!

if/elsei.e.

“conditional”

Page 53: Hacker 101/102 - Introduction to Programming w/Processing

•draw() is already a loop; why another?

•“i” becomes state

•tightens up draw()

Page 54: Hacker 101/102 - Introduction to Programming w/Processing

what about objects?

Page 55: Hacker 101/102 - Introduction to Programming w/Processing

objecti

fied

Page 56: Hacker 101/102 - Introduction to Programming w/Processing

• it says what it is

• it removes a lot of repeated noise

• it’s kinda overkill here

•we don’t use rp1 and rp2 again

Page 57: Hacker 101/102 - Introduction to Programming w/Processing

• design a matter of taste

• sometimes things should be called what they mean

• sometimes an “int i” is just an “int i”

• think about what you’ll understand later

no single answer

Page 58: Hacker 101/102 - Introduction to Programming w/Processing

explore on your own