Bayley Wang
/
manworm_tv_raster
cube
Fork of manworm_tv_gpu by
main.cpp@2:1d16e99f334b, 2017-11-18 (annotated)
- Committer:
- bwang
- Date:
- Sat Nov 18 08:36:25 2017 +0000
- Revision:
- 2:1d16e99f334b
- Parent:
- 1:24fd07a24094
- Child:
- 3:d9edc0575aa3
porf
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 | 2:1d16e99f334b | 11 | int SX_MAX = 95; |
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 | 2:1d16e99f334b | 115 | int s1 = 0, s2 = 0; |
bwang | 2:1d16e99f334b | 116 | |
bwang | 2:1d16e99f334b | 117 | DigitalIn p1_in(A1); |
bwang | 2:1d16e99f334b | 118 | DigitalIn p2_in(A0); |
bwang | 1:24fd07a24094 | 119 | |
dicarloj | 0:7757ab3f7206 | 120 | void make_checkerboard() |
dicarloj | 0:7757ab3f7206 | 121 | { |
dicarloj | 0:7757ab3f7206 | 122 | for(int i = 0; i < H_RES; i++) |
dicarloj | 0:7757ab3f7206 | 123 | for(int j = 0; j < V_RES; j++) |
bwang | 1:24fd07a24094 | 124 | im_line_va[i+j*H_RES] = 0*((i > 20) && (i < 98)) && ((j%2) ^ (i%2)); //checkerboard |
dicarloj | 0:7757ab3f7206 | 125 | |
dicarloj | 0:7757ab3f7206 | 126 | } |
dicarloj | 0:7757ab3f7206 | 127 | |
dicarloj | 0:7757ab3f7206 | 128 | void init_buffers() |
dicarloj | 0:7757ab3f7206 | 129 | { |
dicarloj | 0:7757ab3f7206 | 130 | make_checkerboard(); |
dicarloj | 0:7757ab3f7206 | 131 | for(int i = 0; i < H_RES; i++) |
dicarloj | 0:7757ab3f7206 | 132 | { |
dicarloj | 0:7757ab3f7206 | 133 | im_line_s[i] = 1; |
dicarloj | 0:7757ab3f7206 | 134 | bl_line_s[i] = 1; |
dicarloj | 0:7757ab3f7206 | 135 | bl_line_v[i] = 0; |
dicarloj | 0:7757ab3f7206 | 136 | vb_line_s[i] = 0; |
dicarloj | 0:7757ab3f7206 | 137 | vb_line_v[i] = 0; |
dicarloj | 0:7757ab3f7206 | 138 | } |
dicarloj | 0:7757ab3f7206 | 139 | im_line_s[0] = 0; |
dicarloj | 0:7757ab3f7206 | 140 | im_line_s[1] = 0; |
dicarloj | 0:7757ab3f7206 | 141 | im_line_s[2] = 0; |
dicarloj | 0:7757ab3f7206 | 142 | bl_line_s[0] = 0; |
dicarloj | 0:7757ab3f7206 | 143 | vb_line_s[0] = 1; |
dicarloj | 0:7757ab3f7206 | 144 | bl_line_s[1] = 0; |
dicarloj | 0:7757ab3f7206 | 145 | vb_line_s[1] = 1; |
dicarloj | 0:7757ab3f7206 | 146 | |
dicarloj | 0:7757ab3f7206 | 147 | |
dicarloj | 0:7757ab3f7206 | 148 | |
dicarloj | 0:7757ab3f7206 | 149 | } |
dicarloj | 0:7757ab3f7206 | 150 | void isr() |
dicarloj | 0:7757ab3f7206 | 151 | { |
dicarloj | 0:7757ab3f7206 | 152 | uint8_t nop = 0; //use nops or use wait_us |
dicarloj | 0:7757ab3f7206 | 153 | uint8_t* sptr; //pointer to sync buffer for line |
dicarloj | 0:7757ab3f7206 | 154 | uint8_t* vptr; //pointer to video buffer for line |
dicarloj | 0:7757ab3f7206 | 155 | if(l < V_RES){ vptr = im_line_va + ((l/4)*H_RES); sptr = im_line_s; nop = 1; } //pick line buffers |
dicarloj | 0:7757ab3f7206 | 156 | else if(l < 254){ vptr = bl_line_v; sptr = bl_line_s; nop = 0; } |
dicarloj | 0:7757ab3f7206 | 157 | else{ vptr = vb_line_v; sptr = vb_line_s; nop = 1;} |
dicarloj | 0:7757ab3f7206 | 158 | uint8_t lmax = nop?H_RES:12; //number of columns |
dicarloj | 0:7757ab3f7206 | 159 | for(uint8_t i = 0; i < lmax; i++) //loop over each column |
dicarloj | 0:7757ab3f7206 | 160 | { |
dicarloj | 0:7757ab3f7206 | 161 | vout = vptr[i]; //set output pins |
dicarloj | 0:7757ab3f7206 | 162 | sout = sptr[i]; |
dicarloj | 0:7757ab3f7206 | 163 | if(nop) //nop delay |
dicarloj | 0:7757ab3f7206 | 164 | { |
dicarloj | 0:7757ab3f7206 | 165 | 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 | 166 | } |
dicarloj | 0:7757ab3f7206 | 167 | else {wait_us(1); if(i > 2) i++;} //wait delay |
dicarloj | 0:7757ab3f7206 | 168 | |
dicarloj | 0:7757ab3f7206 | 169 | |
dicarloj | 0:7757ab3f7206 | 170 | } |
dicarloj | 0:7757ab3f7206 | 171 | //move to next line |
dicarloj | 0:7757ab3f7206 | 172 | l++; |
dicarloj | 0:7757ab3f7206 | 173 | if(l > 255) l = 0; |
dicarloj | 0:7757ab3f7206 | 174 | } |
dicarloj | 0:7757ab3f7206 | 175 | |
dicarloj | 0:7757ab3f7206 | 176 | //coordinates for bouncing ball |
dicarloj | 0:7757ab3f7206 | 177 | |
dicarloj | 0:7757ab3f7206 | 178 | |
dicarloj | 0:7757ab3f7206 | 179 | |
dicarloj | 0:7757ab3f7206 | 180 | int k = 0; |
dicarloj | 0:7757ab3f7206 | 181 | uint16_t px = X_0*10; |
dicarloj | 0:7757ab3f7206 | 182 | uint16_t py = Y_0*10; |
dicarloj | 0:7757ab3f7206 | 183 | uint16_t vx = 10; |
dicarloj | 0:7757ab3f7206 | 184 | uint16_t vy = 10; |
dicarloj | 0:7757ab3f7206 | 185 | uint16_t px2 = X_0*10 + 80; |
dicarloj | 0:7757ab3f7206 | 186 | uint16_t py2 = Y_0*10 - 40; |
dicarloj | 0:7757ab3f7206 | 187 | uint16_t vx2 = 3; |
dicarloj | 0:7757ab3f7206 | 188 | uint16_t vy2 = -4; |
dicarloj | 0:7757ab3f7206 | 189 | |
dicarloj | 0:7757ab3f7206 | 190 | int16_t sign(int16_t a) |
dicarloj | 0:7757ab3f7206 | 191 | { |
dicarloj | 0:7757ab3f7206 | 192 | if(a > 0) return 1; |
dicarloj | 0:7757ab3f7206 | 193 | if(a < 0) return -1; |
dicarloj | 0:7757ab3f7206 | 194 | return 0; |
dicarloj | 0:7757ab3f7206 | 195 | } |
dicarloj | 0:7757ab3f7206 | 196 | |
dicarloj | 0:7757ab3f7206 | 197 | void draw_vert(int16_t y0, int16_t y1, int16_t x0) |
dicarloj | 0:7757ab3f7206 | 198 | { |
dicarloj | 0:7757ab3f7206 | 199 | for(int16_t i = y0; i < y1; i++) |
dicarloj | 0:7757ab3f7206 | 200 | im_line_va[H_RES*i + x0] = 1; |
dicarloj | 0:7757ab3f7206 | 201 | } |
dicarloj | 0:7757ab3f7206 | 202 | |
dicarloj | 0:7757ab3f7206 | 203 | void draw_horiz(int16_t x0, int16_t x1, int16_t y0) |
dicarloj | 0:7757ab3f7206 | 204 | { |
dicarloj | 0:7757ab3f7206 | 205 | for(int16_t i = x0; i < x1; i++) |
dicarloj | 0:7757ab3f7206 | 206 | im_line_va[H_RES*y0 + i] = 1; |
dicarloj | 0:7757ab3f7206 | 207 | } |
dicarloj | 0:7757ab3f7206 | 208 | |
dicarloj | 0:7757ab3f7206 | 209 | int16_t imin(int16_t a, int16_t b) |
dicarloj | 0:7757ab3f7206 | 210 | { |
dicarloj | 0:7757ab3f7206 | 211 | if(a<b) return a; |
dicarloj | 0:7757ab3f7206 | 212 | return b; |
dicarloj | 0:7757ab3f7206 | 213 | } |
dicarloj | 0:7757ab3f7206 | 214 | |
dicarloj | 0:7757ab3f7206 | 215 | int16_t imax(int16_t a, int16_t b) |
dicarloj | 0:7757ab3f7206 | 216 | { |
dicarloj | 0:7757ab3f7206 | 217 | if(a>b) return a; |
dicarloj | 0:7757ab3f7206 | 218 | return b; |
dicarloj | 0:7757ab3f7206 | 219 | } |
dicarloj | 0:7757ab3f7206 | 220 | |
dicarloj | 0:7757ab3f7206 | 221 | void draw_line(int16_t x0, int16_t y0, int16_t x1, int16_t y1) |
dicarloj | 0:7757ab3f7206 | 222 | { |
dicarloj | 0:7757ab3f7206 | 223 | if(x0 > x1){ x0 = x0 ^ x1; x1 = x1^x0; x0 = x0^x1;y0 = y0 ^ y1; y1 = y1^y0; y0 = y0^y1; } |
dicarloj | 0:7757ab3f7206 | 224 | if(x0 == x1){draw_vert(y0,y1,x0);} |
dicarloj | 0:7757ab3f7206 | 225 | if(y0 == y1){draw_horiz(x0,x1,y0);} |
dicarloj | 0:7757ab3f7206 | 226 | int16_t dx = x1 - x0; |
dicarloj | 0:7757ab3f7206 | 227 | int16_t dy = y1 - y0; |
dicarloj | 0:7757ab3f7206 | 228 | float derr = fabs((float)(dy)/(float)(dx)); |
dicarloj | 0:7757ab3f7206 | 229 | float err = 0.f; |
dicarloj | 0:7757ab3f7206 | 230 | int16_t y = y0; |
dicarloj | 0:7757ab3f7206 | 231 | for(int16_t x = x0; x < x1; x++) |
dicarloj | 0:7757ab3f7206 | 232 | { |
dicarloj | 0:7757ab3f7206 | 233 | //plotxy |
dicarloj | 0:7757ab3f7206 | 234 | im_line_va[H_RES*y + x] = !draw_line_inv; |
dicarloj | 0:7757ab3f7206 | 235 | err += derr; |
dicarloj | 0:7757ab3f7206 | 236 | while(err >= 0.5f) |
dicarloj | 0:7757ab3f7206 | 237 | { |
dicarloj | 0:7757ab3f7206 | 238 | y += sign(dy); |
dicarloj | 0:7757ab3f7206 | 239 | im_line_va[H_RES*y + x] = !draw_line_inv; |
dicarloj | 0:7757ab3f7206 | 240 | err -= 1.f; |
dicarloj | 0:7757ab3f7206 | 241 | } |
dicarloj | 0:7757ab3f7206 | 242 | } |
dicarloj | 0:7757ab3f7206 | 243 | } |
dicarloj | 0:7757ab3f7206 | 244 | |
dicarloj | 0:7757ab3f7206 | 245 | void draw_cube(float cp[][3]) |
dicarloj | 0:7757ab3f7206 | 246 | { |
dicarloj | 0:7757ab3f7206 | 247 | for(uint8_t i = 0; i < 7; i++) |
dicarloj | 0:7757ab3f7206 | 248 | { |
dicarloj | 0:7757ab3f7206 | 249 | 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 | 250 | } |
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[3][0]+cube_a[0]+X_0,(int16_t)cp[3][1]+cube_a[1]+Y_0); |
dicarloj | 0:7757ab3f7206 | 252 | 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 | 253 | 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 | 254 | 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 | 255 | 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 | 256 | } |
dicarloj | 0:7757ab3f7206 | 257 | |
dicarloj | 0:7757ab3f7206 | 258 | void apply_rot(float cp[][3], float r[][3]) |
dicarloj | 0:7757ab3f7206 | 259 | { |
dicarloj | 0:7757ab3f7206 | 260 | for(uint8_t pti = 0; pti < 8; pti++) |
dicarloj | 0:7757ab3f7206 | 261 | { |
dicarloj | 0:7757ab3f7206 | 262 | float* cpt = cp[pti]; |
dicarloj | 0:7757ab3f7206 | 263 | float xn = r[0][0] * cpt[0] + r[0][1] * cpt[1] + r[0][2] * cpt[2]; |
dicarloj | 0:7757ab3f7206 | 264 | float yn = r[1][0] * cpt[0] + r[1][1] * cpt[1] + r[1][2] * cpt[2]; |
dicarloj | 0:7757ab3f7206 | 265 | float zn = r[2][0] * cpt[0] + r[2][1] * cpt[1] + r[2][2] * cpt[2]; |
dicarloj | 0:7757ab3f7206 | 266 | cpt[0] = xn; |
dicarloj | 0:7757ab3f7206 | 267 | cpt[1] = yn; |
dicarloj | 0:7757ab3f7206 | 268 | cpt[2] = zn; |
dicarloj | 0:7757ab3f7206 | 269 | } |
dicarloj | 0:7757ab3f7206 | 270 | } |
dicarloj | 0:7757ab3f7206 | 271 | |
dicarloj | 0:7757ab3f7206 | 272 | void apply_xf_rot(float cpt[], float r[][3]) |
dicarloj | 0:7757ab3f7206 | 273 | { |
dicarloj | 0:7757ab3f7206 | 274 | float xn = r[0][0] * cpt[0] + r[0][1] * cpt[1] + r[0][2] * cpt[2]; |
dicarloj | 0:7757ab3f7206 | 275 | float yn = r[1][0] * cpt[0] + r[1][1] * cpt[1] + r[1][2] * cpt[2]; |
dicarloj | 0:7757ab3f7206 | 276 | float zn = r[2][0] * cpt[0] + r[2][1] * cpt[1] + r[2][2] * cpt[2]; |
dicarloj | 0:7757ab3f7206 | 277 | cpt[0] = xn; |
dicarloj | 0:7757ab3f7206 | 278 | cpt[1] = yn; |
dicarloj | 0:7757ab3f7206 | 279 | cpt[2] = zn; |
dicarloj | 0:7757ab3f7206 | 280 | } |
dicarloj | 0:7757ab3f7206 | 281 | |
dicarloj | 0:7757ab3f7206 | 282 | void draw_v_check(int8_t r,uint8_t tt) |
dicarloj | 0:7757ab3f7206 | 283 | { |
dicarloj | 0:7757ab3f7206 | 284 | for(int i = 0; i < H_RES; i++) |
dicarloj | 0:7757ab3f7206 | 285 | for(int j = 0; j < V_RES; j++) |
dicarloj | 0:7757ab3f7206 | 286 | im_line_va[i+j*H_RES] = (((i > 20) && (i < 98)) && ( tt ^(((j%(r*2))>=r) ^ ((i%(r*2)))>=r))); //checkerboard |
dicarloj | 0:7757ab3f7206 | 287 | } |
dicarloj | 0:7757ab3f7206 | 288 | |
dicarloj | 0:7757ab3f7206 | 289 | |
dicarloj | 0:7757ab3f7206 | 290 | int jjj = 0; |
dicarloj | 0:7757ab3f7206 | 291 | int f_count = DEMO_LENGTH + 10; |
dicarloj | 0:7757ab3f7206 | 292 | void draw_cube_spin(int kkkk); |
dicarloj | 0:7757ab3f7206 | 293 | //update bouncing balls |
dicarloj | 0:7757ab3f7206 | 294 | |
dicarloj | 0:7757ab3f7206 | 295 | void draw_blank() |
dicarloj | 0:7757ab3f7206 | 296 | { |
dicarloj | 0:7757ab3f7206 | 297 | for(uint16_t h = X_MIN; h < X_MAX; h++) |
dicarloj | 0:7757ab3f7206 | 298 | { |
dicarloj | 0:7757ab3f7206 | 299 | for(uint16_t v = Y_MIN; v < Y_MAX+15; v++) |
dicarloj | 0:7757ab3f7206 | 300 | { |
dicarloj | 0:7757ab3f7206 | 301 | im_line_va[v*H_RES + h] = 0; |
dicarloj | 0:7757ab3f7206 | 302 | } |
dicarloj | 0:7757ab3f7206 | 303 | } |
dicarloj | 0:7757ab3f7206 | 304 | } |
dicarloj | 0:7757ab3f7206 | 305 | |
dicarloj | 0:7757ab3f7206 | 306 | void wipe(); |
dicarloj | 0:7757ab3f7206 | 307 | |
dicarloj | 0:7757ab3f7206 | 308 | void update_image() |
dicarloj | 0:7757ab3f7206 | 309 | { |
dicarloj | 0:7757ab3f7206 | 310 | //delay |
dicarloj | 0:7757ab3f7206 | 311 | k++; |
dicarloj | 0:7757ab3f7206 | 312 | if(k%4000) return; |
dicarloj | 0:7757ab3f7206 | 313 | f_count++; |
dicarloj | 0:7757ab3f7206 | 314 | if(f_count < DEMO_LENGTH/2) |
dicarloj | 0:7757ab3f7206 | 315 | { |
dicarloj | 0:7757ab3f7206 | 316 | draw_cube_spin(0); |
dicarloj | 0:7757ab3f7206 | 317 | } |
dicarloj | 0:7757ab3f7206 | 318 | else if(f_count < DEMO_LENGTH) |
dicarloj | 0:7757ab3f7206 | 319 | { |
bwang | 1:24fd07a24094 | 320 | draw_cube_spin(0); |
dicarloj | 0:7757ab3f7206 | 321 | } |
bwang | 1:24fd07a24094 | 322 | else if(f_count < DEMO_LENGTH * 1.22) |
dicarloj | 0:7757ab3f7206 | 323 | { |
dicarloj | 0:7757ab3f7206 | 324 | for(int k = 1; k < 10; k++) |
bwang | 1:24fd07a24094 | 325 | //for(int kk = 1; kk < 3; kk++) |
dicarloj | 0:7757ab3f7206 | 326 | { |
dicarloj | 0:7757ab3f7206 | 327 | draw_v_check(k,1); |
dicarloj | 0:7757ab3f7206 | 328 | draw_v_check(k,1); |
dicarloj | 0:7757ab3f7206 | 329 | draw_v_check(k,0); |
dicarloj | 0:7757ab3f7206 | 330 | draw_v_check(k,0); |
dicarloj | 0:7757ab3f7206 | 331 | } |
dicarloj | 0:7757ab3f7206 | 332 | |
dicarloj | 0:7757ab3f7206 | 333 | draw_v_check(1,0); |
dicarloj | 0:7757ab3f7206 | 334 | wipe(); |
dicarloj | 0:7757ab3f7206 | 335 | f_count = 0; |
dicarloj | 0:7757ab3f7206 | 336 | } |
dicarloj | 0:7757ab3f7206 | 337 | } |
dicarloj | 0:7757ab3f7206 | 338 | |
dicarloj | 0:7757ab3f7206 | 339 | void wipe() |
dicarloj | 0:7757ab3f7206 | 340 | { |
dicarloj | 0:7757ab3f7206 | 341 | for(int v = Y_MIN; v < Y_MAX+15; v++) |
dicarloj | 0:7757ab3f7206 | 342 | { |
dicarloj | 0:7757ab3f7206 | 343 | for(uint16_t h = X_MIN; h < X_MAX; h++) |
dicarloj | 0:7757ab3f7206 | 344 | { |
dicarloj | 0:7757ab3f7206 | 345 | im_line_va[v*H_RES+h] = 1; |
dicarloj | 0:7757ab3f7206 | 346 | } |
bwang | 1:24fd07a24094 | 347 | wait(.01); |
dicarloj | 0:7757ab3f7206 | 348 | } |
dicarloj | 0:7757ab3f7206 | 349 | |
dicarloj | 0:7757ab3f7206 | 350 | for(int v = Y_MAX+15; v > Y_MIN; v--) |
dicarloj | 0:7757ab3f7206 | 351 | { |
dicarloj | 0:7757ab3f7206 | 352 | for(uint16_t h = X_MIN; h < X_MAX; h++) |
dicarloj | 0:7757ab3f7206 | 353 | { |
dicarloj | 0:7757ab3f7206 | 354 | im_line_va[v*H_RES+h] = 0; |
dicarloj | 0:7757ab3f7206 | 355 | } |
bwang | 1:24fd07a24094 | 356 | wait(.005); |
dicarloj | 0:7757ab3f7206 | 357 | } |
dicarloj | 0:7757ab3f7206 | 358 | |
dicarloj | 0:7757ab3f7206 | 359 | for(uint16_t h = X_MIN; h < X_MAX; h++) |
dicarloj | 0:7757ab3f7206 | 360 | { |
dicarloj | 0:7757ab3f7206 | 361 | for(uint16_t v = Y_MIN; v < Y_MAX+15; v++) |
dicarloj | 0:7757ab3f7206 | 362 | { |
dicarloj | 0:7757ab3f7206 | 363 | im_line_va[v*H_RES + h] = 1; |
dicarloj | 0:7757ab3f7206 | 364 | } |
bwang | 1:24fd07a24094 | 365 | wait(.005); |
dicarloj | 0:7757ab3f7206 | 366 | } |
dicarloj | 0:7757ab3f7206 | 367 | |
dicarloj | 0:7757ab3f7206 | 368 | for(uint16_t h = X_MIN; h < X_MAX; h++) |
dicarloj | 0:7757ab3f7206 | 369 | { |
dicarloj | 0:7757ab3f7206 | 370 | for(uint16_t v = Y_MIN; v < Y_MAX+15; v++) |
dicarloj | 0:7757ab3f7206 | 371 | { |
dicarloj | 0:7757ab3f7206 | 372 | im_line_va[v*H_RES + h] = 0; |
dicarloj | 0:7757ab3f7206 | 373 | } |
bwang | 1:24fd07a24094 | 374 | wait(.005); |
dicarloj | 0:7757ab3f7206 | 375 | } |
dicarloj | 0:7757ab3f7206 | 376 | |
dicarloj | 0:7757ab3f7206 | 377 | for(int v = Y_MIN; v < Y_MAX+15; v++) |
dicarloj | 0:7757ab3f7206 | 378 | { |
dicarloj | 0:7757ab3f7206 | 379 | for(uint16_t h = X_MIN; h < X_MAX; h++) |
dicarloj | 0:7757ab3f7206 | 380 | { |
dicarloj | 0:7757ab3f7206 | 381 | im_line_va[v*H_RES+h] = 0; |
dicarloj | 0:7757ab3f7206 | 382 | } |
dicarloj | 0:7757ab3f7206 | 383 | } |
dicarloj | 0:7757ab3f7206 | 384 | } |
dicarloj | 0:7757ab3f7206 | 385 | |
dicarloj | 0:7757ab3f7206 | 386 | void draw_cube_spin(int kkkk) |
dicarloj | 0:7757ab3f7206 | 387 | { |
dicarloj | 0:7757ab3f7206 | 388 | draw_line_inv = kkkk; |
dicarloj | 0:7757ab3f7206 | 389 | //blank |
dicarloj | 0:7757ab3f7206 | 390 | for(uint16_t h = X_MIN; h < X_MAX; h++) |
dicarloj | 0:7757ab3f7206 | 391 | { |
dicarloj | 0:7757ab3f7206 | 392 | for(uint16_t v = Y_MIN; v < Y_MAX; v++) |
dicarloj | 0:7757ab3f7206 | 393 | { |
dicarloj | 0:7757ab3f7206 | 394 | if( (h > 22) && (h < 76+18)) |
dicarloj | 0:7757ab3f7206 | 395 | im_line_va[v*H_RES + h] = kkkk; |
dicarloj | 0:7757ab3f7206 | 396 | } |
dicarloj | 0:7757ab3f7206 | 397 | } |
dicarloj | 0:7757ab3f7206 | 398 | apply_xf_rot(cube_a,y_rot); |
dicarloj | 0:7757ab3f7206 | 399 | apply_xf_rot(cube_a,y_rot); |
dicarloj | 0:7757ab3f7206 | 400 | apply_rot(cube_pts,x_rot); |
dicarloj | 0:7757ab3f7206 | 401 | apply_rot(cube_pts,x_rot); |
dicarloj | 0:7757ab3f7206 | 402 | apply_rot(cube_pts,y_rot); |
dicarloj | 0:7757ab3f7206 | 403 | apply_rot(cube_pts,y_rot); |
dicarloj | 0:7757ab3f7206 | 404 | apply_rot(cube_pts,z_rot); |
dicarloj | 0:7757ab3f7206 | 405 | //draw ball |
dicarloj | 0:7757ab3f7206 | 406 | im_line_va[(py/10)*H_RES + (px/10)] = 1; |
dicarloj | 0:7757ab3f7206 | 407 | draw_line(X_0,Y_0,(px/10),(py/10)); |
dicarloj | 0:7757ab3f7206 | 408 | draw_cube(cube_pts); |
dicarloj | 0:7757ab3f7206 | 409 | |
dicarloj | 0:7757ab3f7206 | 410 | //update position/check for bounces |
dicarloj | 0:7757ab3f7206 | 411 | px += vx; |
dicarloj | 0:7757ab3f7206 | 412 | py += vy; |
dicarloj | 0:7757ab3f7206 | 413 | px2 += vx2; |
dicarloj | 0:7757ab3f7206 | 414 | py2 += vy2; |
dicarloj | 0:7757ab3f7206 | 415 | if(px/10 > (X_MAX-2) || px/10 < (X_MIN+1)) vx = -vx; |
dicarloj | 0:7757ab3f7206 | 416 | if(py/10 > (Y_MAX-2) || py/10 < (Y_MIN+1)) vy = -vy; |
dicarloj | 0:7757ab3f7206 | 417 | if(px2/10 > (X_MAX-2) || px2/10 < (X_MIN+1)) vx2 = -vx2; |
dicarloj | 0:7757ab3f7206 | 418 | if(py2/10 > (Y_MAX-2) || py2/10 < (Y_MIN+1)) vy2 = -vy2; |
dicarloj | 0:7757ab3f7206 | 419 | if(k%(8000*50)) return; |
dicarloj | 0:7757ab3f7206 | 420 | |
dicarloj | 0:7757ab3f7206 | 421 | jjj = !jjj; |
dicarloj | 0:7757ab3f7206 | 422 | int bmi = 0; |
dicarloj | 0:7757ab3f7206 | 423 | for(int y = BY_0; y < BY_0 + BY; y++) |
dicarloj | 0:7757ab3f7206 | 424 | { |
dicarloj | 0:7757ab3f7206 | 425 | for(int x = BX_0; x < BX_0 + BX; x++) |
dicarloj | 0:7757ab3f7206 | 426 | { |
dicarloj | 0:7757ab3f7206 | 427 | im_line_va[H_RES*y + x] = kkkk^(miters[bmi]*jjj + (!jjj)*tv[bmi]); |
dicarloj | 0:7757ab3f7206 | 428 | bmi++; |
dicarloj | 0:7757ab3f7206 | 429 | } |
dicarloj | 0:7757ab3f7206 | 430 | } |
dicarloj | 0:7757ab3f7206 | 431 | } |
dicarloj | 0:7757ab3f7206 | 432 | |
dicarloj | 0:7757ab3f7206 | 433 | int main() { |
bwang | 1:24fd07a24094 | 434 | potato: |
dicarloj | 0:7757ab3f7206 | 435 | init_buffers(); |
dicarloj | 0:7757ab3f7206 | 436 | t.attach_us(&isr,63); |
bwang | 1:24fd07a24094 | 437 | for(int y = 0; y < PADDLE_LEN; y++) { |
bwang | 1:24fd07a24094 | 438 | im_line_va[H_RES*(y+(int)p1)+SX_MIN] = 1; |
bwang | 1:24fd07a24094 | 439 | im_line_va[H_RES*(y+(int)p2)+SX_MAX] = 1; |
bwang | 1:24fd07a24094 | 440 | } |
bwang | 1:24fd07a24094 | 441 | im_line_va[H_RES*(int)by+(int)bx] = 1; |
dicarloj | 0:7757ab3f7206 | 442 | for(;;) |
bwang | 1:24fd07a24094 | 443 | { |
bwang | 2:1d16e99f334b | 444 | //clear frame |
bwang | 1:24fd07a24094 | 445 | for(int y = 0; y < PADDLE_LEN; y++) { |
bwang | 1:24fd07a24094 | 446 | im_line_va[H_RES*(y+(int)p1)+SX_MIN] = 0; |
bwang | 1:24fd07a24094 | 447 | im_line_va[H_RES*(y+(int)p2)+SX_MAX] = 0; |
bwang | 1:24fd07a24094 | 448 | } |
bwang | 1:24fd07a24094 | 449 | im_line_va[H_RES*(int)by+(int)bx] = 0; |
bwang | 2:1d16e99f334b | 450 | //read inputs |
bwang | 1:24fd07a24094 | 451 | int cmd1 = p1_in.read(); |
bwang | 1:24fd07a24094 | 452 | int cmd2 = p2_in.read(); |
bwang | 1:24fd07a24094 | 453 | if (cmd1 == 0) p1v = 0.1; else p1v = -0.1f; |
bwang | 1:24fd07a24094 | 454 | if (cmd2 == 0) p2v = 0.1; else p2v = -0.1f; |
bwang | 1:24fd07a24094 | 455 | |
bwang | 1:24fd07a24094 | 456 | p1 += p1v; |
bwang | 1:24fd07a24094 | 457 | p2 += p2v; |
bwang | 1:24fd07a24094 | 458 | bx += bxv; |
bwang | 1:24fd07a24094 | 459 | by += byv; |
bwang | 1:24fd07a24094 | 460 | |
bwang | 1:24fd07a24094 | 461 | if (p1 < SY_MIN) p1 = SY_MIN; |
bwang | 1:24fd07a24094 | 462 | if (p1 > SY_MAX-PADDLE_LEN) p1 = SY_MAX-PADDLE_LEN; |
bwang | 1:24fd07a24094 | 463 | if (p2 < SY_MIN) p2 = SY_MIN; |
bwang | 1:24fd07a24094 | 464 | if (p2 > SY_MAX-PADDLE_LEN) p2 = SY_MAX-PADDLE_LEN; |
bwang | 1:24fd07a24094 | 465 | |
bwang | 1:24fd07a24094 | 466 | if (bx < SX_MIN) { |
bwang | 1:24fd07a24094 | 467 | bxv = -bxv; |
bwang | 1:24fd07a24094 | 468 | bx = SX_MIN; |
bwang | 2:1d16e99f334b | 469 | if (by < p1 || by > p1 + PADDLE_LEN) { |
bwang | 2:1d16e99f334b | 470 | im_line_va[H_RES*(SY_MIN-2)+2*s1+SX_MIN] = 1; |
bwang | 2:1d16e99f334b | 471 | s1++; |
bwang | 2:1d16e99f334b | 472 | } |
bwang | 2:1d16e99f334b | 473 | } |
bwang | 1:24fd07a24094 | 474 | if (bx > SX_MAX) { |
bwang | 1:24fd07a24094 | 475 | bxv = -bxv; |
bwang | 1:24fd07a24094 | 476 | bx = SX_MAX; |
bwang | 2:1d16e99f334b | 477 | if (by < p2 || by > p2 + PADDLE_LEN) { |
bwang | 2:1d16e99f334b | 478 | im_line_va[H_RES*(SY_MAX+2)+2*s2+SX_MIN] = 1; |
bwang | 2:1d16e99f334b | 479 | s2++; |
bwang | 2:1d16e99f334b | 480 | } |
bwang | 1:24fd07a24094 | 481 | } |
bwang | 1:24fd07a24094 | 482 | if (by < SY_MIN) {byv = -byv; by = SY_MIN;} |
bwang | 1:24fd07a24094 | 483 | if (by > SY_MAX) {byv = -byv; by = SY_MAX;} |
bwang | 1:24fd07a24094 | 484 | |
bwang | 1:24fd07a24094 | 485 | for(int y = 0; y < PADDLE_LEN; y++) { |
bwang | 1:24fd07a24094 | 486 | im_line_va[H_RES*(y+(int)p1)+SX_MIN] = 1; |
bwang | 1:24fd07a24094 | 487 | im_line_va[H_RES*(y+(int)p2)+SX_MAX] = 1; |
bwang | 1:24fd07a24094 | 488 | } |
bwang | 1:24fd07a24094 | 489 | im_line_va[H_RES*(int)by+(int)bx] = 1; |
bwang | 1:24fd07a24094 | 490 | |
bwang | 2:1d16e99f334b | 491 | wait(1/1200.0f); |
bwang | 1:24fd07a24094 | 492 | } |
bwang | 1:24fd07a24094 | 493 | |
bwang | 2:1d16e99f334b | 494 | p1 = (SY_MIN+SY_MAX)/2-PADDLE_LEN/2, p2 = (SY_MIN+SY_MAX)/2-PADDLE_LEN/2; |
bwang | 2:1d16e99f334b | 495 | p1v = 0.1, p2v = -0.1; |
bwang | 1:24fd07a24094 | 496 | |
bwang | 2:1d16e99f334b | 497 | bx = (SX_MIN+SX_MAX)/2, by = (SY_MIN+SY_MAX)/2; |
bwang | 2:1d16e99f334b | 498 | bxv = 0.03, byv = 0.03; |
bwang | 2:1d16e99f334b | 499 | |
bwang | 1:24fd07a24094 | 500 | for (;;) |
bwang | 1:24fd07a24094 | 501 | { |
bwang | 1:24fd07a24094 | 502 | for(int i = 0; i < 20000; i++) |
bwang | 1:24fd07a24094 | 503 | update_image(); |
bwang | 1:24fd07a24094 | 504 | if(!p1_in.read() || !p2_in.read()) goto potato; |
dicarloj | 0:7757ab3f7206 | 505 | } |
dicarloj | 0:7757ab3f7206 | 506 | } |