CGT 215 Computer Graphics Programming I Introduc9on CGT - - PowerPoint PPT Presentation

cgt 215 computer graphics programming i
SMART_READER_LITE
LIVE PREVIEW

CGT 215 Computer Graphics Programming I Introduc9on CGT - - PowerPoint PPT Presentation

CGT 215 Computer Graphics Programming I Introduc9on CGT 215 Programming fundamentals Logic Problem solving Provides the basis for developing


slide-1
SLIDE 1

CGT ¡215 ¡ Computer ¡Graphics ¡Programming ¡I ¡

Introduc9on ¡

slide-2
SLIDE 2

CGT ¡215 ¡

  • Programming ¡fundamentals ¡
  • Logic ¡
  • Problem ¡solving ¡
  • Provides ¡the ¡basis ¡for ¡developing ¡object-­‑oriented ¡

applica9ons ¡ ¡

  • How ¡to ¡write, ¡compile, ¡build, ¡and ¡debug ¡GRAPHICS ¡
  • applica9ons. ¡ ¡
slide-3
SLIDE 3

Course ¡Philosophy ¡

  • Teach ¡programming ¡through ¡graphics ¡
  • Design ¡& ¡Visualiza9on ¡
  • Interac9vity ¡
  • Experimenta9on ¡
  • Learn ¡by ¡doing ¡5 ¡projects ¡

Processing ¡IDE ¡

slide-4
SLIDE 4

Family ¡Tree ¡

Image ¡from ¡“GeQng ¡started ¡with ¡Processing” ¡

slide-5
SLIDE 5

Course ¡Textbook ¡

slide-6
SLIDE 6

Why ¡Programming? ¡

slide-7
SLIDE 7

LOGO ¡ VIC ¡20, ¡my ¡first ¡computer ¡c. ¡1988 ¡

Computer ¡ar+st, ¡from ¡“Computer ¡graphics ¡with ¡OpenGL” ¡

slide-8
SLIDE 8

Basic ¡Heart. ¡ ¡1999 ¡

slide-9
SLIDE 9

In ¡and ¡Out. ¡Collabora9on ¡with ¡Max ¡Carlson ¡

slide-10
SLIDE 10

Why ¡Programming? ¡

Assignment ¡1 ¡ Why ¡do ¡you ¡want ¡to ¡learn ¡computer ¡graphics ¡ programming? ¡

– Type ¡up ¡in ¡one ¡or ¡two ¡paragraphs. ¡ ¡ – Submit ¡on ¡blackboard ¡ ¡

slide-11
SLIDE 11

? ¡

slide-12
SLIDE 12

Joshua ¡Davis ¡ ¡

h]ps://www.behance.net/joshuadavis ¡ ¡

slide-13
SLIDE 13

Marius ¡Watz ¡ ¡

h]ps://www.flickr.com/photos/watz ¡ ¡

slide-14
SLIDE 14

Rafael ¡Rozendaal ¡ ¡

h]p://www.newrafael.com/ ¡ ¡

slide-15
SLIDE 15

Why ¡Programming ¡

Cyberne9cs ¡ Core ¡competency ¡ Big ¡Data ¡ Digital ¡Fabrica9on ¡ Simula9on ¡ Parametric ¡Design ¡ We ¡are ¡data ¡ (Data ¡trails) ¡ h]p://vimeo.com/91054550 ¡ ¡

slide-16
SLIDE 16

CGT ¡215 ¡

Geometric ¡Primi9ves ¡

slide-17
SLIDE 17
slide-18
SLIDE 18

Geometric ¡primi9ves ¡

  • Point ¡
  • Line ¡
  • Shape ¡
  • Curve ¡
  • Polygon ¡
  • Plane ¡
slide-19
SLIDE 19

Cartesian ¡coordinate ¡system ¡

slide-20
SLIDE 20

Polygons ¡

slide-21
SLIDE 21

Circle ¡

  • r2= ¡x2+y2 ¡
slide-22
SLIDE 22

Composite ¡shapes ¡ + ¡ = ¡ = ¡

slide-23
SLIDE 23

Composite ¡shapes ¡

  • ­‑ ¡

= ¡

slide-24
SLIDE 24

Vector ¡Graphics ¡

Vector ¡graphics ¡is ¡the ¡use ¡of ¡geometrical ¡ primi9ves ¡such ¡as ¡points, ¡lines, ¡curves, ¡and ¡ shapes ¡or ¡polygon(s), ¡which ¡are ¡all ¡based ¡on ¡ mathema9cal ¡expressions, ¡to ¡represent ¡images ¡ in ¡computer ¡graphics. ¡

slide-25
SLIDE 25

Project ¡1:Vector ¡primi9ves ¡

  • Design ¡an ¡abstract ¡composi9on ¡using ¡the ¡geometric ¡

primi9ves ¡(See ¡geometric ¡abstrac9on ¡examples). ¡

  • Use ¡points, ¡lines, ¡shapes, ¡curves ¡and ¡at ¡least ¡4 ¡values ¡to ¡

produce ¡an ¡aesthe9cally ¡pleasing ¡image ¡in ¡the ¡Processing ¡ programming ¡environment. ¡ ¡

  • Use ¡the ¡func9ons ¡explained ¡in ¡Chapter ¡3 ¡(Reas ¡& ¡Fry, ¡2010) ¡
slide-26
SLIDE 26

Assignment ¡2 ¡

slide-27
SLIDE 27
slide-28
SLIDE 28
slide-29
SLIDE 29

Project ¡1 ¡

  • Vector ¡primi9ves ¡
slide-30
SLIDE 30

CGT ¡215 ¡ Computer ¡Graphics ¡Programming ¡I ¡

Variables ¡

slide-31
SLIDE 31

Variables ¡

Data ¡type ¡ Meaning ¡ Value ¡range ¡ Int ¡ Whole ¡numbers ¡

  • ­‑2,147 ¡Million ¡to ¡2,147 ¡Million ¡

float ¡ Floa9ng ¡point ¡(decimals) ¡ 3.40282347E+38 ¡to ¡-­‑3.40282347E+38 ¡ ¡ boolean ¡ T ¡F ¡statements ¡ True ¡or ¡False ¡ string ¡ Store ¡words ¡or ¡sentences ¡ “for ¡example…” ¡ color ¡ Store ¡colors ¡ ~ ¡17 ¡Million ¡

slide-32
SLIDE 32

Assignment ¡3 ¡

On ¡a ¡white ¡piece ¡of ¡paper, ¡ sketch ¡a ¡flow ¡diagram ¡of ¡ your ¡morning ¡rou9ne. ¡Be ¡as ¡ detailed ¡as ¡possible. ¡

slide-33
SLIDE 33

CGT ¡215 ¡ Computer ¡Graphics ¡Programming ¡I ¡

If… ¡else ¡

slide-34
SLIDE 34

CGT ¡215 ¡ Computer ¡Graphics ¡Programming ¡I ¡

And ¡-­‑ ¡Or ¡

slide-35
SLIDE 35

Rela9onal ¡Operators ¡

> ¡ Greater ¡than ¡ < ¡ Less ¡than ¡ >= ¡ Greater ¡than ¡or ¡equal ¡to ¡ <= ¡ Less ¡than ¡or ¡equal ¡to ¡ == ¡ Equality ¡ != ¡ Inequality ¡

slide-36
SLIDE 36

Logical ¡Operators ¡

|| ¡ Logical ¡OR ¡ && ¡ Logical ¡AND ¡ ! ¡ Logical ¡NOT ¡

slide-37
SLIDE 37

Expression ¡(test) ¡ Result ¡ ( ¡5 ¡== ¡4) ¡ False ¡ ( ¡5 ¡== ¡5) ¡ True ¡ !(23 ¡< ¡50) ¡ False ¡ (23 ¡> ¡3) ¡&& ¡(23 ¡< ¡8) ¡ False ¡ (23 ¡> ¡3) ¡|| ¡(23 ¡< ¡8) ¡ True ¡

slide-38
SLIDE 38

Image ¡from ¡Reas ¡& ¡Fry: ¡“GeQng ¡started ¡with ¡Processing” ¡

slide-39
SLIDE 39

Image ¡from ¡Reas ¡& ¡Fry: ¡“GeQng ¡started ¡with ¡Processing” ¡

slide-40
SLIDE 40

Image ¡from ¡Reas ¡& ¡Fry: ¡“GeQng ¡started ¡with ¡Processing” ¡

slide-41
SLIDE 41

CGT ¡215 ¡ Computer ¡Graphics ¡Programming ¡I ¡

Loops ¡

slide-42
SLIDE 42

Image ¡from ¡Reas ¡& ¡Fry: ¡“GeQng ¡started ¡with ¡Processing” ¡

slide-43
SLIDE 43

CGT ¡215 ¡ Computer ¡Graphics ¡Programming ¡I ¡

Geometric ¡Transforma9ons ¡

slide-44
SLIDE 44

Image ¡from ¡Reas ¡& ¡Fry: ¡“GeQng ¡started ¡with ¡Processing” ¡

slide-45
SLIDE 45

Image ¡from ¡Reas ¡& ¡Fry: ¡“GeQng ¡started ¡with ¡Processing” ¡

slide-46
SLIDE 46

Image ¡from ¡Reas ¡& ¡Fry ¡

slide-47
SLIDE 47

Image ¡from ¡Reas ¡& ¡Fry: ¡“GeQng ¡started ¡with ¡Processing” ¡

slide-48
SLIDE 48

Project ¡2 ¡

Recreate ¡the ¡one ¡or ¡more ¡ mail ¡envelope ¡pa]erns ¡ provided ¡in ¡the ¡a]ached ¡

  • PDF. ¡You ¡may ¡use ¡For ¡loops, ¡

If ¡statements ¡or ¡geometric ¡ transforma@ons ¡to ¡produce ¡ a ¡visual ¡output ¡that ¡ resembles ¡the ¡original ¡ pa]ern. ¡

slide-49
SLIDE 49

CGT ¡215 ¡ Computer ¡Graphics ¡Programming ¡I ¡

Digital ¡Images ¡

slide-50
SLIDE 50

Raster Images

  • Have a given resolution
  • Consist of pixels
  • Photorealistic

Examples: JPG, GIF, TIF, BMP, PNG

(different types of compression)

slide-51
SLIDE 51

Vector Images

  • A database of 2D objects
  • Have no fixed resolution
  • Does not consist of pixels
  • Can be scaled arbitrarily
  • Graphics stored as algorithms
  • Simplified as geometric

elements-objects Examples: PDF, SWF, clip arts, SVG, AI

slide-52
SLIDE 52

CGT ¡215 ¡ Computer ¡Graphics ¡Programming ¡I ¡

slide-53
SLIDE 53

white black hue gray shade tint tone

slide-54
SLIDE 54

Color Systems in CG

  • RGB
  • CMY+K
  • HLS or HSB or HSV
  • Lab
  • Color is a 3D

system!

slide-55
SLIDE 55

Pixels and values

slide-56
SLIDE 56

RGB

  • Additive system
  • Reference to value
  • f Pixels
  • 0 to 255
  • Hex is subset of

RGB: #0000FF

  • Screen color, web
slide-57
SLIDE 57

CMYK

  • Substractive system
  • Reference to

pigments

  • %
  • Print
  • Add “K”
slide-58
SLIDE 58

CMYK dot

slide-59
SLIDE 59

HSV

  • Intuitive
  • Easy to find
  • degrees, %
  • Hue, Saturation,

Value

  • Also called HSB,

HLS

slide-60
SLIDE 60

RGB , CMYK & HSV

slide-61
SLIDE 61

CGT ¡215 ¡ Computer ¡Graphics ¡Programming ¡I ¡

Mouse ¡& ¡Keyboard ¡ ¡ Inputs ¡

slide-62
SLIDE 62

? ¡

slide-63
SLIDE 63

Mouse ¡ ¡

mouseBu]on ¡ mouseClicked() ¡ mouseDragged() ¡ mouseMoved() ¡ mousePressed() ¡ mousePressed ¡ mouseReleased() ¡ mouseWheel() ¡ mouseX ¡ mouseY ¡ pmouseX ¡ pmouseY ¡

slide-64
SLIDE 64

Keyboard ¡

key ¡ keyCode ¡ keyPressed() ¡ keyPressed ¡ keyReleased() ¡ keyTyped() ¡

slide-65
SLIDE 65

CGT ¡215 ¡ Computer ¡Graphics ¡Programming ¡I ¡

Func9ons ¡

slide-66
SLIDE 66

Project ¡3: ¡ “Carnival ¡Ride” ¡

Create ¡a ¡program ¡that ¡simulates ¡a ¡ carnival ¡ride ¡that ¡is ¡controlled ¡by ¡the ¡

  • user. ¡

Your ¡program ¡must ¡use ¡the ¡following ¡ elements: ¡

  • Geometric ¡Transforma9ons ¡

(Rotate, ¡Scale) ¡

  • n/off ¡states, ¡backwards ¡ ¡
  • Import ¡Raster/Vector ¡images ¡
slide-67
SLIDE 67

Assignment ¡4 ¡

Concept ¡brief: ¡

  • What ¡are ¡you ¡going ¡to ¡do ¡for ¡

project ¡3? ¡ ¡

  • What ¡kind ¡of ¡programming ¡

elements ¡will ¡you ¡be ¡using? ¡ ¡

  • How ¡will ¡you ¡create ¡your ¡

images? ¡

  • Interac@vity: ¡What ¡will ¡trigger ¡

the ¡different ¡behaviors? ¡

slide-68
SLIDE 68

CGT ¡215 ¡ Computer ¡Graphics ¡Programming ¡I ¡

Func9ons ¡

slide-69
SLIDE 69

Func9ons ¡

  • Also ¡called ¡Methods, ¡

Subrou9nes, ¡Subprograms ¡

  • A ¡program ¡inside ¡a ¡program ¡
  • User-­‑defined ¡or ¡Language ¡

defined ¡

  • Can ¡return ¡values ¡but ¡it ¡

doesn’t ¡have ¡to ¡

slide-70
SLIDE 70

Func9ons ¡

General ¡Form ¡ ¡

Return-type method-name ( argument-type argument-name, …){ statements; return value }

slide-71
SLIDE 71

Func9ons ¡

General ¡Form ¡ ¡

void plant( int x,int y){ translate(x,y); //No return value }

  • float mars ( float w ){

float newWeight= w*0.38; return newWeight; //this value can be used later on the program }

slide-72
SLIDE 72

Func9ons ¡

slide-73
SLIDE 73

Return ¡Values ¡

float d = random(numSides);

slide-74
SLIDE 74

CGT ¡215 ¡ Computer ¡Graphics ¡Programming ¡I ¡

Arrays ¡[ ¡] ¡

slide-75
SLIDE 75

Arrays ¡

  • A ¡list ¡of ¡variables ¡
  • Shared ¡name ¡
  • Allows ¡to ¡work ¡with ¡lots ¡
  • f ¡variables ¡
slide-76
SLIDE 76

Arrays ¡

  • Each ¡item ¡in ¡the ¡list ¡is ¡an ¡

array ¡element ¡

  • We ¡access ¡each ¡element ¡by ¡

calling ¡its ¡index ¡number ¡[6] ¡

  • Elements ¡must ¡be ¡of ¡the ¡

same ¡data ¡type ¡ ¡

slide-77
SLIDE 77

Arrays ¡

  • Each ¡item ¡in ¡the ¡list ¡is ¡an ¡array ¡element ¡
  • We ¡access ¡each ¡element ¡by ¡calling ¡its ¡index ¡number ¡

[6] ¡

  • Elements ¡must ¡be ¡of ¡the ¡same ¡data ¡type: ¡

String [] animals={ cow, cat, dog }; ¡

slide-78
SLIDE 78

Arrays ¡

Image ¡from ¡Reas ¡& ¡Fry: ¡“GeQng ¡started ¡with ¡Processing” ¡

Index ¡# ¡

slide-79
SLIDE 79

Arrays ¡

Compact ¡array ¡assignment: ¡ ¡ int [] x = new int [3000]; ¡

slide-80
SLIDE 80

CGT ¡215 ¡ Computer ¡Graphics ¡Programming ¡I ¡

3D ¡primi9ves ¡

slide-81
SLIDE 81

3D ¡ ¡

slide-82
SLIDE 82

3D ¡

box() ¡ sphere() ¡ beginShape() ¡ endShape() ¡ vertex() ¡ line() ¡ push/popMatrix… ¡ ¡

slide-83
SLIDE 83
slide-84
SLIDE 84

Assignment ¡5 ¡

On ¡a ¡quad ¡piece ¡of ¡paper, ¡sketch ¡the ¡basic ¡geometry ¡of ¡ your ¡house ¡in ¡a ¡orthographic ¡projec9on. ¡Keep ¡the ¡design ¡ simple ¡using ¡planes, ¡boxes ¡or ¡spheres ¡only. ¡

slide-85
SLIDE 85

Assignment ¡5 ¡

h]p://vormplus.be/blog/ar9cle/drawing-­‑a-­‑cylinder-­‑with-­‑ processing ¡ ¡

slide-86
SLIDE 86

Project ¡4 ¡

Create ¡a ¡program ¡that ¡shows ¡your ¡house ¡design ¡in ¡3D. ¡Use ¡ func9ons ¡to ¡change ¡the ¡characteris9cs ¡of ¡the ¡building: ¡ ¡ Colors, ¡size ¡of ¡roof, ¡overall ¡height ¡etc.. ¡ ¡

slide-87
SLIDE 87

CGT ¡215 ¡ Computer ¡Graphics ¡Programming ¡I ¡

Objects ¡

slide-88
SLIDE 88

Object-­‑oriented ¡programming ¡(OOP) ¡

  • Like ¡“real” ¡objects ¡
  • Have ¡common ¡characteris9cs ¡
  • Have ¡common ¡func9ons ¡
slide-89
SLIDE 89

Object-­‑oriented ¡programming ¡(OOP) ¡

  • A ¡collec9on ¡of ¡

related ¡variables ¡ and ¡func9ons ¡

  • A ¡variable ¡is ¡a ¡

“Field” ¡and ¡ behaviors ¡or ¡ func9ons ¡called ¡ “methods” ¡

image ¡from ¡www.processing.lyndondaniels.com/ ¡

slide-90
SLIDE 90

class JitterBug {

  • float x;

float y; int diameter; float speed = 2.5;

  • JitterBug(float tempX, float tempY, int tempDiameter) {

x = tempX; y = tempY; diameter = tempDiameter; } constructor ¡

slide-91
SLIDE 91

constructor ¡

slide-92
SLIDE 92

CGT ¡215 ¡ Computer ¡Graphics ¡Programming ¡I ¡

Objects ¡

slide-93
SLIDE 93

Final ¡project ¡

The ¡theme ¡for ¡our ¡final ¡project ¡is ¡free ¡and ¡therefore, ¡you ¡ must ¡create ¡a ¡concept, ¡design ¡a ¡program ¡and ¡implement ¡

  • it. ¡Take ¡into ¡considera9on ¡the ¡different ¡topics ¡covered ¡

during ¡this ¡course ¡and ¡apply ¡them ¡in ¡a ¡new ¡and ¡crea9ve ¡

  • way. ¡There ¡are ¡no ¡limita9ons ¡what ¡to ¡do, ¡except ¡due ¡
  • dates. ¡This ¡is ¡your ¡opportunity ¡to ¡do ¡what ¡you ¡want! ¡

Imagine ¡it ¡could ¡be ¡a ¡game, ¡an ¡app ¡or ¡anything ¡from ¡ interac9ve ¡to ¡genera9ve… ¡ ¡ ¡

slide-94
SLIDE 94

Assignment ¡6 ¡

Create ¡a ¡brief ¡that ¡outlines ¡the ¡concept ¡of ¡your ¡final ¡

  • project. ¡Provide ¡sketches ¡and ¡flow ¡diagrams ¡to ¡

complement ¡your ¡idea. ¡ ¡