gr-sim: add starfield demo

This commit is contained in:
Vince Weaver 2017-12-14 16:52:58 -05:00
parent c534cf4b3e
commit 58adfcfcd0
2 changed files with 70 additions and 2 deletions

View File

@ -5,7 +5,7 @@ LFLAGS = -lm
SDL_LIBS= `sdl-config --libs`
SDL_INCLUDE= `sdl-config --cflags`
all: fixed_point rainbow sparkle kaleido tfv mode7_demo text tfv_multiply
all: fixed_point rainbow sparkle starfield kaleido tfv mode7_demo text tfv_multiply
@ -144,10 +144,18 @@ sparkle.o: sparkle.c
$(CC) $(CFLAGS) -c sparkle.c
starfield: starfield.o gr-sim.o
$(CC) $(LFLAGS) $(SDL_LIBS) -o starfield starfield.o gr-sim.o
starfield.o: starfield.c
$(CC) $(CFLAGS) -c starfield.c
gr-sim.o: gr-sim.c gr-sim.h apple2_font.h
$(CC) $(CFLAGS) $(SDL_INCLUDE) -c gr-sim.c
clean:
rm -f *~ *.o gr-sim rainbow sparkle kaleido tfv text mode7_demo fixed_point tfv_multiply
rm -f *~ *.o gr-sim rainbow sparkle starfield kaleido \
tfv text mode7_demo fixed_point tfv_multiply

60
gr-sim/starfield.c Normal file
View File

@ -0,0 +1,60 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "gr-sim.h"
#define NUMSTARS 64
struct star_type {
double x;
double y;
double z;
};
static struct star_type stars[NUMSTARS];
int main(int argc, char **argv) {
int ch,i;
int spreadx=40;
int spready=40;
int spreadz=5;
grsim_init();
for(i=0;i<NUMSTARS;i++) {
stars[i].x=(drand48()-0.5)*spreadx;
stars[i].y=(drand48()-0.5)*spready;
stars[i].z=((drand48())*spreadz)+0.1;
printf("%.2lf,%2lf,%.2lf\n",stars[i].x,stars[i].y,stars[i].z);
}
gr();
while(1) {
gr();
color_equals(15);
for(i=0;i<NUMSTARS;i++) {
basic_plot(stars[i].x/stars[i].z+20,
stars[i].y/stars[i].z+20);
}
for(i=0;i<NUMSTARS;i++) {
stars[i].z+=-0.125;
if (stars[i].z<0) {
stars[i].x=(drand48()-0.5)*spreadx;
stars[i].y=(drand48()-0.5)*spready;
stars[i].z=((drand48())*spreadz)+0.1;
}
}
grsim_update();
ch=grsim_input();
if (ch=='q') exit(0);
usleep(30000);
}
return 0;
}