Planets Fly By

427 views
Skip to first unread message

Scott Ferguson

unread,
Oct 1, 2015, 1:13:26 PM10/1/15
to App Inventor Developers Library
This project uses perspective to give the illusion of flying past the planets in our solar system one-by-one.
The relative sizes of the planets in this simulation to each other is correct.
The project is based on the Coding Math tutorial '3D - Postcards in Space'.
For added effect, I animated the rotations of the planets as well.
This was developed with the use of a 10" ASUS TF-101 tablet, so it may not work on your device.
But you can study the blocks, if nothing else.

In a nutshell, you can apply perspective to Text or balls drawn on the canvas, or sprites by using this simple formula

perspective = focal length / (focal length + z)

Multiply that by some <value> where <value> might be an x or y which would move an object toward a vanishing point
or <value> might be width, height or radius where the effect would be to shrink an object

Combine both of these and you get this planet simulation with shrinking text that follows the planet into the distance.

If the z value is zero, then the perspective value is one so has no effect.
The larger z is, the smaller the object will be.

So a loop that increases the value of z from 0 to a large number would shrink the object down to a pixel.

A screen shot from a fly-by of Saturn.


The blocks saved with the new Blocks Viewer save as image feature:


---
sf
PlanetsFlyBy.aia

Scott Ferguson

unread,
Oct 1, 2015, 8:52:38 PM10/1/15
to app-inventor-de...@googlegroups.com


On Thursday, October 1, 2015 at 12:13:26 PM UTC-5, Scott Ferguson wrote:
This project uses perspective to give the illusion of flying past the planets in our solar system one-by-one.
The relative sizes of the planets in this simulation to each other is correct.
The project is based on the Coding Math tutorial '3D - Postcards in Space'.
For added effect, I animated the rotations of the planets as well.
This was developed with the use of a 10" ASUS TF-101 tablet, so it may not work on your device.
But you can study the blocks, if nothing else.

In a nutshell, you can apply perspective to Text or circles drawn on the canvas, or sprites by using this simple formula

perspective = focal length / (focal length + z)

Multiply perspective by some <value> where <value> might be an x or y and increase the value of z to move an object toward a vanishing point
or <value> might be width, height or radius where the effect would be to shrink the object.

So applying perspective in this case makes a planet simulation with shrinking text that follows the planet into the distance.

If the z value is zero, then the perspective value is one so has no effect.
The larger z is, the smaller the object will be.

So a loop that increases the value of z from 0 to a large number would shrink the object down to a pixel.

A screen shot from a fly-by of Saturn.


The blocks saved with the new Blocks Viewer save as image feature:



Note that if you start with a large number for z then subtract from z with each cycle of the Timer block the planets will  move toward you instead.

As I was playing with the app, I imagined a bowling game where the ball rolls away from you into the 'screen' or back to you when it returns.
I haven't found any good bowling tutorials yet, however. 

---
sf
Reply all
Reply to author
Forward
0 new messages