Note : Based on the same animation principles, i have developed this Android game which can be found at Google Play store at
https://play.google.com/store/apps/details?id=com.somitsolutions.training.android.bouncingball
When i was given a task to simulate different functionalities of physics/mechanics, i pondered on it for sometimes. Then i thought to create a simple example app to showcase the concept. this app actually animates the simple pendulum motion on android. it was done using android canvas and sufaceview. you can download the source code from here. the apk is here.
i took the initial angle of the pendulum as PI/4. here is the screen capture of the pendulum motion in the emulator.
the entire locus of the pendulum with respect to time has been divided in 6 parts.
the formula of the simple pendulum motion that i have used to calculate the X-Y co-ordinates of the pendulum is
d⍬ = dt/squrt(l/g) where d⍬ is the delta angle shift of the pendulum in the delta time dt.
the crux of this app lies in the class called Panel which is defined as follows:
The thread function has been defined as follows:
And the Activity class is like the below:
i would like to share some issues that i faced while doing this animation. as all of you know that the simple animation is done by removing the trace of a moving object by repainting the previous position with the background color. i was trying to do the same thing by repainting only that part of the screen which was occupied by the pendulum before moving to a new position. however, it was not giving proper result. when i was scratching my head over the issue, suddenly i saw a simple line in android documentation that says if somebody wants to repaint only a portion of the screen, the result may be undefined. so its better to repaint the whole screen for proper animation. and it solved my problem. and hence the first line of the onDraw() is canvas.drawColor(Color.BLACK).
similarly, using the same principles, i have simulated the circular motion. the apk for the same can be download from here. the screen capture of this app is like the following:
i am also trying to do some experimentation with the simulation of different physics functionality using the game engine called Cocos2D. here is the screen capture of one of such experimentation which simulates the circular motion.
hopefully this article will be able to throw some lights on android graphics and animation.
with this positive hope i would like to end this discussion.
https://play.google.com/store/apps/details?id=com.somitsolutions.training.android.bouncingball
When i was given a task to simulate different functionalities of physics/mechanics, i pondered on it for sometimes. Then i thought to create a simple example app to showcase the concept. this app actually animates the simple pendulum motion on android. it was done using android canvas and sufaceview. you can download the source code from here. the apk is here.
i took the initial angle of the pendulum as PI/4. here is the screen capture of the pendulum motion in the emulator.
the entire locus of the pendulum with respect to time has been divided in 6 parts.
- the first half of the left to right movement
- the middle position of the pendulum while moving from left to right
- the second half of the left to right movement
- the first half of the right to left movement
- the middle position of the pendulum while moving from right to left
- the second half of the right to left movement
the formula of the simple pendulum motion that i have used to calculate the X-Y co-ordinates of the pendulum is
d⍬ = dt/squrt(l/g) where d⍬ is the delta angle shift of the pendulum in the delta time dt.
the crux of this app lies in the class called Panel which is defined as follows:
The thread function has been defined as follows:
And the Activity class is like the below:
i would like to share some issues that i faced while doing this animation. as all of you know that the simple animation is done by removing the trace of a moving object by repainting the previous position with the background color. i was trying to do the same thing by repainting only that part of the screen which was occupied by the pendulum before moving to a new position. however, it was not giving proper result. when i was scratching my head over the issue, suddenly i saw a simple line in android documentation that says if somebody wants to repaint only a portion of the screen, the result may be undefined. so its better to repaint the whole screen for proper animation. and it solved my problem. and hence the first line of the onDraw() is canvas.drawColor(Color.BLACK).
similarly, using the same principles, i have simulated the circular motion. the apk for the same can be download from here. the screen capture of this app is like the following:
i am also trying to do some experimentation with the simulation of different physics functionality using the game engine called Cocos2D. here is the screen capture of one of such experimentation which simulates the circular motion.
hopefully this article will be able to throw some lights on android graphics and animation.
with this positive hope i would like to end this discussion.
No comments:
Post a Comment