void parabola(double x0, double y0, double x1, double y1, double xb, double yb){ register double x, y, t; double c0x, c0y, c1x, c1y; double dt, d2, d1; d1 = sqrt((xb - x0) * (xb - x0) + (yb - y0) * (yb - y0)); d2 = sqrt((xb - x1) * (xb - x1) + (yb - y1) * (yb - y1)); if (d1 <= e1->quantum || d2 <= e1->quantum) { plotline(x0, y0, x1, y1); return; } c0x = x0 + x1 - 2. * xb; c1x = 2. * (xb - x0); c0y = y0 + y1 - 2. * yb; c1y = 2. * (yb - y0); move(x0, y0); dt = e1->quantum / d1; dt /= e1->grade; for (t = dt; t < 0.5; t += dt) { x = (c0x * t + c1x) * t + x0; y = (c0y * t + c1y) * t + y0; vec(x, y); } dt = e1->quantum / d2; dt /= e1->grade; for (; t < 1.0; t += dt) { x = (c0x * t + c1x) * t + x0; y = (c0y * t + c1y) * t + y0; vec(x, y); } vec(x1, y1); }
void main(void) { int i; TRISD = 0b00000111; // All SCK, SDI, D_C, _SCE and _RES are output pins. initlcd(); putstr(" PCD-8544 LCD "); // A test message.... Also a new year's greeting. :) cursorxy(0,1); // Next line. putstr("Graphical Demo"); for(;;) { for(i=0;i<num_of_points;i++) { plot_pt[i] = (char)(rand() % 256); // Generate random numbers. Default is 0-255. } plotline(plot_pt, num_of_points, 255, 10, 2); // Plot the smooth(er) line graph. plotbars(plot_pt, num_of_points, 255, 10, 4); // Plot the bar graph version with the same points. // DelayS(5); // Remark this line if you want to see some really blazing fast plotting. :) } }
void rarc(double x1, double y1, double x2, double y2, double xc, double yc, double rr){ register double dx, dy, a, b; double ph, dph, rd, xnext; register int n; dx = x1 - xc; dy = y1 - yc; rd = sqrt(dx * dx + dy * dy); if (rd / e1->quantum < 1.0) { move(xc, yc); vec(xc, yc); return; } dph = acos(1.0 - (e1->quantum / rd)); if (dph > PI4) dph = PI4; ph=atan2((y2-yc),(x2 - xc)) - atan2(dy, dx); if (ph < 0) ph += 6.2832; if (rr < 0) ph = 6.2832 - ph; if (ph < dph) plotline(x1, y1, x2, y2); else { n = ph / dph; a = cos(dph); b = sin(dph); if (rr < 0) b = -b; move(x1, y1); while ((n--) >= 0) { xnext = dx * a - dy * b; dy = dx * b + dy * a; dx = xnext; vec(dx + xc, dy + yc); } } }
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 line(V3d a,V3d b) { plotline(prepare(a),prepare(b),1); }
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() { 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(); }