The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
4.6KB

  1. /**
  2. @page example_colour_pressure_map Colour Pressure Map
  3. @section colour_pressure_map_introduction Introduction
  4. Learn how to display coloured pressure maps on the Lightpad Block.
  5. Launch the BLOCKS CODE application and open the script called @s_file{ColourPressureMap.littlefoot}. You can find the script in the Littlefoot-Examples repository, which you can download from GitHub @littlefootgithub{here}. If you don't have the BLOCKS CODE IDE installed on your system, please refer to the section @ref getting_started_with_blocks_code for help.
  6. @section colour_pressure_map_drawing_pressure_maps Drawing Pressure Maps
  7. Let's start by drawing white pressure map points onto the screen whenever pressure is applied onto the touch surface of a Lightpad.
  8. We start by clearing the display in the repaint() function using the clearDisplay() function to reset the state of our LEDs. We than call two handy functions that are defined in the littlefoot language that allow us to draw and fade pressure points automatically. These are respectively the drawPressureMap() and fadePressureMap() functions.
  9. @code{.cpp}
  10. void repaint()
  11. {
  12. clearDisplay();
  13. drawPressureMap();
  14. fadePressureMap();
  15. }
  16. @endcode
  17. However, if we run the script at the moment no pressure points are shown on the screen because we need to tell the program where to draw them by calling the addPressurePoint() function with the colour and coordinates of the point.
  18. The littlefoot language has several callback functions that are called when a special event happens. In our case we are interested in the start and movement of a touch gesture and therefore we can implement these as follows:
  19. @code{.cpp}
  20. void touchStart (int index, float x, float y, float z, float vz)
  21. {
  22. addPressurePoint (0xffffff, x, y, z * 100.0);
  23. }
  24. @endcode
  25. When the callback functions are called, we add a pressure point to the pressure map by specifying a colour in hexadecimal (in this case white is 0xffffff) and the coordinates of the touch event.
  26. @code{.cpp}
  27. void touchMove (int index, float x, float y, float z, float vz)
  28. {
  29. addPressurePoint (0xffffff, x, y, z * 20.0);
  30. }
  31. @endcode
  32. Notice here that we multiply the depth z by a scaler in order to make the surface of the pressure point bigger and easier to see.
  33. @section colour_pressure_map_adding_colours Adding Colours
  34. Now let's try to add different colours to the pressure points depending on the number of fingers on the screen. To make these variables accessible in realtime to the Parameters tab of the IDE, we create some variables in the metadata section of the code.
  35. @code{.xml}
  36. <metadata description="Colour Pressure Map">
  37. <variables>
  38. <variable name="pressureColour0" displayName="Heat Colour 0" type="colour" value="0xFF0000" />
  39. <variable name="pressureColour1" displayName="Heat Colour 1" type="colour" value="0x00FF00" />
  40. <variable name="pressureColour2" displayName="Heat Colour 2" type="colour" value="0x0000FF" />
  41. <variable name="pressureColour3" displayName="Heat Colour 3" type="colour" value="0xFF00FF" />
  42. <variable name="scaling" displayName="How hot!" type="float" value="1" min="1" max="200" />
  43. </variables>
  44. </metadata>
  45. @endcode
  46. We also implement a helper function called getPressureColour() that takes an index of the finger from the touch event and returns the desired colour as shown below:
  47. @code{.cpp}
  48. int getPressureColour (int index)
  49. {
  50. int col = pressureColour3;
  51. if (index == 1)
  52. {
  53. col = pressureColour0;
  54. }
  55. else if (index == 2)
  56. {
  57. col = pressureColour1;
  58. }
  59. else if (index == 3)
  60. {
  61. col = pressureColour2;
  62. }
  63. return col;
  64. }
  65. @endcode
  66. Finally we need to modify the callbacks to incorporate this helper function instead of hardcoding the colour white.
  67. @code{.cpp}
  68. void touchStart (int index, float x, float y, float z, float vz)
  69. {
  70. addPressurePoint (getPressureColour (index), x, y, z * float (scaling));
  71. }
  72. @endcode
  73. Notice we also allow the scaling of the pressure point to be controlled by a slider in the Parameters tab in order to change its size in realtime.
  74. @code{.cpp}
  75. void touchMove (int index, float x, float y, float z, float vz)
  76. {
  77. addPressurePoint (getPressureColour (index), x, y, z * float (scaling));
  78. }
  79. @endcode
  80. @section colour_pressure_map_summary Summary
  81. In this example, we learnt how to display pressure maps onto the Lightpad and add colours depending on the number of fingers pressed onto the touch surface.
  82. @section colour_pressure_map_see_also See also
  83. - @ref example_dynamic_parameters
  84. - @ref example_tic_tac_toe
  85. - @ref example_music_gen
  86. */