Rendering - Points
The simplest graphics primitive that can be drawn on WOWCube device screens with WOWCube API is a point
In classical Euclidian geometry, a point is a primitive notion that models an exact location in space, and has no length, nor width or thickess.
So in order to draw a point, we would want to provide three parameters - the pair of (X,Y) coordinates, which define point screen position and the color of a point.
As we know, each WOWCube module has three screens of 240 x 240 pixels. This means, the valid coordinates of a point to draw range from (0,0) to (239,239), while the coordinate of a center of the screen is at (120, 120).
The color of a point is defined as RGB value.
The RGB color model is an additive color model in which the red, green and blue primary colors of light are added together in various ways to reproduce a broad spectrum of colors. The name of the model comes from the first letters of the three primary colors: Red, Green and Blue
Actual values of each primary color range from 0 to 255, the range that a single 8-bit byte can offer. Since higher value means brighter color, the (0,0,0) represents no color, or so-called transparent color, (1,1,1) gives solid black, while (255,255,255) gives white.
The example
In order to demonstrate point rendering, let's create a small cubeapp that implements a starfield effect.
The actual algorithm is rather simple: we take an array of points and shoot them from the center of the screen towards the edges at random speeds and random directions. We would also want to dim the points slightly to create an impression of depth.
First off, let's declare an array of 50 stars. Each start will be drawn as a point.
Then, we need to initialize this array with initial values. To do that, we use AddStar() function in the ON_Init() callback:
The function that adds a start looks like this:
In the function, we initialize initial velocity vector (vx,vy) with a random value to ensure that our stars will be shooting at random directions. Then we set initial position of the star to (0,0) and add it to the array.
Pay attention at the numStars variable. It is used to make sure the array will never be overloaded, even if AddStar() function is called more than 50 times.
The last step is to animate the stars. See the RenderStarfield() function that is called every time the screen is rendered:
We iterate though the array of stars changing star position slightly outwards the center of a screen till the star is visible. Then we move it back to its initial position and repeat the process again.
In order to actually draw the star, WOWCube API function GFX_drawPointXY is used: