dots: more sizecoding

This commit is contained in:
Vince Weaver 2023-11-30 23:45:08 -05:00
parent a2feef02da
commit 085689df38
5 changed files with 146 additions and 72 deletions

View File

@ -4,7 +4,16 @@ CFLAGS = -O2 -Wall -g
SDL_LIBS= `sdl-config --libs`
SDL_INCLUDE= `sdl-config --cflags`
all: dots dots_dump dots_play dots_play2 dots_minimal dots_6502
all: generate_sines \
dots dots_dump dots_play dots_play2 dots_minimal dots_6502
###
generate_sines: generate_sines.o
$(CC) -o generate_sines generate_sines.o $(LFLAGS) -lm
generate_sines.o: generate_sines.c
$(CC) $(CFLAGS) -c generate_sines.c
###

View File

@ -8,7 +8,7 @@
#include "../gr-sim.h"
#include "../tfv_zp.h"
#include "sin1024.h"
#include "sin256.h"
#define MAXDOTS 256
@ -41,11 +41,16 @@ static void drawdots(void) {
/* bx= (ez/dz)*dx + ex */
/* by= (ez/dz)*dy + ey */
//printf("%x %x\n",dot_z[d],dot_x[d]);
temp32=((dot_z[d]*rotcos)-(dot_x[d]*rotsin));
distance=(temp32>>16)+9000;
// distance=distance<<2;
if (distance==0) distance=1;
// printf("%d\n",distance-9000);
// printf("%x\n",distance);
temp32=((dot_x[d]*rotcos)+(dot_z[d]*rotsin));
@ -132,22 +137,23 @@ static void drawdots(void) {
static short isin(short deg) {
return(sin1024[deg&1023]);
return(sin256[deg&255]);
}
static short icos(short deg) {
return(sin1024[(deg+256)&1023]);
return(sin256[(deg+64)&255]);
}
static short dottaul[1024];
//static short dottaul[1024];
int main(int argc,char **argv) {
short dropper;
short frame=0;
short rota=-1*64;
short rota=-1*64*4;
short rot=0,rots=0;
short a,b,c,d,i,j=0;
short a,i;
// short b,c,d;
short grav,gravd;
short f=0;
int ch;
@ -158,9 +164,10 @@ int main(int argc,char **argv) {
gravitybottom=8105;
for(a=0;a<MAXDOTS;a++) {
dottaul[a]=a;
// dottaul[a]=a;
dot_y[a]=2560-dropper;
}
#if 0
for(a=0;a<MAXDOTS-12;a++) {
b=rand()%MAXDOTS;
c=rand()%MAXDOTS;
@ -183,7 +190,7 @@ int main(int argc,char **argv) {
d=dot_y[b]; dot_y[b]=dot_y[c]; dot_y[c]=d;
d=dot_z[b]; dot_z[b]=dot_z[c]; dot_z[c]=d;
}
#endif
grsim_init();
@ -194,7 +201,7 @@ int main(int argc,char **argv) {
ram[DRAW_PAGE]=0;
while(frame<1686) {
while(1) {//frame<1686) {
/* re-draw background */
color_equals(0);
@ -205,17 +212,17 @@ int main(int argc,char **argv) {
frame++;
if(frame==355) f=0;
i=dottaul[j];
j++; j%=MAXDOTS;
i=frame%MAXDOTS; //dotgtaul[frame%MAXDOTS];
// j++; j%=MAXDOTS;
/* initial spin */
if(frame<355) {
// dot[i].x=isin(f*11)*40;
// dot[i].y=icos(f*13)*10-dropper;
// dot[i].z=isin(f*17)*40;
dot_x[i]=isin(f*8)*32;
dot_y[i]=icos(f*16)*8-dropper;
dot_z[i]=isin(f*16)*32;
dot_x[i]=isin(f*2)*32; // 8
dot_y[i]=icos(f*4)*8-dropper; // 16
dot_z[i]=isin(f*4)*32; // 16
dot_yadd[i]=0;
}
/* bouncing ring */
@ -224,9 +231,9 @@ int main(int argc,char **argv) {
// dot[i].y=dropper;
// dot[i].z=isin(f*15)*55;
// dot[i].yadd=-260;
dot_x[i]=icos(f*16)*48;
dot_x[i]=icos(f*4)*48; // 16
dot_y[i]=dropper;
dot_z[i]=isin(f*16)*48;
dot_z[i]=isin(f*4)*48; // 16
dot_yadd[i]=-260;
}
/* fountain */
@ -236,10 +243,10 @@ int main(int argc,char **argv) {
// dot[i].y=8000;
// dot[i].z=isin(f*66)*a;
// dot[i].yadd=-300;
a=sin1024[frame&1023]/8;
dot_x[i]=icos(f*64)*a;
a=sin256[(frame>>2)&255]/8;
dot_x[i]=icos(f*16)*a; // 64
dot_y[i]=8000;
dot_z[i]=isin(f*64)*a;
dot_z[i]=isin(f*16)*a; // 64
dot_yadd[i]=-300;
}
/* swirling */
@ -252,15 +259,16 @@ int main(int argc,char **argv) {
}
if(dropper>4000) dropper-=100;
//rotsin=0; rotcos=64;
printf("rot=%d\n",rot);
rotcos=icos(rot)*64; rotsin=isin(rot)*64;
rots+=2;
rots+=1;
if(frame>1357) {
rot+=rota/64;
rot+=rota/64/4;
rota--;
}
else rot=isin(rots);
} else rot=isin(rots>>2);
f++;
gravity=grav;
@ -270,7 +278,7 @@ int main(int argc,char **argv) {
grsim_update();
/* approximate by 50Hz sleep */
/* approximate 50Hz sleep */
usleep(20000);
ch=grsim_input();

View File

@ -0,0 +1,32 @@
#include <stdio.h>
#include <math.h>
int generate_1024=0;
int main(int argc, char **argv) {
int i;
double s,angle;
if (generate_1024) {
printf("int16_t sin1024[]={\n");
for(i=0;i<1024;i++) {
angle=(i/1024.0)*(2.0*3.1415926535897932384);
s=sin(angle)*256.0;
printf("%d,",(int)s);
if (i%16==15) printf("\n");
}
printf("};\n");
} else {
printf("int16_t sin256[]={\n");
for(i=0;i<256;i++) {
angle=(i/256.0)*(2.0*3.1415926535897932384);
s=sin(angle)*256.0;
printf("%d,",(int)s);
if (i%16==15) printf("\n");
}
printf("};\n");
}
return 0;
}

View File

@ -1,41 +1,41 @@
int16_t sin1024[]={
0, 1, 3, 4, 6, 7, 9, 10, 12, 14, 15, 17, 18, 20, 21, 23,
25, 26, 28, 29, 31, 32, 34, 36, 37, 39, 40, 42, 43, 45, 46, 48,
49, 51, 53, 54, 56, 57, 59, 60, 62, 63, 65, 66, 68, 69, 71, 72,
74, 75, 77, 78, 80, 81, 83, 84, 86, 87, 89, 90, 92, 93, 95, 96,
97, 99,100,102,103,105,106,108,109,110,112,113,115,116,117,119,
120,122,123,124,126,127,128,130,131,132,134,135,136,138,139,140,
142,143,144,146,147,148,149,151,152,153,155,156,157,158,159,161,
162,163,164,166,167,168,169,170,171,173,174,175,176,177,178,179,
181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,
197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,211,
212,213,214,215,216,217,217,218,219,220,221,221,222,223,224,225,
225,226,227,227,228,229,230,230,231,232,232,233,234,234,235,235,
236,237,237,238,238,239,239,240,241,241,242,242,243,243,244,244,
244,245,245,246,246,247,247,247,248,248,249,249,249,250,250,250,
251,251,251,251,252,252,252,252,253,253,253,253,254,254,254,254,
254,254,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
256,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,
254,254,254,254,254,253,253,253,253,252,252,252,252,251,251,251,
251,250,250,250,249,249,249,248,248,247,247,247,246,246,245,245,
244,244,244,243,243,242,242,241,241,240,239,239,238,238,237,237,
236,235,235,234,234,233,232,232,231,230,230,229,228,227,227,226,
225,225,224,223,222,221,221,220,219,218,217,217,216,215,214,213,
212,211,211,210,209,208,207,206,205,204,203,202,201,200,199,198,
197,196,195,194,193,192,191,190,189,188,187,186,185,184,183,182,
181,179,178,177,176,175,174,173,171,170,169,168,167,166,164,163,
162,161,159,158,157,156,155,153,152,151,149,148,147,146,144,143,
142,140,139,138,136,135,134,132,131,130,128,127,126,124,123,122,
120,119,117,116,115,113,112,110,109,108,106,105,103,102,100, 99,
97, 96, 95, 93, 92, 90, 89, 87, 86, 84, 83, 81, 80, 78, 77, 75,
74, 72, 71, 69, 68, 66, 65, 63, 62, 60, 59, 57, 56, 54, 53, 51,
49, 48, 46, 45, 43, 42, 40, 39, 37, 36, 34, 32, 31, 29, 28, 26,
25, 23, 21, 20, 18, 17, 15, 14, 12, 10, 9, 7, 6, 4 , 3 , 1,
0, -1, -3, -4, -6, -7, -9,-10,-12,-14,-15,-17,-18,-20,-21,-23,
-25,-26,-28,-29,-31,-32,-34,-36,-37,-39,-40,-42,-43,-45,-46,-48,
-49,-51,-53,-54,-56,-57,-59,-60,-62,-63,-65,-66,-68,-69,-71,-72,
-74,-75,-77,-78,-80,-81,-83,-84,-86,-87,-89,-90,-92,-93,-95,-96,
-97, -99,-100,-102,-103,-105,-106,-108,-109,-110,-112,-113,-115,-116,-117,-119,
0,1,3,4,6,7,9,10,12,14,15,17,18,20,21,23,
25,26,28,29,31,32,34,36,37,39,40,42,43,45,46,48,
49,51,53,54,56,57,59,60,62,63,65,66,68,69,71,72,
74,75,77,78,80,81,83,84,86,87,89,90,92,93,95,96,
97,99,100,102,103,105,106,108,109,110,112,113,115,116,117,119,
120,122,123,124,126,127,128,130,131,132,134,135,136,138,139,140,
142,143,144,146,147,148,149,151,152,153,155,156,157,158,159,161,
162,163,164,166,167,168,169,170,171,173,174,175,176,177,178,179,
181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,
197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,211,
212,213,214,215,216,217,217,218,219,220,221,221,222,223,224,225,
225,226,227,227,228,229,230,230,231,232,232,233,234,234,235,235,
236,237,237,238,238,239,239,240,241,241,242,242,243,243,244,244,
244,245,245,246,246,247,247,247,248,248,249,249,249,250,250,250,
251,251,251,251,252,252,252,252,253,253,253,253,254,254,254,254,
254,254,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
256,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,
254,254,254,254,254,253,253,253,253,252,252,252,252,251,251,251,
251,250,250,250,249,249,249,248,248,247,247,247,246,246,245,245,
244,244,244,243,243,242,242,241,241,240,239,239,238,238,237,237,
236,235,235,234,234,233,232,232,231,230,230,229,228,227,227,226,
225,225,224,223,222,221,221,220,219,218,217,217,216,215,214,213,
212,211,211,210,209,208,207,206,205,204,203,202,201,200,199,198,
197,196,195,194,193,192,191,190,189,188,187,186,185,184,183,182,
181,179,178,177,176,175,174,173,171,170,169,168,167,166,164,163,
162,161,159,158,157,156,155,153,152,151,149,148,147,146,144,143,
142,140,139,138,136,135,134,132,131,130,128,127,126,124,123,122,
120,119,117,116,115,113,112,110,109,108,106,105,103,102,100,99,
97,96,95,93,92,90,89,87,86,84,83,81,80,78,77,75,
74,72,71,69,68,66,65,63,62,60,59,57,56,54,53,51,
49,48,46,45,43,42,40,39,37,36,34,32,31,29,28,26,
25,23,21,20,18,17,15,14,12,10,9,7,6,4,3,1,
0,-1,-3,-4,-6,-7,-9,-10,-12,-14,-15,-17,-18,-20,-21,-23,
-25,-26,-28,-29,-31,-32,-34,-36,-37,-39,-40,-42,-43,-45,-46,-48,
-49,-51,-53,-54,-56,-57,-59,-60,-62,-63,-65,-66,-68,-69,-71,-72,
-74,-75,-77,-78,-80,-81,-83,-84,-86,-87,-89,-90,-92,-93,-95,-96,
-97,-99,-100,-102,-103,-105,-106,-108,-109,-110,-112,-113,-115,-116,-117,-119,
-120,-122,-123,-124,-126,-127,-128,-130,-131,-132,-134,-135,-136,-138,-139,-140,
-142,-143,-144,-146,-147,-148,-149,-151,-152,-153,-155,-156,-157,-158,-159,-161,
-162,-163,-164,-166,-167,-168,-169,-170,-171,-173,-174,-175,-176,-177,-178,-179,
@ -49,11 +49,18 @@ int16_t sin1024[]={
-254,-254,-255,-255,-255,-255,-255,-255,-255,-255,-255,-255,-255,-255,-255,-255,
-256,-255,-255,-255,-255,-255,-255,-255,-255,-255,-255,-255,-255,-255,-255,-254,
-254,-254,-254,-254,-254,-253,-253,-253,-253,-252,-252,-252,-252,-251,-251,-251,
-251,-250,-250,-250,-249,-249,-249,-248,-248,-247,-247,-247,-246,-246,-245,-245,-244,-244,-244,-243,-243,-242,-242,-241,-241,-240,-239,-239,-238,-238,-237,-237,
-236,-235,-235,-234,-234,-233,-232,-232,-231,-230,-230,-229,-228,-227,-227,-226,-225,-225,-224,-223,-222,-221,-221,-220,-219,-218,-217,-217,-216,-215,-214,-213,
-212,-211,-211,-210,-209,-208,-207,-206,-205,-204,-203,-202,-201,-200,-199,-198,-197,-196,-195,-194,-193,-192,-191,-190,-189,-188,-187,-186,-185,-184,-183,-182,
-181,-179,-178,-177,-176,-175,-174,-173,-171,-170,-169,-168,-167,-166,-164,-163,-162,-161,-159,-158,-157,-156,-155,-153,-152,-151,-149,-148,-147,-146,-144,-143,
-142,-140,-139,-138,-136,-135,-134,-132,-131,-130,-128,-127,-126,-124,-123,-122,-120,-119,-117,-116,-115,-113,-112,-110,-109,-108,-106,-105,-103,-102,-100,-99,
-97,-96,-95,-93,-92,-90,-89,-87,-86,-84,-83,-81,-80,-78,-77,-75,-74,-72,-71,-69,-68,-66,-65,-63,-62,-60,-59,-57,-56,-54,-53,-51,
-49,-48,-46,-45,-43,-42,-40,-39,-37,-36,-34,-32,-31,-29,-28,-26,-25,-23,-21,-20,-18,-17,-15,-14,-12,-10,-9,-7,-6,-4,-3,-1
-251,-250,-250,-250,-249,-249,-249,-248,-248,-247,-247,-247,-246,-246,-245,-245,
-244,-244,-244,-243,-243,-242,-242,-241,-241,-240,-239,-239,-238,-238,-237,-237,
-236,-235,-235,-234,-234,-233,-232,-232,-231,-230,-230,-229,-228,-227,-227,-226,
-225,-225,-224,-223,-222,-221,-221,-220,-219,-218,-217,-217,-216,-215,-214,-213,
-212,-211,-211,-210,-209,-208,-207,-206,-205,-204,-203,-202,-201,-200,-199,-198,
-197,-196,-195,-194,-193,-192,-191,-190,-189,-188,-187,-186,-185,-184,-183,-182,
-181,-179,-178,-177,-176,-175,-174,-173,-171,-170,-169,-168,-167,-166,-164,-163,
-162,-161,-159,-158,-157,-156,-155,-153,-152,-151,-149,-148,-147,-146,-144,-143,
-142,-140,-139,-138,-136,-135,-134,-132,-131,-130,-128,-127,-126,-124,-123,-122,
-120,-119,-117,-116,-115,-113,-112,-110,-109,-108,-106,-105,-103,-102,-100,-99,
-97,-96,-95,-93,-92,-90,-89,-87,-86,-84,-83,-81,-80,-78,-77,-75,
-74,-72,-71,-69,-68,-66,-65,-63,-62,-60,-59,-57,-56,-54,-53,-51,
-49,-48,-46,-45,-43,-42,-40,-39,-37,-36,-34,-32,-31,-29,-28,-26,
-25,-23,-21,-20,-18,-17,-15,-14,-12,-10,-9,-7,-6,-4,-3,-1,
};

View File

@ -0,0 +1,18 @@
int16_t sin256[]={
0,6,12,18,25,31,37,43,49,56,62,68,74,80,86,92,
97,103,109,115,120,126,131,136,142,147,152,157,162,167,171,176,
181,185,189,193,197,201,205,209,212,216,219,222,225,228,231,234,
236,238,241,243,244,246,248,249,251,252,253,254,254,255,255,255,
256,255,255,255,254,254,253,252,251,249,248,246,244,243,241,238,
236,234,231,228,225,222,219,216,212,209,205,201,197,193,189,185,
181,176,171,167,162,157,152,147,142,136,131,126,120,115,109,103,
97,92,86,80,74,68,62,56,49,43,37,31,25,18,12,6,
0,-6,-12,-18,-25,-31,-37,-43,-49,-56,-62,-68,-74,-80,-86,-92,
-97,-103,-109,-115,-120,-126,-131,-136,-142,-147,-152,-157,-162,-167,-171,-176,
-181,-185,-189,-193,-197,-201,-205,-209,-212,-216,-219,-222,-225,-228,-231,-234,
-236,-238,-241,-243,-244,-246,-248,-249,-251,-252,-253,-254,-254,-255,-255,-255,
-256,-255,-255,-255,-254,-254,-253,-252,-251,-249,-248,-246,-244,-243,-241,-238,
-236,-234,-231,-228,-225,-222,-219,-216,-212,-209,-205,-201,-197,-193,-189,-185,
-181,-176,-171,-167,-162,-157,-152,-147,-142,-136,-131,-126,-120,-115,-109,-103,
-97,-92,-86,-80,-74,-68,-62,-56,-49,-43,-37,-31,-25,-18,-12,-6,
};