Skip to content

Commit 912a873

Browse files
committed
Adding an external "drawColon" method, fixing broken P
1 parent b5db7d1 commit 912a873

File tree

4 files changed

+89
-80
lines changed

4 files changed

+89
-80
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ An Arduino library for drawing letters and numbers using a falling block style a
66

77
Tested using ESP8266 & ESP32 on RGB Led matrixes (using the [PxMatrix library](https://github.com/2dom/PxMatrix/)), but potentially works on any display that uses Adafruit GFX library
88

9+
PLEASE NOTE: There are some issues with ESP8266 sketches that make use of WiFi as well, there is an issue open for this: https://github.com/toblum/TetrisAnimation/issues/3
10+
911
## Installation & Setup
1012

1113
Search for "Tetris Animation" on the Arduino library manager

src/TetrisLetters.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -848,8 +848,8 @@ fall_instr_let a90[9] = {
848848
};
849849

850850
// holds the number of blocks in each character
851-
// ! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
852-
int blocksPerChar[64] = {5,4,9,8,7,8,2,4,4,6,5,2,3,1,5,10,8,9,9,8,10,10,6,8,7,2,3,5,4,5,6,8,9,9,8,9,9,7,8,9,8,7,9,6,9,9,9,9,9,9,9,6,9,10,8,7,7,9};
851+
// ! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
852+
int blocksPerChar[64] = {5,4,9,8,7,8,2,4,4,6,5,2,3,1,5,10,8,9,9,8,10,10,6,8,7,2,3,5,4,5,6,8,9,9,8,9,9,7,8,9,8,7,9,6,9,9,9,8,9,9,9,6,9,10,8,7,7,9};
853853

854854
fall_instr_let getFallinstrByAscii(int num, int blockindex)
855855
{

src/TetrisMatrixDraw.cpp

Lines changed: 84 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -518,95 +518,99 @@ bool TetrisMatrixDraw::drawText(int x, int yFinish)
518518
for (int numpos = 0; numpos < this->sizeOfValue; numpos++)
519519
{
520520

521-
// Draw falling shape
522-
//if (numstates[numpos].blockindex < blocksPerNumber[numstates[numpos].num_to_draw])
523-
if (numstates[numpos].blockindex < blocksPerChar[numstates[numpos].num_to_draw-33])
521+
if(numstates[numpos].num_to_draw >= 33)
524522
{
525-
finishedAnimating = false;
526-
fall_instr_let current_fall = getFallinstrByAscii(numstates[numpos].num_to_draw, numstates[numpos].blockindex);
527-
528-
// Handle variations of rotations
529-
uint8_t rotations = current_fall.num_rot;
530-
if (rotations == 1)
531-
{
532-
if (numstates[numpos].fallindex < (int)(current_fall.y_stop / 2))
533-
{
534-
rotations = 0;
535-
}
536-
}
537-
if (rotations == 2)
523+
// Draw falling shape
524+
//if (numstates[numpos].blockindex < blocksPerNumber[numstates[numpos].num_to_draw])
525+
if (numstates[numpos].blockindex < blocksPerChar[numstates[numpos].num_to_draw-33])
538526
{
539-
if (numstates[numpos].fallindex < (int)(current_fall.y_stop / 3))
527+
finishedAnimating = false;
528+
fall_instr_let current_fall = getFallinstrByAscii(numstates[numpos].num_to_draw, numstates[numpos].blockindex);
529+
530+
// Handle variations of rotations
531+
uint8_t rotations = current_fall.num_rot;
532+
if (rotations == 1)
540533
{
541-
rotations = 0;
534+
if (numstates[numpos].fallindex < (int)(current_fall.y_stop / 2))
535+
{
536+
rotations = 0;
537+
}
542538
}
543-
if (numstates[numpos].fallindex < (int)(current_fall.y_stop / 3 * 2))
539+
if (rotations == 2)
544540
{
545-
rotations = 1;
541+
if (numstates[numpos].fallindex < (int)(current_fall.y_stop / 3))
542+
{
543+
rotations = 0;
544+
}
545+
if (numstates[numpos].fallindex < (int)(current_fall.y_stop / 3 * 2))
546+
{
547+
rotations = 1;
548+
}
546549
}
547-
}
548-
if (rotations == 3)
549-
{
550-
if (numstates[numpos].fallindex < (int)(current_fall.y_stop / 4))
550+
if (rotations == 3)
551551
{
552-
rotations = 0;
552+
if (numstates[numpos].fallindex < (int)(current_fall.y_stop / 4))
553+
{
554+
rotations = 0;
555+
}
556+
if (numstates[numpos].fallindex < (int)(current_fall.y_stop / 4 * 2))
557+
{
558+
rotations = 1;
559+
}
560+
if (numstates[numpos].fallindex < (int)(current_fall.y_stop / 4 * 3))
561+
{
562+
rotations = 2;
563+
}
553564
}
554-
if (numstates[numpos].fallindex < (int)(current_fall.y_stop / 4 * 2))
555-
{
556-
rotations = 1;
565+
if(this->scale <= 1){
566+
drawShape(current_fall.blocktype,
567+
this->tetrisColors[current_fall.color],
568+
x + current_fall.x_pos + numstates[numpos].x_shift,
569+
y + numstates[numpos].fallindex - scaledYOffset,
570+
rotations);
571+
} else {
572+
drawLargerShape(this->scale,
573+
current_fall.blocktype,
574+
this->tetrisColors[current_fall.color],
575+
x + (current_fall.x_pos * this->scale) + numstates[numpos].x_shift,
576+
y + (numstates[numpos].fallindex * scaledYOffset) - scaledYOffset,
577+
rotations);
557578
}
558-
if (numstates[numpos].fallindex < (int)(current_fall.y_stop / 4 * 3))
579+
//drawShape(current_fall.blocktype, this->tetrisColors[current_fall.color], x + current_fall.x_pos + numstates[numpos].x_shift, y + numstates[numpos].fallindex - 1, rotations);
580+
numstates[numpos].fallindex++;
581+
582+
if (numstates[numpos].fallindex > current_fall.y_stop)
559583
{
560-
rotations = 2;
584+
numstates[numpos].fallindex = 0;
585+
numstates[numpos].blockindex++;
561586
}
562587
}
563-
if(this->scale <= 1){
564-
drawShape(current_fall.blocktype,
565-
this->tetrisColors[current_fall.color],
566-
x + current_fall.x_pos + numstates[numpos].x_shift,
567-
y + numstates[numpos].fallindex - scaledYOffset,
568-
rotations);
569-
} else {
570-
drawLargerShape(this->scale,
571-
current_fall.blocktype,
572-
this->tetrisColors[current_fall.color],
573-
x + (current_fall.x_pos * this->scale) + numstates[numpos].x_shift,
574-
y + (numstates[numpos].fallindex * scaledYOffset) - scaledYOffset,
575-
rotations);
576-
}
577-
//drawShape(current_fall.blocktype, this->tetrisColors[current_fall.color], x + current_fall.x_pos + numstates[numpos].x_shift, y + numstates[numpos].fallindex - 1, rotations);
578-
numstates[numpos].fallindex++;
579588

580-
if (numstates[numpos].fallindex > current_fall.y_stop)
581-
{
582-
numstates[numpos].fallindex = 0;
583-
numstates[numpos].blockindex++;
584-
}
585-
}
586-
587-
// Draw already dropped shapes
588-
if (numstates[numpos].blockindex > 0)
589-
{
590-
for (int i = 0; i < numstates[numpos].blockindex; i++)
589+
// Draw already dropped shapes
590+
if (numstates[numpos].blockindex > 0)
591591
{
592-
fall_instr_let fallen_block = getFallinstrByAscii(numstates[numpos].num_to_draw, i);
593-
if(this->scale <= 1){
594-
drawShape(fallen_block.blocktype,
595-
this->tetrisColors[fallen_block.color],
596-
x + fallen_block.x_pos + numstates[numpos].x_shift,
597-
y + fallen_block.y_stop - 1,
598-
fallen_block.num_rot);
599-
} else {
600-
drawLargerShape(this->scale,
601-
fallen_block.blocktype,
602-
this->tetrisColors[fallen_block.color],
603-
x + (fallen_block.x_pos * this->scale) + numstates[numpos].x_shift,
604-
y + (fallen_block.y_stop * scaledYOffset) - scaledYOffset,
605-
fallen_block.num_rot);
592+
for (int i = 0; i < numstates[numpos].blockindex; i++)
593+
{
594+
fall_instr_let fallen_block = getFallinstrByAscii(numstates[numpos].num_to_draw, i);
595+
if(this->scale <= 1){
596+
drawShape(fallen_block.blocktype,
597+
this->tetrisColors[fallen_block.color],
598+
x + fallen_block.x_pos + numstates[numpos].x_shift,
599+
y + fallen_block.y_stop - 1,
600+
fallen_block.num_rot);
601+
} else {
602+
drawLargerShape(this->scale,
603+
fallen_block.blocktype,
604+
this->tetrisColors[fallen_block.color],
605+
x + (fallen_block.x_pos * this->scale) + numstates[numpos].x_shift,
606+
y + (fallen_block.y_stop * scaledYOffset) - scaledYOffset,
607+
fallen_block.num_rot);
608+
}
609+
//drawShape(fallen_block.blocktype, this->tetrisColors[fallen_block.color], x + fallen_block.x_pos + numstates[numpos].x_shift, y + fallen_block.y_stop - 1, fallen_block.num_rot);
606610
}
607-
//drawShape(fallen_block.blocktype, this->tetrisColors[fallen_block.color], x + fallen_block.x_pos + numstates[numpos].x_shift, y + fallen_block.y_stop - 1, fallen_block.num_rot);
608611
}
609612
}
613+
610614
}
611615

612616
return finishedAnimating;
@@ -714,19 +718,21 @@ bool TetrisMatrixDraw::drawNumbers(int x, int yFinish, bool displayColon)
714718
}
715719
}
716720

717-
// Hour / minutes divider (blinking)
718-
// if (seconds_odd)
719721
if (displayColon)
720722
{
721-
int colonSize = 2 * this->scale;
722-
int xColonPos = x + (TETRIS_DISTANCE_BETWEEN_DIGITS * 2 * this->scale);
723-
display->fillRect(xColonPos, y + (12 * this->scale), colonSize, colonSize, this->tetrisWHITE);
724-
display->fillRect(xColonPos, y + (8 * this->scale), colonSize, colonSize, this->tetrisWHITE);
723+
this->drawColon(x, y, this->tetrisWHITE);
725724
}
726725

727726
return finishedAnimating;
728727
}
729728

729+
void TetrisMatrixDraw::drawColon(int x, int y, uint16_t colonColour){
730+
int colonSize = 2 * this->scale;
731+
int xColonPos = x + (TETRIS_DISTANCE_BETWEEN_DIGITS * 2 * this->scale);
732+
display->fillRect(xColonPos, y + (12 * this->scale), colonSize, colonSize, colonColour);
733+
display->fillRect(xColonPos, y + (8 * this->scale), colonSize, colonSize, colonColour);
734+
}
735+
730736
void TetrisMatrixDraw::intialiseColors(){
731737
this->tetrisRED = 0xF800;
732738
this->tetrisGREEN = 0x07E0;

src/TetrisMatrixDraw.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class TetrisMatrixDraw
5151
void setNumbers(int value, bool forceRefresh = false);
5252
void setText(String txt, bool forceRefresh = false);
5353
void setNumState(int index, int value, int x_shift);
54+
void drawColon(int x, int y, uint16_t colonColour);
5455
int calculateWidth();
5556
bool _debug = false;
5657
int scale = 1;

0 commit comments

Comments
 (0)