Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //cheap physics simulation of bouncing balls in a tube.
- //Object location history is "graphed" time vs location.
- #include <iostream>
- using namespace std;
- int main()
- { char tube[82]; //width of terminal + 2, must be even
- int blank = 32; //' '
- int wall = 119; //'w'
- int plus = 43; //'+'
- int minus = 45; //'-'
- for(int a = 0; a <= 81; a++)
- { tube[a] = blank;
- }
- tube[0] = wall;
- tube[81] = wall;
- //initial symbol positions (separate by even # of blocks)
- tube[14] = plus;
- tube[17] = minus;
- //"pointers" to symbol positions
- int left_loc = 14, right_loc = 17;
- //initial directional states of symbols (go left = -1, go right = 1)
- int left_state = -1, right_state = 1;
- for(int a = 0; a <= 1020; a++)
- { for(int a = 1; a <= 80; a++)
- { cout << tube[a];
- }
- cout << endl;
- if(tube[left_loc + left_state] == blank) //plus normal move
- { tube[left_loc] = blank;
- tube[left_loc + left_state] = plus;
- left_loc += left_state;
- }
- if(tube[left_loc + left_state] == wall) //plus wall bounce
- { left_state *= -1;
- }
- if(tube[right_loc + right_state] == blank) //minus normal move
- { tube[right_loc] = blank;
- tube[right_loc + right_state] = minus;
- right_loc += right_state;
- }
- if(tube[right_loc + right_state] == wall) //minus wall bounce
- { right_state *= -1;
- }
- if(tube[left_loc + 1] == minus) //plus on minus collision
- { left_state *= -1;
- right_state *= -1;
- }
- for(int waste = 0; waste <= 16000000; waste++){} //for 3.4GHz (i7-5557U)
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement