Jared DiCarlo
/
manworm_tv_gpu
asdf
Fork of manworm_ticker_tv by
main.cpp@1:24fd07a24094, 2017-11-18 (annotated)
- Committer:
- bwang
- Date:
- Sat Nov 18 07:37:42 2017 +0000
- Revision:
- 1:24fd07a24094
- Parent:
- 0:7757ab3f7206
- Child:
- 2:1d16e99f334b
blorp
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dicarloj | 0:7757ab3f7206 | 1 | #include "mbed.h" |
dicarloj | 0:7757ab3f7206 | 2 | #define V_RES 220 |
dicarloj | 0:7757ab3f7206 | 3 | #define H_RES 100 |
dicarloj | 0:7757ab3f7206 | 4 | #include <math.h> |
dicarloj | 0:7757ab3f7206 | 5 | #define X_MIN 24 |
dicarloj | 0:7757ab3f7206 | 6 | #define X_MAX (76+18) |
dicarloj | 0:7757ab3f7206 | 7 | #define Y_MIN 7 |
dicarloj | 0:7757ab3f7206 | 8 | #define Y_MAX (V_RES/4 - 15) |
dicarloj | 0:7757ab3f7206 | 9 | |
bwang | 1:24fd07a24094 | 10 | int SX_MIN = 30; |
bwang | 1:24fd07a24094 | 11 | int SX_MAX = 90; |
bwang | 1:24fd07a24094 | 12 | int SY_MIN = 10; |
bwang | 1:24fd07a24094 | 13 | int SY_MAX = 50; |
bwang | 1:24fd07a24094 | 14 | int PADDLE_LEN = 10; |
bwang | 1:24fd07a24094 | 15 | |
dicarloj | 0:7757ab3f7206 | 16 | #define Y_0 ( (Y_MIN + Y_MAX)/2 ) |
dicarloj | 0:7757ab3f7206 | 17 | #define X_0 ( (X_MIN + X_MAX)/2 ) |
dicarloj | 0:7757ab3f7206 | 18 | #define SIDE 8 |
dicarloj | 0:7757ab3f7206 | 19 | #define HSIDE 8 |
dicarloj | 0:7757ab3f7206 | 20 | #define SIN_V (0.03) |
dicarloj | 0:7757ab3f7206 | 21 | #define COS_V (0.99955f) |
dicarloj | 0:7757ab3f7206 | 22 | #define BX_0 30 |
dicarloj | 0:7757ab3f7206 | 23 | #define BY_0 (V_RES/4 - 15) |
dicarloj | 0:7757ab3f7206 | 24 | #define BX 42 |
dicarloj | 0:7757ab3f7206 | 25 | #define BY 15 |
dicarloj | 0:7757ab3f7206 | 26 | #define DEMO_LENGTH 600 |
dicarloj | 0:7757ab3f7206 | 27 | |
dicarloj | 0:7757ab3f7206 | 28 | |
dicarloj | 0:7757ab3f7206 | 29 | DigitalOut sout(D8); //sync |
dicarloj | 0:7757ab3f7206 | 30 | DigitalOut vout(D7); //video |
dicarloj | 0:7757ab3f7206 | 31 | Ticker t; |
dicarloj | 0:7757ab3f7206 | 32 | uint8_t draw_line_inv = 0; |
dicarloj | 0:7757ab3f7206 | 33 | //9x42 |
dicarloj | 0:7757ab3f7206 | 34 | uint8_t miters[] = { |
dicarloj | 0:7757ab3f7206 | 35 | 1,1,1,1,1,1,1,1,1,1,0,0,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, |
dicarloj | 0:7757ab3f7206 | 36 | 1,1,1,1,1,1,1,1,1,1,0,0,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, |
dicarloj | 0:7757ab3f7206 | 37 | 1,1,0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, |
dicarloj | 0:7757ab3f7206 | 38 | 1,1,0,0,1,1,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,1,1,1,1,1,0,0,1,1,0,0,0,0,0,0,1,1,1,1,1,1, |
dicarloj | 0:7757ab3f7206 | 39 | 1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,0,1,0,0,1,1,1,1,1,1,0,0,1,1,1,1,1,1, |
dicarloj | 0:7757ab3f7206 | 40 | 1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,1,1,1,0,0,0,1,1,1,0,0,0,0,0,0,1,1,0,0,0, |
dicarloj | 0:7757ab3f7206 | 41 | 1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,1,1,0,0, |
dicarloj | 0:7757ab3f7206 | 42 | 1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,1,1,1,1,0,0,1,1,1,0,0,0,0,0,1,1,1,1,1,1, |
dicarloj | 0:7757ab3f7206 | 43 | 1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,1,1,1,1,0,0,1,1,1,0,0,0,0,0,1,1,1,1,1,1, |
dicarloj | 0:7757ab3f7206 | 44 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, |
dicarloj | 0:7757ab3f7206 | 45 | 0,0,0,0,0,0,0,1,1,0,1,0,1,0,1,1,0,0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,1,1,0,0,0,0,0,0, |
dicarloj | 0:7757ab3f7206 | 46 | 1,1,1,1,1,0,1,0,0,1,1,0,1,1,0,0,1,0,1,1,0,0,0,1,1,0,1,1,0,1,1,0,1,1,0,0,0,1,1,1,1,1, |
dicarloj | 0:7757ab3f7206 | 47 | 1,0,1,0,1,0,1,0,0,1,1,0,1,0,0,0,1,0,0,1,0,1,0,1,0,0,1,0,0,0,1,0,1,0,0,0,0,1,0,1,0,1, |
dicarloj | 0:7757ab3f7206 | 48 | 1,0,1,0,1,0,1,0,0,1,1,0,1,0,0,0,1,0,0,1,0,1,0,1,0,0,1,1,0,1,1,0,1,0,0,0,0,1,0,1,0,1, |
dicarloj | 0:7757ab3f7206 | 49 | 1,0,1,0,1,0,0,1,1,0,1,0,1,0,0,0,1,0,0,0,1,1,1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,1,0,1,0,1, |
dicarloj | 0:7757ab3f7206 | 50 | |
dicarloj | 0:7757ab3f7206 | 51 | }; |
dicarloj | 0:7757ab3f7206 | 52 | |
dicarloj | 0:7757ab3f7206 | 53 | uint8_t tv[] = { |
dicarloj | 0:7757ab3f7206 | 54 | 0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, |
dicarloj | 0:7757ab3f7206 | 55 | 0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, |
dicarloj | 0:7757ab3f7206 | 56 | 0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0, |
dicarloj | 0:7757ab3f7206 | 57 | 0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,1,0,1,0,0,1,0,1,0,0,0,0,0,0,0,0, |
dicarloj | 0:7757ab3f7206 | 58 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,1,0,0,1,0,1,0,0,0,0,0,0,0,0, |
dicarloj | 0:7757ab3f7206 | 59 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,1,0,1,0,0,1,0,1,0,0,0,0,0,0,0,0, |
dicarloj | 0:7757ab3f7206 | 60 | 0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0,0,1,0,1,0,0,0,0,0,0,0,0, |
dicarloj | 0:7757ab3f7206 | 61 | 0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,1,0,0,1,0,1,0,0,0,0,0,0,0,0, |
dicarloj | 0:7757ab3f7206 | 62 | 0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,1,1,0,1,0,0,0,1,0,1,0,1,0,1,0,0,1,0,1,0,0,0,0,0,0,0,0, |
dicarloj | 0:7757ab3f7206 | 63 | 0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,1,0,1,0,1,0,0,1,0,1,0,0,0,0,0,0,0,0, |
dicarloj | 0:7757ab3f7206 | 64 | 0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,1,0,1,0,1,0,0,1,0,1,0,0,0,0,0,0,0,0, |
dicarloj | 0:7757ab3f7206 | 65 | 0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,1,0,1,0,0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0, |
dicarloj | 0:7757ab3f7206 | 66 | 0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, |
dicarloj | 0:7757ab3f7206 | 67 | 0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,0,0,1,1,1,0,0,0,0,0,0,0,0, |
dicarloj | 0:7757ab3f7206 | 68 | 0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,0,0,1,1,1,0,0,0,0,0,0,0,0}; |
dicarloj | 0:7757ab3f7206 | 69 | |
dicarloj | 0:7757ab3f7206 | 70 | |
dicarloj | 0:7757ab3f7206 | 71 | |
dicarloj | 0:7757ab3f7206 | 72 | uint16_t l=0; //current line of scan |
dicarloj | 0:7757ab3f7206 | 73 | |
dicarloj | 0:7757ab3f7206 | 74 | uint8_t im_line_s[H_RES]; //image sync buffer |
dicarloj | 0:7757ab3f7206 | 75 | |
dicarloj | 0:7757ab3f7206 | 76 | uint8_t bl_line_s[H_RES]; //lower 1/4 of screen sync buffer |
dicarloj | 0:7757ab3f7206 | 77 | uint8_t bl_line_v[H_RES]; //lower 1/4 of screen video buffer |
dicarloj | 0:7757ab3f7206 | 78 | uint8_t vb_line_s[H_RES]; //vertical sync, sync buffer |
dicarloj | 0:7757ab3f7206 | 79 | uint8_t vb_line_v[H_RES]; //vertical sync, video buffer |
dicarloj | 0:7757ab3f7206 | 80 | |
dicarloj | 0:7757ab3f7206 | 81 | float cube_a[3] = {15.f, 0.f, 0.f}; |
dicarloj | 0:7757ab3f7206 | 82 | |
dicarloj | 0:7757ab3f7206 | 83 | |
dicarloj | 0:7757ab3f7206 | 84 | float cube_pts[8][3] = { {SIDE,SIDE,HSIDE}, |
dicarloj | 0:7757ab3f7206 | 85 | {-SIDE,SIDE,HSIDE}, |
dicarloj | 0:7757ab3f7206 | 86 | {-SIDE,-SIDE,HSIDE}, |
dicarloj | 0:7757ab3f7206 | 87 | {SIDE,-SIDE,HSIDE}, |
dicarloj | 0:7757ab3f7206 | 88 | {SIDE,-SIDE,-HSIDE}, |
dicarloj | 0:7757ab3f7206 | 89 | {-SIDE,-SIDE,-HSIDE}, |
dicarloj | 0:7757ab3f7206 | 90 | {-SIDE,SIDE,-HSIDE}, |
dicarloj | 0:7757ab3f7206 | 91 | {SIDE,SIDE,-HSIDE} }; |
dicarloj | 0:7757ab3f7206 | 92 | |
dicarloj | 0:7757ab3f7206 | 93 | float x_rot[3][3] = { {1.f, 0.f, 0.f}, |
dicarloj | 0:7757ab3f7206 | 94 | {0.f, COS_V, -SIN_V}, |
dicarloj | 0:7757ab3f7206 | 95 | {0.f, SIN_V, COS_V} }; |
dicarloj | 0:7757ab3f7206 | 96 | |
dicarloj | 0:7757ab3f7206 | 97 | float y_rot[3][3] = { {COS_V, 0.f, SIN_V}, |
dicarloj | 0:7757ab3f7206 | 98 | {0.f, 1.f, 0.f}, |
dicarloj | 0:7757ab3f7206 | 99 | {-SIN_V, 0, COS_V} }; |
dicarloj | 0:7757ab3f7206 | 100 | |
dicarloj | 0:7757ab3f7206 | 101 | float z_rot[3][3] = { {COS_V, -SIN_V, 0.f}, |
dicarloj | 0:7757ab3f7206 | 102 | {SIN_V, COS_V, 0.f}, |
dicarloj | 0:7757ab3f7206 | 103 | {0.f, 0.f, 1.f} }; |
dicarloj | 0:7757ab3f7206 | 104 | |
dicarloj | 0:7757ab3f7206 | 105 | |
dicarloj | 0:7757ab3f7206 | 106 | uint8_t im_line_va[H_RES*V_RES]; //image buffer |
dicarloj | 0:7757ab3f7206 | 107 | |
bwang | 1:24fd07a24094 | 108 | //pong variables |
bwang | 1:24fd07a24094 | 109 | float p1 = (SY_MIN+SY_MAX)/2-PADDLE_LEN/2, p2 = (SY_MIN+SY_MAX)/2-PADDLE_LEN/2; |
bwang | 1:24fd07a24094 | 110 | float p1v = 0.1, p2v = -0.1; |
bwang | 1:24fd07a24094 | 111 | |
bwang | 1:24fd07a24094 | 112 | float bx = (SX_MIN+SX_MAX)/2, by = (SY_MIN+SY_MAX)/2; |
bwang | 1:24fd07a24094 | 113 | float bxv = 0.03, byv = 0.03; |
bwang | 1:24fd07a24094 | 114 | |
bwang | 1:24fd07a24094 | 115 | DigitalIn p1_in(A0); |
bwang | 1:24fd07a24094 | 116 | DigitalIn p2_in(A1); |
bwang | 1:24fd07a24094 | 117 | |
dicarloj | 0:7757ab3f7206 | 118 | void make_checkerboard() |
dicarloj | 0:7757ab3f7206 | 119 | { |
dicarloj | 0:7757ab3f7206 | 120 | for(int i = 0; i < H_RES; i++) |
dicarloj | 0:7757ab3f7206 | 121 | for(int j = 0; j < V_RES; j++) |
bwang | 1:24fd07a24094 | 122 | im_line_va[i+j*H_RES] = 0*((i > 20) && (i < 98)) && ((j%2) ^ (i%2)); //checkerboard |
dicarloj | 0:7757ab3f7206 | 123 | |
dicarloj | 0:7757ab3f7206 | 124 | } |
dicarloj | 0:7757ab3f7206 | 125 | |
dicarloj | 0:7757ab3f7206 | 126 | void init_buffers() |
dicarloj | 0:7757ab3f7206 | 127 | { |
dicarloj | 0:7757ab3f7206 | 128 | make_checkerboard(); |
dicarloj | 0:7757ab3f7206 | 129 | for(int i = 0; i < H_RES; i++) |
dicarloj | 0:7757ab3f7206 | 130 | { |
dicarloj | 0:7757ab3f7206 | 131 | im_line_s[i] = 1; |
dicarloj | 0:7757ab3f7206 | 132 | bl_line_s[i] = 1; |
dicarloj | 0:7757ab3f7206 | 133 | bl_line_v[i] = 0; |
dicarloj | 0:7757ab3f7206 | 134 | vb_line_s[i] = 0; |
dicarloj | 0:7757ab3f7206 | 135 | vb_line_v[i] = 0; |
dicarloj | 0:7757ab3f7206 | 136 | } |
dicarloj | 0:7757ab3f7206 | 137 | im_line_s[0] = 0; |
dicarloj | 0:7757ab3f7206 | 138 | im_line_s[1] = 0; |
dicarloj | 0:7757ab3f7206 | 139 | im_line_s[2] = 0; |
dicarloj | 0:7757ab3f7206 | 140 | bl_line_s[0] = 0; |
dicarloj | 0:7757ab3f7206 | 141 | vb_line_s[0] = 1; |
dicarloj | 0:7757ab3f7206 | 142 | bl_line_s[1] = 0; |
dicarloj | 0:7757ab3f7206 | 143 | vb_line_s[1] = 1; |
dicarloj | 0:7757ab3f7206 | 144 | |
dicarloj | 0:7757ab3f7206 | 145 | |
dicarloj | 0:7757ab3f7206 | 146 | |
dicarloj | 0:7757ab3f7206 | 147 | } |
dicarloj | 0:7757ab3f7206 | 148 | void isr() |
dicarloj | 0:7757ab3f7206 | 149 | { |
dicarloj | 0:7757ab3f7206 | 150 | uint8_t nop = 0; //use nops or use wait_us |
dicarloj | 0:7757ab3f7206 | 151 | uint8_t* sptr; //pointer to sync buffer for line |
dicarloj | 0:7757ab3f7206 | 152 | uint8_t* vptr; //pointer to video buffer for line |
dicarloj | 0:7757ab3f7206 | 153 | if(l < V_RES){ vptr = im_line_va + ((l/4)*H_RES); sptr = im_line_s; nop = 1; } //pick line buffers |
dicarloj | 0:7757ab3f7206 | 154 | else if(l < 254){ vptr = bl_line_v; sptr = bl_line_s; nop = 0; } |
dicarloj | 0:7757ab3f7206 | 155 | else{ vptr = vb_line_v; sptr = vb_line_s; nop = 1;} |
dicarloj | 0:7757ab3f7206 | 156 | uint8_t lmax = nop?H_RES:12; //number of columns |
dicarloj | 0:7757ab3f7206 | 157 | for(uint8_t i = 0; i < lmax; i++) //loop over each column |
dicarloj | 0:7757ab3f7206 | 158 | { |
dicarloj | 0:7757ab3f7206 | 159 | vout = vptr[i]; //set output pins |
dicarloj | 0:7757ab3f7206 | 160 | sout = sptr[i]; |
dicarloj | 0:7757ab3f7206 | 161 | if(nop) //nop delay |
dicarloj | 0:7757ab3f7206 | 162 | { |
dicarloj | 0:7757ab3f7206 | 163 | asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");//asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop"); |
dicarloj | 0:7757ab3f7206 | 164 | } |
dicarloj | 0:7757ab3f7206 | 165 | else {wait_us(1); if(i > 2) i++;} //wait delay |
dicarloj | 0:7757ab3f7206 | 166 | |
dicarloj | 0:7757ab3f7206 | 167 | |
dicarloj | 0:7757ab3f7206 | 168 | } |
dicarloj | 0:7757ab3f7206 | 169 | //move to next line |
dicarloj | 0:7757ab3f7206 | 170 | l++; |
dicarloj | 0:7757ab3f7206 | 171 | if(l > 255) l = 0; |
dicarloj | 0:7757ab3f7206 | 172 | } |
dicarloj | 0:7757ab3f7206 | 173 | |
dicarloj | 0:7757ab3f7206 | 174 | //coordinates for bouncing ball |
dicarloj | 0:7757ab3f7206 | 175 | |
dicarloj | 0:7757ab3f7206 | 176 | |
dicarloj | 0:7757ab3f7206 | 177 | |
dicarloj | 0:7757ab3f7206 | 178 | int k = 0; |
dicarloj | 0:7757ab3f7206 | 179 | uint16_t px = X_0*10; |
dicarloj | 0:7757ab3f7206 | 180 | uint16_t py = Y_0*10; |
dicarloj | 0:7757ab3f7206 | 181 | uint16_t vx = 10; |
dicarloj | 0:7757ab3f7206 | 182 | uint16_t vy = 10; |
dicarloj | 0:7757ab3f7206 | 183 | uint16_t px2 = X_0*10 + 80; |
dicarloj | 0:7757ab3f7206 | 184 | uint16_t py2 = Y_0*10 - 40; |
dicarloj | 0:7757ab3f7206 | 185 | uint16_t vx2 = 3; |
dicarloj | 0:7757ab3f7206 | 186 | uint16_t vy2 = -4; |
dicarloj | 0:7757ab3f7206 | 187 | |
dicarloj | 0:7757ab3f7206 | 188 | int16_t sign(int16_t a) |
dicarloj | 0:7757ab3f7206 | 189 | { |
dicarloj | 0:7757ab3f7206 | 190 | if(a > 0) return 1; |
dicarloj | 0:7757ab3f7206 | 191 | if(a < 0) return -1; |
dicarloj | 0:7757ab3f7206 | 192 | return 0; |
dicarloj | 0:7757ab3f7206 | 193 | } |
dicarloj | 0:7757ab3f7206 | 194 | |
dicarloj | 0:7757ab3f7206 | 195 | void draw_vert(int16_t y0, int16_t y1, int16_t x0) |
dicarloj | 0:7757ab3f7206 | 196 | { |
dicarloj | 0:7757ab3f7206 | 197 | for(int16_t i = y0; i < y1; i++) |
dicarloj | 0:7757ab3f7206 | 198 | im_line_va[H_RES*i + x0] = 1; |
dicarloj | 0:7757ab3f7206 | 199 | } |
dicarloj | 0:7757ab3f7206 | 200 | |
dicarloj | 0:7757ab3f7206 | 201 | void draw_horiz(int16_t x0, int16_t x1, int16_t y0) |
dicarloj | 0:7757ab3f7206 | 202 | { |
dicarloj | 0:7757ab3f7206 | 203 | for(int16_t i = x0; i < x1; i++) |
dicarloj | 0:7757ab3f7206 | 204 | im_line_va[H_RES*y0 + i] = 1; |
dicarloj | 0:7757ab3f7206 | 205 | } |
dicarloj | 0:7757ab3f7206 | 206 | |
dicarloj | 0:7757ab3f7206 | 207 | int16_t imin(int16_t a, int16_t b) |
dicarloj | 0:7757ab3f7206 | 208 | { |
dicarloj | 0:7757ab3f7206 | 209 | if(a<b) return a; |
dicarloj | 0:7757ab3f7206 | 210 | return b; |
dicarloj | 0:7757ab3f7206 | 211 | } |
dicarloj | 0:7757ab3f7206 | 212 | |
dicarloj | 0:7757ab3f7206 | 213 | int16_t imax(int16_t a, int16_t b) |
dicarloj | 0:7757ab3f7206 | 214 | { |
dicarloj | 0:7757ab3f7206 | 215 | if(a>b) return a; |
dicarloj | 0:7757ab3f7206 | 216 | return b; |
dicarloj | 0:7757ab3f7206 | 217 | } |
dicarloj | 0:7757ab3f7206 | 218 | |
dicarloj | 0:7757ab3f7206 | 219 | void draw_line(int16_t x0, int16_t y0, int16_t x1, int16_t y1) |
dicarloj | 0:7757ab3f7206 | 220 | { |
dicarloj | 0:7757ab3f7206 | 221 | if(x0 > x1){ x0 = x0 ^ x1; x1 = x1^x0; x0 = x0^x1;y0 = y0 ^ y1; y1 = y1^y0; y0 = y0^y1; } |
dicarloj | 0:7757ab3f7206 | 222 | if(x0 == x1){draw_vert(y0,y1,x0);} |
dicarloj | 0:7757ab3f7206 | 223 | if(y0 == y1){draw_horiz(x0,x1,y0);} |
dicarloj | 0:7757ab3f7206 | 224 | int16_t dx = x1 - x0; |
dicarloj | 0:7757ab3f7206 | 225 | int16_t dy = y1 - y0; |
dicarloj | 0:7757ab3f7206 | 226 | float derr = fabs((float)(dy)/(float)(dx)); |
dicarloj | 0:7757ab3f7206 | 227 | float err = 0.f; |
dicarloj | 0:7757ab3f7206 | 228 | int16_t y = y0; |
dicarloj | 0:7757ab3f7206 | 229 | for(int16_t x = x0; x < x1; x++) |
dicarloj | 0:7757ab3f7206 | 230 | { |
dicarloj | 0:7757ab3f7206 | 231 | //plotxy |
dicarloj | 0:7757ab3f7206 | 232 | im_line_va[H_RES*y + x] = !draw_line_inv; |
dicarloj | 0:7757ab3f7206 | 233 | err += derr; |
dicarloj | 0:7757ab3f7206 | 234 | while(err >= 0.5f) |
dicarloj | 0:7757ab3f7206 | 235 | { |
dicarloj | 0:7757ab3f7206 | 236 | y += sign(dy); |
dicarloj | 0:7757ab3f7206 | 237 | im_line_va[H_RES*y + x] = !draw_line_inv; |
dicarloj | 0:7757ab3f7206 | 238 | err -= 1.f; |
dicarloj | 0:7757ab3f7206 | 239 | } |
dicarloj | 0:7757ab3f7206 | 240 | } |
dicarloj | 0:7757ab3f7206 | 241 | } |
dicarloj | 0:7757ab3f7206 | 242 | |
dicarloj | 0:7757ab3f7206 | 243 | void draw_cube(float cp[][3]) |
dicarloj | 0:7757ab3f7206 | 244 | { |
dicarloj | 0:7757ab3f7206 | 245 | for(uint8_t i = 0; i < 7; i++) |
dicarloj | 0:7757ab3f7206 | 246 | { |
dicarloj | 0:7757ab3f7206 | 247 | draw_line((int16_t)cp[i][0]+cube_a[0]+X_0,(int16_t)cp[i][1]+cube_a[1]+Y_0,(int16_t)cp[i+1][0]+cube_a[0]+X_0,(int16_t)cp[i+1][1]+cube_a[1]+Y_0); |
dicarloj | 0:7757ab3f7206 | 248 | } |
dicarloj | 0:7757ab3f7206 | 249 | draw_line((int16_t)cp[0][0]+cube_a[0]+X_0,(int16_t)cp[0][1]+cube_a[1]+Y_0,(int16_t)cp[3][0]+cube_a[0]+X_0,(int16_t)cp[3][1]+cube_a[1]+Y_0); |
dicarloj | 0:7757ab3f7206 | 250 | draw_line((int16_t)cp[4][0]+cube_a[0]+X_0,(int16_t)cp[4][1]+cube_a[1]+Y_0,(int16_t)cp[7][0]+cube_a[0]+X_0,(int16_t)cp[7][1]+cube_a[1]+Y_0); |
dicarloj | 0:7757ab3f7206 | 251 | draw_line((int16_t)cp[0][0]+cube_a[0]+X_0,(int16_t)cp[0][1]+cube_a[1]+Y_0,(int16_t)cp[7][0]+cube_a[0]+X_0,(int16_t)cp[7][1]+cube_a[1]+Y_0); |
dicarloj | 0:7757ab3f7206 | 252 | draw_line((int16_t)cp[1][0]+cube_a[0]+X_0,(int16_t)cp[1][1]+cube_a[1]+Y_0,(int16_t)cp[6][0]+cube_a[0]+X_0,(int16_t)cp[6][1]+cube_a[1]+Y_0); |
dicarloj | 0:7757ab3f7206 | 253 | draw_line((int16_t)cp[2][0]+cube_a[0]+X_0,(int16_t)cp[2][1]+cube_a[1]+Y_0,(int16_t)cp[5][0]+cube_a[0]+X_0,(int16_t)cp[5][1]+cube_a[1]+Y_0); |
dicarloj | 0:7757ab3f7206 | 254 | } |
dicarloj | 0:7757ab3f7206 | 255 | |
dicarloj | 0:7757ab3f7206 | 256 | void apply_rot(float cp[][3], float r[][3]) |
dicarloj | 0:7757ab3f7206 | 257 | { |
dicarloj | 0:7757ab3f7206 | 258 | for(uint8_t pti = 0; pti < 8; pti++) |
dicarloj | 0:7757ab3f7206 | 259 | { |
dicarloj | 0:7757ab3f7206 | 260 | float* cpt = cp[pti]; |
dicarloj | 0:7757ab3f7206 | 261 | float xn = r[0][0] * cpt[0] + r[0][1] * cpt[1] + r[0][2] * cpt[2]; |
dicarloj | 0:7757ab3f7206 | 262 | float yn = r[1][0] * cpt[0] + r[1][1] * cpt[1] + r[1][2] * cpt[2]; |
dicarloj | 0:7757ab3f7206 | 263 | float zn = r[2][0] * cpt[0] + r[2][1] * cpt[1] + r[2][2] * cpt[2]; |
dicarloj | 0:7757ab3f7206 | 264 | cpt[0] = xn; |
dicarloj | 0:7757ab3f7206 | 265 | cpt[1] = yn; |
dicarloj | 0:7757ab3f7206 | 266 | cpt[2] = zn; |
dicarloj | 0:7757ab3f7206 | 267 | } |
dicarloj | 0:7757ab3f7206 | 268 | } |
dicarloj | 0:7757ab3f7206 | 269 | |
dicarloj | 0:7757ab3f7206 | 270 | void apply_xf_rot(float cpt[], float r[][3]) |
dicarloj | 0:7757ab3f7206 | 271 | { |
dicarloj | 0:7757ab3f7206 | 272 | float xn = r[0][0] * cpt[0] + r[0][1] * cpt[1] + r[0][2] * cpt[2]; |
dicarloj | 0:7757ab3f7206 | 273 | float yn = r[1][0] * cpt[0] + r[1][1] * cpt[1] + r[1][2] * cpt[2]; |
dicarloj | 0:7757ab3f7206 | 274 | float zn = r[2][0] * cpt[0] + r[2][1] * cpt[1] + r[2][2] * cpt[2]; |
dicarloj | 0:7757ab3f7206 | 275 | cpt[0] = xn; |
dicarloj | 0:7757ab3f7206 | 276 | cpt[1] = yn; |
dicarloj | 0:7757ab3f7206 | 277 | cpt[2] = zn; |
dicarloj | 0:7757ab3f7206 | 278 | } |
dicarloj | 0:7757ab3f7206 | 279 | |
dicarloj | 0:7757ab3f7206 | 280 | void draw_v_check(int8_t r,uint8_t tt) |
dicarloj | 0:7757ab3f7206 | 281 | { |
dicarloj | 0:7757ab3f7206 | 282 | for(int i = 0; i < H_RES; i++) |
dicarloj | 0:7757ab3f7206 | 283 | for(int j = 0; j < V_RES; j++) |
dicarloj | 0:7757ab3f7206 | 284 | im_line_va[i+j*H_RES] = (((i > 20) && (i < 98)) && ( tt ^(((j%(r*2))>=r) ^ ((i%(r*2)))>=r))); //checkerboard |
dicarloj | 0:7757ab3f7206 | 285 | } |
dicarloj | 0:7757ab3f7206 | 286 | |
dicarloj | 0:7757ab3f7206 | 287 | |
dicarloj | 0:7757ab3f7206 | 288 | int jjj = 0; |
dicarloj | 0:7757ab3f7206 | 289 | int f_count = DEMO_LENGTH + 10; |
dicarloj | 0:7757ab3f7206 | 290 | void draw_cube_spin(int kkkk); |
dicarloj | 0:7757ab3f7206 | 291 | //update bouncing balls |
dicarloj | 0:7757ab3f7206 | 292 | |
dicarloj | 0:7757ab3f7206 | 293 | void draw_blank() |
dicarloj | 0:7757ab3f7206 | 294 | { |
dicarloj | 0:7757ab3f7206 | 295 | for(uint16_t h = X_MIN; h < X_MAX; h++) |
dicarloj | 0:7757ab3f7206 | 296 | { |
dicarloj | 0:7757ab3f7206 | 297 | for(uint16_t v = Y_MIN; v < Y_MAX+15; v++) |
dicarloj | 0:7757ab3f7206 | 298 | { |
dicarloj | 0:7757ab3f7206 | 299 | im_line_va[v*H_RES + h] = 0; |
dicarloj | 0:7757ab3f7206 | 300 | } |
dicarloj | 0:7757ab3f7206 | 301 | } |
dicarloj | 0:7757ab3f7206 | 302 | } |
dicarloj | 0:7757ab3f7206 | 303 | |
dicarloj | 0:7757ab3f7206 | 304 | void wipe(); |
dicarloj | 0:7757ab3f7206 | 305 | |
dicarloj | 0:7757ab3f7206 | 306 | void update_image() |
dicarloj | 0:7757ab3f7206 | 307 | { |
dicarloj | 0:7757ab3f7206 | 308 | //delay |
dicarloj | 0:7757ab3f7206 | 309 | k++; |
dicarloj | 0:7757ab3f7206 | 310 | if(k%4000) return; |
dicarloj | 0:7757ab3f7206 | 311 | f_count++; |
dicarloj | 0:7757ab3f7206 | 312 | if(f_count < DEMO_LENGTH/2) |
dicarloj | 0:7757ab3f7206 | 313 | { |
dicarloj | 0:7757ab3f7206 | 314 | draw_cube_spin(0); |
dicarloj | 0:7757ab3f7206 | 315 | } |
dicarloj | 0:7757ab3f7206 | 316 | else if(f_count < DEMO_LENGTH) |
dicarloj | 0:7757ab3f7206 | 317 | { |
bwang | 1:24fd07a24094 | 318 | draw_cube_spin(0); |
dicarloj | 0:7757ab3f7206 | 319 | } |
bwang | 1:24fd07a24094 | 320 | else if(f_count < DEMO_LENGTH * 1.22) |
dicarloj | 0:7757ab3f7206 | 321 | { |
dicarloj | 0:7757ab3f7206 | 322 | for(int k = 1; k < 10; k++) |
bwang | 1:24fd07a24094 | 323 | //for(int kk = 1; kk < 3; kk++) |
dicarloj | 0:7757ab3f7206 | 324 | { |
dicarloj | 0:7757ab3f7206 | 325 | draw_v_check(k,1); |
dicarloj | 0:7757ab3f7206 | 326 | draw_v_check(k,1); |
dicarloj | 0:7757ab3f7206 | 327 | draw_v_check(k,0); |
dicarloj | 0:7757ab3f7206 | 328 | draw_v_check(k,0); |
dicarloj | 0:7757ab3f7206 | 329 | } |
dicarloj | 0:7757ab3f7206 | 330 | |
dicarloj | 0:7757ab3f7206 | 331 | draw_v_check(1,0); |
dicarloj | 0:7757ab3f7206 | 332 | wipe(); |
dicarloj | 0:7757ab3f7206 | 333 | f_count = 0; |
dicarloj | 0:7757ab3f7206 | 334 | } |
dicarloj | 0:7757ab3f7206 | 335 | } |
dicarloj | 0:7757ab3f7206 | 336 | |
dicarloj | 0:7757ab3f7206 | 337 | void wipe() |
dicarloj | 0:7757ab3f7206 | 338 | { |
dicarloj | 0:7757ab3f7206 | 339 | for(int v = Y_MIN; v < Y_MAX+15; v++) |
dicarloj | 0:7757ab3f7206 | 340 | { |
dicarloj | 0:7757ab3f7206 | 341 | for(uint16_t h = X_MIN; h < X_MAX; h++) |
dicarloj | 0:7757ab3f7206 | 342 | { |
dicarloj | 0:7757ab3f7206 | 343 | im_line_va[v*H_RES+h] = 1; |
dicarloj | 0:7757ab3f7206 | 344 | } |
bwang | 1:24fd07a24094 | 345 | wait(.01); |
dicarloj | 0:7757ab3f7206 | 346 | } |
dicarloj | 0:7757ab3f7206 | 347 | |
dicarloj | 0:7757ab3f7206 | 348 | for(int v = Y_MAX+15; v > Y_MIN; v--) |
dicarloj | 0:7757ab3f7206 | 349 | { |
dicarloj | 0:7757ab3f7206 | 350 | for(uint16_t h = X_MIN; h < X_MAX; h++) |
dicarloj | 0:7757ab3f7206 | 351 | { |
dicarloj | 0:7757ab3f7206 | 352 | im_line_va[v*H_RES+h] = 0; |
dicarloj | 0:7757ab3f7206 | 353 | } |
bwang | 1:24fd07a24094 | 354 | wait(.005); |
dicarloj | 0:7757ab3f7206 | 355 | } |
dicarloj | 0:7757ab3f7206 | 356 | |
dicarloj | 0:7757ab3f7206 | 357 | for(uint16_t h = X_MIN; h < X_MAX; h++) |
dicarloj | 0:7757ab3f7206 | 358 | { |
dicarloj | 0:7757ab3f7206 | 359 | for(uint16_t v = Y_MIN; v < Y_MAX+15; v++) |
dicarloj | 0:7757ab3f7206 | 360 | { |
dicarloj | 0:7757ab3f7206 | 361 | im_line_va[v*H_RES + h] = 1; |
dicarloj | 0:7757ab3f7206 | 362 | } |
bwang | 1:24fd07a24094 | 363 | wait(.005); |
dicarloj | 0:7757ab3f7206 | 364 | } |
dicarloj | 0:7757ab3f7206 | 365 | |
dicarloj | 0:7757ab3f7206 | 366 | for(uint16_t h = X_MIN; h < X_MAX; h++) |
dicarloj | 0:7757ab3f7206 | 367 | { |
dicarloj | 0:7757ab3f7206 | 368 | for(uint16_t v = Y_MIN; v < Y_MAX+15; v++) |
dicarloj | 0:7757ab3f7206 | 369 | { |
dicarloj | 0:7757ab3f7206 | 370 | im_line_va[v*H_RES + h] = 0; |
dicarloj | 0:7757ab3f7206 | 371 | } |
bwang | 1:24fd07a24094 | 372 | wait(.005); |
dicarloj | 0:7757ab3f7206 | 373 | } |
dicarloj | 0:7757ab3f7206 | 374 | |
dicarloj | 0:7757ab3f7206 | 375 | for(int v = Y_MIN; v < Y_MAX+15; v++) |
dicarloj | 0:7757ab3f7206 | 376 | { |
dicarloj | 0:7757ab3f7206 | 377 | for(uint16_t h = X_MIN; h < X_MAX; h++) |
dicarloj | 0:7757ab3f7206 | 378 | { |
dicarloj | 0:7757ab3f7206 | 379 | im_line_va[v*H_RES+h] = 0; |
dicarloj | 0:7757ab3f7206 | 380 | } |
dicarloj | 0:7757ab3f7206 | 381 | } |
dicarloj | 0:7757ab3f7206 | 382 | } |
dicarloj | 0:7757ab3f7206 | 383 | |
dicarloj | 0:7757ab3f7206 | 384 | void draw_cube_spin(int kkkk) |
dicarloj | 0:7757ab3f7206 | 385 | { |
dicarloj | 0:7757ab3f7206 | 386 | draw_line_inv = kkkk; |
dicarloj | 0:7757ab3f7206 | 387 | //blank |
dicarloj | 0:7757ab3f7206 | 388 | for(uint16_t h = X_MIN; h < X_MAX; h++) |
dicarloj | 0:7757ab3f7206 | 389 | { |
dicarloj | 0:7757ab3f7206 | 390 | for(uint16_t v = Y_MIN; v < Y_MAX; v++) |
dicarloj | 0:7757ab3f7206 | 391 | { |
dicarloj | 0:7757ab3f7206 | 392 | if( (h > 22) && (h < 76+18)) |
dicarloj | 0:7757ab3f7206 | 393 | im_line_va[v*H_RES + h] = kkkk; |
dicarloj | 0:7757ab3f7206 | 394 | } |
dicarloj | 0:7757ab3f7206 | 395 | } |
dicarloj | 0:7757ab3f7206 | 396 | apply_xf_rot(cube_a,y_rot); |
dicarloj | 0:7757ab3f7206 | 397 | apply_xf_rot(cube_a,y_rot); |
dicarloj | 0:7757ab3f7206 | 398 | apply_rot(cube_pts,x_rot); |
dicarloj | 0:7757ab3f7206 | 399 | apply_rot(cube_pts,x_rot); |
dicarloj | 0:7757ab3f7206 | 400 | apply_rot(cube_pts,y_rot); |
dicarloj | 0:7757ab3f7206 | 401 | apply_rot(cube_pts,y_rot); |
dicarloj | 0:7757ab3f7206 | 402 | apply_rot(cube_pts,z_rot); |
dicarloj | 0:7757ab3f7206 | 403 | //draw ball |
dicarloj | 0:7757ab3f7206 | 404 | im_line_va[(py/10)*H_RES + (px/10)] = 1; |
dicarloj | 0:7757ab3f7206 | 405 | draw_line(X_0,Y_0,(px/10),(py/10)); |
dicarloj | 0:7757ab3f7206 | 406 | draw_cube(cube_pts); |
dicarloj | 0:7757ab3f7206 | 407 | |
dicarloj | 0:7757ab3f7206 | 408 | //update position/check for bounces |
dicarloj | 0:7757ab3f7206 | 409 | px += vx; |
dicarloj | 0:7757ab3f7206 | 410 | py += vy; |
dicarloj | 0:7757ab3f7206 | 411 | px2 += vx2; |
dicarloj | 0:7757ab3f7206 | 412 | py2 += vy2; |
dicarloj | 0:7757ab3f7206 | 413 | if(px/10 > (X_MAX-2) || px/10 < (X_MIN+1)) vx = -vx; |
dicarloj | 0:7757ab3f7206 | 414 | if(py/10 > (Y_MAX-2) || py/10 < (Y_MIN+1)) vy = -vy; |
dicarloj | 0:7757ab3f7206 | 415 | if(px2/10 > (X_MAX-2) || px2/10 < (X_MIN+1)) vx2 = -vx2; |
dicarloj | 0:7757ab3f7206 | 416 | if(py2/10 > (Y_MAX-2) || py2/10 < (Y_MIN+1)) vy2 = -vy2; |
dicarloj | 0:7757ab3f7206 | 417 | if(k%(8000*50)) return; |
dicarloj | 0:7757ab3f7206 | 418 | |
dicarloj | 0:7757ab3f7206 | 419 | jjj = !jjj; |
dicarloj | 0:7757ab3f7206 | 420 | int bmi = 0; |
dicarloj | 0:7757ab3f7206 | 421 | for(int y = BY_0; y < BY_0 + BY; y++) |
dicarloj | 0:7757ab3f7206 | 422 | { |
dicarloj | 0:7757ab3f7206 | 423 | for(int x = BX_0; x < BX_0 + BX; x++) |
dicarloj | 0:7757ab3f7206 | 424 | { |
dicarloj | 0:7757ab3f7206 | 425 | im_line_va[H_RES*y + x] = kkkk^(miters[bmi]*jjj + (!jjj)*tv[bmi]); |
dicarloj | 0:7757ab3f7206 | 426 | bmi++; |
dicarloj | 0:7757ab3f7206 | 427 | } |
dicarloj | 0:7757ab3f7206 | 428 | } |
dicarloj | 0:7757ab3f7206 | 429 | } |
dicarloj | 0:7757ab3f7206 | 430 | |
dicarloj | 0:7757ab3f7206 | 431 | int main() { |
bwang | 1:24fd07a24094 | 432 | potato: |
dicarloj | 0:7757ab3f7206 | 433 | init_buffers(); |
dicarloj | 0:7757ab3f7206 | 434 | t.attach_us(&isr,63); |
bwang | 1:24fd07a24094 | 435 | for(int y = 0; y < PADDLE_LEN; y++) { |
bwang | 1:24fd07a24094 | 436 | im_line_va[H_RES*(y+(int)p1)+SX_MIN] = 1; |
bwang | 1:24fd07a24094 | 437 | im_line_va[H_RES*(y+(int)p2)+SX_MAX] = 1; |
bwang | 1:24fd07a24094 | 438 | } |
bwang | 1:24fd07a24094 | 439 | im_line_va[H_RES*(int)by+(int)bx] = 1; |
dicarloj | 0:7757ab3f7206 | 440 | for(;;) |
bwang | 1:24fd07a24094 | 441 | { |
bwang | 1:24fd07a24094 | 442 | for(int y = 0; y < PADDLE_LEN; y++) { |
bwang | 1:24fd07a24094 | 443 | im_line_va[H_RES*(y+(int)p1)+SX_MIN] = 0; |
bwang | 1:24fd07a24094 | 444 | im_line_va[H_RES*(y+(int)p2)+SX_MAX] = 0; |
bwang | 1:24fd07a24094 | 445 | } |
bwang | 1:24fd07a24094 | 446 | im_line_va[H_RES*(int)by+(int)bx] = 0; |
bwang | 1:24fd07a24094 | 447 | |
bwang | 1:24fd07a24094 | 448 | int cmd1 = p1_in.read(); |
bwang | 1:24fd07a24094 | 449 | int cmd2 = p2_in.read(); |
bwang | 1:24fd07a24094 | 450 | if (cmd1 == 0) p1v = 0.1; else p1v = -0.1f; |
bwang | 1:24fd07a24094 | 451 | if (cmd2 == 0) p2v = 0.1; else p2v = -0.1f; |
bwang | 1:24fd07a24094 | 452 | |
bwang | 1:24fd07a24094 | 453 | p1 += p1v; |
bwang | 1:24fd07a24094 | 454 | p2 += p2v; |
bwang | 1:24fd07a24094 | 455 | bx += bxv; |
bwang | 1:24fd07a24094 | 456 | by += byv; |
bwang | 1:24fd07a24094 | 457 | |
bwang | 1:24fd07a24094 | 458 | if (p1 < SY_MIN) p1 = SY_MIN; |
bwang | 1:24fd07a24094 | 459 | if (p1 > SY_MAX-PADDLE_LEN) p1 = SY_MAX-PADDLE_LEN; |
bwang | 1:24fd07a24094 | 460 | if (p2 < SY_MIN) p2 = SY_MIN; |
bwang | 1:24fd07a24094 | 461 | if (p2 > SY_MAX-PADDLE_LEN) p2 = SY_MAX-PADDLE_LEN; |
bwang | 1:24fd07a24094 | 462 | |
bwang | 1:24fd07a24094 | 463 | if (bx < SX_MIN) { |
bwang | 1:24fd07a24094 | 464 | bxv = -bxv; |
bwang | 1:24fd07a24094 | 465 | bx = SX_MIN; |
bwang | 1:24fd07a24094 | 466 | if ((int) by < (int) p1 || (int) by > (int) (p1 + 10)) break; |
bwang | 1:24fd07a24094 | 467 | } |
bwang | 1:24fd07a24094 | 468 | if (bx > SX_MAX) { |
bwang | 1:24fd07a24094 | 469 | bxv = -bxv; |
bwang | 1:24fd07a24094 | 470 | bx = SX_MAX; |
bwang | 1:24fd07a24094 | 471 | if ((int) by < (int) p2 || (int) by > (int) (p2 + 10)) break; |
bwang | 1:24fd07a24094 | 472 | } |
bwang | 1:24fd07a24094 | 473 | if (by < SY_MIN) {byv = -byv; by = SY_MIN;} |
bwang | 1:24fd07a24094 | 474 | if (by > SY_MAX) {byv = -byv; by = SY_MAX;} |
bwang | 1:24fd07a24094 | 475 | |
bwang | 1:24fd07a24094 | 476 | for(int y = 0; y < PADDLE_LEN; y++) { |
bwang | 1:24fd07a24094 | 477 | im_line_va[H_RES*(y+(int)p1)+SX_MIN] = 1; |
bwang | 1:24fd07a24094 | 478 | im_line_va[H_RES*(y+(int)p2)+SX_MAX] = 1; |
bwang | 1:24fd07a24094 | 479 | } |
bwang | 1:24fd07a24094 | 480 | im_line_va[H_RES*(int)by+(int)bx] = 1; |
bwang | 1:24fd07a24094 | 481 | |
bwang | 1:24fd07a24094 | 482 | wait(1/600.0f); |
bwang | 1:24fd07a24094 | 483 | } |
bwang | 1:24fd07a24094 | 484 | |
bwang | 1:24fd07a24094 | 485 | p1 = (SY_MIN+SY_MAX)/2-PADDLE_LEN/2, p2 = (SY_MIN+SY_MAX)/2-PADDLE_LEN/2; |
bwang | 1:24fd07a24094 | 486 | p1v = 0.1, p2v = -0.1; |
bwang | 1:24fd07a24094 | 487 | |
bwang | 1:24fd07a24094 | 488 | bx = (SX_MIN+SX_MAX)/2, by = (SY_MIN+SY_MAX)/2; |
bwang | 1:24fd07a24094 | 489 | bxv = 0.03, byv = 0.03; |
bwang | 1:24fd07a24094 | 490 | for (;;) |
bwang | 1:24fd07a24094 | 491 | { |
bwang | 1:24fd07a24094 | 492 | for(int i = 0; i < 20000; i++) |
bwang | 1:24fd07a24094 | 493 | update_image(); |
bwang | 1:24fd07a24094 | 494 | if(!p1_in.read() || !p2_in.read()) goto potato; |
dicarloj | 0:7757ab3f7206 | 495 | } |
dicarloj | 0:7757ab3f7206 | 496 | } |