70 likes | 215 Views
Simulating Motion and Implementing Animation. B. Ramamurthy. Processing Features for Motion/animation. f ill(), nofill () in color commands l oop(), noloop () : this is for controlling draw() function frameRate () h eight, width Displaying text on the screen t ranslate () r otate().
E N D
Simulating Motion and Implementing Animation B. Ramamurthy
Processing Features for Motion/animation fill(), nofill() in color commands loop(), noloop() : this is for controlling draw() function frameRate() height, width Displaying text on the screen translate () rotate()
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 }
Print text on the terminal window These are useful for debugging print( string); println(string) Example: println (“Position of the animal is” + x, “ “ + y);
frameRate() Observe naming convention “frame” “Rate” Specifies the number of frames to be displayed every second: default is 60 sec void setup() { frameRate(4); } intpos = 0; void draw() { background(204); pos++; line(pos, 20, pos, 80); if (pos > width) { pos = 0; } }
loop() and noloop() And redraw() draw() function by default keeps looping without any control . You make control it using loop() and noloop() function calls You can also call draw to execute only once by calling redraw() function
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.