void main() { Map2d<short> *from=new Map2d<short>(scrwid,scrhei); JBmp *to=new JBmp(scrwid,scrhei); randomise(); allegrosetup(320,200); for (int i=0;i<256;i++) { mypalette(i,myRGB::hue((float)i/256)); } for (int x=0;x<scrwid;x++) for (int y=0;y<scrhei;y++) { from->pos[x][y]=intrnd(-60,60); } to->bmp[0][0]=myrnd()*256; to->bmp[0][scrwid-1]=myrnd()*256; to->bmp[scrhei-1][0]=myrnd()*256; to->bmp[scrhei-1][scrwid-1]=myrnd()*256; do { make(to,from,0,0,scrwid-1,scrhei-1); to->display(); for (int x=0;x<scrwid;x++) for (int y=0;y<scrhei;y++) { from->pos[x][y]+=intrnd(-5,5); } } while (!key[KEY_ESC]); }
int main(String *argv,int argc) { int i; allegrosetup(scrwid,scrhei); mypalette(0,0,0,0); mypalette(255,1,1,1); if (glasses) { mypalette(128,0,0,0); for (i=1;i<128;i++) { mypalette(i,0.3+0.4*i/128,0,0); mypalette(128+i,0,0.3+0.5*i/128,0); } } for (i=0;i<numparts;i++) { part[i].gwell=0; newpart(i); } while (!key[KEY_ESC]) { for (i=0;i<numparts;i++) { movepart(i); } } allegro_exit(); }
void main() { JBmp *j=new JBmp(scrwid,scrhei); JBmp *k=new JBmp(scrwid,scrhei); JBmp *tmp; short *change=new short[cs]; srand((int)time(NULL)); for (int i=0;i<cs;i++) { change[i]=(i/ss/ss/ss/ss)%ss; if (myrnd()>.8) change[i]=(change[i]-1+ss)%ss; // change[i]=myrnd()*ss; } for (int x=0;x<scrwid;x++) for (int y=0;y<scrhei;y++) { j->bmp[y][x]=myrnd()*ss; // j->bmp[y][x]=0; } allegrosetup(320,200); for (int i=0;i<ss;i++) { // mypalette(i,myrnd(),myrnd(),myrnd()); mypalette(i,(float)i/ss,(float)i/ss,(float)i/ss); // mypalette(i,myRGB::hue((float)i/ss)); } do { j->writetoscreen(); tmp=k; k=j; j=tmp; for (int x=0;x<scrwid;x++) for (int y=0;y<scrhei;y++) { // Collect neighbours int c=0; int n=0; for (int dx=-1;dx<=1;dx++) for (int dy=-1;dy<=1;dy++) { n=n+pow(ss,c)*k->pointat(x+dx,y+dy); c++; } j->bmp[y][x]=change[n]; } } while (!key[KEY_ESC]); }
void SetPalettePNGImg( const std::vector<gimg::colorRGB24> & srcpal, const std::string & filepath ) { fstream inimg(filepath, std::ios_base::in | std::ios_base::binary ); png::reader< std::fstream > reader(inimg); reader.read_info(); png::color_type colorType = reader.get_color_type(); const uint32_t bitdepth = reader.get_bit_depth(); if( colorType != png::color_type::color_type_palette ) throw runtime_error( "Error: the image to inject a palette into does not have already a color palette !" ); //Build palette png::palette mypalette( srcpal.size() ); for( unsigned int i = 0; i < mypalette.size(); ++i ) { mypalette[i].red = srcpal[i].red; mypalette[i].green = srcpal[i].green; mypalette[i].blue = srcpal[i].blue; } //Set palette if( bitdepth == 4 ) { png::image<png::index_pixel_4> tmpimg; tmpimg.read( filepath, png::require_color_space<png::index_pixel_4>() ); tmpimg.set_palette( mypalette ); tmpimg.write(filepath); } else if( bitdepth == 8 ) { png::image<png::index_pixel> tmpimg; tmpimg.read( filepath, png::require_color_space<png::index_pixel>() ); tmpimg.set_palette( mypalette ); tmpimg.write(filepath); } else throw runtime_error("Error: the image to inject a palette into has an unsupported bitdepth!"); }
void main() { allegrosetup(scrwid,scrhei); psychedelicpalette(); mypalette(255,0,0,0); V3d pos=V3d(0,0,0); V3d vel=V3d(0,0,0); V3d acc=V3d(0,0,0); Ori ori; float roll=0; float yaw=0; JBmp b=JBmp(scrwid,scrhei); PPsetup(scrwid,scrhei,4); do { b.clear(255); V3d off=V3d(mymod(pos.x,gjump),mymod(pos.y,gjump),mymod(pos.z,gjump)); int ioff=-mydiv(pos.x,gjump); int joff=-mydiv(pos.y,gjump); int koff=-mydiv(pos.z,gjump); for (int k=gridsize;k>=-gridsize;k-=gjump) for (int i=-gridsize;i<=gridsize;i+=gjump) for (int j=-gridsize;j<=gridsize;j+=gjump) { int x,y; V3d cen=V3d(i,j,k)-off; cen=V3d::orientate(cen,ori); int c=256.0*mymod(5*mysquare((i-ioff)/gjump)-11*(j-joff)/gjump-7*(k-koff)/gjump,6)/6.0; PPgetscrpos(cen,&x,&y); b.filledcircle(x,y,0.1*PPgetunit(cen),c); } b.writetoscreen(); acc=hang(acc,V3d::origin,0.93,0.02); vel=hang(vel,V3d::origin,0.93,0)+acc; pos=pos+vel; roll=hang(roll,0,0.92,0.01); yaw=hang(yaw,0,0.92,0.01); ori.roll(roll); ori.yaw(yaw); } while (!key[KEY_ESC]); }
void main() { Map2d<uchar> *from=new Map2d<uchar>(scrwid,scrhei); Map2d<uchar> *dest=new Map2d<uchar>(scrwid,scrhei); JBmp *rto=new JBmp(scrwid*2,scrhei); Map2d<int> *to=new Map2d<int>(scrwid,scrhei,0); randomise(); allegrosetup(320,200); for (int i=0;i<256;i++) { mypalette(i,myRGB::hue(mymod(4.0*(float)i/256.0))); } for (int x=0;x<scrwid;x++) for (int y=0;y<scrhei;y++) { from->pos[x][y]=intrnd(512+256); dest->pos[x][y]=intrnd(512+256); } do { to->clear(0); to->pos[0][0]=from->pos[0][0]; to->pos[scrwid-1][0]=from->pos[scrwid-1][0]; to->pos[0][scrhei-1]=from->pos[0][scrhei-1]; to->pos[scrwid-1][scrhei-1]=from->pos[scrwid-1][scrhei-1]; make(rto,to,from,0,0,toppow); rto->display(); for (int x=0;x<scrwid;x++) for (int y=0;y<scrhei;y++) { // from->pos[x][y]=ucharchop(from->pos[x][y]+magrnd(10)); int speed=3; if (from->pos[x][y]<=dest->pos[x][y]-speed) from->pos[x][y]+=speed; else if (from->pos[x][y]>=dest->pos[x][y]+speed) from->pos[x][y]-=speed; else dest->pos[x][y]=intrnd(512+256); } } while (!key[KEY_ESC]); }
void main() { allegrosetup(scrwid,scrhei); makepalette(&greypalette); mypalette(255,0,0,0); mypalette(0,0,0,0); mypalette(255,1,1,1); mypalette(128,0,0,0); randomise(); for (int i=0;i<=5;i++) { waves+Wave(); //waves.num(i).display(); } for (int r=0;r<8;r++) { for (int g=0;g<8;g++) { int palc=r+g*8; mypalette(palc,(r==0?0:0.1+0.6*r/7.0),(g==0?0:0.1+0.2*g/7.0),(g==0?0:0.1+0.7*g/7.0)); // Good colours: mypalette(palc,(r==0?0:0.3+0.4*r/7.0),(g==0?0:0.1+0.2*g/7.0),(g==0?0:0.3+0.5*g/7.0)); } } V3d vel=V3d(0,0,0); V3d acc=V3d(0,0,0); Ori ori; float droll=0; float dyaw=0; float roll=0; float yaw=0; float pitch=0; int frame=0; List<V3d> particles=List<V3d>(gridsize*gridsize*gridsize); /* for (int i=1;i<gridsize*gridsize*gridsize;i++) { particles+gridsize*V3d(floatrnd(-1,1),floatrnd(-1,1),floatrnd(-1,1)); }*/ for (float thru=0;thru<1.0;thru+=0.01) { particles+getpos(thru); //v.print(); } starttimer(); float thru=0; V3d pos=getpos(thru); do { thru+=0.001; V3d last=pos; V3d pos=getpos(thru); V3d newz=pos-last; ori.forcez(newz); frame++; float pd=1.6+1.3*sin(2*pi*frame/1000.0); PPsetup(scrwid,scrhei,pd); left.clear(0); right.clear(0); // b.fadeby(16); V3d off=V3d(mymod(pos.x,gridsize),mymod(pos.y,gridsize),mymod(pos.z,gridsize)); int ioff=-mydiv(pos.x,gjump); int joff=-mydiv(pos.y,gjump); int koff=-mydiv(pos.z,gjump); ori.quickorisetup(); // Need to find largest axis, and do loops with that one outside int ks=mysgn(ori.qz.z); int js=-mysgn(ori.qz.y); int is=-mysgn(ori.qz.x); for (int i=1;i<=particles.len;i++) { int x,y; V3d p=particles.num(i); //V3d cen=p-off; V3d cen=p+pos; cen=V3d(mymod2(cen.x,-gridsize,gridsize),mymod2(cen.y,-gridsize,gridsize),mymod2(cen.z,-gridsize,gridsize)); cen=V3d::qorientate(cen,ori); int c=7.0-chop(6.0*(cen.z+gridsize)/(float)(gridsize*2),0,6); plotsphere(cen,c); } for (int i=0;i<scrwid;i++) { for (int j=0;j<scrhei;j++) { b.bmp[j][i]=(left.bmp[j][i] | right.bmp[j][i]); } } b.writetoscreen(); // acc=hang(acc,V3d::origin,0.95,0.01); // vel=hang(vel,(ori.qz/5.0).neg(),0.9,0)+acc; // pos=pos+vel; // droll=hang(droll,0,0.9,0.01); // dyaw=hang(dyaw,0,0.95,0.01); // roll=hang(roll,0,0.95,0)+droll; // yaw=hang(yaw,0,0.92,0)+dyaw; // pitch=hang(pitch,0,0.999,0.01); // pos=pos+ori.qz*4; // ori.roll(roll/5.0); // ori.yaw(yaw/5.0); // pos=pos-ori.z()*4; framedone(); } while (!key[KEY_SPACE] && !key[KEY_ESC]); savetimer(); allegro_exit(); displayframespersecond(); }
void main() { allegrosetup(scrwid,scrhei); makepalette(&greypalette); mypalette(255,0,0,0); mypalette(0,0,0,0); mypalette(255,1,1,1); mypalette(128,0,0,0); for (int r=0;r<8;r++) { for (int g=0;g<8;g++) { int palc=r+g*8; mypalette(palc,(r==0?0:0.3+0.4*r/7.0),(g==0?0:0.1+0.2*g/7.0),(g==0?0:0.3+0.5*g/7.0)); } } // randomise(); V3d pos=V3d(0,0,0); V3d vel=V3d(0,0,0); V3d acc=V3d(0,0,0); Ori ori; float droll=0; float dyaw=0; float roll=0; float yaw=0; float pitch=0; int frame=0; starttimer(); do { frame++; float pd=2.0+1.8*sin(2*pi*frame/1000.0); PPsetup(scrwid,scrhei,pd); left.clear(0); right.clear(0); // b.fadeby(16); V3d off=V3d(mymod(pos.x,gjump),mymod(pos.y,gjump),mymod(pos.z,gjump)); int ioff=-mydiv(pos.x,gjump); int joff=-mydiv(pos.y,gjump); int koff=-mydiv(pos.z,gjump); ori.quickorisetup(); // Need to find largest axis, and do loops with that one outside int ks=mysgn(ori.qz.z); int js=-mysgn(ori.qz.y); int is=-mysgn(ori.qz.x); for (int k=ks*gridsize;k!=-ks*gridsize;k=k-ks*gjump) for (int i=-is*gridsize;i!=is*gridsize;i=i+is*gjump) for (int j=-js*gridsize;j!=js*gridsize;j=j+js*gjump) { int x,y; V3d cen=V3d(i,j,k)-off; cen=V3d::qorientate(cen,ori); int c=7-chop(7*(cen.z+pd+1)/(gridsize+2),0,7); plotsphere(cen,c); } for (int i=0;i<scrwid;i++) { for (int j=0;j<scrhei;j++) { b.bmp[j][i]=(left.bmp[j][i] | right.bmp[j][i]); } } b.writetoscreen(); acc=hang(acc,V3d::origin,0.95,0.01); vel=hang(vel,ori.qz/10,0.94,0)+acc; pos=pos+vel; droll=hang(droll,0,0.9,0.01); dyaw=hang(dyaw,0,0.95,0.01); roll=hang(roll,0,0.95,0)+droll; yaw=hang(yaw,0,0.92,0)+dyaw; pitch=hang(pitch,0,0.999,0.01); pos=pos+ori.qz*4; ori.roll(roll/5.0); ori.yaw(yaw/5.0); pos=pos-ori.z()*4; framedone(); } while (!key[KEY_SPACE] && !key[KEY_ESC]); savetimer(); allegro_exit(); displayframespersecond(); }
void makepalette(myRGB (*fn)(float)) { for (int i=0;i<=255;i++) mypalette(i,fn((float)i/255)); }
void main() { allegrosetup(scrwid,scrhei); makepalette(&greypalette); mypalette(255,0,0,0); mypalette(0,0,0,0); mypalette(255,1,1,1); mypalette(128,0,0,0); randomise(); for (int i=0;i<=15;i++) { waves+Wave(); // waves.num(i).display(); } for (int r=0;r<16;r++) { for (int g=0;g<16;g++) { int palc=r+g*16; mypalette(palc,(r==0?0:brightness+0.2+change*0.5*r/15.0),(g==0?0:brightness+change*0.1+0.2*g/15.0),(g==0?0:brightness+change*0.2+0.6*g/15.0)); // Groovy colours mypalette(palc,(r==0?0:0.1+0.6*r/15.0),(g==0?0:0.1+0.2*g/15.0),(g==0?0:0.1+0.7*g/15.0)); // Good colours: mypalette(palc,(r==0?0:0.3+0.4*r/15.0),(g==0?0:0.1+0.2*g/15.0),(g==0?0:0.3+0.5*g/15.0)); } } V3d vel=V3d(0,0,0); V3d acc=V3d(0,0,0); Ori ori; float droll=0; float dyaw=0; float dpitch=0; int frame=0; List<V3d> particles=List<V3d>(gridsize*gridsize*gridsize); /* for (int i=1;i<gridsize*gridsize*gridsize;i++) { particles+gridsize*V3d(floatrnd(-1,1),floatrnd(-1,1),floatrnd(-1,1)); }*/ int ps=1; float rad=0; for (float thru=0;thru<1.0;thru+=0.0016) { V3d here=getpos(thru); V3d forward=getpos(thru+0.00001)-here; V3d up=V3d::normcross(V3d::crazy,forward); V3d right=V3d::normcross(forward,up); for (int i=0;i<ps;i++) { float t=2*pi*(float)i/(float)ps; float s=sin(t); float c=cos(t); particles+(here+rad*(s*up+c*right)); } // v.print(); } starttimer(); float thru=0; float marker=0; V3d pos=getpos(marker); V3d *tail=new V3d[taillen]; int tailpos=0; do { thru+=0.001; // V3d last=V3d(pos.x,pos.y,pos.z); // V3d pos=getpos(thru); // V3d next=getpos(thru+0.00001); // V3d newz=next-pos; // ori.forcez(newz); frame++; // float pd=1.6+1.3*sin(2*pi*frame/1000.0); float pd=2.0; PPsetup(scrwid,scrhei,pd); left.clear(0); right.clear(0); // b.fadeby(16); int ioff=-mydiv(pos.x,gjump); int joff=-mydiv(pos.y,gjump); int koff=-mydiv(pos.z,gjump); ori.quickorisetup(); // Need to find largest axis, and do loops with that one outside int ks=mysgn(ori.qz.z); int js=-mysgn(ori.qz.y); int is=-mysgn(ori.qz.x); for (int i=1;i<=particles.len;i++) { int x,y; V3d p=particles.num(i); V3d cen=p-pos+0.0*ori.y; cen=V3d::disorientate(cen,ori); int c=15.0-chop(14.0*(cen.z+gridsize)/(float)(gridsize*2),0,14); // int c=7.0-chop(6.0*(i/particles.len),0,6); plotsphere(cen,c); } // Plot and move marker V3d m; for (int i=1;i<=15;i++) { m=V3d::disorientate(getpos(marker)-pos,ori); if (m.mod()<markerrange) marker+=0.0002; } float u=PPgetunitnoadd(m); bool plot=false; if (u) { int x,y; float rad=0.08*u; PPgetscrposnoadd(m,PPlefteye,&x,&y); if (left.inimage(x,y)) { plot=true; left.opencircle(x,y,rad,15); } PPgetscrposnoadd(m,PPrighteye,&x,&y); if (right.inimage(x,y)) { plot=true; right.opencircle(x,y,rad,15*16); } } if (!plot) { V2d v=scrwid*2*V2d(m.x,m.y).norm(); if (abs(v.x)>scrwid/2) { float change=(float)scrwid/2.0/abs(v.x); v=change*v; } if (abs(v.y)>scrhei/2) { float change=(float)scrhei/2.0/abs(v.y); v=change*v; } v=v+V2d(scrwid/2,scrhei/2); left.opencircle(v,5,15); right.opencircle(v,5,15*16); } // Pull player towards marker // if (m.mod()>markerrange+.1) { V3d pulldir=getpos(marker)-pos; // vel=vel+pulldir*0.02; // float amount=(V3d::normdot(ori.z(),pulldir)+5.0)/6.0; float amount=chop(0.99-(m.mod()-markerrange)/5.0,0,1); V3d newz=ori.z()*amount+(1.0-amount)*pulldir; ori.forcez(newz); // vel=vel*amount; // //} // Draw and update tail V3d last=(tail[tailpos]-pos).disorientate(ori); for (int k=1;k<taillen;k++) { int j=mymod(tailpos+k,taillen); V3d next=(tail[j]-pos).disorientate(ori); plotline(last,next,(float)k/(float)taillen); last=next; } if ((frame % 5)==0) { tail[tailpos]=pos-ori.qz; tailpos=mymod(tailpos+1,taillen); } // Or screens for (int i=0;i<scrwid;i++) { for (int j=0;j<scrhei;j++) { b.bmp[j][i]=(left.bmp[j][i] | right.bmp[j][i]); } } b.writetoscreen(); // acc=hang(acc,V3d::origin,0.95,0.01); // Movement float angvel=turnability; if (key[KEY_LCONTROL]) vel=vel+ori.z()*forcevel; else angvel=turnability*2.0; if (key[KEY_UP]) dpitch=dpitch+angvel; if (key[KEY_DOWN]) dpitch=dpitch-angvel; if (key[KEY_LEFT]) if (key[KEY_ALT]) droll=droll-angvel; else dyaw=dyaw-angvel; if (key[KEY_RIGHT]) if (key[KEY_ALT]) droll=droll+angvel; else dyaw=dyaw+angvel; vel=hang(vel,V3d::o,0.91,0); pos=pos+vel; droll=hang(droll,0,0.9,0); dyaw=hang(dyaw,0,0.9,0); dpitch=hang(dpitch,0,0.9,0); ori.roll(droll/5.0); ori.yaw(dyaw/5.0); ori.pitch(dpitch/5.0); framedone(); } while (!key[KEY_SPACE] && !key[KEY_ESC]); savetimer(); allegro_exit(); displayframespersecond(); }
void main() { setuptriglookup(); allegrosetup(scrwid,scrhei); makepalette(&greypalette); mypalette(255,0,0,0); mypalette(0,0,0,0); mypalette(255,1,1,1); mypalette(128,0,0,0); for (int r=0;r<16;r++) { for (int g=0;g<16;g++) { int palc=r+g*16; mypalette(palc,(r==0?0:brightness+0.2+change*0.5*r/15.0),(g==0?0:brightness+change*0.1+0.2*g/15.0),(g==0?0:brightness+change*0.2+0.6*g/15.0)); // Groovy colours mypalette(palc,(r==0?0:0.1+0.6*r/15.0),(g==0?0:0.1+0.2*g/15.0),(g==0?0:0.1+0.7*g/15.0)); // Good colours: mypalette(palc,(r==0?0:0.3+0.4*r/15.0),(g==0?0:0.1+0.2*g/15.0),(g==0?0:0.3+0.5*g/15.0)); } } float pd=2.5; PPsetup(scrwid,scrhei,pd); V3d vel=V3d(0,0,0); V3d acc=V3d(0,0,0); float droll=0; float dyaw=0; float dpitch=0; int frame=0; // Set up track randomise(); for (int i=0;i<=15;i++) { waves+Wave(); // waves.num(i).display(); } for (float thru=0;thru<1.0;thru+=1.0/(float)numps) { V3d here=getpos(thru); V3d forward=getpos(thru+0.00001)-here; V3d up=V3d::normcross(V3d::crazy,forward); V3d right=V3d::normcross(forward,up); for (int i=0;i<tunnelps;i++) { float t=2*pi*(float)i/(float)tunnelps; float s=sin(t); float c=cos(t); V3d v=here+tunnelrad*(s*up+c*right); octree.add(v); } } for (int i=1;i<500;i++) { octree.add(8.0*V3d(floatrnd(-1,1),floatrnd(-1,1),floatrnd(-1,1))); } // Display track float t=0; do { t=t+0.03; V3d from=V3d::rotate(6.0*V3d::k,V3d::j,t); ori.forcez(from.neg()); pos=from; plotscene(); writescreen(); } while (!key[KEY_SPACE]); do { } while (key[KEY_SPACE]); // Race starttimer(); float thru=0; float marker=0; pos=getpos(marker); V3d *tail=new V3d[taillen]; int tailpos=0; do { thru+=0.001; // V3d last=V3d(pos.x,pos.y,pos.z); // V3d pos=getpos(thru); // V3d next=getpos(thru+0.00001); // V3d newz=next-pos; // ori.forcez(newz); frame++; // float pd=1.6+1.3*sin(2*pi*frame/1000.0); plotscene(); // Plot and move marker V3d m; for (int i=1;i<=15;i++) { m=V3d::disorientate(getpos(marker)-pos,ori); if (m.mod()<markerrange) marker+=0.0002; } float u=PPgetunitnoadd(m); bool plot=false; if (u) { int x,y; float rad=0.12*u; if (PPgetscrposnoadd(m,PPlefteye,&x,&y)) if (left.inimage(x,y)) { plot=true; left.opencircle(x,y,rad,15); left.opencircle(x,y,rad/2,15); } if (PPgetscrposnoadd(m,PPrighteye,&x,&y)) if (right.inimage(x,y)) { plot=true; right.opencircle(x,y,rad,15*16); right.opencircle(x,y,rad/2,15*16); } } if (!plot) { V2d v=scrwid*2*V2d(m.x,m.y).norm(); if (abs(v.x)>scrwid/2) { float change=(float)scrwid/2.0/abs(v.x); v=change*v; } if (abs(v.y)>scrhei/2) { float change=(float)scrhei/2.0/abs(v.y); v=change*v; } v=v+V2d(scrwid/2,scrhei/2); left.opencircle(v,5,15); right.opencircle(v,5,15*16); } // Pull player towards marker // if (m.mod()>markerrange+.1) { V3d pulldir=getpos(marker)-pos; // vel=vel+pulldir*0.02; // float amount=(V3d::normdot(ori.z(),pulldir)+5.0)/6.0; float amount=chop(0.99-(m.mod()-markerrange)/5.0,0,1); V3d newz=ori.z()*amount+(1.0-amount)*pulldir; ori.forcez(newz); // vel=vel*amount; // // // } // Draw and update tail V3d last=(tail[tailpos]-pos).disorientate(ori); for (int k=1;k<taillen;k++) { int j=mymod(tailpos+k,taillen); V3d next=(tail[j]-pos).disorientate(ori); plotline(last,next,(float)k/(float)taillen); last=next; } if ((frame % 2)==0) { tail[tailpos]=pos-ori.qz; tailpos=mymod(tailpos+1,taillen); } writescreen(); // acc=hang(acc,V3d::origin,0.95,0.01); // Movement float angvel=turnability; if (key[KEY_LCONTROL]) vel=vel+ori.z()*forcevel; else angvel=turnability*2.0; if (key[KEY_DOWN]) dpitch=dpitch+angvel; if (key[KEY_UP]) dpitch=dpitch-angvel; if (key[KEY_LEFT]) if (key[KEY_ALT]) droll=droll-angvel; else dyaw=dyaw-angvel; if (key[KEY_RIGHT]) if (key[KEY_ALT]) droll=droll+angvel; else dyaw=dyaw+angvel; vel=hang(vel,V3d::o,0.92,0); pos=pos+vel; droll=hang(droll,0,0.9,0); dyaw=hang(dyaw,0,0.9,0); dpitch=hang(dpitch,0,0.9,0); ori.roll(droll/5.0); ori.yaw(dyaw/5.0); ori.pitch(dpitch/5.0); framedone(); } while (!key[KEY_SPACE] && !key[KEY_ESC]); savetimer(); allegro_exit(); displayframespersecond(); }
void main(int argc,String *argv) { ArgParser a=ArgParser(argc,argv); size=a.intafter("-gs","grid size",20); float rotspeed=a.floatafter("-rs","rotation speed",pi/80.0); float elevang=a.floatafter("-ea","elevation angle",pi/7.0); float waterlevel=a.floatafter("-wl","water level",-0.2); bool funky=a.argexists("-f","funky"); bool groovy=a.argexists("-g","groovy"); a.done(); int scrwid=800; int scrhei=600; //printf("z\n"); allegrosetup(scrwid,scrhei); //printf("a\n"); PPsetup(scrwid,scrhei,4.0,4.0); //printf("b\n"); mypalette(0,myRGB(0,0,0)); mypalette(255,myRGB(0,255,0)); makepalette(&greypalette); alt=Map2d<float>(size,size,0.0); randomise(); drv=Map2d<float>(size,size,&myrnd); vel=Map2d<float>(size,size,0.0); vs=Map2d<V3d>(size,size); int time=0; dogeol(300); while (!keypressed()) { //printf("d\n"); time++; // Generate new mountain alt.pos[0][0]=drv.pos[0][0]; alt.pos[size-1][0]=drv.pos[size-1][0]; alt.pos[0][size-1]=drv.pos[0][size-1]; alt.pos[size-1][size-1]=drv.pos[size-1][size-1]; makemountain(0,0,size-1,size-1); // Render mountain PPclear(); Matrix ma=Matrix::rotation(V3d(0,1,0),rotspeed*(float)time); Matrix mb=Matrix::rotation(V3d(1,0,0),elevang); //printf("!"); Octree<Renderable*> o=Octree<Renderable*>(V3d::o,2.0,&getpos); for (int i=0;i<size;i++) for (int j=0;j<size;j++) { //printf(">"); V3d x=V3d((float)i/(float)size*2.0-1.0,alt.pos[i][j],(float)j/(float)size*2.0-1.0); // x.y=x.y*ramp((float)i/(float)size*2.0); x=x*V3d(1,2,1)-V3d(0,1,0); bool wat; if (x.y<waterlevel) { x.y=waterlevel; wat=true; } else wat=false; x=ma*x; x=mb*x; vs.pos[i][j]=x; if (i>0 && j>0) { o.add(new Triangle3d(x,vs.pos[i-1][j],vs.pos[i][j-1])); o.add(new Triangle3d(vs.pos[i-1][j],vs.pos[i][j-1],vs.pos[i-1][j-1])); } } Ori ori; Viewpoint v=Viewpoint(V3d(0,0,-4),ori); // Viewpoint v=Viewpoint(mb*(ma*V3d(0,0,-4)),mb*(ma*ori)); render(&o,&v); o.freedom(); // PPshow(); // alt.display(); // Change drivers dogeol(1); } }
void main() { allegrosetup(scrwid,scrhei); makepalette(&greypalette); mypalette(255,0,0,0); randomise(); V3d pos=V3d(0,0,0); V3d vel=V3d(0,0,0); V3d acc=V3d(0,0,0); Ori ori; float droll=0; float dyaw=0; float roll=0; float yaw=0; float pitch=0; for (int i=1;i<1000;i++) { acc=hang(acc,V3d::origin,0.92,0.01); vel=hang(vel,ori.qz/5,0.99,0)+acc; pos=pos+vel; droll=hang(droll,0,0.9,0.01); dyaw=hang(dyaw,0,0.95,0.01); roll=hang(roll,0,0.95,0)+droll; yaw=hang(yaw,0,0.92,0)+dyaw; pitch=hang(pitch,0,0.999,0.01); pos=pos+ori.qz*4; ori.roll(roll/5.0); ori.yaw(yaw/5.0); pos=pos-ori.z()*4; } JBmp b=JBmp(scrwid,scrhei); int frame=0; starttimer(); do { frame++; float pd=2.0-1.5*cos(2*pi*frame/200.0); PPsetup(scrwid,scrhei,pd); b.clear(255); // b.fadeby(16); V3d off=V3d(mymod(pos.x,gjump),mymod(pos.y,gjump),mymod(pos.z,gjump)); int ioff=-mydiv(pos.x,gjump); int joff=-mydiv(pos.y,gjump); int koff=-mydiv(pos.z,gjump); ori.quickorisetup(); // Need to find largest axis, and do loops with that one outside int ks=mysgn(ori.qz.z); int js=-mysgn(ori.qz.y); int is=-mysgn(ori.qz.x); for (int k=ks*gridsize;k!=-ks*gridsize;k=k-ks*gjump) for (int i=-is*gridsize;i!=is*gridsize;i=i+is*gjump) for (int j=-js*gridsize;j!=js*gridsize;j=j+js*gjump) { int x,y; V3d cen=V3d(i,j,k)-off; cen=V3d::qorientate(cen,ori); if (PPgetscrpos(cen,&x,&y)) { int c=255-ucharchop(255*(cen.z+pd+1)/(gridsize+2)); c=quantiseto(64,c+63); b.filledcircle(x,y,0.1*PPgetunit(cen),c); } } b.writetoscreen(); b.saveframe(); acc=hang(acc,V3d::origin,0.92,0.01); vel=hang(vel,ori.qz/5,0.99,0)+acc; pos=pos+vel; droll=hang(droll,0,0.9,0.01); dyaw=hang(dyaw,0,0.95,0.01); roll=hang(roll,0,0.95,0)+droll; yaw=hang(yaw,0,0.92,0)+dyaw; pitch=hang(pitch,0,0.999,0.01); pos=pos+ori.qz*4; ori.roll(roll/5.0); ori.yaw(yaw/5.0); pos=pos-ori.z()*4; framedone(); } while (!key[KEY_SPACE] && !key[KEY_ESC]); savetimer(); allegro_exit(); displayframespersecond(); }
void main(int argc,String *argv) { ArgParser a=ArgParser(argc,argv); size=a.intafter("-gs","grid size",20); float rotspeed=a.floatafter("-rs","rotation speed",pi/80.0); float elevang=a.floatafter("-ea","elevation angle",pi/7.0); float waterlevel=a.floatafter("-wl","water level",-0.2); a.done(); int scrwid=640; int scrhei=480; allegrosetup(scrwid,scrhei); PPsetup(scrwid,scrhei,4.0,4.0); mypalette(0,myRGB(0,0,0)); mypalette(255,myRGB(0,255,0)); alt=Map2d<float>(size,size,0.0); randomise(); drv=Map2d<float>(size,size,&myrnd); vel=Map2d<float>(size,size,0.0); vs=Map2d<V3d>(size,size); int time=0; dogeol(1000); while (!key[KEY_ESC]) { time++; // Generate new mountain alt.pos[0][0]=drv.pos[0][0]; alt.pos[size-1][0]=drv.pos[size-1][0]; alt.pos[0][size-1]=drv.pos[0][size-1]; alt.pos[size-1][size-1]=drv.pos[size-1][size-1]; makemountain(0,0,size-1,size-1); Matrix ma=Matrix::rotation(V3d(0,1,0),rotspeed*(float)time); Matrix mb=Matrix::rotation(V3d(1,0,0),elevang); // Render mountain PPclear(); for (int i=0;i<size;i++) for (int j=0;j<size;j++) { V3d x=V3d((float)i/(float)size*2.0-1.0,alt.pos[i][j],(float)j/(float)size*2.0-1.0); x.y=x.y*ramp((float)i/(float)size*2.0); x=x*V3d(1,2,1)-V3d(0,1,0); if (x.y<waterlevel) x.y=waterlevel; x=ma*x; x=mb*x; /* x=V3d::rotate(x,V3d(0,1,0),rotspeed*(float)time); x=V3d::rotate(x,V3d(1,0,0),elevang);*/ vs.pos[i][j]=x; if (i>0) PPplotline(x,vs.pos[i-1][j]); if (j>0) PPplotline(x,vs.pos[i][j-1]); } PPshow(); // alt.display(); // Change drivers dogeol(1); } }
void main() { allegrosetup(scrwid,scrhei); makepalette(&greypalette); mypalette(255,0,0,0); mypalette(0,0,0,0); mypalette(255,1,1,1); mypalette(128,0,0,0); randomise(); for (int i=0;i<=10;i++) { waves+Wave(); //waves.num(i).display(); } for (int r=0;r<8;r++) { for (int g=0;g<8;g++) { int palc=r+g*8; mypalette(palc,(r==0?0:0.2+0.5*r/7.0),(g==0?0:0.1+0.2*g/7.0),(g==0?0:0.2+0.6*g/7.0)); // Groovy colours mypalette(palc,(r==0?0:0.1+0.6*r/7.0),(g==0?0:0.1+0.2*g/7.0),(g==0?0:0.1+0.7*g/7.0)); // Good colours: mypalette(palc,(r==0?0:0.3+0.4*r/7.0),(g==0?0:0.1+0.2*g/7.0),(g==0?0:0.3+0.5*g/7.0)); } } V3d vel=V3d(0,0,0); V3d acc=V3d(0,0,0); Ori ori; float droll=0; float dyaw=0; float dpitch=0; int frame=0; List<V3d> particles=List<V3d>(gridsize*gridsize*gridsize); /* for (int i=1;i<gridsize*gridsize*gridsize;i++) { particles+gridsize*V3d(floatrnd(-1,1),floatrnd(-1,1),floatrnd(-1,1)); }*/ int ps=1; float rad=0; for (float thru=0;thru<1.0;thru+=0.002) { V3d here=getpos(thru); V3d forward=getpos(thru+0.00001)-here; V3d up=V3d::normcross(V3d::crazy,forward); V3d right=V3d::normcross(forward,up); for (int i=0;i<ps;i++) { float t=2*pi*(float)i/(float)ps; float s=sin(t); float c=cos(t); particles+(here+rad*(s*up+c*right)); } //v.print(); } starttimer(); float thru=0; V3d pos=getpos(thru); do { thru+=0.001; // V3d last=V3d(pos.x,pos.y,pos.z); // V3d pos=getpos(thru); // V3d next=getpos(thru+0.00001); // V3d newz=next-pos; // ori.forcez(newz); frame++; // float pd=1.6+1.3*sin(2*pi*frame/1000.0); float pd=2.0; PPsetup(scrwid,scrhei,pd); left.clear(0); right.clear(0); // b.fadeby(16); int ioff=-mydiv(pos.x,gjump); int joff=-mydiv(pos.y,gjump); int koff=-mydiv(pos.z,gjump); ori.quickorisetup(); // Need to find largest axis, and do loops with that one outside int ks=mysgn(ori.qz.z); int js=-mysgn(ori.qz.y); int is=-mysgn(ori.qz.x); float maxdist=100000; int maxp; for (int i=1;i<=particles.len;i++) { int x,y; V3d p=particles.num(i); V3d cen=p-pos+0.0*ori.y; if (cen.mod()<maxdist) { maxdist=cen.mod(); maxp=i; } cen=V3d::disorientate(cen,ori); int c=7.0-chop(6.0*(cen.z+gridsize)/(float)(gridsize*2),0,6); // int c=7.0-chop(6.0*(i/particles.len),0,6); plotsphere(cen,c); } plotline(V3d(-0.1,0,0),V3d(0,0,0.5)); plotline(V3d(0.1,0,0),V3d(0,0,0.5)); plotline(V3d(0,-0.1,0),V3d(0,0,0.5)); plotline(V3d(0,0.1,0),V3d(0,0,0.5)); for (int i=0;i<scrwid;i++) { for (int j=0;j<scrhei;j++) { b.bmp[j][i]=(left.bmp[j][i] | right.bmp[j][i]); } } // Simple crosshair // b.hline(scrwid/2-10,scrhei/2,scrwid/2+10,255); // b.vline(scrwid/2,scrhei/2-10,scrhei/2+10,255); b.writetoscreen(); // acc=hang(acc,V3d::origin,0.95,0.01); if (key[KEY_UP]) dpitch=dpitch+angvel; if (key[KEY_DOWN]) dpitch=dpitch-angvel; if (key[KEY_LEFT]) if (key[KEY_ALT]) droll=droll-angvel; else dyaw=dyaw-angvel; if (key[KEY_RIGHT]) if (key[KEY_ALT]) droll=droll+angvel; else dyaw=dyaw+angvel; if (key[KEY_LCONTROL]) vel=vel+ori.z()*forcevel; V3d pulldir=particles.num(maxp)-pos; vel=hang(vel,V3d::o,0.98,0)+pulldir*0.02; // pos=hang(pos,particles.num(maxp),0.9,0)+vel; pos=pos+vel; droll=hang(droll,0,0.9,0); dyaw=hang(dyaw,0,0.9,0); dpitch=hang(dpitch,0,0.9,0); ori.roll(droll/5.0); ori.yaw(dyaw/5.0); ori.pitch(dpitch/5.0); V3d at=particles.num(mymod2(maxp+10,1,particles.len+1))-pos; V3d newz=ori.z()*.99+.01*at; ori.forcez(newz); framedone(); } while (!key[KEY_SPACE] && !key[KEY_ESC]); savetimer(); allegro_exit(); displayframespersecond(); }