diff --git a/gr-sim/Makefile b/gr-sim/Makefile index 0d30ab55..090c544a 100644 --- a/gr-sim/Makefile +++ b/gr-sim/Makefile @@ -1,11 +1,11 @@ CC = gcc -CFLAGS = -Wall -O2 +CFLAGS = -Wall -O2 -g LFLAGS = SDL_LIBS= `sdl-config --libs` SDL_INCLUDE= `sdl-config --cflags` -all: rainbow +all: rainbow sparkle kaleido rainbow: rainbow.o gr-sim.o $(CC) $(LFLAGS) $(SDL_LIBS) -o rainbow rainbow.o gr-sim.o @@ -14,10 +14,24 @@ rainbow.o: rainbow.c $(CC) $(CFLAGS) -c rainbow.c +kaleido: kaleido.o gr-sim.o + $(CC) $(LFLAGS) $(SDL_LIBS) -o kaleido kaleido.o gr-sim.o + +kaleido.o: kaleido.c + $(CC) $(CFLAGS) -c kaleido.c + + +sparkle: sparkle.o gr-sim.o + $(CC) $(LFLAGS) $(SDL_LIBS) -o sparkle sparkle.o gr-sim.o + +sparkle.o: sparkle.c + $(CC) $(CFLAGS) -c sparkle.c + + gr-sim.o: gr-sim.c $(CC) $(CFLAGS) $(SDL_INCLUDE) -c gr-sim.c clean: - rm -f *~ *.o gr-sim rainbow + rm -f *~ *.o gr-sim rainbow sparkle kaleido diff --git a/gr-sim/gr-sim.c b/gr-sim/gr-sim.c index 1a241871..f5050b77 100644 --- a/gr-sim/gr-sim.c +++ b/gr-sim/gr-sim.c @@ -137,11 +137,28 @@ int grsim_init(void) { static int current_color=0; int color_equals(int new_color) { - current_color=new_color; + current_color=new_color%16; return 0; } int plot(int x, int y) { + if (x>40) { + printf("X too big %d\n",x); + return -1; + } + if (y>40) { + printf("Y too big %d\n",y); + return -1; + } + if (x<0) { + printf("X too small %d\n",x); + return -1; + } + if (y<0) { + printf("Y too small %d\n",y); + return -1; + } + framebuffer[x][y]=current_color; return 0; } @@ -164,4 +181,11 @@ int vlin(int y1, int y2, int at) { return 0; } +int gr(void) { + int x,y; + /* Init screen */ + for(y=0;y +#include +#include + +#include "gr-sim.h" + +static int r[11]; +static int x,y,j,a,b,x2,y2,n; + +static void tooo(void) { + + color_equals(r[n]); + plot(x2,y2); + return; +} + +static void noo(void) { + int t,w; + + // 900 + color_equals(r[0]); + plot(x,y); + grsim_update(); + if (j==1) return; + // 920 + w=j/2; + t=j-w-1; + // 930 + for(n=1;n<=w;n++) { + if (x==a) { + y2=y; x2=x+n; tooo(); + x2=x-n; tooo(); + continue; + } + if (y==b) { + x2=x; y2=y+n; tooo(); + y2=y-n; tooo(); + continue; + } + y2=y; + if (x +#include +#include + +#include "gr-sim.h" + +int main(int argc, char **argv) { + + int ch; + int j,k; + int t; + int r,w,c,m,n,l; + int x,y; + +#define S 19 + int a[S+1],b[S+1]; + + grsim_init(); + + // 120 + gr(); + // 125 + + // 130 + x=19,y=19; + +label140: + // 140 + t=rand()%16; + + // 150 + for(j=0;j<=S;j++) { + a[j]=j; + b[j]=j; + } + // 160+170 + for(j=0;j<=S;j++) { + r=rand()%(S+1); + w=a[j]; + a[j]=a[r]; + a[r]=w; + } + // 180+190 + for(j=0;j<=S;j++) { + r=rand()%(S+1); + w=b[j]; + b[j]=b[r]; + b[r]=w; + } + // 200 + for(j=0;j<=S;j++) { + for(k=0;k<=S;k++) { + // 210 + r=a[j]; + w=b[k]; + c=r+w+t; + // 220 + color_equals(c); + // 240 + if (x+r>40) { + printf("ERROR! %d %d\n",x,r); + return -1; + } + plot(x+r,y+w); + plot(x+r,y-w); + plot(x-r,y-w); + plot(x-r,y+w); + plot(x+w,y+r); + plot(x+w,y-r); + plot(x-w,y-r); + plot(x-w,y+r); + grsim_update(); + //320 + } + } + // 350 + for(j=1;j<10;j++) { + ch=grsim_input(); + if (ch=='q') exit(0); + if (ch==' ') { + while(grsim_input()!=' ') usleep(10000); + } + usleep(10000); + } + + // 400 + m=15; + // 405 + n=(random()%21)+10; + // 410 + for(j=1;j<=n;j++) { + r=(random()%22)+1; + w=random()%m; + color_equals(w); + for(l=(y-S);l<=(y+S);l+=(r/4)+1) { + for(k=(x-S);k<=(x+S);k+=r) { + plot(k,l); + } + } + } + goto label140; + + return 0; +}