int menu_wait() { menu_show(); int chosen_option; while ((get_int_input("Insira a sua opção: ", &chosen_option)) == 1) { printf("Opção não válida.\n"); } if (chosen_option > 0 && chosen_option <= N_OPTIONS) { return chosen_option; } clear_screen(); return -1; }
int main(int argc, char * args[]) { UNUSED(argc); UNUSED(args); init_bob_rand(); seedMT(4357U); srand(time(NULL)); s_lcrand(time(NULL)); s_rand_qpr(0, 0); int selected_mode = 999999; while(selected_mode>10){ printf("Select random function by pressing number key\n1:Windows random \t2:LFSR \t3:Mersenne twister" "\t4BobByrtle \t5Linear Congruential\t6Random with array \t7xorShift \t8Quadratic Resides" "\t9Concatenate 16 \t10Tausworth\n"); selected_mode = get_int_input(); } SDL_Init(SDL_INIT_VIDEO); SDL_Window * sdlWindow = SDL_CreateWindow("Visualize PRNG", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_OPENGL); if (sdlWindow == NULL) { printf("Could not create window: %s\n", SDL_GetError()); return 1; } SDL_Renderer * sdlRenderer = SDL_CreateRenderer(sdlWindow, -1, 0); if (sdlRenderer == NULL) { printf("Could not create renderer: %s\n", SDL_GetError()); return 1; } SDL_RenderClear(sdlRenderer); SDL_RenderPresent(sdlRenderer); SDL_Texture * sdlTexture = SDL_CreateTexture(sdlRenderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STREAMING, 640, 480); if (sdlTexture == NULL) { printf("Could not create texture: %s\n", SDL_GetError()); return 1; } SDL_SetTextureBlendMode(sdlTexture, SDL_BLENDMODE_BLEND); uint8 * data = (uint8 * ) malloc(sizeof(uint8) * 640 * 480); uint32 * pixels = (uint32 * ) malloc(sizeof(uint32) * 640 * 480); memset(pixels, 0, 640 * 480 * sizeof(uint32)); memset(data, 0, 640 * 480 * sizeof(uint8)); int cnt=5999999; uint32 * itable =createdata(cnt,selected_mode); CameraData camData; camData.xshift=0; camData.yshift=0; camData.zoom=1; camData.phata=0; SDL_PixelFormat* format = SDL_AllocFormat(SDL_PIXELFORMAT_RGBA8888); int arr_size = 640 * 480; bool keep_running = true; while (keep_running) { memset(pixels, 0, 640 * 480 * sizeof(uint32)); update_data(data,640,480,itable,cnt,&camData); for(int i=0;i<arr_size;++i){ uint8 data_value = data[i]; if(data_value){ pixels[i] = SDL_MapRGBA( format, 0xFF, 0xFF, 0xFF, data_value ); } } SDL_UpdateTexture(sdlTexture, NULL, pixels, 640 * sizeof(Uint32)); SDL_RenderClear(sdlRenderer); SDL_RenderCopy(sdlRenderer, sdlTexture, NULL, NULL); SDL_RenderPresent(sdlRenderer); SDL_Delay(20); keep_running = handle_events(&camData); } SDL_DestroyWindow(sdlWindow); SDL_Quit(); free(pixels); SDL_DestroyTexture(sdlTexture); SDL_DestroyRenderer(sdlRenderer); return 0; }