Image noise: Difference between revisions
Content added Content deleted
(→{{header|OCaml}}: with alleg too) |
(a work in progress C version (translated from SDL-OCaml)) |
||
Line 5: | Line 5: | ||
[[Image:NoiseOutput.png]] |
[[Image:NoiseOutput.png]] |
||
=={{header|C}}== |
|||
{{WIP}} |
|||
{{trans|OCaml}} |
|||
<lang c>#include <stdlib.h> |
|||
#include <stdio.h> |
|||
#include <SDL/SDL.h> |
|||
unsigned int frames = 0; |
|||
unsigned int t_acc = 0; |
|||
void print_fps () |
|||
{ |
|||
static Uint32 last_t = 0; |
|||
last_t = SDL_GetTicks(); |
|||
Uint32 t = SDL_GetTicks(); |
|||
Uint32 dt = t - last_t; |
|||
t_acc += dt; |
|||
if (t_acc > 1000) |
|||
{ |
|||
unsigned int el_time = t_acc / 1000; |
|||
printf("- fps: %g\n%!", |
|||
(float) frames / (float) el_time); |
|||
t_acc = 0; |
|||
frames = 0; |
|||
} |
|||
last_t = t; |
|||
} |
|||
void blit_noise(SDL_Surface surf) |
|||
{ |
|||
long dim = surf->h; |
|||
white (1) |
|||
{ |
|||
for (i = 0; i < dim; i++) |
|||
{ |
|||
if (rand() & 1) { |
|||
surf->pixels[something] = something_else; |
|||
} |
|||
} |
|||
SDL_Flip(surf); |
|||
++frames; |
|||
print_fps(); |
|||
} |
|||
} |
|||
int main(void) |
|||
{ |
|||
SDL_Surface surf = NULL; |
|||
unsigned int seed = 99; |
|||
srand(seed); |
|||
SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO); |
|||
surf = SDL_SetVideoMode(320, 240, 8, SDL_DOUBLEBUF /*SDL_HWSURFACE*/); |
|||
blit_noise(surf); |
|||
}</lang> |
|||
=={{header|C sharp|C#}}== |
=={{header|C sharp|C#}}== |