B. RAMAMURTHY Simulating Motion and Implementing Animation.

7
B. RAMAMURTHY Simulating Motion and Implementing Animation

Transcript of B. RAMAMURTHY Simulating Motion and Implementing Animation.

Page 1: B. RAMAMURTHY Simulating Motion and Implementing Animation.

B. RAMAMURTHY

Simulating Motion and Implementing Animation

Page 2: B. RAMAMURTHY Simulating Motion and Implementing Animation.

Processing Features for Motion/animation

fill(), nofill() in color commandsloop(), noloop() : this is for controlling draw()

functionframeRate()height, widthDisplaying text on the screentranslate ()rotate()

Page 3: B. RAMAMURTHY Simulating Motion and Implementing Animation.

Display Text on Screen

PFont f; // STEP 1 Declare PFont variable void setup() { size(200,200); f = createFont("Arial",16,true); // STEP 2 Create Font } int x= 10; int y = 100;void draw() { background(255); textFont(f,16); // STEP 3 Specify font

fill(0); // STEP 4 Specify font color

text("Hello Strings!", x, y); // STEP 5 Display Text }

Page 4: B. RAMAMURTHY Simulating Motion and Implementing Animation.

Print text on the terminal window

These are useful for debuggingprint( string);println(string)Example: println (“Position of the animal is” + x, “ “ + y);

Page 5: B. RAMAMURTHY Simulating Motion and Implementing Animation.

frameRate()

Observe naming convention “frame” “Rate” Specifies the number of frames to be displayed every second: default

is 60 secvoid setup() { frameRate(4);}int pos = 0;void draw() { background(204); pos++; line(pos, 20, pos, 80); if (pos > width) { pos = 0; }}

Page 6: B. RAMAMURTHY Simulating Motion and Implementing Animation.

loop() and noloop()

And redraw()draw() function by default keeps looping

without any control .You make control it using loop() and noloop()

function callsYou can also call draw to execute only once

by calling redraw() function

Page 7: B. RAMAMURTHY Simulating Motion and Implementing Animation.

translate and rotate

Last class we looked at translating (moving x and y) by moving the object. You can also simulate this by moving the grid, that’s what translate(x,y) function does.

You can also rotate the object by rotating the grid. It takes the parameters in radians. We think is degrees. We have a function radians() to convert degrees to radians.

Lets look at some examples.