Sunday, December 22, 2019

A Torrid Tail of Too Many Circles - Continued

Previously

In my earlier post, I covered how I attempted to create a Moire pattern on my pyportal screen. While the implementation was pretty simple, there were issues with excessive memory usage and dreadful refresh speed.

Moving to a faster speed


The first implementation used a lot of system memory because each rendered circle consisted of a TileGrid, Bitmap and Palette. The goal for the second implementation was to reduce the amount of memory used by using one Bitmap per group of circles. I first needed to refresh my memory on how to find the points on a circle. A quick trip down the Google results lead me to this page. I was able to quickly implement a draw_circle function to a circle to a provided Bitmap. The center and radius of the of the circle are used as the basis of the function and a SMOOTHNESS value is used to determine the size of each calculated step. The draw_circle is wrapped in two loops to generate each set of circles into a single bitmap. Parameters are provided for the number and spacing of the generated circles and how much time to wait between each set of calculations.

Journey Review


The new circle function is much faster and generates a pleasing set of circles. Memory usage is much less since only one TileGrid, Bitmap and Palette is used for the display. However, it takes quite a few seconds to generate a new set of circles in the Bitmap. However, the random placement of the circles results in display updates which can be displeasing. This issue was rectified by adding a 'wobble' to the previous generation's centers. The math still takes a long time but the updates are more pleasing.

Where to go next


Is it possible to make the updates faster?

No comments:

Post a Comment