Skip to content

Instantly share code, notes, and snippets.

@MartinRGB
Last active November 11, 2023 11:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MartinRGB/07a88ba00be5ef8491c55ef94644eb21 to your computer and use it in GitHub Desktop.
Save MartinRGB/07a88ba00be5ef8491c55ef94644eb21 to your computer and use it in GitHub Desktop.

opengl_Pikachu

/*
 * Square.ino
 * Created by Fabio de Albuquerque Dela Antonio
 * fabio914 at gmail.com
 * 
 * An OpenGL example that draws a rotated and scaled square.
 */
#include "SPI.h"
#include "ILI9341_t3n.h"
#include <TeensyGL.h> 
//#define ILI9488 1
#define ILI9341 1

// For the Adafruit shield, these are the default.
#define TFT_DC  9
#define TFT_CS 10

// Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
#if defined(ILI9488)
Arduino_OpenGL tft = Arduino_OpenGL(&SPI, TFT_CS, TFT_DC, 8);
#elif defined(ILI9341)
Teensy_OpenGL tft = Teensy_OpenGL(9, 10, 6);
#endif
uint8_t use_fb = 1;

// Color definitions
#define BLACK       0x0000      /*   0,   0,   0 */
#define YELLOW      0xFFE0      /* 255, 255,   0 */
#define WHITE       0xFFFF      /* 255, 255, 255 */

const float model[3708] PROGMEM = { -5.539738f, -3.768954f, 0.000000f, -4.307949f, -3.812735f, 0.000000f, -1.438539f, -1.200866f, 0.000000f, -1.438539f, -1.200866f, 0.000000f, -4.038570f, -1.214379f, 0.000000f, -5.539738f, -3.768954f, 0.000000f, -4.307949f, -3.812735f, 0.000000f, -4.144053f, -4.801568f, -0.000000f, -1.438539f, -1.200866f, 0.000000f, -4.144053f, -4.801568f, -0.000000f, -3.012833f, -4.785862f, -0.000000f, -1.438539f, -1.200866f, 0.000000f, -3.012833f, -4.785862f, -0.000000f, -2.848938f, -5.774698f, -0.000000f, -0.794038f, -4.081137f, -0.000000f, -0.794038f, -4.081137f, -0.000000f, -1.438539f, -1.200866f, 0.000000f, -3.012833f, -4.785862f, -0.000000f, -4.038570f, -1.214379f, 0.000000f, -1.438539f, -1.200866f, 0.000000f, 0.212833f, 5.974901f, 0.000000f, 0.212833f, 5.974901f, 0.000000f, -1.438539f, -1.200866f, 0.000000f, 2.833840f, -1.001984f, 0.000000f, -1.438539f, -1.200866f, 0.000000f, -0.794038f, -4.081137f, -0.000000f, 2.833840f, -1.001984f, 0.000000f, -4.144053f, -4.801568f, -0.000000f, -4.307949f, -3.812735f, 0.000000f, -3.771819f, -3.505237f, 1.297074f, -3.771819f, -3.505237f, 1.297074f, -2.964740f, -4.217257f, 1.438483f, -4.144053f, -4.801568f, -0.000000f, -3.012833f, -4.785862f, -0.000000f, -4.144053f, -4.801568f, -0.000000f, -2.964740f, -4.217257f, 1.438483f, -2.848938f, -5.774698f, -0.000000f, -3.012833f, -4.785862f, -0.000000f, -2.964740f, -4.217257f, 1.438483f, -2.964740f, -4.217257f, 1.438483f, -2.224502f, -4.870309f, 1.568181f, -2.848938f, -5.774698f, -0.000000f, -4.307949f, -3.812735f, 0.000000f, -5.539738f, -3.768954f, 0.000000f, -3.771819f, -3.505237f, 1.297074f, -3.771819f, -3.505237f, 1.297074f, -5.539738f, -3.768954f, 0.000000f, -4.605422f, -2.769094f, 1.151340f, -0.794038f, -4.081137f, -0.000000f, -2.848938f, -5.774698f, -0.000000f, -2.224502f, -4.870309f, 1.568181f, -2.224502f, -4.870309f, 1.568181f, -0.095399f, -3.493686f, 3.396854f, -0.794038f, -4.081137f, -0.000000f, 2.833840f, -1.001984f, 0.000000f, -0.794038f, -4.081137f, -0.000000f, -0.095399f, -3.493686f, 3.396854f, -4.038570f, -1.214379f, 0.000000f, 0.212833f, 5.974901f, 0.000000f, -2.797724f, -0.015615f, 3.409093f, -4.038570f, -1.214379f, 0.000000f, -2.797724f, -0.015615f, 3.409093f, -4.605422f, -2.769094f, 1.151340f, -4.605422f, -2.769094f, 1.151340f, -5.539738f, -3.768954f, 0.000000f, -4.038570f, -1.214379f, 0.000000f, -2.964740f, -4.217257f, 1.438483f, -3.771819f, -3.505237f, 1.297074f, -2.797724f, -0.015615f, 3.409093f, -2.224502f, -4.870309f, 1.568181f, -2.964740f, -4.217257f, 1.438483f, -2.797724f, -0.015615f, 3.409093f, -3.771819f, -3.505237f, 1.297074f, -4.605422f, -2.769094f, 1.151340f, -2.797724f, -0.015615f, 3.409093f, -0.095399f, -3.493686f, 3.396854f, -2.224502f, -4.870309f, 1.568181f, -2.797724f, -0.015615f, 3.409093f, -0.095399f, -3.493686f, 3.396854f, -2.797724f, -0.015615f, 3.409093f, -4.924707f, -1.414091f, 6.819679f, -4.924707f, -1.414091f, 6.819679f, -1.064041f, -6.094393f, 6.538823f, -0.095399f, -3.493686f, 3.396854f, -2.797724f, -0.015615f, 3.409093f, 0.212833f, 5.974901f, 0.000000f, -2.806269f, 9.701880f, 6.911485f, -2.806269f, 9.701880f, 6.911485f, -4.924707f, -1.414091f, 6.819679f, -2.797724f, -0.015615f, 3.409093f, -0.095399f, -3.493686f, 3.396854f, -1.064041f, -6.094393f, 6.538823f, 7.318575f, -8.181732f, 7.251115f, 7.318575f, -8.181732f, 7.251115f, 7.332893f, -4.468502f, 3.035453f, -0.095399f, -3.493686f, 3.396854f, 7.332893f, -4.468502f, 3.035453f, 2.833840f, -1.001984f, 0.000000f, -0.095399f, -3.493686f, 3.396854f, 2.833840f, -1.001984f, 0.000000f, 7.332893f, -4.468502f, 3.035453f, 7.347628f, -0.345043f, 0.000000f, -2.806269f, 9.701880f, 6.911485f, 0.212833f, 5.974901f, 0.000000f, 4.992514f, 8.669660f, 0.000000f, 4.992514f, 8.669660f, 0.000000f, 7.404200f, 15.154014f, 6.717684f, -2.806269f, 9.701880f, 6.911485f, 7.390337f, 11.355589f, 25.343040f, -1.156504f, 6.769886f, 25.503311f, -2.806269f, 9.701880f, 6.911485f, -2.806269f, 9.701880f, 6.911485f, 7.404200f, 15.154014f, 6.717684f, 7.390337f, 11.355589f, 25.343040f, -1.156504f, 6.769886f, 25.503311f, 7.390337f, 11.355589f, 25.343040f, 7.392986f, 12.969517f, 30.596918f, 7.392986f, 12.969517f, 30.596918f, -2.378038f, 7.609754f, 29.987549f, -1.156504f, 6.769886f, 25.503311f, -2.378038f, 7.609754f, 29.987549f, 7.392986f, 12.969517f, 30.596918f, 7.389394f, 10.209548f, 43.675125f, 7.389394f, 10.209548f, 43.675125f, -1.112535f, 5.337115f, 44.135113f, -2.378038f, 7.609754f, 29.987549f, 4.992514f, 8.669660f, 0.000000f, 6.560344f, 24.639845f, 0.000000f, 5.476238f, 27.080624f, 3.887028f, 5.476238f, 27.080624f, 3.887028f, 4.129376f, 20.061457f, 5.779599f, 4.992514f, 8.669660f, 0.000000f, 4.129376f, 20.061457f, 5.779599f, 5.476238f, 27.080624f, 3.887028f, 6.155193f, 24.991884f, 8.632037f, 6.155193f, 24.991884f, 8.632037f, 4.831220f, 17.723888f, 10.245268f, 4.129376f, 20.061457f, 5.779599f, 4.831220f, 17.723888f, 10.245268f, 6.155193f, 24.991884f, 8.632037f, 5.734873f, 29.086515f, 14.934714f, 5.734873f, 29.086515f, 14.934714f, 4.065323f, 20.013741f, 17.045088f, 4.831220f, 17.723888f, 10.245268f, 4.065323f, 20.013741f, 17.045088f, 5.734873f, 29.086515f, 14.934714f, 6.355259f, 28.509245f, 21.455393f, 6.355259f, 28.509245f, 21.455393f, 4.143809f, 15.594004f, 24.428383f, 4.065323f, 20.013741f, 17.045088f, 4.143809f, 15.594004f, 24.428383f, 6.355259f, 28.509245f, 21.455393f, 6.044722f, 36.033566f, 32.743652f, 6.044722f, 36.033566f, 32.743652f, 3.680145f, 27.997072f, 42.629868f, 4.143809f, 15.594004f, 24.428383f, 7.404200f, 15.154014f, 6.717684f, 4.992514f, 8.669660f, 0.000000f, 7.395069f, 12.652242f, 3.473820f, 4.992514f, 8.669660f, 0.000000f, 4.129376f, 20.061457f, 5.779599f, 7.395069f, 12.652242f, 3.473820f, -1.156504f, 6.769886f, 25.503311f, -3.251845f, -0.057658f, 19.269463f, -4.924707f, -1.414091f, 6.819679f, -4.924707f, -1.414091f, 6.819679f, -2.806269f, 9.701880f, 6.911485f, -1.156504f, 6.769886f, 25.503311f, -1.156504f, 6.769886f, 25.503311f, -2.155961f, 2.247481f, 25.289112f, -3.251845f, -0.057658f, 19.269463f, -3.251845f, -0.057658f, 19.269463f, -2.155961f, 2.247481f, 25.289112f, -4.784894f, -4.558351f, 21.355616f, -4.784894f, -4.558351f, 21.355616f, -4.747807f, -4.044468f, 15.678835f, -3.251845f, -0.057658f, 19.269463f, -4.747807f, -4.044468f, 15.678835f, -4.784894f, -4.558351f, 21.355616f, 1.405830f, -8.681398f, 17.677410f, 1.405830f, -8.681398f, 17.677410f, -0.400345f, -7.063436f, 13.588383f, -4.747807f, -4.044468f, 15.678835f, -0.400345f, -7.063436f, 13.588383f, 1.405830f, -8.681398f, 17.677410f, 4.569384f, -8.806929f, 17.070992f, -0.400345f, -7.063436f, 13.588383f, 4.569384f, -8.806929f, 17.070992f, 4.459775f, -8.170643f, 15.255916f, -0.400345f, -7.063436f, 13.588383f, 4.459775f, -8.170643f, 15.255916f, 4.120597f, -7.750196f, 14.155172f, -0.400345f, -7.063436f, 13.588383f, 4.120597f, -7.750196f, 14.155172f, 3.805834f, -7.357590f, 13.126703f, -1.112535f, 5.337115f, 44.135113f, 7.389394f, 10.209548f, 43.675125f, 7.342481f, -1.755349f, 46.878002f, 7.342481f, -1.755349f, 46.878002f, 0.265503f, -0.751631f, 45.553356f, -1.112535f, 5.337115f, 44.135113f, 1.080373f, -8.575625f, 31.963448f, 7.308156f, -11.159800f, 32.688374f, 7.312078f, -10.085270f, 28.536547f, 7.312078f, -10.085270f, 28.536547f, -0.296664f, -7.294125f, 28.770905f, 1.080373f, -8.575625f, 31.963448f, -0.296664f, -7.294125f, 28.770905f, 7.312078f, -10.085270f, 28.536547f, 7.327550f, -5.846064f, 24.956141f, 7.327550f, -5.846064f, 24.956141f, 1.895971f, -4.169862f, 25.367369f, -0.296664f, -7.294125f, 28.770905f, 1.251503f, -5.247501f, 37.201290f, 3.653726f, -6.376678f, 37.277554f, 3.668271f, -5.650332f, 34.978966f, 3.668271f, -5.650332f, 34.978966f, 1.256280f, -4.414838f, 34.583401f, 1.251503f, -5.247501f, 37.201290f, 4.129376f, 20.061457f, 5.779599f, 4.831220f, 17.723888f, 10.245268f, 7.411455f, 17.763485f, 10.409961f, 7.411455f, 17.763485f, 10.409961f, 7.421850f, 19.989561f, 5.611809f, 4.129376f, 20.061457f, 5.779599f, 7.422492f, 20.165249f, 17.050919f, 7.411455f, 17.763485f, 10.409961f, 4.831220f, 17.723888f, 10.245268f, 4.831220f, 17.723888f, 10.245268f, 4.065323f, 20.013741f, 17.045088f, 7.422492f, 20.165249f, 17.050919f, 4.065323f, 20.013741f, 17.045088f, 4.143809f, 15.594004f, 24.428383f, 7.402476f, 15.512046f, 24.353392f, 7.402476f, 15.512046f, 24.353392f, 7.422492f, 20.165249f, 17.050919f, 4.065323f, 20.013741f, 17.045088f, 4.143809f, 15.594004f, 24.428383f, 3.680145f, 27.997072f, 42.629868f, 7.451022f, 27.981888f, 42.640167f, 7.451022f, 27.981888f, 42.640167f, 7.402476f, 15.512046f, 24.353392f, 4.143809f, 15.594004f, 24.428383f, 4.129376f, 20.061457f, 5.779599f, 7.421850f, 19.989561f, 5.611809f, 7.395069f, 12.652242f, 3.473820f, 4.459775f, -8.170643f, 15.255916f, 4.881968f, -7.958671f, 14.516864f, 4.120597f, -7.750196f, 14.155172f, 4.459775f, -8.170643f, 15.255916f, 4.569384f, -8.806929f, 17.070992f, 5.154751f, -8.509578f, 16.012430f, 4.120597f, -7.750196f, 14.155172f, 4.509461f, -7.648806f, 13.743653f, 3.805834f, -7.357590f, 13.126703f, 1.405830f, -8.681398f, 17.677410f, -4.784894f, -4.558351f, 21.355616f, -0.802266f, -3.523405f, 21.358763f, -0.802266f, -3.523405f, 21.358763f, 1.079479f, -4.688925f, 20.261789f, 1.405830f, -8.681398f, 17.677410f, -4.747807f, -4.044468f, 15.678835f, -0.400345f, -7.063436f, 13.588383f, -0.405376f, -5.446152f, 12.146640f, -0.405376f, -5.446152f, 12.146640f, -2.666151f, -2.447883f, 13.083079f, -4.747807f, -4.044468f, 15.678835f, 4.569384f, -8.806929f, 17.070992f, 1.405830f, -8.681398f, 17.677410f, 1.079479f, -4.688925f, 20.261789f, 1.079479f, -4.688925f, 20.261789f, 4.887557f, -5.936971f, 18.927929f, 4.569384f, -8.806929f, 17.070992f, -0.400345f, -7.063436f, 13.588383f, 3.805834f, -7.357590f, 13.126703f, 3.708996f, -6.551171f, 12.173764f, 3.708996f, -6.551171f, 12.173764f, -0.405376f, -5.446152f, 12.146640f, -0.400345f, -7.063436f, 13.588383f, 5.154751f, -8.509578f, 16.012430f, 4.569384f, -8.806929f, 17.070992f, 4.887557f, -5.936971f, 18.927929f, 4.887557f, -5.936971f, 18.927929f, 5.991712f, -6.647191f, 16.045710f, 5.154751f, -8.509578f, 16.012430f, 3.805834f, -7.357590f, 13.126703f, 4.509461f, -7.648806f, 13.743653f, 5.477915f, -6.819143f, 13.787570f, 5.477915f, -6.819143f, 13.787570f, 3.708996f, -6.551171f, 12.173764f, 3.805834f, -7.357590f, 13.126703f, 4.459775f, -8.170643f, 15.255916f, 5.154751f, -8.509578f, 16.012430f, 5.991712f, -6.647191f, 16.045710f, 5.991712f, -6.647191f, 16.045710f, 5.360450f, -6.560156f, 15.408227f, 4.459775f, -8.170643f, 15.255916f, 4.120597f, -7.750196f, 14.155172f, 4.881968f, -7.958671f, 14.516864f, 5.890128f, -6.807933f, 14.691280f, 5.890128f, -6.807933f, 14.691280f, 5.070531f, -6.644487f, 14.224989f, 4.120597f, -7.750196f, 14.155172f, 4.509461f, -7.648806f, 13.743653f, 4.120597f, -7.750196f, 14.155172f, 5.070531f, -6.644487f, 14.224989f, 5.070531f, -6.644487f, 14.224989f, 5.477915f, -6.819143f, 13.787570f, 4.509461f, -7.648806f, 13.743653f, 4.881968f, -7.958671f, 14.516864f, 4.459775f, -8.170643f, 15.255916f, 5.360450f, -6.560156f, 15.408227f, 5.360450f, -6.560156f, 15.408227f, 5.890128f, -6.807933f, 14.691280f, 4.881968f, -7.958671f, 14.516864f, -4.784894f, -4.558351f, 21.355616f, -2.155961f, 2.247481f, 25.289112f, -0.802266f, -3.523405f, 21.358763f, -4.747807f, -4.044468f, 15.678835f, -2.666151f, -2.447883f, 13.083079f, -3.251845f, -0.057658f, 19.269463f, 5.991712f, -6.647191f, 16.045710f, 4.887557f, -5.936971f, 18.927929f, 7.324408f, -6.706909f, 18.302906f, 7.324408f, -6.706909f, 18.302906f, 7.323162f, -7.048462f, 15.838820f, 5.991712f, -6.647191f, 16.045710f, 3.708996f, -6.551171f, 12.173764f, 5.477915f, -6.819143f, 13.787570f, 7.321928f, -7.386584f, 13.399504f, 7.321928f, -7.386584f, 13.399504f, 7.321089f, -7.616257f, 11.742564f, 3.708996f, -6.551171f, 12.173764f, 5.360450f, -6.560156f, 15.408227f, 5.991712f, -6.647191f, 16.045710f, 7.323162f, -7.048462f, 15.838820f, 7.323162f, -7.048462f, 15.838820f, 7.322854f, -7.132998f, 15.228947f, 5.360450f, -6.560156f, 15.408227f, 5.070531f, -6.644487f, 14.224989f, 5.890128f, -6.807933f, 14.691280f, 7.322489f, -7.232655f, 14.509995f, 7.322489f, -7.232655f, 14.509995f, 7.322289f, -7.287514f, 14.114231f, 5.070531f, -6.644487f, 14.224989f, 5.477915f, -6.819143f, 13.787570f, 5.070531f, -6.644487f, 14.224989f, 7.322289f, -7.287514f, 14.114231f, 7.322289f, -7.287514f, 14.114231f, 7.321928f, -7.386584f, 13.399504f, 5.477915f, -6.819143f, 13.787570f, 5.890128f, -6.807933f, 14.691280f, 5.360450f, -6.560156f, 15.408227f, 7.322854f, -7.132998f, 15.228947f, 7.322854f, -7.132998f, 15.228947f, 7.322489f, -7.232655f, 14.509995f, 5.890128f, -6.807933f, 14.691280f, 3.708996f, -6.551171f, 12.173764f, 7.321089f, -7.616257f, 11.742564f, 7.318575f, -8.181732f, 7.251115f, -1.064041f, -6.094393f, 6.538823f, -0.405376f, -5.446152f, 12.146640f, 3.708996f, -6.551171f, 12.173764f, 3.708996f, -6.551171f, 12.173764f, 7.318575f, -8.181732f, 7.251115f, -1.064041f, -6.094393f, 6.538823f, 4.887557f, -5.936971f, 18.927929f, 1.079479f, -4.688925f, 20.261789f, 1.895971f, -4.169862f, 25.367369f, 7.324408f, -6.706909f, 18.302906f, 4.887557f, -5.936971f, 18.927929f, 1.895971f, -4.169862f, 25.367369f, 1.895971f, -4.169862f, 25.367369f, 7.327550f, -5.846064f, 24.956141f, 7.324408f, -6.706909f, 18.302906f, -2.666151f, -2.447883f, 13.083079f, -0.405376f, -5.446152f, 12.146640f, -1.064041f, -6.094393f, 6.538823f, -1.064041f, -6.094393f, 6.538823f, -4.924707f, -1.414091f, 6.819679f, -2.666151f, -2.447883f, 13.083079f, -3.251845f, -0.057658f, 19.269463f, -2.666151f, -2.447883f, 13.083079f, -4.924707f, -1.414091f, 6.819679f, 1.895971f, -4.169862f, 25.367369f, 1.079479f, -4.688925f, 20.261789f, -0.802266f, -3.523405f, 21.358763f, -0.802266f, -3.523405f, 21.358763f, -2.155961f, 2.247481f, 25.289112f, 1.895971f, -4.169862f, 25.367369f, 7.347628f, -0.345043f, 0.000000f, 4.992514f, 8.669660f, 0.000000f, 0.212833f, 5.974901f, 0.000000f, 0.212833f, 5.974901f, 0.000000f, 2.833840f, -1.001984f, 0.000000f, 7.347628f, -0.345043f, 0.000000f, 5.476238f, 27.080624f, 3.887028f, 6.560344f, 24.639845f, 0.000000f, 7.438875f, 24.654293f, 0.000000f, 7.438875f, 24.654293f, 0.000000f, 7.448072f, 27.173620f, 4.010532f, 5.476238f, 27.080624f, 3.887028f, -1.112535f, 5.337115f, 44.135113f, 0.265503f, -0.751631f, 45.553356f, -2.306926f, 0.087779f, 49.248196f, -2.306926f, 0.087779f, 49.248196f, -2.891684f, 6.301509f, 47.072754f, -1.112535f, 5.337115f, 44.135113f, -5.250957f, 5.681880f, 43.694244f, -5.527353f, -0.421932f, 43.762058f, -2.655676f, -1.320220f, 40.688511f, -2.655676f, -1.320220f, 40.688511f, -1.801986f, 4.293036f, 39.759407f, -5.250957f, 5.681880f, 43.694244f, -1.112535f, 5.337115f, 44.135113f, -2.891684f, 6.301509f, 47.072754f, -5.250957f, 5.681880f, 43.694244f, -5.250957f, 5.681880f, 43.694244f, -1.801986f, 4.293036f, 39.759407f, -1.112535f, 5.337115f, 44.135113f, -5.527353f, -0.421932f, 43.762058f, -2.306926f, 0.087779f, 49.248196f, 0.265503f, -0.751631f, 45.553356f, 0.265503f, -0.751631f, 45.553356f, -2.655676f, -1.320220f, 40.688511f, -5.527353f, -0.421932f, 43.762058f, 1.895971f, -4.169862f, 25.367369f, -2.155961f, 2.247481f, 25.289112f, -4.095365f, -1.711470f, 29.019276f, -4.095365f, -1.711470f, 29.019276f, -0.296664f, -7.294125f, 28.770905f, 1.895971f, -4.169862f, 25.367369f, -3.737267f, -1.586870f, 31.882002f, -2.378038f, 7.609754f, 29.987549f, -1.801986f, 4.293036f, 39.759407f, -1.801986f, 4.293036f, 39.759407f, -2.655676f, -1.320220f, 40.688511f, -3.737267f, -1.586870f, 31.882002f, -1.801986f, 4.293036f, 39.759407f, -2.378038f, 7.609754f, 29.987549f, -1.112535f, 5.337115f, 44.135113f, 0.114188f, -5.271675f, 40.927006f, -2.655676f, -1.320220f, 40.688511f, 0.265503f, -0.751631f, 45.553356f, -2.378038f, 7.609754f, 29.987549f, -4.095365f, -1.711470f, 29.019276f, -2.155961f, 2.247481f, 25.289112f, -2.155961f, 2.247481f, 25.289112f, -1.156504f, 6.769886f, 25.503311f, -2.378038f, 7.609754f, 29.987549f, -4.095365f, -1.711470f, 29.019276f, -2.378038f, 7.609754f, 29.987549f, -3.737267f, -1.586870f, 31.882002f, 0.265503f, -0.751631f, 45.553356f, 7.342481f, -1.755349f, 46.878002f, 7.320009f, -7.912378f, 40.945305f, 7.320009f, -7.912378f, 40.945305f, 0.114188f, -5.271675f, 40.927006f, 0.265503f, -0.751631f, 45.553356f, 7.314791f, -9.341828f, 33.737534f, 7.308156f, -11.159800f, 32.688374f, 1.080373f, -8.575625f, 31.963448f, 1.080373f, -8.575625f, 31.963448f, -0.047018f, -6.856034f, 32.473053f, 7.314791f, -9.341828f, 33.737534f, -2.655676f, -1.320220f, 40.688511f, 0.114188f, -5.271675f, 40.927006f, -0.047018f, -6.856034f, 32.473053f, -0.047018f, -6.856034f, 32.473053f, -3.737267f, -1.586870f, 31.882002f, -2.655676f, -1.320220f, 40.688511f, -2.891684f, 6.301509f, 47.072754f, -2.306926f, 0.087779f, 49.248196f, -5.861135f, 1.639917f, 53.478088f, -5.861135f, 1.639917f, 53.478088f, -6.854596f, 5.761014f, 52.715530f, -2.891684f, 6.301509f, 47.072754f, -5.527353f, -0.421932f, 43.762058f, -5.250957f, 5.681880f, 43.694244f, -8.320417f, 5.422955f, 48.878498f, -8.320417f, 5.422955f, 48.878498f, -8.509175f, 1.068752f, 48.895195f, -5.527353f, -0.421932f, 43.762058f, -2.306926f, 0.087779f, 49.248196f, -5.527353f, -0.421932f, 43.762058f, -8.509175f, 1.068752f, 48.895195f, -8.509175f, 1.068752f, 48.895195f, -5.861135f, 1.639917f, 53.478088f, -2.306926f, 0.087779f, 49.248196f, -5.250957f, 5.681880f, 43.694244f, -2.891684f, 6.301509f, 47.072754f, -6.854596f, 5.761014f, 52.715530f, -6.854596f, 5.761014f, 52.715530f, -8.320417f, 5.422955f, 48.878498f, -5.250957f, 5.681880f, 43.694244f, -5.861135f, 1.639917f, 53.478088f, -8.980489f, 3.165865f, 55.744457f, -9.483842f, 4.570985f, 55.744457f, -9.483842f, 4.570985f, 55.744457f, -6.854596f, 5.761014f, 52.715530f, -5.861135f, 1.639917f, 53.478088f, -8.320417f, 5.422955f, 48.878498f, -10.229669f, 4.314857f, 55.744457f, -10.231610f, 3.514750f, 55.744457f, -10.231610f, 3.514750f, 55.744457f, -8.509175f, 1.068752f, 48.895195f, -8.320417f, 5.422955f, 48.878498f, -8.509175f, 1.068752f, 48.895195f, -10.231610f, 3.514750f, 55.744457f, -8.980489f, 3.165865f, 55.744457f, -8.980489f, 3.165865f, 55.744457f, -5.861135f, 1.639917f, 53.478088f, -8.509175f, 1.068752f, 48.895195f, -6.854596f, 5.761014f, 52.715530f, -9.483842f, 4.570985f, 55.744457f, -10.229669f, 4.314857f, 55.744457f, -10.229669f, 4.314857f, 55.744457f, -8.320417f, 5.422955f, 48.878498f, -6.854596f, 5.761014f, 52.715530f, 0.114188f, -5.271675f, 40.927006f, 0.283189f, -5.667732f, 39.128136f, 0.220241f, -6.632166f, 34.222805f, 0.220241f, -6.632166f, 34.222805f, -0.047018f, -6.856034f, 32.473053f, 0.114188f, -5.271675f, 40.927006f, 7.314791f, -9.341828f, 33.737534f, 4.032390f, -7.922213f, 34.709949f, 3.894432f, -6.999287f, 38.999115f, 3.894432f, -6.999287f, 38.999115f, 7.320009f, -7.912378f, 40.945305f, 7.314791f, -9.341828f, 33.737534f, 0.114188f, -5.271675f, 40.927006f, 7.320009f, -7.912378f, 40.945305f, 3.894432f, -6.999287f, 38.999115f, 3.894432f, -6.999287f, 38.999115f, 0.283189f, -5.667732f, 39.128136f, 0.114188f, -5.271675f, 40.927006f, 7.314791f, -9.341828f, 33.737534f, -0.047018f, -6.856034f, 32.473053f, 0.220241f, -6.632166f, 34.222805f, 0.220241f, -6.632166f, 34.222805f, 4.032390f, -7.922213f, 34.709949f, 7.314791f, -9.341828f, 33.737534f, 0.220241f, -6.632166f, 34.222805f, 0.283189f, -5.667732f, 39.128136f, 1.251503f, -5.247501f, 37.201290f, 1.251503f, -5.247501f, 37.201290f, 1.256280f, -4.414838f, 34.583401f, 0.220241f, -6.632166f, 34.222805f, 0.283189f, -5.667732f, 39.128136f, 3.894432f, -6.999287f, 38.999115f, 3.653726f, -6.376678f, 37.277554f, 3.653726f, -6.376678f, 37.277554f, 1.251503f, -5.247501f, 37.201290f, 0.283189f, -5.667732f, 39.128136f, 3.894432f, -6.999287f, 38.999115f, 4.032390f, -7.922213f, 34.709949f, 3.668271f, -5.650332f, 34.978966f, 3.668271f, -5.650332f, 34.978966f, 3.653726f, -6.376678f, 37.277554f, 3.894432f, -6.999287f, 38.999115f, 4.032390f, -7.922213f, 34.709949f, 0.220241f, -6.632166f, 34.222805f, 1.256280f, -4.414838f, 34.583401f, 1.256280f, -4.414838f, 34.583401f, 3.668271f, -5.650332f, 34.978966f, 4.032390f, -7.922213f, 34.709949f, 5.734873f, 29.086515f, 14.934714f, 6.155193f, 24.991884f, 8.632037f, 7.438042f, 25.047373f, 8.677461f, 7.438042f, 25.047373f, 8.677461f, 7.455090f, 29.096563f, 14.903179f, 5.734873f, 29.086515f, 14.934714f, 6.355259f, 28.509245f, 21.455393f, 5.734873f, 29.086515f, 14.934714f, 7.455090f, 29.096563f, 14.903179f, 7.455090f, 29.096563f, 14.903179f, 7.449881f, 28.499632f, 21.485111f, 6.355259f, 28.509245f, 21.455393f, 6.044722f, 36.033566f, 32.743652f, 6.355259f, 28.509245f, 21.455393f, 7.449881f, 28.499632f, 21.485111f, 7.449881f, 28.499632f, 21.485111f, 7.480425f, 36.037731f, 32.738682f, 6.044722f, 36.033566f, 32.743652f, 7.451022f, 27.981888f, 42.640167f, 3.680145f, 27.997072f, 42.629868f, 6.044722f, 36.033566f, 32.743652f, 6.044722f, 36.033566f, 32.743652f, 7.480425f, 36.037731f, 32.738682f, 7.451022f, 27.981888f, 42.640167f, 6.155193f, 24.991884f, 8.632037f, 5.476238f, 27.080624f, 3.887028f, 7.448072f, 27.173620f, 4.010532f, 7.448072f, 27.173620f, 4.010532f, 7.438042f, 25.047373f, 8.677461f, 6.155193f, 24.991884f, 8.632037f, 7.438875f, 24.654293f, 0.000000f, 6.560344f, 24.639845f, 0.000000f, 4.992514f, 8.669660f, 0.000000f, 4.992514f, 8.669660f, 0.000000f, 7.347628f, -0.345043f, 0.000000f, 7.438875f, 24.654293f, 0.000000f, -0.296664f, -7.294125f, 28.770905f, -4.095365f, -1.711470f, 29.019276f, -0.047018f, -6.856034f, 32.473053f, -0.047018f, -6.856034f, 32.473053f, 1.080373f, -8.575625f, 31.963448f, -0.296664f, -7.294125f, 28.770905f, -3.737267f, -1.586870f, 31.882002f, -0.047018f, -6.856034f, 32.473053f, -4.095365f, -1.711470f, 29.019276f, -10.229669f, 4.314857f, 55.744457f, -9.483842f, 4.570985f, 55.744457f, -8.980489f, 3.165865f, 55.744457f, -8.980489f, 3.165865f, 55.744457f, -10.231610f, 3.514750f, 55.744457f, -10.229669f, 4.314857f, 55.744457f, 20.209656f, -3.862938f, -0.000000f, 18.727179f, -1.297473f, 0.000000f, 16.127314f, -1.264982f, 0.000000f, 16.127314f, -1.264982f, 0.000000f, 18.977581f, -3.897727f, -0.000000f, 20.209656f, -3.862938f, -0.000000f, 18.977581f, -3.897727f, -0.000000f, 16.127314f, -1.264982f, 0.000000f, 18.806473f, -4.885337f, 0.000000f, 18.806473f, -4.885337f, 0.000000f, 16.127314f, -1.264982f, 0.000000f, 17.675398f, -4.861373f, 0.000000f, 17.675398f, -4.861373f, 0.000000f, 16.127314f, -1.264982f, 0.000000f, 15.461807f, -4.140471f, 0.000000f, 15.461807f, -4.140471f, 0.000000f, 17.504288f, -5.848987f, 0.000000f, 17.675398f, -4.861373f, 0.000000f, 18.727179f, -1.297473f, 0.000000f, 14.528370f, 5.922650f, 0.000000f, 16.127314f, -1.264982f, 0.000000f, 14.528370f, 5.922650f, 0.000000f, 11.856124f, -1.032645f, 0.000000f, 16.127314f, -1.264982f, 0.000000f, 16.127314f, -1.264982f, 0.000000f, 11.856124f, -1.032645f, 0.000000f, 15.461807f, -4.140471f, 0.000000f, 18.806473f, -4.885337f, 0.000000f, 17.631454f, -4.292431f, 1.438478f, 18.443754f, -3.586349f, 1.297154f, 18.443754f, -3.586349f, 1.297154f, 18.977581f, -3.897727f, -0.000000f, 18.806473f, -4.885337f, 0.000000f, 17.675398f, -4.861373f, 0.000000f, 17.631454f, -4.292431f, 1.438478f, 18.806473f, -4.885337f, 0.000000f, 17.504288f, -5.848987f, 0.000000f, 16.886425f, -4.940037f, 1.568099f, 17.631454f, -4.292431f, 1.438478f, 17.631454f, -4.292431f, 1.438478f, 17.675398f, -4.861373f, 0.000000f, 17.504288f, -5.848987f, 0.000000f, 18.977581f, -3.897727f, -0.000000f, 18.443754f, -3.586349f, 1.297154f, 20.209656f, -3.862938f, -0.000000f, 18.443754f, -3.586349f, 1.297154f, 19.282759f, -2.856338f, 1.151509f, 20.209656f, -3.862938f, -0.000000f, 15.461807f, -4.140471f, 0.000000f, 14.767524f, -3.547750f, 3.397244f, 16.886425f, -4.940037f, 1.568099f, 16.886425f, -4.940037f, 1.568099f, 17.504288f, -5.848987f, 0.000000f, 15.461807f, -4.140471f, 0.000000f, 11.856124f, -1.032645f, 0.000000f, 14.767524f, -3.547750f, 3.397244f, 15.461807f, -4.140471f, 0.000000f, 18.727179f, -1.297473f, 0.000000f, 17.495457f, -0.090444f, 3.409453f, 14.528370f, 5.922650f, 0.000000f, 18.727179f, -1.297473f, 0.000000f, 20.209656f, -3.862938f, -0.000000f, 19.282759f, -2.856338f, 1.151509f, 19.282759f, -2.856338f, 1.151509f, 17.495457f, -0.090444f, 3.409453f, 18.727179f, -1.297473f, 0.000000f, 17.631454f, -4.292431f, 1.438478f, 17.495457f, -0.090444f, 3.409453f, 18.443754f, -3.586349f, 1.297154f, 16.886425f, -4.940037f, 1.568099f, 17.495457f, -0.090444f, 3.409453f, 17.631454f, -4.292431f, 1.438478f, 18.443754f, -3.586349f, 1.297154f, 17.495457f, -0.090444f, 3.409453f, 19.282759f, -2.856338f, 1.151509f, 14.767524f, -3.547750f, 3.397244f, 17.495457f, -0.090444f, 3.409453f, 16.886425f, -4.940037f, 1.568099f, 14.767524f, -3.547750f, 3.397244f, 15.717390f, -6.157343f, 6.537314f, 19.611834f, -1.503649f, 6.819679f, 19.611834f, -1.503649f, 6.819679f, 17.495457f, -0.090444f, 3.409453f, 14.767524f, -3.547750f, 3.397244f, 17.495457f, -0.090444f, 3.409453f, 19.611834f, -1.503649f, 6.819679f, 17.574598f, 9.627490f, 6.911485f, 17.574598f, 9.627490f, 6.911485f, 14.528370f, 5.922650f, 0.000000f, 17.495457f, -0.090444f, 3.409453f, 14.767524f, -3.547750f, 3.397244f, 7.332893f, -4.468502f, 3.035453f, 7.318575f, -8.181732f, 7.251115f, 7.318575f, -8.181732f, 7.251115f, 15.717390f, -6.157343f, 6.537314f, 14.767524f, -3.547750f, 3.397244f, 7.332893f, -4.468502f, 3.035453f, 14.767524f, -3.547750f, 3.397244f, 11.856124f, -1.032645f, 0.000000f, 11.856124f, -1.032645f, 0.000000f, 7.347628f, -0.345043f, 0.000000f, 7.332893f, -4.468502f, 3.035453f, 17.574598f, 9.627490f, 6.911485f, 7.404200f, 15.154014f, 6.717684f, 9.768484f, 8.652227f, 0.000000f, 9.768484f, 8.652227f, 0.000000f, 14.528370f, 5.922650f, 0.000000f, 17.574598f, 9.627490f, 6.911485f, 7.390337f, 11.355589f, 25.343040f, 7.404200f, 15.154014f, 6.717684f, 17.574598f, 9.627490f, 6.911485f, 17.574598f, 9.627490f, 6.911485f, 15.936548f, 6.715140f, 25.493473f, 7.390337f, 11.355589f, 25.343040f, 15.936548f, 6.715140f, 25.493473f, 17.085196f, 7.535858f, 29.997444f, 7.392986f, 12.969517f, 30.596918f, 7.392986f, 12.969517f, 30.596918f, 7.390337f, 11.355589f, 25.343040f, 15.936548f, 6.715140f, 25.493473f, 17.085196f, 7.535858f, 29.997444f, 15.764883f, 5.300316f, 43.846039f, 7.389394f, 10.209548f, 43.675125f, 7.389394f, 10.209548f, 43.675125f, 7.392986f, 12.969517f, 30.596918f, 17.085196f, 7.535858f, 29.997444f, 9.768484f, 8.652227f, 0.000000f, 10.714760f, 20.037420f, 5.779599f, 9.419173f, 27.066231f, 3.887028f, 9.419173f, 27.066231f, 3.887028f, 8.317277f, 24.633436f, 0.000000f, 9.768484f, 8.652227f, 0.000000f, 10.714760f, 20.037420f, 5.779599f, 9.991334f, 17.705053f, 10.245268f, 8.720451f, 24.982521f, 8.632037f, 8.720451f, 24.982521f, 8.632037f, 9.419173f, 27.066231f, 3.887028f, 10.714760f, 20.037420f, 5.779599f, 9.991334f, 17.705053f, 10.245268f, 10.778464f, 19.989239f, 17.045088f, 9.175188f, 29.073957f, 14.934714f, 9.175188f, 29.073957f, 14.934714f, 8.720451f, 24.982521f, 8.632037f, 9.991334f, 17.705053f, 10.245268f, 10.778464f, 19.989239f, 17.045088f, 10.661654f, 15.570215f, 24.428383f, 8.544544f, 28.501253f, 21.455393f, 8.544544f, 28.501253f, 21.455393f, 9.175188f, 29.073957f, 14.934714f, 10.778464f, 19.989239f, 17.045088f, 10.661654f, 15.570215f, 24.428383f, 11.292462f, 27.969028f, 42.629868f, 8.916059f, 36.023087f, 32.743652f, 8.916059f, 36.023087f, 32.743652f, 8.544544f, 28.501253f, 21.455393f, 10.661654f, 15.570215f, 24.428383f, 7.404200f, 15.154014f, 6.717684f, 7.395069f, 12.652242f, 3.473820f, 9.768484f, 8.652227f, 0.000000f, 9.768484f, 8.652227f, 0.000000f, 7.395069f, 12.652242f, 3.473820f, 10.714760f, 20.037420f, 5.779599f, 15.936548f, 6.715140f, 25.493473f, 17.574598f, 9.627490f, 6.911485f, 19.611834f, -1.503649f, 6.819679f, 19.611834f, -1.503649f, 6.819679f, 17.948919f, -0.135040f, 19.269463f, 15.936548f, 6.715140f, 25.493473f, 15.936548f, 6.715140f, 25.493473f, 17.948919f, -0.135040f, 19.269463f, 16.836815f, 2.170514f, 25.298950f, 17.948919f, -0.135040f, 19.269463f, 19.415737f, -4.132664f, 15.678835f, 19.449072f, -4.646804f, 21.355616f, 19.449072f, -4.646804f, 21.355616f, 16.836815f, 2.170514f, 25.298950f, 17.948919f, -0.135040f, 19.269463f, 19.415737f, -4.132664f, 15.678835f, 15.046353f, -7.119816f, 13.588383f, 13.228415f, -8.724550f, 17.677410f, 13.228415f, -8.724550f, 17.677410f, 19.449072f, -4.646804f, 21.355616f, 19.415737f, -4.132664f, 15.678835f, 15.046353f, -7.119816f, 13.588383f, 10.838140f, -7.383258f, 13.126703f, 10.520519f, -7.773556f, 14.155172f, 15.046353f, -7.119816f, 13.588383f, 10.520519f, -7.773556f, 14.155172f, 10.178280f, -8.191515f, 15.255916f, 15.046353f, -7.119816f, 13.588383f, 10.178280f, -8.191515f, 15.255916f, 10.064029f, -8.826984f, 17.070992f, 15.046353f, -7.119816f, 13.588383f, 10.064029f, -8.826984f, 17.070992f, 13.228415f, -8.724550f, 17.677410f, 15.764883f, 5.300316f, 43.846039f, 14.186281f, -0.591499f, 45.610146f, 7.342481f, -1.755349f, 46.878002f, 7.342481f, -1.755349f, 46.878002f, 7.389394f, 10.209548f, 43.675125f, 15.764883f, 5.300316f, 43.846039f, 13.534257f, -8.606539f, 31.960472f, 14.914590f, -7.331017f, 28.766878f, 7.312078f, -10.085270f, 28.536547f, 7.312078f, -10.085270f, 28.536547f, 7.308156f, -11.159800f, 32.688374f, 13.534257f, -8.606539f, 31.960472f, 14.914590f, -7.331017f, 28.766878f, 12.771220f, -4.209557f, 25.367369f, 7.327550f, -5.846064f, 24.956141f, 7.327550f, -5.846064f, 24.956141f, 7.312078f, -10.085270f, 28.536547f, 14.914590f, -7.331017f, 28.766878f, 13.407806f, -5.291871f, 37.201290f, 13.409106f, -4.459196f, 34.583401f, 10.988160f, -5.677050f, 34.978966f, 10.988160f, -5.677050f, 34.978966f, 10.997403f, -6.403482f, 37.277554f, 13.407806f, -5.291871f, 37.201290f, 10.714760f, 20.037420f, 5.779599f, 7.421850f, 19.989561f, 5.611809f, 7.411455f, 17.763485f, 10.409961f, 7.411455f, 17.763485f, 10.409961f, 9.991334f, 17.705053f, 10.245268f, 10.714760f, 20.037420f, 5.779599f, 7.422492f, 20.165249f, 17.050919f, 10.778464f, 19.989239f, 17.045088f, 9.991334f, 17.705053f, 10.245268f, 9.991334f, 17.705053f, 10.245268f, 7.411455f, 17.763485f, 10.409961f, 7.422492f, 20.165249f, 17.050919f, 10.778464f, 19.989239f, 17.045088f, 7.422492f, 20.165249f, 17.050919f, 7.402476f, 15.512046f, 24.353392f, 7.402476f, 15.512046f, 24.353392f, 10.661654f, 15.570215f, 24.428383f, 10.778464f, 19.989239f, 17.045088f, 10.661654f, 15.570215f, 24.428383f, 7.402476f, 15.512046f, 24.353392f, 7.451022f, 27.981888f, 42.640167f, 7.451022f, 27.981888f, 42.640167f, 11.292462f, 27.969028f, 42.629868f, 10.661654f, 15.570215f, 24.428383f, 10.714760f, 20.037420f, 5.779599f, 7.395069f, 12.652242f, 3.473820f, 7.421850f, 19.989561f, 5.611809f, 10.178280f, -8.191515f, 15.255916f, 10.520519f, -7.773556f, 14.155172f, 9.757647f, -7.976467f, 14.516864f, 10.178280f, -8.191515f, 15.255916f, 9.480849f, -8.525368f, 16.012430f, 10.064029f, -8.826984f, 17.070992f, 10.520519f, -7.773556f, 14.155172f, 10.838140f, -7.383258f, 13.126703f, 10.132405f, -7.669329f, 13.743653f, 13.228415f, -8.724550f, 17.677410f, 13.583903f, -4.734566f, 20.261789f, 15.474106f, -3.582813f, 21.358763f, 15.474106f, -3.582813f, 21.358763f, 19.449072f, -4.646804f, 21.355616f, 13.228415f, -8.724550f, 17.677410f, 19.415737f, -4.132664f, 15.678835f, 17.345793f, -2.520926f, 13.083079f, 15.063190f, -5.502612f, 12.146640f, 15.063190f, -5.502612f, 12.146640f, 15.046353f, -7.119816f, 13.588383f, 19.415737f, -4.132664f, 15.678835f, 10.064029f, -8.826984f, 17.070992f, 9.766815f, -5.954780f, 18.927929f, 13.583903f, -4.734566f, 20.261789f, 13.583903f, -4.734566f, 20.261789f, 13.228415f, -8.724550f, 17.677410f, 10.064029f, -8.826984f, 17.070992f, 15.046353f, -7.119816f, 13.588383f, 15.063190f, -5.502612f, 12.146640f, 10.940862f, -6.577568f, 12.173764f, 10.940862f, -6.577568f, 12.173764f, 10.838140f, -7.383258f, 13.126703f, 15.046353f, -7.119816f, 13.588383f, 9.480849f, -8.525368f, 16.012430f, 8.657505f, -6.656920f, 16.045710f, 9.766815f, -5.954780f, 18.927929f, 9.766815f, -5.954780f, 18.927929f, 10.064029f, -8.826984f, 17.070992f, 9.480849f, -8.525368f, 16.012430f, 10.838140f, -7.383258f, 13.126703f, 10.940862f, -6.577568f, 12.173764f, 9.170033f, -6.832619f, 13.787570f, 9.170033f, -6.832619f, 13.787570f, 10.132405f, -7.669329f, 13.743653f, 10.838140f, -7.383258f, 13.126703f, 10.178280f, -8.191515f, 15.255916f, 9.289386f, -6.574497f, 15.408227f, 8.657505f, -6.656920f, 16.045710f, 8.657505f, -6.656920f, 16.045710f, 9.480849f, -8.525368f, 16.012430f, 10.178280f, -8.191515f, 15.255916f, 10.520519f, -7.773556f, 14.155172f, 9.578681f, -6.660942f, 14.224989f, 8.757914f, -6.818400f, 14.691280f, 8.757914f, -6.818400f, 14.691280f, 9.757647f, -7.976467f, 14.516864f, 10.520519f, -7.773556f, 14.155172f, 10.132405f, -7.669329f, 13.743653f, 9.170033f, -6.832619f, 13.787570f, 9.578681f, -6.660942f, 14.224989f, 9.578681f, -6.660942f, 14.224989f, 10.520519f, -7.773556f, 14.155172f, 10.132405f, -7.669329f, 13.743653f, 9.757647f, -7.976467f, 14.516864f, 8.757914f, -6.818400f, 14.691280f, 9.289386f, -6.574497f, 15.408227f, 9.289386f, -6.574497f, 15.408227f, 10.178280f, -8.191515f, 15.255916f, 9.757647f, -7.976467f, 14.516864f, 19.449072f, -4.646804f, 21.355616f, 15.474106f, -3.582813f, 21.358763f, 16.836815f, 2.170514f, 25.298950f, 19.415737f, -4.132664f, 15.678835f, 17.948919f, -0.135040f, 19.269463f, 17.345793f, -2.520926f, 13.083079f, 8.657505f, -6.656920f, 16.045710f, 7.323162f, -7.048462f, 15.838820f, 7.324408f, -6.706909f, 18.302906f, 7.324408f, -6.706909f, 18.302906f, 9.766815f, -5.954780f, 18.927929f, 8.657505f, -6.656920f, 16.045710f, 10.940862f, -6.577568f, 12.173764f, 7.321089f, -7.616257f, 11.742564f, 7.321928f, -7.386584f, 13.399504f, 7.321928f, -7.386584f, 13.399504f, 9.170033f, -6.832619f, 13.787570f, 10.940862f, -6.577568f, 12.173764f, 9.289386f, -6.574497f, 15.408227f, 7.322854f, -7.132998f, 15.228947f, 7.323162f, -7.048462f, 15.838820f, 7.323162f, -7.048462f, 15.838820f, 8.657505f, -6.656920f, 16.045710f, 9.289386f, -6.574497f, 15.408227f, 9.578681f, -6.660942f, 14.224989f, 7.322289f, -7.287514f, 14.114231f, 7.322489f, -7.232655f, 14.509995f, 7.322489f, -7.232655f, 14.509995f, 8.757914f, -6.818400f, 14.691280f, 9.578681f, -6.660942f, 14.224989f, 9.170033f, -6.832619f, 13.787570f, 7.321928f, -7.386584f, 13.399504f, 7.322289f, -7.287514f, 14.114231f, 7.322289f, -7.287514f, 14.114231f, 9.578681f, -6.660942f, 14.224989f, 9.170033f, -6.832619f, 13.787570f, 8.757914f, -6.818400f, 14.691280f, 7.322489f, -7.232655f, 14.509995f, 7.322854f, -7.132998f, 15.228947f, 7.322854f, -7.132998f, 15.228947f, 9.289386f, -6.574497f, 15.408227f, 8.757914f, -6.818400f, 14.691280f, 10.940862f, -6.577568f, 12.173764f, 7.318575f, -8.181732f, 7.251115f, 7.321089f, -7.616257f, 11.742564f, 15.717390f, -6.157343f, 6.537314f, 7.318575f, -8.181732f, 7.251115f, 10.940862f, -6.577568f, 12.173764f, 10.940862f, -6.577568f, 12.173764f, 15.063190f, -5.502612f, 12.146640f, 15.717390f, -6.157343f, 6.537314f, 9.766815f, -5.954780f, 18.927929f, 12.771220f, -4.209557f, 25.367369f, 13.583903f, -4.734566f, 20.261789f, 7.324408f, -6.706909f, 18.302906f, 7.327550f, -5.846064f, 24.956141f, 12.771220f, -4.209557f, 25.367369f, 12.771220f, -4.209557f, 25.367369f, 9.766815f, -5.954780f, 18.927929f, 7.324408f, -6.706909f, 18.302906f, 17.345793f, -2.520926f, 13.083079f, 19.611834f, -1.503649f, 6.819679f, 15.717390f, -6.157343f, 6.537314f, 15.717390f, -6.157343f, 6.537314f, 15.063190f, -5.502612f, 12.146640f, 17.345793f, -2.520926f, 13.083079f, 17.948919f, -0.135040f, 19.269463f, 19.611834f, -1.503649f, 6.819679f, 17.345793f, -2.520926f, 13.083079f, 12.771220f, -4.209557f, 25.367369f, 16.836815f, 2.170514f, 25.298950f, 15.474106f, -3.582813f, 21.358763f, 15.474106f, -3.582813f, 21.358763f, 13.583903f, -4.734566f, 20.261789f, 12.771220f, -4.209557f, 25.367369f, 7.347628f, -0.345043f, 0.000000f, 11.856124f, -1.032645f, 0.000000f, 14.528370f, 5.922650f, 0.000000f, 14.528370f, 5.922650f, 0.000000f, 9.768484f, 8.652227f, 0.000000f, 7.347628f, -0.345043f, 0.000000f, 9.419173f, 27.066231f, 3.887028f, 7.448072f, 27.173620f, 4.010532f, 7.438875f, 24.654293f, 0.000000f, 7.438875f, 24.654293f, 0.000000f, 8.317277f, 24.633436f, 0.000000f, 9.419173f, 27.066231f, 3.887028f, 15.764883f, 5.300316f, 43.846039f, 15.398161f, 6.227328f, 47.229149f, 13.922662f, -0.086341f, 48.652729f, 13.922662f, -0.086341f, 48.652729f, 14.186281f, -0.591499f, 45.610146f, 15.764883f, 5.300316f, 43.846039f, 18.722847f, 5.664664f, 45.879768f, 16.430836f, 4.127841f, 39.671680f, 17.347752f, -1.501161f, 40.807026f, 17.347752f, -1.501161f, 40.807026f, 19.166872f, -0.439006f, 45.890106f, 18.722847f, 5.664664f, 45.879768f, 15.764883f, 5.300316f, 43.846039f, 16.430836f, 4.127841f, 39.671680f, 18.722847f, 5.664664f, 45.879768f, 18.722847f, 5.664664f, 45.879768f, 15.398161f, 6.227328f, 47.229149f, 15.764883f, 5.300316f, 43.846039f, 19.166872f, -0.439006f, 45.890106f, 17.347752f, -1.501161f, 40.807026f, 14.186281f, -0.591499f, 45.610146f, 14.186281f, -0.591499f, 45.610146f, 13.922662f, -0.086341f, 48.652729f, 19.166872f, -0.439006f, 45.890106f, 12.771220f, -4.209557f, 25.367369f, 14.914590f, -7.331017f, 28.766878f, 18.842646f, -1.809262f, 29.013023f, 18.842646f, -1.809262f, 29.013023f, 16.836815f, 2.170514f, 25.298950f, 12.771220f, -4.209557f, 25.367369f, 18.528133f, -1.663332f, 31.894547f, 17.347752f, -1.501161f, 40.807026f, 16.430836f, 4.127841f, 39.671680f, 16.430836f, 4.127841f, 39.671680f, 17.085196f, 7.535858f, 29.997444f, 18.528133f, -1.663332f, 31.894547f, 16.430836f, 4.127841f, 39.671680f, 15.764883f, 5.300316f, 43.846039f, 17.085196f, 7.535858f, 29.997444f, 14.571514f, -5.343407f, 40.930904f, 14.186281f, -0.591499f, 45.610146f, 17.347752f, -1.501161f, 40.807026f, 17.085196f, 7.535858f, 29.997444f, 15.936548f, 6.715140f, 25.493473f, 16.836815f, 2.170514f, 25.298950f, 16.836815f, 2.170514f, 25.298950f, 18.842646f, -1.809262f, 29.013023f, 17.085196f, 7.535858f, 29.997444f, 18.842646f, -1.809262f, 29.013023f, 18.528133f, -1.663332f, 31.894547f, 17.085196f, 7.535858f, 29.997444f, 14.186281f, -0.591499f, 45.610146f, 14.571514f, -5.343407f, 40.930904f, 7.320009f, -7.912378f, 40.945305f, 7.320009f, -7.912378f, 40.945305f, 7.342481f, -1.755349f, 46.878002f, 14.186281f, -0.591499f, 45.610146f, 7.314791f, -9.341828f, 33.737534f, 14.683560f, -6.901972f, 32.471439f, 13.534257f, -8.606539f, 31.960472f, 13.534257f, -8.606539f, 31.960472f, 7.308156f, -11.159800f, 32.688374f, 7.314791f, -9.341828f, 33.737534f, 17.347752f, -1.501161f, 40.807026f, 18.528133f, -1.663332f, 31.894547f, 14.683560f, -6.901972f, 32.471439f, 14.683560f, -6.901972f, 32.471439f, 14.571514f, -5.343407f, 40.930904f, 17.347752f, -1.501161f, 40.807026f, 15.398161f, 6.227328f, 47.229149f, 16.094458f, 5.721723f, 54.928432f, 15.006015f, 1.519569f, 55.115219f, 15.006015f, 1.519569f, 55.115219f, 13.922662f, -0.086341f, 48.652729f, 15.398161f, 6.227328f, 47.229149f, 19.166872f, -0.439006f, 45.890106f, 19.285433f, 1.019830f, 51.916763f, 19.018568f, 5.331750f, 51.836819f, 19.018568f, 5.331750f, 51.836819f, 18.722847f, 5.664664f, 45.879768f, 19.166872f, -0.439006f, 45.890106f, 13.922662f, -0.086341f, 48.652729f, 15.006015f, 1.519569f, 55.115219f, 19.285433f, 1.019830f, 51.916763f, 19.285433f, 1.019830f, 51.916763f, 19.166872f, -0.439006f, 45.890106f, 13.922662f, -0.086341f, 48.652729f, 18.722847f, 5.664664f, 45.879768f, 19.018568f, 5.331750f, 51.836819f, 16.094458f, 5.721723f, 54.928432f, 16.094458f, 5.721723f, 54.928432f, 15.398161f, 6.227328f, 47.229149f, 18.722847f, 5.664664f, 45.879768f, 15.006015f, 1.519569f, 55.115219f, 16.094458f, 5.721723f, 54.928432f, 17.434431f, 4.480306f, 58.874214f, 17.434431f, 4.480306f, 58.874214f, 17.096628f, 3.139414f, 58.951324f, 15.006015f, 1.519569f, 55.115219f, 19.018568f, 5.331750f, 51.836819f, 19.285433f, 1.019830f, 51.916763f, 18.274830f, 3.296629f, 58.839859f, 18.274830f, 3.296629f, 58.839859f, 18.170647f, 4.230951f, 58.858616f, 19.018568f, 5.331750f, 51.836819f, 19.285433f, 1.019830f, 51.916763f, 15.006015f, 1.519569f, 55.115219f, 17.096628f, 3.139414f, 58.951324f, 17.096628f, 3.139414f, 58.951324f, 18.274830f, 3.296629f, 58.839859f, 19.285433f, 1.019830f, 51.916763f, 16.094458f, 5.721723f, 54.928432f, 19.018568f, 5.331750f, 51.836819f, 18.170647f, 4.230951f, 58.858616f, 18.170647f, 4.230951f, 58.858616f, 17.434431f, 4.480306f, 58.874214f, 16.094458f, 5.721723f, 54.928432f, 14.571514f, -5.343407f, 40.930904f, 14.683560f, -6.901972f, 32.471439f, 14.428933f, -6.684027f, 34.222805f, 14.428933f, -6.684027f, 34.222805f, 14.373026f, -5.719159f, 39.128136f, 14.571514f, -5.343407f, 40.930904f, 7.314791f, -9.341828f, 33.737534f, 7.320009f, -7.912378f, 40.945305f, 10.752159f, -7.024318f, 38.999115f, 10.752159f, -7.024318f, 38.999115f, 10.607469f, -7.946212f, 34.709949f, 7.314791f, -9.341828f, 33.737534f, 14.571514f, -5.343407f, 40.930904f, 14.373026f, -5.719159f, 39.128136f, 10.752159f, -7.024318f, 38.999115f, 10.752159f, -7.024318f, 38.999115f, 7.320009f, -7.912378f, 40.945305f, 14.571514f, -5.343407f, 40.930904f, 7.314791f, -9.341828f, 33.737534f, 10.607469f, -7.946212f, 34.709949f, 14.428933f, -6.684027f, 34.222805f, 14.428933f, -6.684027f, 34.222805f, 14.683560f, -6.901972f, 32.471439f, 7.314791f, -9.341828f, 33.737534f, 14.428933f, -6.684027f, 34.222805f, 13.409106f, -4.459196f, 34.583401f, 13.407806f, -5.291871f, 37.201290f, 13.407806f, -5.291871f, 37.201290f, 14.373026f, -5.719159f, 39.128136f, 14.428933f, -6.684027f, 34.222805f, 14.373026f, -5.719159f, 39.128136f, 13.407806f, -5.291871f, 37.201290f, 10.997403f, -6.403482f, 37.277554f, 10.997403f, -6.403482f, 37.277554f, 10.752159f, -7.024318f, 38.999115f, 14.373026f, -5.719159f, 39.128136f, 10.752159f, -7.024318f, 38.999115f, 10.997403f, -6.403482f, 37.277554f, 10.988160f, -5.677050f, 34.978966f, 10.988160f, -5.677050f, 34.978966f, 10.607469f, -7.946212f, 34.709949f, 10.752159f, -7.024318f, 38.999115f, 10.607469f, -7.946212f, 34.709949f, 10.988160f, -5.677050f, 34.978966f, 13.409106f, -4.459196f, 34.583401f, 13.409106f, -4.459196f, 34.583401f, 14.428933f, -6.684027f, 34.222805f, 10.607469f, -7.946212f, 34.709949f, 9.175188f, 29.073957f, 14.934714f, 7.455090f, 29.096563f, 14.903179f, 7.438042f, 25.047373f, 8.677461f, 7.438042f, 25.047373f, 8.677461f, 8.720451f, 24.982521f, 8.632037f, 9.175188f, 29.073957f, 14.934714f, 8.544544f, 28.501253f, 21.455393f, 7.449881f, 28.499632f, 21.485111f, 7.455090f, 29.096563f, 14.903179f, 7.455090f, 29.096563f, 14.903179f, 9.175188f, 29.073957f, 14.934714f, 8.544544f, 28.501253f, 21.455393f, 8.916059f, 36.023087f, 32.743652f, 7.480425f, 36.037731f, 32.738682f, 7.449881f, 28.499632f, 21.485111f, 7.449881f, 28.499632f, 21.485111f, 8.544544f, 28.501253f, 21.455393f, 8.916059f, 36.023087f, 32.743652f, 7.451022f, 27.981888f, 42.640167f, 7.480425f, 36.037731f, 32.738682f, 8.916059f, 36.023087f, 32.743652f, 8.916059f, 36.023087f, 32.743652f, 11.292462f, 27.969028f, 42.629868f, 7.451022f, 27.981888f, 42.640167f, 8.720451f, 24.982521f, 8.632037f, 7.438042f, 25.047373f, 8.677461f, 7.448072f, 27.173620f, 4.010532f, 7.448072f, 27.173620f, 4.010532f, 9.419173f, 27.066231f, 3.887028f, 8.720451f, 24.982521f, 8.632037f, 7.438875f, 24.654293f, 0.000000f, 7.347628f, -0.345043f, 0.000000f, 9.768484f, 8.652227f, 0.000000f, 9.768484f, 8.652227f, 0.000000f, 8.317277f, 24.633436f, 0.000000f, 7.438875f, 24.654293f, 0.000000f, 14.914590f, -7.331017f, 28.766878f, 13.534257f, -8.606539f, 31.960472f, 14.683560f, -6.901972f, 32.471439f, 14.683560f, -6.901972f, 32.471439f, 18.842646f, -1.809262f, 29.013023f, 14.914590f, -7.331017f, 28.766878f, 18.528133f, -1.663332f, 31.894547f, 18.842646f, -1.809262f, 29.013023f, 14.683560f, -6.901972f, 32.471439f, 18.170647f, 4.230951f, 58.858616f, 18.274830f, 3.296629f, 58.839859f, 17.096628f, 3.139414f, 58.951324f, 17.096628f, 3.139414f, 58.951324f, 17.434431f, 4.480306f, 58.874214f, 18.170647f, 4.230951f, 58.858616f };

void glVertexFromMemory(int i) {

    tft.glVertex3f(pgm_read_float(&model[i*3 + 0]), pgm_read_float(&model[i*3 + 1]), pgm_read_float(&model[i*3 + 2]));
}

void drawModel(void) {

    int i;

    for(i = 0; i < 412; i++) {

        tft.glBegin(GL_POLYGON);
        glVertexFromMemory(i*3);
        glVertexFromMemory(i*3 + 1);
        glVertexFromMemory(i*3 + 2);
        tft.glEnd();
    }
}

void setup() {
  tft.begin();


  tft.fillScreen(BLACK);
  tft.setTextColor(YELLOW);
  tft.setTextSize(2);
  tft.setRotation(3);
  tft.println("Waiting for Arduino Serial Monitor...");

  Serial.begin(9600);
  while (!Serial) ; // wait for Arduino Serial Monitor
  Serial.println("OpenGL Test!"); 

  delay(1000);
  tft.useFrameBuffer(use_fb);
  /* Pass the canvas to the OpenGL environment */
  tft.glClear(BLACK);
  tft.glPointSize(4);
    
  tft.glMatrixMode(GL_PROJECTION);
  tft.glLoadIdentity();

  tft.gluPerspective(60.0, (float)tft.width()/(float)tft.height(), 0.1f, 9999.f);
    
  tft.glMatrixMode(GL_MODELVIEW);
  tft.updateScreen();
}

void loop() {
  static int angle = 0.f;

  tft.glClear(BLACK); 
  
  tft.glLoadIdentity();
  tft.gluLookAt(0, 0, -15, 0, 3, 0, 0, 1, 0);
  
  tft.glScalef(0.1f, 0.1f, 0.1f);
  tft.glRotatef(angle, 0.f, 1.f, 0.f);
  tft.glRotatef(-90.f, 1.f, 0.f, 0.f);

  drawModel();
  tft.updateScreen();
  angle+=5;
  angle %= 360;
  //delayMicroseconds(500);
}
@MartinRGB
Copy link
Author

openGL_sphere

/*
 * Square.ino
 * Created by Fabio de Albuquerque Dela Antonio
 * fabio914 at gmail.com
 * 
 * An OpenGL example that draws a rotated and scaled square.
 */
#include "SPI.h"
#include "ILI9341_t3n.h"
#include <TeensyGL.h> 

// For the Adafruit shield, these are the default.
#define TFT_DC  9
#define TFT_CS 10

// Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
Teensy_OpenGL tft = Teensy_OpenGL(9, 10, 6);
uint8_t use_fb = 1;


void drawSphere(float radius, float p) {

  float theta1 = 0.f, theta2 = 0.f, theta3 = 0.f;
  float ex, ey, ez;
        
  for(int i = 0; i < p/2; i++) {
            
    theta1 = i * (M_PI * 2.f)/p - M_PI_2;
    theta2 = (i + 1) * (M_PI * 2.f)/p - M_PI_2;
          
    tft.glBegin(GL_TRIANGLE_STRIP);
    for(int j = 0; j <= p; j++) {
                
      theta3 = j * (M_PI * 2.f)/p;
      ex = cosf(theta2) * cosf(theta3);
      ey = sinf(theta2);
      ez = cosf(theta2) * sinf(theta3);
                
      tft.glVertex3f(radius * ex, radius * ey, radius * ez);
      
      ex = cosf(theta1) * cosf(theta3);
      ey = sinf(theta1);
      ez = cosf(theta1) * sinf(theta3);
                
      tft.glVertex3f(radius * ex, radius * ey, radius * ez);
    }
    tft.glEnd();
  }
}


void setup() {
  tft.begin();
  tft.fillScreen(ILI9341_BLACK);
  tft.setTextColor(ILI9341_YELLOW);
  tft.setTextSize(2);
  tft.println("Waiting for Arduino Serial Monitor...");

  Serial.begin(9600);
  while (!Serial) ; // wait for Arduino Serial Monitor
  Serial.println("OpenGL Test!"); 

  delay(1000);

  /* Pass the canvas to the OpenGL environment */
  tft.glClear(ILI9341_BLACK);
  tft.glPointSize(4);
    
  tft.glMatrixMode(GL_PROJECTION);
  tft.glLoadIdentity();

  tft.gluPerspective(30.0, 0.8, 0.1f, 9999.f);
    
  tft.glMatrixMode(GL_MODELVIEW);
}

void loop() {
  /* Read the scale factor from a potentiometer attached to pin A0 */
  float scale = 0.5 * 4.f;
  static int angle = 0.f;

  tft.glClear(ILI9341_BLACK); 
  
  tft.glLoadIdentity();
  tft.gluLookAt(10, 8, -10, 0, 0, 0, 0, 1, 0);
  
  tft.glScalef(scale + 1.f, scale + 1.f, scale + 1.f);
  tft.glRotatef(angle, 0.f, 1.f, 0.f);
  
  drawSphere(1.0, 10);

  angle+=5;
  angle %= 360;
  
  delay(1);
}

@MartinRGB
Copy link
Author

openGL_square

/*
 * Square.ino
 * Created by Fabio de Albuquerque Dela Antonio
 * fabio914 at gmail.com
 * 
 * An OpenGL example that draws a rotated and scaled square.
 */
#include "SPI.h"
#include "ILI9341_t3n.h"
#include <TeensyGL.h> 

//#define ILI9488 1
#define ILI9341 1

// For the Adafruit shield, these are the default.
#define TFT_DC  9
#define TFT_CS 10

// Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
#if defined(ILI9488)
Arduino_OpenGL tft = Arduino_OpenGL(&SPI, TFT_CS, TFT_DC, 8);
#elif defined(ILI9341)
Teensy_OpenGL tft = Teensy_OpenGL(9, 10, 6);
#endif

// Color definitions
#define BLACK       0x0000      /*   0,   0,   0 */
#define YELLOW      0xFFE0      /* 255, 255,   0 */
#define WHITE       0xFFFF      /* 255, 255, 255 */

uint8_t use_fb = 1;


void setup() {
  tft.begin();
  tft.fillScreen(BLACK);
  tft.setTextColor(YELLOW);
  tft.setTextSize(2);
  tft.println("Waiting for Arduino Serial Monitor...");

  Serial.begin(9600);
  while (!Serial) ; // wait for Arduino Serial Monitor
  Serial.println("OpenGL Test!"); 

  delay(1000);
  tft.useFrameBuffer(use_fb);

  /* Pass the canvas to the OpenGL environment */
  tft.glClear(BLACK);
  tft.glPointSize(4);
    
  tft.glMatrixMode(GL_PROJECTION);
  tft.glLoadIdentity();
  tft.gluOrtho2D(-5.0, 5.0, -5.0, 5.0);
    
  tft.glMatrixMode(GL_MODELVIEW);
}

void loop() {

  /* Read the rotation angle from a potentiometer attached to pin A0 */
  float angle = .4 * 360.f;
  
  static float scale = 3.0, scaleInc = 0.4;
  const float maxScale = 8.0, minScale = 2.0;

  tft.glClear(BLACK); 
  
  tft.glLoadIdentity();
  tft.glRotatef(angle, 0.f, 0.f, 1.f);
  tft.glScalef(scale, scale, 0.f);
  tft.glTranslatef(-0.5f, -0.5f, 0.f);
  
  tft.glBegin(GL_POINTS);
    tft.glVertex3f(0.f, 1.f, 0.f);
    tft.glVertex3f(0.f, 0.f, 0.f);
    tft.glVertex3f(1.f, 0.f, 0.f);
    tft.glVertex3f(1.f, 1.f, 0.f);
  tft.glEnd();

  tft.glBegin(GL_POLYGON);
    tft.glVertex3f(0.f, 1.f, 0.f);
    tft.glVertex3f(0.f, 0.f, 0.f);
    tft.glVertex3f(1.f, 0.f, 0.f);
    tft.glVertex3f(1.f, 1.f, 0.f);
  tft.glEnd();
  tft.updateScreen();

  scale += scaleInc;

  if(scale > maxScale)
    scaleInc *= -1.f;

  if(scale < minScale)
    scaleInc *= -1.f;
  
  delay(1);
}

@MartinRGB
Copy link
Author

opengl_torus

#include "SPI.h"
//#include "ST7789_t3.h"
#include "ILI9341_t3n.h"
#include <TeensyGL.h> 
//#include "teapot_high_res.h"
#include "teapot_low_res.h"
//#include "monkey_high_res.h"
//#include "small_bunny.h"

#define _use_triangle 0
#define _use_quad1 0
#define _use_pyramid 0
#define _use_torus 1
#define _use_cube 0
#define _use_model 0
#define _use_diamond 0


#define _use_FacetShader  1     //Phong shading, no lighting
#define _use_SimpleShader 0     //flat shading (use single color)
                                //Interpolation shading each vertex has a different color
#define _use_SmoothShader 0     //Phong: "Phong", Gourand: "Gourand"
#define _use_perspective  0


// For the Adafruit shield, these are the default.
#define TFT_DC  9
#define TFT_CS  10

// Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
Teensy_OpenGL tft = Teensy_OpenGL(9, 10, 6);
uint8_t use_fb = 1;

#define PI_ 3.14159265358979323846
int numc = 8;
int numt = 25;


void setup() {
  tft.begin();
  tft.fillScreen(ILI9341_BLACK);
  tft.setTextColor(ILI9341_YELLOW);
  tft.setTextSize(2);
  tft.println("Waiting for Arduino Serial Monitor...");
  //tft.setRotation(1);
  
  Serial.begin(9600);
  while (!Serial) ; // wait for Arduino Serial Monitor
  Serial.println("OpenGL Test!"); 

  delay(1000);

  /* Pass the canvas to the OpenGL environment */
  tft.glClear(ILI9341_BLACK);
  tft.glPointSize(2);
    
  if(_use_FacetShader == 1){
    tft.glAttachShader(FacetShader);
  } else if(_use_SimpleShader == 1){
    tft.glAttachShader(SimpleVertexShader);
  } else if(_use_SmoothShader == 1) {
    //tft.glAttachShader(SmoothShader,"Phong");
    tft.glAttachShader(SmoothShader,"Gourand");
  }

  //copper - taken from
  float light_ambient[] = {.19125, .0735, .0225, 1.0}; // whitelight {r, g, b, Intensity}
  float light_diffuse[] = {.7038, .27048, .0828, 1.0}; // {r, g, b, Intensity}
  float light_specular[] = {.256771, .137622, .137622, 1.0}; // {r, g, b, Intensity}
  
  //float light_ambient[] = {.329412, .223529, .023451, 0.7}; // whitelight {r, g, b, Intensity}
  //float light_diffuse[] = {.780392, .568627, .113725, 0.4}; // {r, g, b, Intensity}  //float light_specular[] = {1., 1., 1., 0.8};

  float light_position[] =  {-1., 1., -1};    // direction of the diffuse light
                                              // (this vector should have length 1)
  tft.glLight(GL_LIGHT0, GL_AMBIENT, light_ambient);
  tft.glLight(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
  tft.glLight(GL_LIGHT0, GL_SPECULAR, light_specular);
  tft.glLight(GL_LIGHT0, GL_POSITION, light_position);
  
  tft.useFrameBuffer(1);

}

float angle = -0.;
float angley = -0.;

void loop() {
  tft.glClear(ILI9341_BLACK); 

  reShape();
  
  if(_use_model == 1){
    //tft.glTranslatef(0.0, 3., 0.0);
    tft.glRotatef(angle, 0., 1., 1.f);  //note to self -75 for torus
    //tft.glScalef(0.05, 0.05, 0.05);
    tft.glScalef(0.03, 0.03, 0.03);
  } else {
  //tft.glTranslatef(0.0, -2.5, 0.0);
    tft.glRotatef(angle, 0., 1., 1.f);  //note to self -75 for torus
    tft.glScalef(2.0, 2.0, 2.0);  //was 2.5
  }
  
  if(_use_triangle == 1)  drawTri();
  if(_use_quad1 == 1)     drawQuad2();
  if(_use_torus == 1)     torus();
  if(_use_pyramid == 1)   drawPyramid();
  if(_use_model == 1)     drawFromModel();
  if(_use_cube == 1)      drawCube1();
  if(_use_diamond == 1)   drawDiamond();
  
//  reShape();
//  tft.glTranslatef(0.0, 2.5, 0.0);
//    tft.glRotatef(-angle, 0., 1., 1.f);  //note to self -75 for torus
//    tft.glScalef(1.0, 1.0, 1.0);  //was 2.5
//  drawDiamond();


  tft.setCursor(0,0);
  //tft.println(angle);
  //Serial.println(angle);
  tft.print(angle);
  tft.updateScreen();


  //exit(1);
  //nextAngle();
  angle -= 10;
  if(abs(angle) > 350) angle = 0;

  delay(100);
  //Serial.print("Temp: ");
  //Serial.println(tempmonGetTemp());
}

void reShape(){
  tft.glMatrixMode(GL_PROJECTION);
  tft.glLoadIdentity();

    float ar = (float)tft.width() / (float) tft.height();

  if (_use_perspective == 1) {
      tft.gluPerspective(65.0, ar, 0.1f, 9999.f);
   } else {
      tft.glOrtho(-5.0, 5.0, -6.0, 6.0, -5, 5);
  }
  
  tft.glMatrixMode(GL_MODELVIEW);

  tft.glLoadIdentity();

  if(_use_perspective == 1)
      tft.gluLookAt(0, 0, -15, 0, 3, 0, 0, 1, 0);
}

void nextAngle()
{
  Serial.println("Press anykey to continue");
  while (Serial.read() == -1) ;
  while (Serial.read() != -1) ;
}

@MartinRGB
Copy link
Author

MartinRGB commented Nov 11, 2023

demosauce

/***************************************************
                 **  DemoSauce!  **
  State-of-the-art graphics for your beautiful TFT display.

  Greetz to the Portland Dorkbot Crew!!!!

         Programmed by Zach Archer (@zkarcher)  ::  http://controlzinc.com/
  Using hardware by Thomas Hudson (@hydronics)  ::  http://thomashudson.org/

  Usage:
    * Connect a microphone to MIC_PIN.
    * Connect TFT backlight to BACKLIGHT_PIN.

  MIT license, all text above must be included in any redistribution

 https://github.com/zkarcher/demosauce


  Adapted from  https://github.com/KurtE/ILI9341_t3n/tree/master/examples/DemoSauce
  to use the ILI9341_T4 library
 ****************************************************/

 
#include "ILI9341Wrapper.h"

#include "FrameParams.h"

// Animations
#include "Checkerboard.h"
#include "Cube3D.h"
#include "Leaves.h"
#include "MagentaSquares.h"
//#include "MicCheck.h"
#include "PlasmaCloud.h"
#include "PlasmaYellow.h"
#include "Sphere3D.h"
#include "TriangleWeb.h"
#include "TwistyText.h"
#include "Waveform.h"

// Transitions
#include "TransitionDither.h"
#include "TransitionHalftone.h"
#include "TransitionScroll.h"
#include "TransitionSquares.h"



//
// DEFAULT WIRING USING SPI 0 ON TEENSY 4/4.1
//
#define PIN_SCK0     13      // mandatory
#define PIN_MISO0    12      // mandatory  (if the display has no MISO line, set this to 255 but then VSync will be disabled)
#define PIN_MOSI0    11      // mandatory
#define PIN_DC0      10      // mandatory, can be any pin but using pin 10 (or 36 or 37 on T4.1) provides greater performance

#define PIN_CS0      9       // optional (but recommended), can be any pin.  
#define PIN_RESET0   6       // optional (but recommended), can be any pin. 
#define PIN_BACKLIGHT0 255   // optional, set this only if the screen LED pin is connected directly to the Teensy.
#define PIN_TOUCH_IRQ0 255   // optional, set this only if the touchscreen is connected on the same SPI bus
#define PIN_TOUCH_CS0  255   // optional, set this only if the touchscreen is connected on the same spi bus


//
// ALTERNATE WIRING USING SPI 1 ON TEENSY 4/4.1 
//
#define PIN_SCK1     27      // mandatory 
#define PIN_MISO1    1       // mandatory  (if the display has no MISO line, set this to 255 but then VSync will be disabled)
#define PIN_MOSI1    26      // mandatory
#define PIN_DC1      0       // mandatory, can be any pin but using pin 0 (or 38 on T4.1) provides greater performance

#define PIN_CS1      30      // optional (but recommended), can be any pin.  
#define PIN_RESET1   29      // optional (but recommended), can be any pin.  
#define PIN_BACKLIGHT1 255   // optional, set this only if the screen LED pin is connected directly to the Teensy. 
#define PIN_TOUCH_IRQ1 255   // optional, set this only if the touchscreen is connected on the same SPI bus
#define PIN_TOUCH_CS1  255   // optional, set this only if the touchscreen is connected on the same spi bus




#define MIC_PIN         14  // optional. 


#define SPI_SPEED 70000000

#define LX  320
#define LY  240


ILI9341Wrapper tft0(PIN_CS0, PIN_DC0, PIN_SCK0, PIN_MOSI0, PIN_MISO0, PIN_RESET0, PIN_TOUCH_CS0, PIN_TOUCH_IRQ0);
ILI9341Wrapper tft1(PIN_CS1, PIN_DC1, PIN_SCK1, PIN_MOSI1, PIN_MISO1, PIN_RESET1, PIN_TOUCH_CS1, PIN_TOUCH_IRQ1);
//ILI9341_T4::ILI9341Driver tft0(PIN_CS0, PIN_DC0, PIN_SCK0, PIN_MOSI0, PIN_MISO0, PIN_RESET0, PIN_TOUCH_CS0, PIN_TOUCH_IRQ0); // for screen on SPI0
//ILI9341_T4::ILI9341Driver tft1(PIN_CS1, PIN_DC1, PIN_SCK1, PIN_MOSI1, PIN_MISO1, PIN_RESET1, PIN_TOUCH_CS1, PIN_TOUCH_IRQ1); // for screen on SPI1

ILI9341_T4::DiffBuffStatic<40000> diff1;
ILI9341_T4::DiffBuffStatic<40000> diff2;

ILI9341_T4::DiffBuffStatic<40000> diff3; // for the driver on SPI1
ILI9341_T4::DiffBuffStatic<40000> diff4; //



//DMAMEM uint16_t internal_fb[LX * LY];     // used by the library for buffering
//uint16_t fb[LX * LY];              // the main framebuffer we draw onto.
DMAMEM uint16_t internal_fb0[LX * LY]; // internal fb used by the library for the first screen
DMAMEM uint16_t internal_fb1[LX * LY]; // internal fb used by the library for the second screen
uint16_t fb[LX * LY];                  // main framebuffer we draw onto




#define ILI9341_BLACK 0x0000       /*   0,   0,   0 */
#define ILI9341_BLUE 0x001F        /*   0,   0, 255 */
#define ILI9341_GREEN 0x07E0       /*   0, 255,   0 */
#define ILI9341_RED 0xF800         /* 255,   0,   0 */
#define ILI9341_YELLOW 0xFFE0      /* 255, 255,   0 */
#define ILI9341_WHITE 0xFFFF       /* 255, 255, 255 */





const boolean DO_BENCHMARKS = true;
const uint32_t SERIAL_BAUD_RATE = 9600;

const boolean DEBUG_ANIM = false; // dev: for hacking on one animation.
const uint_fast8_t DEBUG_ANIM_INDEX = 0;

const boolean DEBUG_TRANSITION = false;  // dev: set to true for short animation durations
const int_fast8_t DEBUG_TRANSITION_INDEX = -1;  // Supports -1: chooses a transition at random

const int_fast16_t DEFAULT_ANIM_TIME = 20.0f * 1000.0f;  // ms


FrameParams frameParams;
long previousMillis = 0;

Checkerboard* _checkerboard = new Checkerboard();
Cube3D* _cube3D = new Cube3D();
Leaves* _leaves = new Leaves();
MagentaSquares* _magentaSquares = new MagentaSquares();
PlasmaCloud* _plasmaCloud = new PlasmaCloud();
PlasmaYellow* _plasmaYellow = new PlasmaYellow();
Sphere3D* _sphere3D = new Sphere3D();
TriangleWeb* _triangleWeb = new TriangleWeb();
TwistyText* _twistyText = new TwistyText();
Waveform* _waveform = new Waveform();

TransitionDither* _transDither = new TransitionDither();
TransitionHalftone* _transHalftone = new TransitionHalftone();
TransitionScroll* _transScroll = new TransitionScroll();
TransitionSquares* _transSquares = new TransitionSquares();

BaseAnimation** anims; // Array of pointers to BaseAnimation's. Initialized in setup() below.
int_fast8_t animCount;

BaseAnimation* activeAnim = 0;
int_fast16_t animTimeLeft = 0;
BaseAnimation* nextAnim;

BaseTransition** transitions;
int_fast8_t transCount;
boolean isTransition = true;
BaseTransition* activeTransition = 0;

void clear(uint16_t* fb, uint16_t color = 0) 
    {
    for (int i = 0; i < 240 * 320; i++) fb[i] = color;
    }

// Benchmarks
uint32_t frameCount;

// Search the anims[] aray for the activeAnim pointer. If found, return the array index.
int_fast8_t getActiveAnimIndex() {
    for (int_fast8_t i = 0; i < animCount; i++) {
        if (anims[i] == activeAnim) return i;
    }
    return -1;  // not found
}

void setup() 
    {
    Serial.begin(9600);

    tft0.output(&Serial);                // output debug infos to serial port. 
    while (!tft0.begin(SPI_SPEED));      // init the display
    tft0.setRotation(3);                 // landscape 320x240
    tft0.setFramebuffer(internal_fb0);    // internal framebuffer
    tft0.setDiffBuffers(&diff1, &diff2); // 2 diff buffers
    tft0.setDiffGap(3);                  // very small gap !
    tft0.setRefreshRate(120);            // 120hz refresh rate
    tft0.setVSyncSpacing(1);             // fps lock at max 120hz (may also try 0 = max fps and 2 = locked at 60fps

    tft1.output(&Serial);                // output debug infos to serial port. 
    while (!tft1.begin(SPI_SPEED));      // init the display
    tft1.setRotation(3);                 // landscape 320x240
    tft1.setFramebuffer(internal_fb1);    // internal framebuffer
    tft1.setDiffBuffers(&diff3, &diff4); // 2 diff buffers
    tft1.setDiffGap(3);                  // very small gap !
    tft1.setRefreshRate(120);            // 120hz refresh rate
    tft1.setVSyncSpacing(1);             // fps lock at max 120hz (may also try 0 = max fps and 2 = locked at 60fps


    if (PIN_BACKLIGHT0 != 255)
    { // make sure backlight is on is needed. 
      pinMode(PIN_BACKLIGHT0, OUTPUT);
      digitalWrite(PIN_BACKLIGHT0,HIGH);
    }

    if (PIN_BACKLIGHT1 != 255)
    { // make sure backlight is on is needed. 
      pinMode(PIN_BACKLIGHT1, OUTPUT);
      digitalWrite(PIN_BACKLIGHT1,HIGH);
    }

    tft0.setCanvas(fb, LX, LY); // set the framebuffer we draw onto (extended method from ILI9341Wrapper).
    tft1.setCanvas(fb, LX, LY); // set the framebuffer we draw onto (extended method from ILI9341Wrapper).


    // Microphone
    pinMode(MIC_PIN, INPUT);

    tft0.fillScreen(ILI9341_BLACK);
    tft1.fillScreen(ILI9341_BLACK);

    previousMillis = millis();

    // Clear
    uint16_t w0 = tft0.width();
    uint16_t h0 = tft0.height();
    tft0.fillRect(0, 0, w0, h0, 0x0);

    tft0.setRotation(3); // ribbon cable on left
    tft0.setScroll(0);

    uint16_t w1 = tft1.width();
    uint16_t h1 = tft1.height();
    tft1.fillRect(0, 0, w1, h1, 0x0);

    tft1.setRotation(3); // ribbon cable on left
    tft1.setScroll(0);

    // Populate anims in the order you want them to display.
    BaseAnimation* ANIMS_TEMP[] = {
      _twistyText,
      _plasmaCloud,
      _waveform,
      _magentaSquares,
      _sphere3D,
      _checkerboard,
      _leaves,
      _cube3D,
      _plasmaYellow,
      _triangleWeb
    };
    animCount = sizeof(ANIMS_TEMP) / sizeof(BaseAnimation*);

    // Retain ANIMS_TEMP objects permanently
    anims = (BaseAnimation**)malloc(animCount * sizeof(BaseAnimation*));
    for (int_fast8_t i = 0; i < animCount; i++) {
        anims[i] = ANIMS_TEMP[i];
        anims[i]->init(tft0);      // Initalize all animations
        anims[i]->init(tft1);      // Initalize all animations
    }

    BaseTransition* TRANS_TEMP[] = {
      _transDither,
      _transHalftone,
      _transScroll,
      _transSquares
    };
    transCount = sizeof(TRANS_TEMP) / sizeof(BaseTransition*);

    // Retain TRANS_TEMP objects permanently
    transitions = (BaseTransition**)malloc(transCount * sizeof(BaseTransition*));
    for (int_fast8_t i = 0; i < transCount; i++) {
        transitions[i] = TRANS_TEMP[i];
        transitions[i]->init(tft0);
        transitions[i]->init(tft1);
    }

    // Start!
    if (!activeAnim) {
        if (DEBUG_ANIM) {
            startAnimation(anims[DEBUG_ANIM_INDEX]);
        }
        else {
            startAnimation(anims[0]);
        }
    }
}

void startAnimation(BaseAnimation* newAnim) {
    isTransition = false;

    activeAnim = newAnim;
    tft0.fillScreen(activeAnim->bgColor());
    tft0.setScroll(0);
    activeAnim->reset(tft0);

    tft1.fillScreen(activeAnim->bgColor());
    tft1.setScroll(0);
    activeAnim->reset(tft1);

    animTimeLeft = DEFAULT_ANIM_TIME;

    if (DEBUG_TRANSITION) animTimeLeft = 2000;

    if (DO_BENCHMARKS) {
        Serial.println("---");
        Serial.print(activeAnim->title());

        if (activeAnim->willForceTransition()) {
            // TwistyText does not obey DEFAULT_ANIM_TIME
            Serial.println("");

        }
        else {
            Serial.print("  [");
            Serial.print((uint8_t)(animTimeLeft / 1000.0f));
            Serial.println(" secs]");
        }

        frameCount = 0;
    }
}

void loop() {
    // Frame multiplier
    long newMillis = millis();
    uint_fast8_t elapsed = newMillis - previousMillis;
    previousMillis = newMillis;
    frameParams.timeMult = elapsed * (60.0f / 1000);  // 1.0==exactly 60fps. 4.0==15fps, 4x slower

    // Get some audio input
    const uint_fast8_t SAMPLES_PER_FRAME = 1;
    frameParams.audioPeak = 0;
    uint_fast16_t sum = 0;

    for (uint_fast8_t s = 0; s < SAMPLES_PER_FRAME; s++) {
        uint_fast16_t sample = abs(analogRead(MIC_PIN) - 511);
        frameParams.audioPeak = max(frameParams.audioPeak, sample);
        sum += sample;
    }
    frameParams.audioMean = sum * (1.0 / (512 * SAMPLES_PER_FRAME));  // Range: 0..1

    frameParams.audioPeak = min((uint_fast16_t)frameParams.audioPeak, (uint_fast16_t)511);

    if (!isTransition) {
        clear(fb, 0); // clear the framebuffer 
        activeAnim->perFrame(tft0, frameParams);
        tft0.overlayFPS(fb); // draw the FPS counter on the top right corner of the framebuffer
        tft0.update(fb); // update the screen.

        clear(fb, 0); // clear the framebuffer 
        activeAnim->perFrame(tft1, frameParams);
        tft1.overlayFPS(fb); // draw the FPS counter on the top right corner of the framebuffer
        tft1.update(fb); // update the screen.

        animTimeLeft -= elapsed;
        if (DO_BENCHMARKS) frameCount++;
    }

    // Has this animation expired?
    boolean willForceTransition = activeAnim->willForceTransition();
    boolean forceTransitionNow = activeAnim->forceTransitionNow();

    // Debugging transitions: Ignore animations hogging the screen
    if (DEBUG_TRANSITION) willForceTransition = false;

    if (!DEBUG_ANIM) {
        if ((!willForceTransition && (animTimeLeft <= 0)) || forceTransitionNow) {

            // If the transition has not started yet, then start it.
            if (!isTransition) {
                isTransition = true;

                nextAnim = anims[(getActiveAnimIndex() + 1) % animCount];

                /*
                // Print some debug stuff
                if( DO_BENCHMARKS ) {
                  Serial.println("---------- Testing sinf() vs sin() performance");
                  unsigned long then = micros();
                  float z = 0;
                  for( uint32_t i=0; i<50000; i++ ) {
                    z += sinf( (float)i );
                  }
                  unsigned long now = micros();
                  Serial.print("sinf:");
                  Serial.println( now - then );
                  Serial.print("   z:");
                  Serial.println( z );

                  then = micros();
                  z = 0;
                  for( uint32_t i=0; i<50000; i++ ) {
                    z += sin( (float)i );
                  }
                  now = micros();
                  Serial.print(" sin:");
                  Serial.println( now - then );
                  Serial.print("   z:");
                  Serial.println( z );
                }
                */

                // When we loop back to the first animation, shuffle the other ones for variety.
                if (nextAnim == anims[0]) {
                    for (int_fast8_t i = 1; i < animCount - 1; i++) {
                        uint_fast8_t shuffleIdx = random(i, animCount);

                        BaseAnimation* temp = anims[i];
                        anims[i] = anims[shuffleIdx];
                        anims[shuffleIdx] = temp;
                    }
                }

                // Choose a random transition
                activeTransition = transitions[random(transCount)];
                if (DEBUG_TRANSITION && (DEBUG_TRANSITION_INDEX >= 0)) {
                    activeTransition = transitions[DEBUG_TRANSITION_INDEX];
                }

                activeTransition->restart(tft0, nextAnim->bgColor());
                activeTransition->restart(tft1, nextAnim->bgColor());
                // Benchmark: show how many frames the animation completed while alive.
                if (DO_BENCHMARKS) {
                    Serial.print("Frame count (more is better):  ");
                    Serial.print(frameCount);

                    if (!activeAnim->willForceTransition()) {
                        Serial.print("  (");
                        Serial.print((float)frameCount / (DEFAULT_ANIM_TIME / 1000.0f));
                        Serial.println(" FPS)");
                    }
                    else {
                        Serial.println("");
                    }
                }
            }

            // After the transition ends, advance to the next animation
            clear(fb, 0); // clear the framebuffer 
            activeTransition->perFrame(tft0, frameParams);
            tft0.overlayFPS(fb); // draw the FPS counter on the top right corner of the framebuffer
            tft0.update(fb);

            activeTransition->perFrame(tft1, frameParams);
            tft1.overlayFPS(fb); // draw the FPS counter on the top right corner of the framebuffer
            tft1.update(fb);

            if (activeTransition->isComplete()) {
                startAnimation(nextAnim);
            }

        }
    }

}

@MartinRGB
Copy link
Author

MartinRGB commented Nov 11, 2023

dualDisplay

/**
* CREDIT: Example created by Bruno@DIYLAB.DE. Thanks a lot !
*
* SRC: https://github.com/DIYLAB-DE/DualDisplay_T4
*
* Example for Teensy 4/4.1 on using two ILI9341 screens 
* simultaneously (one on SPI0 and the other one on SPI1) 
**/


// the screen driver library
#include <ILI9341_T4.h>


//
// FIRST SCREEN IS WIRED TO SPI0 
//
#define PIN_SCK0        13  // mandatory 
#define PIN_MISO0       12  // mandatory  (if the display has no MISO line, set this to 255 but then VSync will be disabled)
#define PIN_MOSI0       11  // mandatory
#define PIN_DC0         10  // mandatory, can be any pin but using pin 10 (or 36 or 37 on T4.1) provides greater performance

#define PIN_CS0          9  // optional (but recommended), can be any pin.  
#define PIN_RESET0       6  // optional (but recommended), can be any pin.  
#define PIN_BACKLIGHT0 255  // optional, set this only if the screen LED pin is connected directly to the Teensy. 
#define PIN_TOUCH_IRQ0 255  // optional, set this only if the touchscreen is connected on the same SPI bus
#define PIN_TOUCH_CS0  255  // optional, set this only if the touchscreen is connected on the same SPI bus


//
// SECOND SCREEN IS WIRED TO SPI1 
//
#define PIN_SCK1        27  // mandatory 
#define PIN_MISO1        1  // mandatory  (if the display has no MISO line, set this to 255 but then VSync will be disabled)
#define PIN_MOSI1       26  // mandatory
#define PIN_DC1          0  // mandatory, can be any pin but using pin 0 (or 38 on T4.1) provides greater performance

#define PIN_CS1         30  // optional (but recommended), can be any pin.  
#define PIN_RESET1      29  // optional (but recommended), can be any pin.  
#define PIN_BACKLIGHT1 255  // optional, set this only if the screen LED pin is connected directly to the Teensy. 
#define PIN_TOUCH_IRQ1 255  // optional. set this only if the touchscreen is connected on the same SPI bus
#define PIN_TOUCH_CS1  255  // optional. set this only if the touchscreen is connected on the same SPI bus


#define SPI_SPEED 70000000


// screen size in portrait mode
#define LX 320
#define LY 240

// screen driver objects
ILI9341_T4::ILI9341Driver tft0(PIN_CS0, PIN_DC0, PIN_SCK0, PIN_MOSI0, PIN_MISO0, PIN_RESET0, PIN_TOUCH_CS0, PIN_TOUCH_IRQ0); // for screen on SPI0
ILI9341_T4::ILI9341Driver tft1(PIN_CS1, PIN_DC1, PIN_SCK1, PIN_MOSI1, PIN_MISO1, PIN_RESET1, PIN_TOUCH_CS1, PIN_TOUCH_IRQ1); // for screen on SPI1

// framebuffers
DMAMEM uint16_t internal_fb0[LX * LY]; // internal fb used by the library for the first screen
DMAMEM uint16_t internal_fb1[LX * LY]; // internal fb used by the library for the second screen
uint16_t fb[LX * LY];                  // main framebuffer we draw onto


// 4 diff buffers with about 6K memory each
ILI9341_T4::DiffBuffStatic<6000> diff1; // for the driver on SPI0
ILI9341_T4::DiffBuffStatic<6000> diff2; //

ILI9341_T4::DiffBuffStatic<6000> diff3; // for the driver on SPI1
ILI9341_T4::DiffBuffStatic<6000> diff4; //


/// <summary>
/// fill a framebuffer with a given color
/// </summary>
/// <param name="fb"></param>
/// <param name="color"></param>
void clear(uint16_t* fb, uint16_t color = 0) 
    {
    for (int i = 0; i < 240 * 320; i++) fb[i] = color;
    }

/// <summary>
/// draw a disk centered at (x,y) with radius r and color col
/// </summary>
/// <param name="fb"></param>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="r"></param>
/// <param name="col"></param>
void drawDisk(uint16_t* fb, double x, double y, double r, uint16_t col) {
    int xmin = (int)(x - r);
    int xmax = (int)(x + r);
    int ymin = (int)(y - r);
    int ymax = (int)(y + r);
    if (xmin < 0) xmin = 0;
    if (xmax >= LX) xmax = LX - 1;
    if (ymin < 0) ymin = 0;
    if (ymax >= LY) ymax = LY - 1;
    const double r2 = r * r;
    for (int j = ymin; j <= ymax; j++) {
        double dy2 = (y - j) * (y - j);
        for (int i = xmin; i <= xmax; i++) {
            const double dx2 = (x - i) * (x - i);
            if (dx2 + dy2 <= r2) fb[i + (j * LX)] = col;
        }
    }
}

/// <summary>
/// draw a pixel
/// </summary>
/// <param name="fb"></param>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="color"></param>
void drawPixel(uint16_t* fb, int x, int y, uint16_t color) {
    if ((x < 0) || (y < 0) || (x >= LX) || (y >= LY)) return;
    fb[x + LX * y] = color;
}

/// <summary>
/// draw a line
/// </summary>
/// <param name="fb"></param>
/// <param name="x0"></param>
/// <param name="y0"></param>
/// <param name="x1"></param>
/// <param name="y1"></param>
/// <param name="color"></param>
void drawLine(uint16_t* fb, int x0, int y0, int x1, int y1, uint16_t color) {
    bool yLonger = false;
    int shortLen = y1 - y0;
    int longLen = x1 - x0;
    if (abs(shortLen) > abs(longLen)) {
        int swap = shortLen;
        shortLen = longLen;
        longLen = swap;
        yLonger = true;
    }
    int decInc;
    if (longLen == 0) decInc = 0;
    else decInc = (shortLen << 16) / longLen;

    if (yLonger) {
        if (longLen > 0) {
            longLen += y0;
            for (int j = 0x8000 + (x0 << 16); y0 <= longLen; ++y0) {
                drawPixel(fb, j >> 16, y0, color);
                j += decInc;
            }
            return;
        }
        longLen += y0;
        for (int j = 0x8000 + (x0 << 16); y0 >= longLen; --y0) {
            drawPixel(fb, j >> 16, y0, color);
            j -= decInc;
        }
        return;
    }

    if (longLen > 0) {
        longLen += x0;
        for (int j = 0x8000 + (y0 << 16); x0 <= longLen; ++x0) {
            drawPixel(fb, x0, j >> 16, color);
            j += decInc;
        }
        return;
    }
    longLen += x0;
    for (int j = 0x8000 + (y0 << 16); x0 >= longLen; --x0) {
        drawPixel(fb, x0, j >> 16, color);
        j -= decInc;
    }
}

/// <summary>
/// return a uniform in [0,1)
/// </summary>
/// <returns></returns>
double unif() {
    return random(2147483647) / 2147483647.0;
}

/// <summary>
/// a bouncing ball
/// </summary>
struct Ball {
    double x, y, dirx, diry, r; // position, direction, radius. 
    uint16_t color;

    Ball() {
        r = unif() * 25; // random radius
        x = r; // start at the corner
        y = r; //
        dirx = unif() * 5; // direction and speed are random...
        diry = unif() * 5; // ...but not isotropic !
        color = random(65536); // random color
    }

    void move() {
        // move
        x += dirx;
        y += diry;
        // and bounce against border
        if (x - r < 0) { x = r;  dirx = -dirx; }
        if (y - r < 0) { y = r;  diry = -diry; }
        if (x > LX - r) { x = LX - r;  dirx = -dirx; }
        if (y > LY - r) { y = LY - r;  diry = -diry; }
    }

    void draw(uint16_t* fb) {
        drawDisk(fb, x, y, r, color);
    }
};

// vars
Ball balls[99];
int nFrames = 120;

/// <summary>
/// setup
/// </summary>
void setup() {
        
        
    Serial.begin(9600);

    // use USB serial for debug information / troubleshooting.  
    tft0.output(&Serial);
    tft1.output(&Serial);
    
    // init the screens
    while (!tft0.begin(SPI_SPEED)) 
        {
        Serial.print("\n\n\n ****** ERROR CONNECTING TO ILI9341 SCREEN ON SPI 0 ****** \n\n");
        delay(1000);
        }
    while (!tft1.begin(SPI_SPEED))
        {
        Serial.print("\n\n\n ****** ERROR CONNECTING TO ILI9341 SCREEN ON SPI 1 ****** \n\n");
        delay(1000);
        }

    // set parameters for the first display
    tft0.setRotation(3);                 // portrait mode 240 x320
    tft0.setFramebuffer(internal_fb0);   // set the internal framebuffer (enables double buffering)
    tft0.setDiffBuffers(&diff1, &diff2); // set the 2 diff buffers => activate differential updates. 
    tft0.setDiffGap(4);                  // use a small gap for the diff buffers
    tft0.setRefreshRate(150);            // max refresh rate. 
    tft0.setVSyncSpacing(2);             // set framerate = refreshrate/2 (and enable vsync at the same time). 

    // set parameters for the second display
    tft1.setRotation(3);                 // portrait mode 240 x320
    tft1.setFramebuffer(internal_fb1);   // set the internal framebuffer (enables double buffering)
    tft1.setDiffBuffers(&diff3, &diff4); // set the 2 diff buffers => activate differential updates. 
    tft1.setDiffGap(4);                  // use a small gap for the diff buffers
    tft1.setRefreshRate(150);            // max refresh rate. 
    tft1.setVSyncSpacing(2);             // set framerate = refreshrate/2 (and enable vsync at the same time). 

     // make sure backlight is on
    if (PIN_BACKLIGHT0 != 255) {
        pinMode(PIN_BACKLIGHT0, OUTPUT);
        digitalWrite(PIN_BACKLIGHT0, HIGH);
    }
    if (PIN_BACKLIGHT1 != 255) {
        pinMode(PIN_BACKLIGHT1, OUTPUT);
        digitalWrite(PIN_BACKLIGHT1, HIGH);
    }
}

/// <summary>
/// main loop
/// </summary>

elapsedMillis em = 0; 
void loop() 
    {
    for (int frame = 0; frame < nFrames; frame++) draw(frame);
    for (int frame = (nFrames); frame >= 0; frame--) draw(frame);
    
    // output some info about the drivers every 5 seconds.
    if (em > 5000)
        { 
        em = 0;  // reset counter        
        Serial.println("\n\n\n ******* INFO ABOUT THE FIRST SCREEN (ON SPI0) ******* \n");
        tft0.printStats();
        diff1.printStats();
        diff2.printStats();        
        Serial.println("\n\n\n ******* INFO ABOUT THE FIRST SCREEN (ON SPI1) ******* \n");
        tft1.printStats();
        diff3.printStats();
        diff4.printStats();        
        }
    }

/// <summary>
/// draw on both displays
/// </summary>
/// <param name="frame"></param>
void draw(int frame) {
    
    // draw on display 0
    clear(fb, 0); // clear the framebuffer 
    // draw the balls
    for (auto& b : balls) 
        {
        b.move();
        b.draw(fb);
        }
        
    tft0.overlayFPS(fb); // draw the FPS counter on the top right corner of the framebuffer
    tft0.update(fb, false); // update screen 1 on SPI0 async. via DMA. 

    // NOTE: here the update on screen 1 is still in progress but we can
    // reuse fb because all changes have been saved in the internal framebuffer. 

    // draw on display 1
    clear(fb, 0); // clear the framebuffer 
    
    // draw the balls
    for (auto& b : balls) 
        {
        b.move();
        b.draw(fb);
        }
        
    tft1.overlayFPS(fb); // draw the FPS counter on the top right corner of the framebuffer
    tft1.update(fb, false); // update screen 1 on SPI0 async. via DMA. 

    // NOTE: here the update on screen 2 is still in progress but we can
    // reuse fb because all changes have been saved in the internal framebuffer. 
    // ... so we can directly start the next iteration without waiting ! 
}

/** end of file */

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment