Vizic Technologies
/
BouncingBalls
SMARTGPU bouncing balls demo!
main.cpp@0:e8934310aa9d, 2011-09-14 (annotated)
- Committer:
- emmanuelchio
- Date:
- Wed Sep 14 05:30:31 2011 +0000
- Revision:
- 0:e8934310aa9d
Rev 1.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emmanuelchio | 0:e8934310aa9d | 1 | /**************************************************************************************/ |
emmanuelchio | 0:e8934310aa9d | 2 | /*SMARTGPU intelligent embedded graphics processor unit |
emmanuelchio | 0:e8934310aa9d | 3 | those examples are for use the SMARTGPU with the mbed microcontoller, just connect tx,rx,and reset |
emmanuelchio | 0:e8934310aa9d | 4 | Board: |
emmanuelchio | 0:e8934310aa9d | 5 | http://www.vizictechnologies.com/#/desarrollo/4554296549 |
emmanuelchio | 0:e8934310aa9d | 6 | |
emmanuelchio | 0:e8934310aa9d | 7 | www.vizictechnologies.com |
emmanuelchio | 0:e8934310aa9d | 8 | Vizic Technologies copyright 2011 */ |
emmanuelchio | 0:e8934310aa9d | 9 | /**************************************************************************************/ |
emmanuelchio | 0:e8934310aa9d | 10 | /**************************************************************************************/ |
emmanuelchio | 0:e8934310aa9d | 11 | |
emmanuelchio | 0:e8934310aa9d | 12 | #include "mbed.h" |
emmanuelchio | 0:e8934310aa9d | 13 | #include "SMARTGPU.h" |
emmanuelchio | 0:e8934310aa9d | 14 | |
emmanuelchio | 0:e8934310aa9d | 15 | SMARTGPU lcd(p13,p14,p15); //(TX,RX,Reset); |
emmanuelchio | 0:e8934310aa9d | 16 | |
emmanuelchio | 0:e8934310aa9d | 17 | // defines for balls |
emmanuelchio | 0:e8934310aa9d | 18 | #define radiusBall1 15 //ball1 size |
emmanuelchio | 0:e8934310aa9d | 19 | #define colourBall1 GREEN //ball1 colour |
emmanuelchio | 0:e8934310aa9d | 20 | #define radiusBall2 8 //ball2 size |
emmanuelchio | 0:e8934310aa9d | 21 | #define colourBall2 YELLOW //ball2 colour |
emmanuelchio | 0:e8934310aa9d | 22 | #define radiusBall3 11 //ball3 size |
emmanuelchio | 0:e8934310aa9d | 23 | #define colourBall3 RED //ball3 colour |
emmanuelchio | 0:e8934310aa9d | 24 | #define radiusBall4 18 //ball4 size |
emmanuelchio | 0:e8934310aa9d | 25 | #define colourBall4 BLUE //ball4 colour |
emmanuelchio | 0:e8934310aa9d | 26 | |
emmanuelchio | 0:e8934310aa9d | 27 | //variables used by move ball methods |
emmanuelchio | 0:e8934310aa9d | 28 | int speedBall1=3; //ball1 moving speed - amount of pixels that ball move each time |
emmanuelchio | 0:e8934310aa9d | 29 | int speedBall2=4; //ball2 moving speed - amount of pixels that ball move each time |
emmanuelchio | 0:e8934310aa9d | 30 | int speedBall3=8; //ball3 moving speed - amount of pixels that ball move each time |
emmanuelchio | 0:e8934310aa9d | 31 | int speedBall4=6; //ball4 moving speed - amount of pixels that ball move each time |
emmanuelchio | 0:e8934310aa9d | 32 | int dirx1=1; //xball1 initial positive direction |
emmanuelchio | 0:e8934310aa9d | 33 | int diry1=1; //yball1 initial positive direction |
emmanuelchio | 0:e8934310aa9d | 34 | int xBall1=300; //x initial position of ball1 |
emmanuelchio | 0:e8934310aa9d | 35 | int yBall1=100; //y initial position of ball1 |
emmanuelchio | 0:e8934310aa9d | 36 | int dirx2=-1; //xball2 initial negative direction |
emmanuelchio | 0:e8934310aa9d | 37 | int diry2=-1; //yball2 initial negative direction |
emmanuelchio | 0:e8934310aa9d | 38 | int xBall2=30; //x initial position of ball2 |
emmanuelchio | 0:e8934310aa9d | 39 | int yBall2=80; //y initial position of ball2 |
emmanuelchio | 0:e8934310aa9d | 40 | int dirx3=-1; //xball3 initial negative direction |
emmanuelchio | 0:e8934310aa9d | 41 | int diry3=1; //yball3 initial negative direction |
emmanuelchio | 0:e8934310aa9d | 42 | int xBall3=60; //x initial position of ball3 |
emmanuelchio | 0:e8934310aa9d | 43 | int yBall3=15; //y initial position of ball3 |
emmanuelchio | 0:e8934310aa9d | 44 | int dirx4=1; //xball4 initial negative direction |
emmanuelchio | 0:e8934310aa9d | 45 | int diry4=-1; //yball4 initial negative direction |
emmanuelchio | 0:e8934310aa9d | 46 | int xBall4=150; //x initial position of ball4 |
emmanuelchio | 0:e8934310aa9d | 47 | int yBall4=80; //y initial position of ball4 |
emmanuelchio | 0:e8934310aa9d | 48 | |
emmanuelchio | 0:e8934310aa9d | 49 | /***************************************************/ |
emmanuelchio | 0:e8934310aa9d | 50 | //Function that updates the current position of the ball1 |
emmanuelchio | 0:e8934310aa9d | 51 | void moveBall1(){ |
emmanuelchio | 0:e8934310aa9d | 52 | lcd.drawCircle(xBall1,yBall1,radiusBall1,BLACK,UNFILL); // Erase previous ball position |
emmanuelchio | 0:e8934310aa9d | 53 | xBall1+=(dirx1*speedBall1); // Calculate new x coordinate for ball1 |
emmanuelchio | 0:e8934310aa9d | 54 | yBall1+=(diry1*speedBall1); // Calculate new y coordinate for ball1 |
emmanuelchio | 0:e8934310aa9d | 55 | lcd.drawCircle(xBall1,yBall1,radiusBall1,colourBall1,UNFILL); // Draw new ball position |
emmanuelchio | 0:e8934310aa9d | 56 | if((xBall1+speedBall1+radiusBall1)>318 | (xBall1-speedBall1-radiusBall1)<=1){ // if ball reaches the left or right corner, we invert moving direction |
emmanuelchio | 0:e8934310aa9d | 57 | dirx1= dirx1*(-1); // Invert the moving direction by multiplying by -1 |
emmanuelchio | 0:e8934310aa9d | 58 | } |
emmanuelchio | 0:e8934310aa9d | 59 | if((yBall1+speedBall1+radiusBall1)>238 | (yBall1-speedBall1-radiusBall1)<=1){ // if ball reaches the top or bottom corner, we invert moving direction |
emmanuelchio | 0:e8934310aa9d | 60 | diry1= diry1*(-1); // Invert the moving direction by multiplying by -1 |
emmanuelchio | 0:e8934310aa9d | 61 | } |
emmanuelchio | 0:e8934310aa9d | 62 | } |
emmanuelchio | 0:e8934310aa9d | 63 | |
emmanuelchio | 0:e8934310aa9d | 64 | /***************************************************/ |
emmanuelchio | 0:e8934310aa9d | 65 | //Function that updates the current position of the ball2 |
emmanuelchio | 0:e8934310aa9d | 66 | void moveBall2(){ |
emmanuelchio | 0:e8934310aa9d | 67 | lcd.drawCircle(xBall2,yBall2,radiusBall2,BLACK,FILL); // Erase previous ball position |
emmanuelchio | 0:e8934310aa9d | 68 | xBall2+=(dirx2*speedBall2); // Calculate new x coordinate for ball2 |
emmanuelchio | 0:e8934310aa9d | 69 | yBall2+=(diry2*speedBall2); // Calculate new y coordinate for ball2 |
emmanuelchio | 0:e8934310aa9d | 70 | lcd.drawCircle(xBall2,yBall2,radiusBall2,colourBall2,FILL); // Draw new ball position |
emmanuelchio | 0:e8934310aa9d | 71 | if((xBall2+speedBall2+radiusBall2)>318 | (xBall2-speedBall2-radiusBall2)<=1){ // if ball reaches the left or right corner, we invert moving direction |
emmanuelchio | 0:e8934310aa9d | 72 | dirx2= dirx2*(-1); // Invert the moving direction by multiplying by -1 |
emmanuelchio | 0:e8934310aa9d | 73 | } |
emmanuelchio | 0:e8934310aa9d | 74 | if((yBall2+speedBall2+radiusBall2)>238 | (yBall2-speedBall2-radiusBall2)<=1){ // if ball reaches the top or bottom corner, we invert moving direction |
emmanuelchio | 0:e8934310aa9d | 75 | diry2= diry2*(-1); // Invert the moving direction by multiplying by -1 |
emmanuelchio | 0:e8934310aa9d | 76 | } |
emmanuelchio | 0:e8934310aa9d | 77 | } |
emmanuelchio | 0:e8934310aa9d | 78 | |
emmanuelchio | 0:e8934310aa9d | 79 | /***************************************************/ |
emmanuelchio | 0:e8934310aa9d | 80 | //Function that updates the current position of the ball3 |
emmanuelchio | 0:e8934310aa9d | 81 | void moveBall3(){ |
emmanuelchio | 0:e8934310aa9d | 82 | lcd.drawCircle(xBall3,yBall3,radiusBall3,BLACK,FILL); // Erase previous ball position |
emmanuelchio | 0:e8934310aa9d | 83 | xBall3+=(dirx3*speedBall3); // Calculate new x coordinate for ball3 |
emmanuelchio | 0:e8934310aa9d | 84 | yBall3+=(diry3*speedBall3); // Calculate new y coordinate for ball3 |
emmanuelchio | 0:e8934310aa9d | 85 | lcd.drawCircle(xBall3,yBall3,radiusBall3,colourBall3,FILL); // Draw new ball position |
emmanuelchio | 0:e8934310aa9d | 86 | if((xBall3+speedBall3+radiusBall3)>318 | (xBall3-speedBall3-radiusBall3)<=1){ // if ball reaches the left or right corner, we invert moving direction |
emmanuelchio | 0:e8934310aa9d | 87 | dirx3= dirx3*(-1); // Invert the moving direction by multiplying by -1 |
emmanuelchio | 0:e8934310aa9d | 88 | } |
emmanuelchio | 0:e8934310aa9d | 89 | if((yBall3+speedBall3+radiusBall3)>238 | (yBall3-speedBall3-radiusBall3)<=1){ // if ball reaches the top or bottom corner, we invert moving direction |
emmanuelchio | 0:e8934310aa9d | 90 | diry3= diry3*(-1); // Invert the moving direction by multiplying by -1 |
emmanuelchio | 0:e8934310aa9d | 91 | } |
emmanuelchio | 0:e8934310aa9d | 92 | } |
emmanuelchio | 0:e8934310aa9d | 93 | |
emmanuelchio | 0:e8934310aa9d | 94 | /***************************************************/ |
emmanuelchio | 0:e8934310aa9d | 95 | //Function that updates the current position of the ball4 |
emmanuelchio | 0:e8934310aa9d | 96 | void moveBall4(){ |
emmanuelchio | 0:e8934310aa9d | 97 | lcd.drawCircle(xBall4,yBall4,radiusBall4,BLACK,UNFILL); // Erase previous ball position |
emmanuelchio | 0:e8934310aa9d | 98 | xBall4+=(dirx4*speedBall4); // Calculate new x coordinate for ball4 |
emmanuelchio | 0:e8934310aa9d | 99 | yBall4+=(diry4*speedBall4); // Calculate new y coordinate for ball4 |
emmanuelchio | 0:e8934310aa9d | 100 | lcd.drawCircle(xBall4,yBall4,radiusBall4,colourBall4,UNFILL); // Draw new ball position |
emmanuelchio | 0:e8934310aa9d | 101 | if((xBall4+speedBall4+radiusBall4)>318 | (xBall4-speedBall4-radiusBall4)<=1){ // if ball reaches the left or right corner, we invert moving direction |
emmanuelchio | 0:e8934310aa9d | 102 | dirx4= dirx4*(-1); // Invert the moving direction by multiplying by -1 |
emmanuelchio | 0:e8934310aa9d | 103 | } |
emmanuelchio | 0:e8934310aa9d | 104 | if((yBall4+speedBall4+radiusBall4)>238 | (yBall4-speedBall4-radiusBall4)<=1){ // if ball reaches the top or bottom corner, we invert moving direction |
emmanuelchio | 0:e8934310aa9d | 105 | diry4= diry4*(-1); // Invert the moving direction by multiplying by -1 |
emmanuelchio | 0:e8934310aa9d | 106 | } |
emmanuelchio | 0:e8934310aa9d | 107 | } |
emmanuelchio | 0:e8934310aa9d | 108 | |
emmanuelchio | 0:e8934310aa9d | 109 | /***************************************************/ |
emmanuelchio | 0:e8934310aa9d | 110 | /***************************************************/ |
emmanuelchio | 0:e8934310aa9d | 111 | int main() { |
emmanuelchio | 0:e8934310aa9d | 112 | lcd.reset(); //physically reset SMARTGPU |
emmanuelchio | 0:e8934310aa9d | 113 | lcd.start(); //initialize the SMARTGPU processor |
emmanuelchio | 0:e8934310aa9d | 114 | |
emmanuelchio | 0:e8934310aa9d | 115 | lcd.baudChange(1000000); //set a fast baud! for fast drawing |
emmanuelchio | 0:e8934310aa9d | 116 | lcd.drawRectangle(0,0,319,239,MAGENTA,UNFILL); //draw corners |
emmanuelchio | 0:e8934310aa9d | 117 | |
emmanuelchio | 0:e8934310aa9d | 118 | while(1){ // Loop forever |
emmanuelchio | 0:e8934310aa9d | 119 | moveBall1(); // move ball1 |
emmanuelchio | 0:e8934310aa9d | 120 | moveBall2(); // move ball2 |
emmanuelchio | 0:e8934310aa9d | 121 | moveBall3(); // move ball3 |
emmanuelchio | 0:e8934310aa9d | 122 | moveBall4(); // move ball4 |
emmanuelchio | 0:e8934310aa9d | 123 | wait_ms(15); // wait a little |
emmanuelchio | 0:e8934310aa9d | 124 | } |
emmanuelchio | 0:e8934310aa9d | 125 | } |