Created
July 12, 2015 16:40
-
-
Save mithi/b7e839a174784d95a6c7 to your computer and use it in GitHub Desktop.
simple animation with Sparki's LCD
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Sparki.h> | |
class RectangleWaveAnimation{ | |
int hNumRect; | |
int length; | |
int width; | |
int space; | |
int diffHeight; | |
int yCenter; | |
int xCenter; | |
int xStart; | |
int yStart; | |
public: | |
RectangleWaveAnimation(int numRect, int xlength, int xwidth, int xspace, int xdiffheight){ | |
hNumRect = numRect/2; | |
length = xlength; | |
width = xwidth; | |
space = xspace; | |
diffHeight = xdiffheight; | |
yCenter = 32; | |
xCenter = 64; | |
} | |
void test(int thisLength){ | |
yStart = yCenter - thisLength/2; | |
xStart = xCenter - width*hNumRect - space*(hNumRect -1); | |
int xCorner; | |
int diff = width + space; | |
int yCorner = yStart; | |
sparki.clearLCD(); | |
for (int i = 0; i < 2*hNumRect; i++){ | |
xCorner = xStart + i*diff; | |
sparki.drawRectFilled(xCorner, yCorner, width, thisLength); | |
sparki.updateLCD(); | |
} | |
} | |
void movingRect(){ | |
yStart = yCenter - length; | |
xStart = xCenter - width*hNumRect - space*(hNumRect -1); | |
int diff = width + space; | |
int yCorner = yStart; | |
int xCorner = xStart + diff; | |
for (int i = 0; i < 2*hNumRect; i++){ | |
sparki.clearLCD(); | |
xCorner = xStart + i*diff; | |
sparki.drawRectFilled(xCorner, yCorner, width, length); | |
sparki.updateLCD(); | |
delay(100); | |
} | |
} | |
void testAnimation(int x){ | |
int t = 0; | |
while (true){ | |
test(t); | |
delay(100); | |
t++; | |
if (t == x) | |
break; | |
} | |
} | |
}; | |
class CircleAnimation{ | |
int n; | |
int xCenter; | |
int yCenter; | |
int maxR; | |
int xC; | |
int yC; | |
int r; | |
int xStart; | |
int yStart; | |
public: | |
CircleAnimation(int maxRadius){ | |
n = 5; | |
xCenter = 64+5; | |
yCenter = 32; | |
maxR = maxRadius; | |
xStart = xCenter - n*maxR; | |
yStart = yCenter; | |
yC = yStart; | |
} | |
void animateUniform(){ | |
sparki.clearLCD(); | |
for (int i=0; i<maxR; i++){ | |
for (int j=0; j<n; j++){ | |
xC = xStart + j*2*maxR; | |
sparki.drawCircle(xC, yC, i); | |
} | |
sparki.updateLCD(); | |
delay(100); | |
} | |
} | |
void goLarger(){ | |
for (int i=0; i<maxR+n; i++){ | |
sparki.clearLCD(); | |
for (int j=0; j<n; j++){ | |
xC = xStart + j*2*maxR; | |
r = i - j; | |
if(r < 0) | |
r=1; | |
if(r > maxR -2 ) | |
r=maxR - 2; | |
sparki.drawCircleFilled(xC, yC, r); | |
} | |
sparki.updateLCD(); | |
delay(50); | |
} | |
} | |
void goSmaller(){ | |
for (int i=maxR+n; i>0; i--){ //radius of the circle | |
sparki.clearLCD(); | |
for (int j=0; j<n; j++){ //location of the circle | |
xC = xStart + j*2*maxR; | |
r = i - j; | |
if(r < 0) | |
r=1; | |
if(r > maxR-2) | |
r=maxR-2; | |
sparki.drawCircleFilled(xC, yC, r); | |
} | |
sparki.updateLCD(); | |
delay(50); | |
} | |
} | |
void animateNonUniform(){ | |
goLarger(); | |
goSmaller(); | |
} | |
void movingCircle(){ | |
for (int blink = 0; blink < 5; blink++){ | |
delay(200); | |
for (int j=0; j<n; j++){ //number of circles | |
sparki.clearLCD(); | |
xC = xStart + j*2*maxR; | |
sparki.drawCircleFilled(xC, yC, 2); | |
sparki.updateLCD(); | |
delay(200); | |
} | |
} | |
} | |
}; | |
RectangleWaveAnimation test(8, 12, 6, 2, 4); | |
CircleAnimation circles(10); | |
void setup(){ | |
sparki.clearLCD(); | |
} | |
void loop(){ | |
//test.movingRect(); | |
//test.testAnimation(10); | |
//circles.animateUniform(); | |
//circles.animateNonUniform(); | |
circles.movingCircle(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment