B. RAMAMURTHY Simulating Motion and Implementing Animation.
-
Upload
bruno-shaw -
Category
Documents
-
view
215 -
download
1
Transcript of B. RAMAMURTHY Simulating Motion and Implementing Animation.
![Page 1: B. RAMAMURTHY Simulating Motion and Implementing Animation.](https://reader036.fdocuments.net/reader036/viewer/2022082819/56649f2f5503460f94c491e1/html5/thumbnails/1.jpg)
B. RAMAMURTHY
Simulating Motion and Implementing Animation
![Page 2: B. RAMAMURTHY Simulating Motion and Implementing Animation.](https://reader036.fdocuments.net/reader036/viewer/2022082819/56649f2f5503460f94c491e1/html5/thumbnails/2.jpg)
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.](https://reader036.fdocuments.net/reader036/viewer/2022082819/56649f2f5503460f94c491e1/html5/thumbnails/3.jpg)
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.](https://reader036.fdocuments.net/reader036/viewer/2022082819/56649f2f5503460f94c491e1/html5/thumbnails/4.jpg)
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.](https://reader036.fdocuments.net/reader036/viewer/2022082819/56649f2f5503460f94c491e1/html5/thumbnails/5.jpg)
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.](https://reader036.fdocuments.net/reader036/viewer/2022082819/56649f2f5503460f94c491e1/html5/thumbnails/6.jpg)
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.](https://reader036.fdocuments.net/reader036/viewer/2022082819/56649f2f5503460f94c491e1/html5/thumbnails/7.jpg)
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.