From e230cf96fbdd983ade785ba42688aea5e7099973 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Mon, 3 Sep 2018 15:14:39 +0200 Subject: [PATCH] Improve texturing --- game.cpp | 316 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 199 insertions(+), 117 deletions(-) diff --git a/game.cpp b/game.cpp index efc58e5..e43ebc6 100644 --- a/game.cpp +++ b/game.cpp @@ -12,7 +12,6 @@ #include #include "raycastlib.h" #include "Pokitto.h" -#include #define SUBSAMPLE 2 @@ -94,6 +93,162 @@ const unsigned char image[] = ,0x09,0x09 }; +const unsigned char image2[] = +{ 32, 32 // width, height + ,0xff,0xbf,0xff,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xff + ,0xff,0xbf,0xbf,0xff,0xff,0xff,0xff,0xbf,0xff,0xff,0xff,0xff,0xff,0xff + ,0xff,0xff,0xff,0xbf,0xff,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf + ,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf + ,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0x25,0xbf,0xbf,0xbf,0x77,0x76,0x77 + ,0x76,0x77,0x77,0x77,0x77,0x77,0x77,0xbf,0xbf,0x77,0x77,0xbf,0xbf,0xbf + ,0x77,0x77,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0x77,0xbf,0x1c,0xbf,0xbf + ,0x76,0x76,0x76,0x76,0x76,0x76,0x76,0x76,0x77,0x76,0x76,0xbf,0xbf,0x77 + ,0x76,0x77,0x77,0xb7,0x77,0x77,0xbf,0xbf,0xbf,0xbf,0xbf,0xbf,0x77,0x77 + ,0xbf,0x24,0xbf,0xbf,0x77,0x76,0x76,0x76,0x76,0x76,0x76,0x77,0x77,0xb7 + ,0x77,0xbf,0xbf,0x77,0x76,0x77,0x77,0x77,0x77,0x77,0xbf,0xbf,0xbf,0xbf + ,0xbf,0xbf,0xbf,0xbf,0xbf,0x1c,0xbf,0xbf,0x76,0x76,0x25,0x24,0x1c,0x1c + ,0x24,0x24,0x25,0x25,0x25,0x24,0x24,0x25,0x25,0x24,0x24,0x25,0x25,0x24 + ,0x24,0x25,0x6d,0x6d,0x6e,0xbf,0xbf,0xbf,0xbf,0x1c,0xbf,0x76,0x76,0x76 + ,0x1c,0x1c,0x1c,0x24,0x24,0x25,0x25,0x65,0x25,0x25,0x6d,0x6d,0x6d,0x6d + ,0x65,0x24,0x24,0x24,0x24,0x24,0x65,0x6d,0x76,0xbf,0xbf,0xb7,0xbf,0x1c + ,0xbf,0x77,0x76,0x76,0x1c,0x1c,0x76,0x76,0x77,0x76,0x76,0x76,0x77,0x76 + ,0x76,0x77,0x76,0x76,0x77,0x77,0x76,0x76,0x77,0x77,0xbf,0xbf,0xbf,0xff + ,0x77,0x77,0x77,0x1c,0xbf,0x76,0x76,0x76,0x1c,0x1c,0x76,0x76,0x76,0x76 + ,0x76,0x76,0x76,0x76,0x76,0x77,0x76,0x76,0x77,0x77,0x76,0x76,0x77,0xb7 + ,0xbf,0xbf,0xff,0xbf,0x76,0x76,0x76,0x1c,0xbf,0x76,0x6e,0x6e,0x1c,0x1c + ,0x6e,0x76,0x76,0x76,0x76,0x6e,0x6e,0x76,0x76,0x76,0x76,0x76,0x76,0x76 + ,0x76,0x76,0x77,0x77,0x77,0xbf,0xff,0xbf,0x76,0x76,0x77,0x1c,0xbf,0x76 + ,0x76,0x76,0x1c,0x1c,0x76,0x76,0x76,0x76,0x76,0x76,0x76,0x76,0x76,0x76 + ,0x76,0x76,0x76,0x76,0x76,0x76,0x76,0x76,0x76,0x77,0xbf,0xbf,0x76,0x77 + ,0x77,0x1c,0xbf,0x76,0x6e,0x76,0x1c,0x1c,0x6e,0x6e,0x76,0x76,0x76,0x76 + ,0x76,0x76,0x76,0x76,0x76,0x76,0x76,0x76,0x76,0x76,0x76,0x77,0x77,0x76 + ,0xbf,0xbf,0x76,0x77,0x77,0x1c,0xb7,0x6e,0x6e,0x6e,0x1c,0x1c,0x6e,0x6e + ,0x6e,0x76,0x76,0x76,0x6e,0x76,0x76,0x76,0x76,0x76,0x76,0x6e,0x6e,0x76 + ,0x76,0x76,0x76,0x76,0xbf,0xbf,0x76,0x77,0x76,0x1c,0x77,0x6e,0x6e,0x6e + ,0x1c,0x1c,0x6e,0x6e,0x6e,0x76,0x76,0x76,0x76,0x76,0x6e,0x6e,0x76,0x76 + ,0x76,0x6e,0x6e,0x76,0x76,0x76,0x76,0x76,0xbf,0xbf,0x76,0x76,0x76,0x1c + ,0xbf,0x76,0x6e,0x76,0x24,0x24,0x6e,0x76,0x76,0x76,0x76,0x76,0x6e,0x6e + ,0x6e,0x6e,0x6e,0x6d,0x6e,0x76,0x76,0x76,0x76,0x76,0x76,0x76,0xbf,0xbf + ,0x76,0x76,0x76,0x1c,0x77,0x76,0x76,0x76,0x25,0x25,0x76,0x76,0x76,0x76 + ,0x76,0x6e,0x6e,0x6e,0x6d,0x6e,0x6d,0x6d,0x6d,0x6e,0x6e,0x76,0x6e,0x6e + ,0x76,0x6e,0xbf,0xbf,0x76,0x76,0x6e,0x1c,0x76,0x76,0x76,0x76,0x25,0x65 + ,0x76,0x77,0x77,0x76,0x76,0x6e,0x6e,0x6e,0x6e,0x6e,0x6d,0x6d,0x6e,0x6e + ,0x6e,0x76,0x6e,0x76,0x76,0x76,0xbf,0xbf,0x6e,0x6e,0x6e,0x1c,0x76,0x6e + ,0x6e,0x6e,0x24,0x25,0x76,0x77,0x77,0x76,0x76,0x76,0x6e,0x6e,0x6e,0x6e + ,0x6e,0x6e,0x6e,0x76,0x76,0x76,0x76,0x6e,0x6e,0x6e,0xbf,0xbf,0x76,0x6e + ,0x76,0x1c,0x6e,0x6d,0x6d,0x6d,0x1c,0x24,0x76,0x76,0x76,0x76,0x76,0x76 + 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,0x24,0x24,0x24,0x24,0x24,0x1c,0x1c,0x1c,0x24,0x1c + ,0x1c,0x1c +}; + +const unsigned char image3[] = +{ 32, 32 // width, height + ,0x65,0x1d,0x1c,0x25,0x1d,0x1b,0x0a,0x0a,0x14,0x25,0x1d,0x0a,0x14,0x12 + ,0x09,0x14,0x66,0x6f,0x1b,0x13,0x1c,0x66,0x77,0x6e,0x6e,0x1d,0x25,0x66 + ,0x25,0x0a,0x1e,0x25,0x1d,0x14,0x1d,0x14,0x65,0x0a,0x14,0x15,0x14,0x02 + ,0x1c,0x0a,0x6f,0x6f,0x66,0x6f,0x6f,0x6f,0x25,0x0a,0x6e,0x77,0x7f,0x67 + ,0x67,0x66,0x66,0x6e,0x25,0x25,0x13,0x0a,0x01,0x13,0x1c,0x13,0x14,0x01 + ,0x0b,0x1d,0x5d,0x1d,0x66,0x66,0x6f,0x6f,0x6f,0x77,0x6f,0x6e,0x1d,0x01 + ,0x77,0x6f,0x67,0x6f,0x26,0x66,0x1c,0x25,0x5e,0x1d,0x1d,0x1c,0x1c,0x6e + ,0x77,0x6e,0x2e,0x1d,0x14,0x0a,0x14,0x25,0x66,0x67,0x77,0x67,0x6e,0x77 + ,0x25,0x6e,0x1c,0x1c,0x6e,0x77,0x77,0x7f,0x67,0x66,0x6e,0x6e,0x1d,0x66 + ,0x14,0x1d,0x12,0x6e,0x67,0x6f,0x26,0x65,0x6e,0x01,0x14,0x1d,0x65,0x66 + ,0x6f,0x77,0x2f,0x2e,0x1c,0x25,0x1d,0x13,0x77,0x6f,0x77,0x6f,0x6f,0x6f + ,0x66,0x1d,0x6e,0x14,0x65,0x1c,0x0a,0x66,0x6f,0x6f,0x77,0x1e,0x65,0x5d + ,0x0a,0x09,0x6e,0x25,0x67,0x1d,0x6e,0x25,0x5d,0x0a,0x14,0x0a,0x6f,0x77 + ,0x77,0x77,0x77,0x6e,0x26,0x1d,0x25,0x25,0x66,0x25,0x01,0x6f,0x6f,0x77 + ,0x6d,0x6f,0x1d,0x6e,0x1d,0x13,0x1c,0x13,0x6e,0x77,0x26,0x1c,0x65,0x13 + ,0x01,0x6e,0x25,0x26,0x6f,0x6f,0x67,0x6f,0x66,0x6e,0x1c,0x66,0x66,0x1d + ,0x13,0x77,0x77,0x6f,0x67,0x6e,0x66,0x5c,0x5d,0x1c,0x09,0x1c,0x13,0x13 + ,0x1c,0x0a,0x01,0x12,0x25,0x09,0x0a,0x6f,0x6e,0x6e,0x6f,0x6f,0x66,0x25 + ,0x25,0x6e,0x25,0x1c,0x14,0x77,0x67,0x77,0x6f,0x67,0x1d,0x25,0x1c,0x1d + ,0x1c,0x24,0x0a,0x66,0x6f,0x65,0x66,0x6e,0x25,0x1d,0x1c,0x0b,0x5d,0x66 + ,0x1d,0x5d,0x25,0x13,0x66,0x1d,0x1d,0x14,0x6e,0x6f,0x77,0x77,0x25,0x66 + ,0x66,0x1d,0x6e,0x66,0x1d,0x14,0x09,0x77,0x66,0x6f,0x1e,0x6f,0x66,0x65 + ,0x1d,0x25,0x13,0x0a,0x6e,0x1d,0x1c,0x1d,0x1d,0x25,0x14,0x01,0x2e,0x66 + ,0x77,0x77,0x6f,0x66,0x1d,0x1e,0x1d,0x1d,0x14,0x25,0x13,0x6f,0x6f,0x6f + ,0x6f,0x66,0x6e,0x25,0x1d,0x1c,0x14,0x01,0x14,0x0a,0x0a,0x14,0x09,0x09 + ,0x0a,0x1b,0x0b,0x66,0x66,0x1d,0x5e,0x65,0x66,0x26,0x65,0x1c,0x1c,0x1c + ,0x12,0x6f,0x7f,0x6f,0x6f,0x6f,0x6f,0x66,0x66,0x25,0x1d,0x13,0x0a,0x25 + ,0x66,0x5e,0x1d,0x1c,0x14,0x0a,0x1c,0x13,0x13,0x1d,0x5d,0x14,0x14,0x1d + ,0x5d,0x0b,0x0b,0x0b,0x1d,0x6f,0x6f,0x7f,0x6f,0x66,0x1d,0x66,0x1d,0x25 + ,0x1c,0x1d,0x01,0x26,0x6f,0x77,0x77,0x66,0x15,0x1d,0x1d,0x25,0x0a,0x01 + ,0x0b,0x1c,0x25,0x1b,0x1d,0x14,0x01,0x1d,0x66,0x77,0x7f,0x6f,0x77,0x65 + ,0x6f,0x6e,0x6e,0x25,0x1d,0x14,0x13,0x6f,0x7f,0x27,0x6f,0x77,0x65,0x65 + ,0x2e,0x0a,0x14,0x25,0x5d,0x25,0x14,0x14,0x0a,0x0b,0x1d,0x6e,0x6f,0x6f + ,0x6f,0x77,0x6f,0x66,0x66,0x65,0x15,0x66,0x1d,0x65,0x01,0x6f,0x6f,0x7f + ,0x66,0x6f,0x7f,0x6f,0x1d,0x01,0x77,0x67,0x6f,0x65,0x6e,0x25,0x01,0x65 + ,0x6e,0x77,0x66,0x66,0x6f,0x77,0x6f,0x6f,0x1d,0x25,0x26,0x1d,0x14,0x14 + ,0x25,0x6f,0x6f,0x77,0x6f,0x66,0x77,0x1d,0x13,0x6e,0x66,0x7f,0x6f,0x6e + ,0x66,0x25,0x14,0x2d,0x77,0x7f,0x5e,0x77,0x6e,0x66,0x6e,0x66,0x1d,0x65 + ,0x25,0x1b,0x1d,0x02,0x66,0x7f,0x6f,0x7f,0x66,0x7f,0x66,0x66,0x0b,0x66 + ,0x6f,0x6f,0x26,0x66,0x25,0x1d,0x1c,0x09,0x66,0x77,0x6e,0x77,0x6e,0x6f + ,0x6f,0x25,0x1d,0x6e,0x5e,0x25,0x0a,0x01,0x77,0x6f,0x66,0x67,0x66,0x77 + ,0x25,0x65,0x13,0x01,0x77,0x6f,0x1d,0x66,0x66,0x14,0x25,0x0a,0x1c,0x5e + ,0x66,0x6f,0x66,0x6e,0x66,0x66,0x6e,0x1d,0x25,0x0a,0x09,0x1d,0x66,0x6f + ,0x6f,0x66,0x66,0x1d,0x1d,0x6e,0x65,0x12,0x66,0x66,0x77,0x6e,0x5d,0x1d + ,0x0a,0x09,0x1c,0x1c,0x25,0x6e,0x6f,0x6e,0x1d,0x25,0x1d,0x65,0x13,0x1d + ,0x1c,0x1c,0x65,0x6f,0x77,0x67,0x6e,0x6e,0x1d,0x66,0x1d,0x02,0x1b,0x66 + ,0x66,0x66,0x66,0x14,0x01,0x14,0x6e,0x65,0x14,0x13,0x13,0x25,0x1d,0x0a + ,0x0b,0x13,0x1d,0x6e,0x66,0x13,0x1c,0x77,0x6e,0x1d,0x65,0x1c,0x1d,0x1d + ,0x1d,0x01,0x13,0x14,0x1c,0x1c,0x25,0x13,0x12,0x66,0x6f,0x6f,0x25,0x25 + ,0x13,0x14,0x0a,0x01,0x6e,0x65,0x77,0x67,0x77,0x66,0x0b,0x0a,0x66,0x1d + ,0x66,0x1d,0x6e,0x14,0x13,0x1b,0x66,0x66,0x13,0x02,0x0a,0x01,0x1c,0x6f + ,0x6f,0x7f,0x26,0x26,0x1d,0x01,0x66,0x6e,0x6f,0x6f,0x77,0x67,0x66,0x2e + ,0x66,0x09,0x0a,0x13,0x65,0x1d,0x1c,0x0a,0x66,0x6e,0x77,0x6f,0x6f,0x1d + ,0x6e,0x25,0x0b,0x66,0x77,0x6e,0x25,0x25,0x66,0x0a,0x6f,0x77,0x77,0x77 + ,0x66,0x6f,0x67,0x66,0x25,0x1d,0x1b,0x09,0x1c,0x0a,0x14,0x0a,0x6f,0x77 + ,0x6f,0x7f,0x6f,0x77,0x6f,0x6e,0x01,0x66,0x7f,0x6f,0x6f,0x66,0x1d,0x09 + ,0x66,0x77,0x7f,0x67,0x66,0x66,0x6e,0x77,0x66,0x6f,0x26,0x76,0x1d,0x25 + ,0x13,0x1b,0x6e,0x77,0x77,0x6f,0x6f,0x6e,0x6f,0x25,0x1c,0x1c,0x77,0x77 + ,0x1d,0x65,0x25,0x0a,0x2e,0x6f,0x6f,0x7f,0x6e,0x1d,0x1c,0x6e,0x66,0x6e + ,0x1d,0x66,0x1d,0x66,0x65,0x12,0x65,0x77,0x6f,0x77,0x66,0x77,0x6e,0x25 + ,0x14,0x0a,0x5e,0x6f,0x77,0x66,0x66,0x0b,0x6e,0x6f,0x77,0x6f,0x6f,0x65 + ,0x65,0x1e,0x25,0x15,0x5e,0x24,0x65,0x1d,0x1d,0x1c,0x6f,0x77,0x6f,0x6f + ,0x67,0x66,0x1d,0x25,0x25,0x01,0x6e,0x67,0x6f,0x66,0x65,0x14,0x6e,0x6e + ,0x77,0x77,0x77,0x6e,0x66,0x25,0x6e,0x25,0x1d,0x1c,0x14,0x25,0x1c,0x0a + ,0x77,0x77,0x6f,0x1d,0x66,0x25,0x13,0x1d,0x0b,0x0b,0x6f,0x6f,0x66,0x6e + ,0x6e,0x1d,0x14,0x6e,0x66,0x6f,0x7f,0x67,0x66,0x25,0x66,0x1c,0x65,0x1b + ,0x1c,0x13,0x0a,0x14,0x7f,0x6f,0x26,0x25,0x65,0x13,0x65,0x1c,0x1b,0x14 + ,0x67,0x6f,0x6e,0x66,0x1d,0x0a,0x13,0x14,0x66,0x6e,0x6e,0x6f,0x6d,0x6e + ,0x1d,0x1d,0x13,0x13,0x25,0x0a,0x0a,0x6e,0x6f,0x6f,0x6e,0x1d,0x6e,0x5c + ,0x5c,0x01,0x25,0x66,0x6f,0x66,0x66,0x6e,0x1d,0x14,0x12,0x1d,0x13,0x14 + ,0x12,0x6e,0x1c,0x0a,0x14,0x1d,0x0a,0x13,0x0a,0x1d,0x65,0x66,0x6f,0x6e + ,0x1d,0x66,0x1c,0x1d,0x01,0x0a,0x14,0x1c,0x6f,0x25,0x1c,0x14,0x0a,0x13 + ,0x14,0x6e,0x5d,0x1c,0x13,0x13,0x09,0x13,0x0a,0x13,0x1d,0x1d,0x0a,0x14 + ,0x1d,0x25 +}; + uint8_t sampleImage(const unsigned char *image, Unit x, Unit y) { int32_t index = clamp( @@ -110,20 +265,30 @@ inline uint8_t rgbToIndex(uint8_t r, uint8_t g, uint8_t b) return (r & 0b00000111) | ((g & 0b00000111) << 3) | ((b & 0b00000011) << 6); } -inline uint8_t darkenColor(uint8_t color, uint8_t intensity) +inline uint8_t addIntensity(uint8_t color, int intensity) { uint8_t r = color & 0b00000111; uint8_t g = (color & 0b00111000) >> 3; uint8_t b = (color & 0b11000000) >> 6; - r += intensity; - r = r > 7 ? 7 : r; + if (intensity >= 0) + { + r += intensity; + r = r > 7 ? 7 : r; - g += intensity; - g = g > 7 ? 7 : g; + g += intensity; + g = g > 7 ? 7 : g; - b += intensity / 2; - b = b > 3 ? 3 : b; + b += intensity / 2; + b = b > 3 ? 3 : b; + } + else + { + intensity *= -1; + r = (intensity > r) ? 0 : r - intensity; + g = (intensity > g) ? 0 : g - intensity; + b = (intensity / 2) > b ? 0 : b - (intensity / 2); + } return rgbToIndex(r,g,b); } @@ -152,11 +317,11 @@ public: Character() { - mCamera.position.x = 14337; // UNITS_PER_SQUARE * 4; - mCamera.position.y = 7963; //UNITS_PER_SQUARE * 5; - mCamera.direction = -340; //0; + mCamera.position.x = UNITS_PER_SQUARE * 4; + mCamera.position.y = UNITS_PER_SQUARE * 5; + mCamera.direction = 0; mCamera.fovAngle = UNITS_PER_SQUARE / 4; - mCamera.height = 2756; //UNITS_PER_SQUARE / 2; + mCamera.height = UNITS_PER_SQUARE / 2; mCamera.resolution.x = 110 / SUBSAMPLE; mCamera.resolution.y = 88; } @@ -171,55 +336,33 @@ Unit heightFunc(int16_t x, int16_t y) return level.getHeight(x,y) * UNITS_PER_SQUARE / 4; } -bool dither(uint8_t intensity, uint32_t x, uint32_t y) -{ - switch (intensity) - { - case 0: return false; break; - case 1: return x % 2 == 0 && y % 2 == 0; break; - case 2: return x % 2 == y % 2; break; - case 3: return x % 2 != 0 || y % 2 != 0; break; - default: return true; break; - } -} - inline void pixelFunc(PixelInfo pixel) { + uint8_t c; -uint8_t c; + Unit depth = pixel.depth - UNITS_PER_SQUARE; -#if 0 -c = pixel.isWall ? pixel.hit.direction + 4 : 1; + if (depth < 0) + depth = 0; -for (uint8_t i = 0; i < SUBSAMPLE; ++i) - p.display.drawPixel(pixel.position.x * SUBSAMPLE + i,pixel.position.y,c); - -#else -Unit depth = pixel.depth - UNITS_PER_SQUARE; - -if (depth < 0) - depth = 0; - -int intensity = 7 - (depth * 7) / (UNITS_PER_SQUARE * 5); - -if (intensity < 0) - intensity = 0; - - - -if (pixel.isWall) -{ - if ((pixel.hit.direction == 0 || pixel.hit.direction == 2)) - intensity -= 2; + int intensity = 7 - (depth * 7) / (UNITS_PER_SQUARE * 5); if (intensity < 0) intensity = 0; - c = sampleImage(image,pixel.hit.textureCoord,pixel.textureCoordY); - c = darkenColor(c,intensity); -} -else - c = rgbToIndex(intensity,intensity,intensity / 2); + if (pixel.isWall) + { + if ((pixel.hit.direction == 0 || pixel.hit.direction == 2)) + intensity -= 2; + + if (intensity < 0) + intensity = 0; + + c = sampleImage(image2,pixel.hit.textureCoord,pixel.textureCoordY); + c = addIntensity(c,intensity - 3); + } + else + c = rgbToIndex(intensity/2,intensity,intensity/3); uint8_t *buf = p.display.screenbuffer; @@ -230,94 +373,33 @@ else *buf++ = c; *buf = c; -#endif - } unsigned short pal[256]; void draw() { - -/* -uint8_t a = 0; -for (uint8_t j = 0; j < 88; ++j) -for (uint8_t i = 0; i < 110; ++i) -{ -p.display.drawPixel(i,j,sampleImage(image,i * 10,j * 9)); -++a; -} -return; -*/ - RayConstraints c; c.maxHits = 16; c.maxSteps = 16; render(player.mCamera,heightFunc,pixelFunc,c); - -/* - p.display.setCursor(1,1); - p.display.print(player.mCamera.position.x); - p.display.print(' '); - p.display.print(player.mCamera.position.y); - p.display.print(' '); - p.display.print(player.mCamera.height); - p.display.print(' '); - p.display.print(player.mCamera.direction); -*/ } int main() { p.begin(); -/* - int a,s,r,g,b; - for(a=0; a<=63; a++){ - s = 0; r = a; g = 63-a; b = 0; pal[a+s] = p.display.RGBto565(r*4,g*4,b*4); - s = 64; r = 63-a; g = 0; b = a; pal[a+s] = p.display.RGBto565(r*4,g*4,b*4); - s = 128; r = 0; g = 0; b = 63-a; pal[a+s] = p.display.RGBto565(r*4,g*4,b*4); - s = 192; r = 0; g = a; b = 0; pal[a+s] = p.display.RGBto565(r*4,g*4,b*4); - } -*/ + for (uint8_t r = 0; r < 8; ++r) + for (uint8_t g = 0; g < 8; ++g) + for (uint8_t b = 0; b < 4; ++b) + pal[rgbToIndex(r,g,b)] = p.display.RGBto565(36 * r, 36 * g, 85 * b); -for (uint8_t r = 0; r < 8; ++r) -for (uint8_t g = 0; g < 8; ++g) -for (uint8_t b = 0; b < 4; ++b) -{ - pal[rgbToIndex(r,g,b)] = p.display.RGBto565(36 * r, 36 * g, 85 * b); -} - -/* -for (int i = 0; i < 16; ++i) -pal[i] = p.display.RGBto565(255-i,255-i,255-i); - -pal[0] = p.display.RGBto565(0,0,0); -pal[1] = p.display.RGBto565(64,0,0); -pal[2] = p.display.RGBto565(128,0,0); -pal[3] = p.display.RGBto565(192,0,0); -pal[4] = p.display.RGBto565(0,64,0); -pal[5] = p.display.RGBto565(0,128,0); -pal[6] = p.display.RGBto565(0,192,0); -pal[7] = p.display.RGBto565(0,0,64); -pal[8] = p.display.RGBto565(0,0,128); -pal[9] = p.display.RGBto565(0,0,192); -pal[10] = p.display.RGBto565(64,64,0); -pal[11] = p.display.RGBto565(128,128,0); -pal[12] = p.display.RGBto565(192,192,0); -pal[13] = p.display.RGBto565(64,64,64); -pal[14] = p.display.RGBto565(128,128,128); -pal[15] = p.display.RGBto565(192,192,192); -*/ p.display.load565Palette(&pal[0]); // load a palette the same way as any other palette in any other screen mode - p.display.persistence = 1; - p.setFrameRate(60); - p.display.setFont(fontTiny); while (p.isRunning())