Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdbool.h>
- #include <stddef.h>
- #include <stdint.h>
- #include <tice.h>
- #include <math.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <graphx.h>
- #include <keypadc.h>
- #include <fileioc.h>
- #include "gfx/gfx.h"
- //while (!os_GetCSC());
- float rand_0_1(void);
- float randFunc(void);
- float interpolate(float pa, float pb, float px);
- uint32_t M = 9355500, //M, A, and C are constant members of the Linear Congruential Generator (LCG)
- A = 311851;
- uint16_t W = 320, // width of screen
- x = 0; //x position along the screen
- uint8_t C = 1,
- H = 240, //height of screen
- amp = 100, //amplitude
- wl = 10; //wavelength
- float y, fq, a, b, z;
- void main(void)
- {
- y = H / 2,
- fq = (float)1 / wl,
- z = rand_0_1() * M;
- a = randFunc(),
- b = randFunc();
- srand(rtc_Time());
- gfx_Begin();
- while(x < W){
- if(x % wl == 0)
- {
- a = b;
- b = randFunc();
- y = H / 2 + a * amp;
- } else {
- y = H / 2 + interpolate(a, b, ((x % wl) / (float)wl)) * amp;
- }
- gfx_SetPixel( x, (uint8_t)y);
- x += 1;
- }
- while (!os_GetCSC());
- gfx_End();
- }
- float rand_0_1()
- {
- return rand()/(float)RAND_MAX;
- }
- float randFunc()
- {
- z = (A * (int)z + C) % M;
- return z / (float)M - 0.5;
- }
- float interpolate(float pa, float pb, float px){
- float ft = px * M_PI,
- f = (1 - cos(ft)) * 0.5;
- return pa * (1 - f) + pb * f;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement