This article continues from the second of a 3-part segment on an example of the point cloud feature within Flowcode 6.
This week, the graphing component will be completed and various improvement ideas will be discussed. For the graph to be tested, an array of data must be available. In practice, a source of data can be accessed from any other flowcode component, such as an ADC, or external data from a communication port.
In this case, data is generated by a function of x^2 (x squared)
An array of 2000 elements (the maximum defined in the previous article) is then created that ranges equally spaced values of the function as x moves to 1 from 0.
Because the component is being tested from within itself, the initialise macro must be called to create the pointcloud and axis.
The plotgraph macro is called and the xyz values passed as an argument.
Shown above is the contents of plotgraph. The points passed are iterated through and assigned to the global dynamic array for the graph. The RGB values are also assigned from the colour set in the properties panel. Then the array is assigned as points on the pointcloud shape and the respective colours are set.
Within this section of code, is lots of scope for expandability. The colour of the graph can be set to vary with the Y value on the graph for instance.
Also, an offset or scale to the graph could be set. This could either be pre-determined by the user, or calculated by checking the values in the data set defined by the user, and scaling the values to fit the -1 to 1 limits of the pointcloud.
For the EditGraph macro, a section of the plot graph code is used. Whereby the idx value indexes the pre-existing xyz array and assigns the new value of Y to the indexed element.
The graph is then re-plotted and the new value will take effect.
When a property is changed, the ev_porperty macro will be called. In the case of these values changing, the component simply needs to re-plot the graph
Click here for the Flowcode files for this weeks example: Graphing files (c)
Next week’s article will cover a gLCD pop-the-bubble game whereby a hardware component saleable by Matrix can be used to run a user-created game.
3,794 total views, 3 views today