#![no_main]
use dos_like::{
key_state, screen_buffer, set_double_buffer, set_pal, set_video_mode, shutting_down,
swap_buffers_and_get, wait_vbl, KeyCode, VideoMode,
};
use std::os::raw::c_int;
dos_like::dos_main! {
let mut plasma = [[0 as c_int; 320]; 200];
set_video_mode(VideoMode::Graphics320x200);
set_double_buffer(true);
let w = 320;
let h = 200;
for x in 0..256 {
let r = (128. + 128. * (x as f64 * 3.1415 / 32.).sin()) as u8;
let g = (128. + 128. * (x as f64 * 3.1415 / 64.).sin()) as u8;
let b = (128. + 128. * (x as f64 * 3.1415 / 128.).sin()) as u8;
set_pal(x, r >> 2, g >> 2, b >> 2);
}
for y in 0..h {
for x in 0..w {
let color = (128.0
+ (128.0 * (x as f32 / 32.).sin())
+ 128.0
+ (128.0 * (y as f32 / 16.).sin())
+ 128.0
+ (128.0 * ((x as f32 + y as f32) / 32.).sin())
+ 128.0
+ (128.0 * (x * x + y * y) as f64 / 16.).sqrt().sin() as f32)
as c_int
/ 4;
plasma[y][x] = color;
}
}
let mut palette_shift = 0;
unsafe {
let mut buffer = screen_buffer();
while !shutting_down() {
wait_vbl();
palette_shift += 1;
for y in 0..h {
for x in 0..w {
buffer[x + y * 320] = (plasma[y][x] + palette_shift) as u8;
}
}
buffer = swap_buffers_and_get();
if key_state(KeyCode::KEY_ESCAPE) {
break;
}
}
}
}