Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. #include <iostream>
  2. #include <chrono>
  3. #include <cmath>
  4.  
  5. #define DELAY_BETWEEN_WIGGLES 50 //In milliseconds.
  6. #define MAX_WIGGLE_SHIFT 50 //In spaces.
  7.  
  8. #define PI 3.14159265
  9. #define PID4 0.785398163397
  10.  
  11. void nanowait(){
  12. std::chrono::time_point<std::chrono::high_resolution_clock> start = std::chrono::high_resolution_clock::now();
  13. for(;;){
  14. if(std::chrono::high_resolution_clock::now()-start>std::chrono::milliseconds(DELAY_BETWEEN_WIGGLES)){
  15. return;
  16. }
  17. }
  18. }
  19.  
  20. int main(){
  21.  
  22. float wavelength = 5.0f; //Not exact. Actual wavelength is x8 of this value.
  23.  
  24. for(;;){
  25.  
  26. //Limited loop so it doesn't break down due to float percision errors.
  27. for(unsigned int i = 0; i < floor(wavelength*8) ;i++){
  28.  
  29. int shift = floor((cos(( float(i)/wavelength ) * PID4 )+1.0f)*(MAX_WIGGLE_SHIFT/2));
  30.  
  31. std::cout << std::string( shift , ' ') << "wiggle" << i << std::endl;
  32. nanowait();
  33.  
  34. }
  35.  
  36. }
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement