-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPLASMA4.C
More file actions
95 lines (84 loc) · 1.81 KB
/
PLASMA4.C
File metadata and controls
95 lines (84 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <stdio.h>
#include <stdlib.h>
#include <alloc.h>
#include <conio.h>
#include <dos.h>
#include <math.h>
#include <mem.h>
#include "types.h"
#include "vga.h"
#include "pal.h"
#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 200
byte far *framebuf;
byte SIN256[256];
byte pal[768];
#define SETPIX(x,y,c) *(framebuf + (dword)SCREEN_WIDTH * (y) + (x)) = c
#define GETPIX(x,y) *(framebuf + (dword)SCREEN_WIDTH * (y) + (x))
#define MODE_Y
void init_sin()
{
word i;
float v;
for( i = 0; i < 256; ++i ) {
v = (sin( 2.0 * M_PI * i / 255.0 ) + 1.0 ) / 2.0;
SIN256[ i ] = (byte)(255 * v);
}
}
void draw_plasma(word x, word y, word w, word h, dword t)
{
byte c;
word c1,c2,c3,v1,v2;
word i,j;
v1 = SIN256[(t*3)%256];
v2 = SIN256[(64+t*5)%256];
for(j = y; j < y + h; j++){
c3 = SIN256[(j*3 + t*3) % 256];
for(i = x; i < x + w; i++) {
c1 = SIN256[(i*3 + t*2) % 256];
c2 = SIN256[((i*v1)/w + (j*v2)/h + t) % 256];
c = (byte)((c1 + c2 + c3) / 3);
SETPIX(i,j,c);
}
}
}
int main()
{
byte do_quit = 0;
int i;
dword t;
init_sin();
randomize();
t = random(4096);
framebuf = malloc(SCREEN_WIDTH*SCREEN_HEIGHT);
if(framebuf == NULL) {
printf("not enough memory\n");
return 1;
}
#ifdef MODE_Y
set_mode_y();
#else
set_graphics_mode();
#endif
set_palette(fire_pal);
memset(framebuf, 0x00, SCREEN_WIDTH*SCREEN_HEIGHT);
while( !do_quit ) {
if(kbhit()){
getch();
do_quit = 1;
}
#ifdef MODE_Y
draw_plasma(0,0,80,50,t);
wait_for_retrace();
blit4(framebuf,0,0,80,50);
#else
draw_plasma(80,50,160,100,t);
wait_for_retrace();
memcpy(VGA,framebuf,SCREEN_WIDTH*SCREEN_HEIGHT);
#endif
t++;
}
set_text_mode();
return 0;
}