Programming in Processing - PowerPoint PPT Presentation

1 / 10
About This Presentation
Title:

Programming in Processing

Description:

Your coordinate axes will rotate around their center by the number of radians you specify. ... Inverting colors: You might want some color to be the exact ... – PowerPoint PPT presentation

Number of Views:12
Avg rating:3.0/5.0
Slides: 11
Provided by: mish154
Category:

less

Transcript and Presenter's Notes

Title: Programming in Processing


1
Programming in Processing
  • Taught by Ms. Madsen
  • Assistants Ms. Fischer and Ms. Yen
  • Winsor School, 4/2/08

2
Coordinate transformations!
3
0 remember resetMatrix().
  • After any of the coordinate transformations were
    about to learn, you can use resetMatrix() to
    return to the original axes.

4
Transformation 1 scale.
  • You call scale with one argument, like
    this scale(scaleFactor)
  • If scaleFactor2, for example.
  • each pixel will be 2x as wide and 2x as long as
    before.
  • So, if you had a window of size (500, 500)
  • the biggest rectangle that can now fit in the
    window is of width 250 and height 250, since only
    half as many pixels in each direction can fit in
    the window.

5
Transformation 2 translate.
  • You call translate with 2 arguments, like this
  • translate(xShift, yShift)
  • Your coordinate axes will move to the right by
    xShift and downwards by yShift.
  • So, if you have a window of size (500, 500)
  • You can move (0,0) to the exact middle of the
    window with
  • translate(250, 250)

6
Transformation 3 rotate.
  • You call rotate with 1 argument, like this
  • rotate(rotateFactor)
  • Your coordinate axes will rotate around their
    center by the number of radians you specify.
  • if rotateFactor PI/4, your axes rotate 45
    degrees.
  • If rotateFactor PI/2, your axes rotate 90
    degrees.

7
Inverting colors
  • You might want some color to be the exact
    opposite of some other color.
  • (Like black-white, red-green, yellow-purple,
    etc.)
  • You can get this effect this way
  • If this is the color youre starting with
  • color start color(redValue, greenValue,
    blueValue)
  • then this is the inverted color
  • color invert color(255-redValue, 255-greenValue,
    255-blueValue)

8
Keyboard input using keyPressed boolean
  • You can use the keyPressed boolean in your draw()
    method to make something happen as long as any
    key is pressed, like this
  • if (keyPressed)
  • ...// this will happen as long as a key is
    pressed

9
Keyboard input using keyPressed() method
  • Alternatively, we can use the void keyPressed()
    method like this
  • void keyPressed()
  • switch (key)
  • case (a)
  • // whatever you put here will happen once
  • // for each time a is pressed
  • break
  • case (m)
  • // whatever you put here happens once
  • // for each time m is pressed
  • break
  • default
  • // this happens if a key is pressed
  • // that you didnt specify an action for.
  • // ...you dont need to have default!
  • break

This is on the second page of your handout.
10
Here are the characters you can use in your case
statements
  • all of the letter keys
  • ? case (a)
  • all of the number keys
  • ? case (4)
  • BACKSPACE, TAB, and ENTER.
  • ? case (ENTER)
Write a Comment
User Comments (0)
About PowerShow.com