SHARE
TWEET

Untitled

a guest Feb 14th, 2020 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdbool.h>
  2. #include <stddef.h>
  3. #include <stdint.h>
  4. #include <tice.h>
  5.  
  6. #include <math.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10.  
  11. #include <graphx.h>
  12. #include <keypadc.h>
  13. #include <fileioc.h>
  14.  
  15. #include "gfx/gfx.h"
  16.  
  17. //while (!os_GetCSC());
  18.  
  19. float rand_0_1(void);
  20. float randFunc(void);
  21. float interpolate(float pa, float pb, float px);
  22.  
  23. uint32_t M = 9355500, //M, A, and C are constant members of the Linear Congruential Generator (LCG)
  24.          A = 311851;
  25.          
  26. uint16_t W = 320, // width of screen
  27.          x = 0; //x position along the screen
  28. uint8_t  C = 1,
  29.          H = 240, //height of screen
  30.          amp = 100, //amplitude
  31.          wl = 10; //wavelength
  32. float    y, fq, a, b, z;
  33.            
  34. void main(void)
  35. {
  36.     y = H / 2,
  37.     fq = (float)1 / wl,
  38.     z = rand_0_1() * M;
  39.     a = randFunc(),
  40.     b = randFunc();
  41.    
  42.    
  43.     srand(rtc_Time());
  44.    
  45.     gfx_Begin();
  46.    
  47.     while(x < W){
  48.        
  49.         if(x % wl == 0)
  50.         {
  51.             a = b;
  52.             b = randFunc();
  53.             y = H / 2 + a * amp;
  54.         } else {
  55.             y = H / 2 + interpolate(a, b, ((x % wl) / (float)wl)) * amp;
  56.         }
  57.         gfx_SetPixel( x, (uint8_t)y);
  58.         x += 1;
  59.     }
  60.    
  61.     while (!os_GetCSC());
  62.     gfx_End();
  63. }
  64.  
  65.  
  66.  
  67.  
  68. float rand_0_1()
  69. {
  70.     return rand()/(float)RAND_MAX;
  71. }
  72.  
  73. float randFunc()
  74. {
  75.   z = (A * (int)z + C) % M;
  76.   return z / (float)M - 0.5;
  77. }
  78.  
  79. float interpolate(float pa, float pb, float px){
  80.     float ft = px * M_PI,
  81.           f = (1 - cos(ft)) * 0.5;
  82.          
  83.     return pa * (1 - f) + pb * f;
  84. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top