Ejemplo n.º 1
0
//
//	A person
//
unsigned long CALLBACK person_thread(void *p) {
    int from = 0, to; /* start on the ground floor */
    Lift_info *l;

    randomise();
    while (1) {     /* stay in the building forever */
        Sleep(rnd(PEOPLESPEED)); /* work for a while */
        do
            to = rnd(NFLOORS);
        while (to == from);	/* pick a different floor to go to*/
        if (to > from) {	/* if we are going up */
            floor[from].waitingtogoup++;
            char_at_xy(NLIFTS * 4 + floor[from].waitingtogoup + floor[from].waitingtogodown, NFLOORS - from, 0xdc);

            wait(floor[from].up_arrow);     //wait
        }
        else {  /* if we are going down */
            floor[from].waitingtogodown++;
            char_at_xy(NLIFTS * 4 + floor[from].waitingtogodown
                + floor[from].waitingtogoup, NFLOORS - from, 0xdc);

            wait(floor[from].down_arrow);   //wait
        }

        l = global_lift_ptr;                //get Lift pointer from shared data

        l->stops[to]++;  /* press the button for the floor we want */
        if (l->stops[to] == 1)  /* light up the button if we were the first */
            char_at_xy(l->no * 4 + 1 + 2, NFLOORS - to, '-');

        wait(l->stopsem[to]);               //wait

        from = to;  /* we have reached our destination */
    }
}
Ejemplo n.º 2
0
double optimise_parameters(int helices, int r){

    	rotation = r;
    	vbest = VBIG;
	ncalls = 0;

   	 /*
    	printf("Optimum Parameter Search Program\n");
    	printf("Build date : %s\n",__DATE__);
    	printf("Copyright (C) 1994/2005 David T. Jones\n\n");
    	*/

    	randomise();
    	readparams(helices);

    	/*
    	printf("Number of parameters = %d\n", genlen);
    	printf("Pool size = %d\n", poolsize);
    	printf("Mutation rate = %f\n", mutrate);
   	 printf("Crossover rate = %f\n", crosrate);
    	printf("Mutation scaling factor = %f\n", mutscfac);
    	*/

    	ga_init();
    	run_ga();
    	printf("Best score:\t%f\n",best);
	return(best);

}
Ejemplo n.º 3
0
void randomiserem() {
  int i=(int)time(NULL);
  randomise(i);
  FILE* f=fopen("lastrndseed","w");
  fprintf(f,"%i",i);
  fclose(f);
}
Ejemplo n.º 4
0
void main(int argc,String *argv) {

  ArgParser a=ArgParser(argc,argv);
  String fname=a.argafter("-i","Font file (.jf)");
  float size=scrhei/2.0;
//  float size=scrhei/2.0*5;

  JBmp j=JBmp(scrwid,scrhei,0);
  j.setupfastsmooth(6);
  JFont font=JFont(fname);
//  String word="retro asymptotic cyberdruid";
  String word=Salphabet();
  int l=1;
  allegrosetup(scrwid,scrhei);
  makepalette(&greypalette);
  randomise();
  while (!keypressed()) {
//    String c=Smid(word,intrnd(1,Slen(word)),1);
    String c=Smid(word,l,1);
    if (myrnd()<0.07)
    font.writeString(Smid(word,intrnd(1,Slen(word)),1),&j,myrnd()*scrwid,myrnd()*scrhei,0.5+0.5*myrnd()*size,255);
    if (myrnd()<0.07)
    font.centerString("retro",&j,myrnd()*scrwid,myrnd()*scrhei,0.5+0.5*myrnd()*size,255);
    if (myrnd()<0.07)
    font.centerString("asymptotic",&j,myrnd()*scrwid,myrnd()*scrhei,0.5+0.5*myrnd()*size,255);
    if (myrnd()<0.07)
    font.centerString("cyber druid",&j,myrnd()*scrwid,myrnd()*scrhei,0.5+0.5*myrnd()*size,255);
    j.fadeby(10);
    j.randomfastsmooth();
    j.writetoscreen();
    //l=(l%Slen(word))+1;
  }

}
Ejemplo n.º 5
0
void main(int argc,String *argv) {
  
  ArgParser a=ArgParser(argc,argv);
  String iname=a.getarg();
  String fname=Sconc("home/joey/images/",iname,".bmp");
  String ename=Sconc("home/joey/images/exp",iname,".bmp");
  a.done();

  randomise();
  
  image=RGBmp::readfile(fname)->getv3ds();
  greyscale=image->applyfn(&V3dtofloat);
  
  greyscale->edgedetection(Map2d<float>::sobel(),&edgemag,&edgeang);
  expected=Map2d<float>::readfile(ename)->scaleto(image->width,image->height)->threshold(0.5);
  
  printf("Starting segmentation...\n");
  Seg seg=Seg(&measureglvariance);
//  Seg seg=Seg(&classifytrain);
//  Map2d<bool> *b=seg.classifytopdown();
  Map2d<bool> *b=seg.classifyneighbours();
//  Map2d<bool> *b=seg.classifywindows();
  // b->scaleto(expected->width,expected->height)->writefile("textseg.bmp");
  
}
Ejemplo n.º 6
0
Archivo: hue1.c Proyecto: 10crimes/code
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]);
}
Ejemplo n.º 7
0
void main() {
  allegrosetup(scrwid,scrhei);
  makesplitpalette(&redtowhitepalette,&greentowhitepalette);
  randomise();
  PPsetup(scrwid,scrhei,4);
  JBmp j=JBmp(scrwid,scrhei);
  j.clear();
  List<Part> ps=List<Part>();
  for (int i=1;i<=numparts/line;i++) {
    newparts(&ps);
  }
  int frame=0;
  do {
    for (int i=1;i<=ps.len;i++) {
      Part *p=ps.p2num(i);
      int sx,sy;
      PPgetscrpos(p->pos,&sx,&sy);
      int sxb,syb;
      PPgetscrpos(p->pos+V3d(p->rad,0,0),&sxb,&syb);
      float rad=sqrt(mysquare(sx-sxb)+mysquare(sy-syb));
      j.filledcirclenodarker(sx,sy,rad,p->outc);
      j.filledcirclenodarker(sx,sy,rad/3,p->inc);
//      j.shadedcirclenodarker(sx,sy,rad,p->inc,p->outc);
    }
    for (int x=0;x<scrwid;x++)
      for (int y=0;y<scrhei;y++) {
        int k=j.bmp[y][x];
        if (k>=128+fade)
          j.bmp[y][x]-=fade;
        else
          if (k<128)
            if (k>=fade)
              j.bmp[y][x]-=fade;
//            j.bmp[y][x]=intchop(k-fade,0,128);
//          j.bmp[y][x]=128+intchop(k-fade-128,0,128);
        if (k>=128 && k<=128+3)
          j.bmp[y][x]=0;
      }
    j.writetoscreen();
    Matrix m,n;
    V3d rotaxis=V3d::rotate(V3d(0,1,0),V3d(0,0,1),pi/4.0*sin(2*pi*frame/2000));
    m.makerotation(rotaxis,pi/1000.0);
    n.makerotation(rotaxis,-pi/1000.0);
    for (int i=1;i<=ps.len;i++) {
      Part *p=ps.p2num(i);
      if (p->sgn>0)
        p->pos=m*p->pos;
      else
        p->pos=n*p->pos;
      p->pos=p->pos+V3d(0,0,-0.03);
      if ((p->pos.z<-4 || max(myabs(p->pos.x),myabs(p->pos.y))>2)) {
        ps.removenum(i);
        if (ps.len<numparts-line)
          newparts(&ps);
      }
    }
    frame++;
  } while (!key[KEY_ESC]);
}
Ejemplo n.º 8
0
void main() {
  allegrosetup(scrwid,scrhei);
  makepalette(&greypalette);
  makepalette(&myRGB::hue);
  randomise();
  for (int i=0;i<20;i++) {
    float amp=0;
    S s=S(V3d::randomvolume(1),radfromamp(amp),0);
    S v=S(V3d(0,0,0),0,0);
    xs+s;
    xvs+v;
  }
  for (int rndloop=0;rndloop<100;rndloop++) {
    for (int i=0;i<20;i++) {
      S *v=xvs.p2num(i);
      S *x=xs.p2num(i);
      domovement(v,x);
    }
  }
  JBmp j=JBmp(scrwid,scrhei);
  Map2d<int> intmap=Map2d<int>(scrwid,scrhei);
  do {
    for (int x=0;x<scrwid;x+=jump)
    for (int y=0;y<scrhei;y+=jump) {
      V3d here=V3d((x-scrwid/2)*2.0/scrhei,-1.0+2.0*y/scrhei,0);
      float sum=getpotentialfor(here);
      int newcol=128+128*sum;
      intmap.pos[x][y]=newcol;
      if (x>0 && y>0) {
        int nwcol=intmap.pos[x-jump][y-jump];
        int wcol=intmap.pos[x-jump][y];
        int ncol=intmap.pos[x][y-jump];
        for (int i=0;i<=jump;i++)
        for (int k=0;k<=jump;k++) {
          float e=(float)i/(float)jump;
          float w=1.0-e;
          float s=(float)k/(float)jump;
          float n=1.0-s;
          j.bmp[y-jump+k][x-jump+i]=ucharmod(s*e*newcol+n*w*nwcol+s*w*wcol+n*e*ncol);
          // j.bmp[y-jump+k][x-jump+i]=(1.0-i/(float)jump)*(1.0-k/(float)jump)*nwcol+(1.0-i/(float)jump)*(k/(float)jump)*wcol+(i/(float)jump)*(1.0-k/(float)jump)*ncol+(i/(float)jump)*(k/(float)jump)*newcol;
        }
      }
    }
    for (int i=1;i<=xs.len;i++) {
      S *v=xvs.p2num(i);
      S *x=xs.p2num(i);
      domovement(v,x);
      /* if (debug) {
           // int c=j.point(x->cx,x->cy)+x->amp;
           int c=0;
           j.vliner(x->cx,x->cy,plusminus(i)*x->amp,c);
           j.hliner(x->cx,x->cy,x->rad,c);
           j.setpixel(x->cx+radfromamp(x->amp),x->cy,c);
         }*/
    }
    j.writetoscreen();
  } while (!key[KEY_ESC]);
}
Ejemplo n.º 9
0
void main(int argc,String *argv) {
  
  ArgParser a=ArgParser(argc,argv);
  a.com=Sconc(a.com,"[source directories] ");
  String dest=a.argafter("-dest","destination file location",Sconc(safegetenv("JPATH"),"/background.jpg"));

  // Get possible files
  List<String> fs;
  if (a.argsleft()==0) {
    fs.add(getfilesrecursive(Sconc(safegetenv("JPATH"),"/wallpapers/"))); // Default if no args
  }
  while (a.argsleft()) {
    String d=a.getarg();
    fs.add(getfilesrecursive(d));
  }
//  printf("%s\n",fs.toString());
  a.done();

  // Exclude those of wrong type
  List<String> types;
  types.add("jpg");
  types.add("jpeg");
  types.add("bmp");
  types.add("gif");
  types.add("tgz");
  types.add("gz");
  for (int i=1;i<=fs.len;i++) {
    String fname=fs.num(i);
    String ext=Safterlastorall(fname,".");
//    printf("%s has ext %s\n",fname,ext);
    if (    types.find(ext,&Sequiv)==0
         || Sinstr(fname,"wallpapers/tiles/")>0
         || Sinstr(fname,"wallpapers/small/")>0
         || Sinstr(fname,"wallpapers/naff/")>0
         || Sinstr(fname,"wallpapers/for/")>0
         || Sinstr(fname,"/babes/")>0
         || Sinstr(fname,"/fairies/")>0
         || Sinstr(fname,"/mermaids/")>0
         || Sinstr(fname,"/.xvpics/")>0 ) { // Case-insensitive search
//      printf("Didn't find extension %s\n",ext);
      fs.removenum(i);
      i--;
    }
  }

  // Choose a random file and symbolically link it
  randomise();
  int n=intrnd(1,fs.len);
  #ifdef DOS
  String call=Sformat("copy \"%s\" \"%s\"",fs.num(n),dest);
  #else
  String call=Sformat("ln -s -f \"%s\" \"%s\"",fs.num(n),dest);
  #endif
  system(call);
//  setenv("RANDOMFILENAME",fs.num(n),true);

}
Ejemplo n.º 10
0
void main(int argc,String *argv) {
  
  ArgParser a=ArgParser(argc,argv);
  bool writingframes=a.argexists("-wf","write frames");
  int tol=a.intafter("-t","colour tolerance",8);
  int res=a.intafter("-r","resolution",5);
  a.done();
  
  allegrosetup(scrwid,scrhei);
  makepalette(&greypalette);
  PPsetup(scrwid,scrhei,2.0);
  
  JBmp img=JBmp(scrwid,scrhei);
  
  randomise();
  for (int i=1;i<=5;i++) {
    // int j=intrnd(1,2);
    if (odd(i))
      es.add(new Radial());
    else
      es.add(new Stripey());
    // es.num(es.len)->amp=floatrnd(0,1);
    es.num(es.len)->amp=1;
  }
  
  for (int i=1;i<=es.len;i++)
  for (int j=1;j<=200;j++)
  es.num(i)->evolve();
  
  int frame=0;
  
  while (!keypressed()) {
    
    frame++;
    
    // Make new image
    
    quadify(&img,&effectat,tol,res,20);
    
    // Show new image
    img.writetoscreen();
    
    // Evolve drivers
    for (int i=1;i<=es.len;i++)
    for (int j=1;j<=5;j++) {
      Effect2d *e=es.num(i);
      e->evolve();
      // e->pos=e->cen+V2d::rotate(e->off,e->rotvel*(float)frame);
    }
    
    if (writingframes)
      img.writeframe();
    
  }
  
}
Ejemplo n.º 11
0
void main() {
  int scrwid=320;
  int scrhei=200;
  int indent=(scrwid-scrhei)/2;
  float cenx=0;
  float ceny=0;
  float wid=0.75;
  float hei=0.75;
  float left=cenx-wid;
  float right=cenx+wid;
  float top=ceny-hei;
  float bottom=ceny+hei;
  float dslice=0;
  float front=-1.5;
  float back=-0.5;
  float scale=2.0/(back-front);
  int steps=250;
  JBmp *b=new JBmp(scrwid,scrhei);
  allegrosetup(scrwid,scrhei);
  makepalette(&greypalette);
  _farsetsel(screen->seg);
  randomise();
//  Quaternion c=*new Quaternion(floatrnd(-2.0,2.0),floatrnd(-2.0,2.0),floatrnd(-2.0,2.0),floatrnd(-2.0,2.0));
  Quaternion c=*new Quaternion(floatrnd(-.5,.5),floatrnd(-.5,.5),floatrnd(-.5,.5),floatrnd(-.5,.5));
  do {
  c=c*Quaternion(0.99,0,0,0)+Quaternion(floatrnd(-.05,.05),floatrnd(-.05,.05),floatrnd(-.05,.05),floatrnd(-.05,.05));
  dslice=c.d;
  for (int i=0;i<scrhei;i+=2) {
    for (int j=0;j<scrhei;j+=2) {
      int col=0;
      for (int k=0;k<steps && col==0;k++) {
        float x=left+2.0*wid*i/(float)scrhei;
        float y=top+2.0*hei*j/(float)scrhei;
        float z=front+(back-front)*k/(float)steps;
        float scrz=(z-front)*scale+1.0;
        x=x/z; y=y/z;
        int r=julquat(Quaternion(x,y,z,dslice),Quaternion(x,y,z,dslice));
        if (r==0)
          col=255.0*(1.0-(float)k/(float)steps);
      }
      b->setpixel(indent+i,j,col);
      b->setpixel(indent+i+1,j,col);
      b->setpixel(indent+i,j+1,col);
      b->setpixel(indent+i+1,j+1,col);
      if (key[KEY_SPACE])
        exit(0);
    }
    b->writetoscreen();
  }
  } while (!key[KEY_SPACE]);
  allegro_exit();
}
Ejemplo n.º 12
0
void main(int argc,String *argv) {

  randomise();
  
  ArgParser a=ArgParser(argc,argv);  
  String imname=a.getarg(1);
  int quant=a.intafter("-q","Quantisation",16);
//  if (a.argsleft())
  String oname=a.argor("edgehist.dat");
  a.done();

//int quant=16;

    RGBmp *oi=RGBmp::readfile(imname);
    Map2d<float> *gs=oi->getgreyscale();

    // Edge detection
    printf("Doing edge detection\n");
    gs->edgedetection(Map2d<float>::sobel(),&mag,&angs);
  
  mag->writefile("tmp.bmp");
  angs->writefile("tmp2.bmp");
  
//  Map1d<float> hist=Map1d<float>(quant);
  float *hist=new float[quant];
  for (int i=0;i<quant;i++)
    hist[i]=0;
  
  for (int x=0;x<gs->width;x++)
  for (int y=0;y<gs->height;y++) {
    float i=angs->pos[x][y]*(float)quant/2.0/pi;
    i=i+(float)quant/2.0;
    int j=i;
//    printf("%i",j);
    hist[j]+=mag->pos[x][y];
  }
  
  List<String> data;
  for (int i=0;i<quant;i++) {
    data.add(Sformat("%.2f",hist[i]));
  }
  
  data.add(Sformat("Score: %.2f",scorefor()));
  data.add(Sformat("V/area: %.2f",keepoffness));

  printf("Score: %.2f\n",scorefor());
  printf("V/area: %.2f\n",keepoffness);
  
  writelinestofile(data,oname);

}
Ejemplo n.º 13
0
int main(void)
{
    char *strings[N];
    char buffer[1000*(3+1)];
    char *p;
    int i;

    p = buffer;
    for (i = 0; i < 1000; i++) {
        sprintf(p, "%03d", i);
        strings[i] = p;
        p += 3+1;
    }
    randomise(strings, N);
    sort(strings, N);
}
Ejemplo n.º 14
0
void main() {
  int scrwid=320;
  int scrhei=200;
  float cenx=-0.5;
  float ceny=0;
  float wid=2.0;
  float hei=1.5;
  float left=cenx-wid;
  float right=cenx+wid;
  float top=ceny-hei;
  float bottom=ceny+hei;
  float front=-1.0;
  float back=0.5;
  float scale=2.0/(2.0*front);
  float crazy=0.1234567;
  int steps=20;
  int jump=1;
  int frames=30;
  JBmp *b=new JBmp(scrwid,scrhei);
  allegrosetup(scrwid,scrhei);
//  makepalette(&greypalette);
  _farsetsel(screen->seg);
  randomise();
  Map2d<float> *map=new Map2d<float>(scrhei,scrhei);
  for (int frame=0;frame<frames;frame++) {
    float angle=pi*(float)frame/(float)frames;
    for (int i=0;i<scrwid;i+=jump) {
      for (int j=0;j<scrhei;j+=jump) {
        // b->setpixelud(indent+i,j,255);
        // b->writetoscreen();
        int col=0;
        V3d tmp=V3d(left+2.0*wid*i/(float)scrwid,top+2.0*hei*j/(float)scrhei,0);
        tmp=V3d::rotate(tmp,V3d(0,1,0),angle);
        current=Quaternion(tmp.x,tmp.y,tmp.z,0);
        b->bmp[j][i]=julquat(Quaternion(0,0,0,0));
        if (key[KEY_SPACE])
          exit(0);
      }
    b->writetoscreen();
    }
//    PALETTE pal;
//    get_palette(pal);
//    save_bitmap(getnextfilename("bmp"),screen,pal);
  } while (!key[KEY_SPACE]);
  allegro_exit();
}
Ejemplo n.º 15
0
void main() {
  int scrwid=320;
  int scrhei=200;
  float cenx=0;
  float ceny=0;
  float wid=2.0;
  float hei=1.5;
  float left=cenx-wid;
  float right=cenx+wid;
  float top=ceny-hei;
  float bottom=ceny+hei;
  JBmp *b=new JBmp(scrwid,scrhei);
  allegrosetup(scrwid,scrhei);
//  makepalette(&greypalette);
  _farsetsel(screen->seg);
  randomise();
  Complex c=Complex(floatrnd(-4.0,4.0),floatrnd(-4.0,4.0));
  do {
  c=c*Complex(0.99,0)+Complex(floatrnd(-.5,.5),floatrnd(-.5,.5));
  for (int i=0;i<scrwid;i+=2) {
    for (int j=0;j<scrhei;j+=2) {
      float x=left+2.0*wid*i/(float)scrwid;
      float y=top+2.0*hei*j/(float)scrhei;
      Complex z=Complex(x,y);
      int k=0;
      bool over=false;
      do {
        k++;
        z=z*z+c;
        if (k>255)
          over=true;
      } while (!over && !(z.mod()>2.0));
      if (over)
        k=0;
      b->setpixel(i,j,k);
      b->setpixel(i+1,j,k);
      b->setpixel(i,j+1,k);
      b->setpixel(i+1,j+1,k);
      if (key[KEY_SPACE])
        break;
    }
  }
  b->writetoscreen();
  } while (!key[KEY_SPACE]);
  allegro_exit();
}
Ejemplo n.º 16
0
void main() {

  allegrosetup(scrwid,scrhei);
  makepalette(&greypalette);
  _farsetsel(screen->seg);
  PALETTE pal;
  get_palette(pal);

  randomise(0.456);
  for (int i=0;i<20;i++) {
    S s=S(V3d::randomvolume(1),0,0);
    S v=S(V3d(0,0,0),0,0);
    xs+s;
    xvs+v;
  }
  for (int rndloop=0;rndloop<100;rndloop++) {
    for (int i=0;i<xs.len;i++) {
      S *v=xvs.p2num(i);
      S *x=xs.p2num(i);
      domovement(v,x);
    }
  }
  do {

    rend->clear(crazy);

    for (int i=0;i<scrhei;i+=jump) {
      for (int j=0;j<scrhei;j+=jump) {
        fillsquare(i,j,jump,jump);
      }
      b->writetoscreen();
    }

    for (int lkg=0;lkg<1;lkg++)
    for (int i=1;i<=xs.len;i++) {
      S *v=xvs.p2num(i);
      S *x=xs.p2num(i);
      domovement(v,x);
    }
    b->writefile(getnextfilename("bmp"));
  } while (!key[KEY_ESC]);
}
Ejemplo n.º 17
0
void main(int argc,String *argv) {
  
  ArgParser a=ArgParser(argc,argv);
  a.done();
  
  randomise();

  for (int i=0;i<20;i++) {
    Line3d la=Line3d(V3d::random(),V3d::random());
    Line3d lb=Line3d(V3d::random(),V3d::random());
    V3d *i=la.intersection(lb);
    if (i==NULL)
      printf("fail\n");
    V3d nor=V3d::cross(la.b-la.a,lb.b-lb.a);
		printf("%f %f\n",
				V3d::normdot(la.b-la.a,nor),
				V3d::normdot(lb.b-lb.a,nor)
		);
	}
		
}
Ejemplo n.º 18
0
void main() {
  RGBmp *j=new RGBmp(scrwid,scrhei);
  RGBmp *k=new RGBmp(scrwid,scrhei);
  randomise();
//  setcolordepth(16);
//  allegrosetup(320,200);
  for (int x=0;x<scrwid;x++)
  for (int y=0;y<scrhei;y++) {
    j->bmp[y][x]=myRGB(myrnd(),myrnd(),myrnd());
  }
  do {
    k->bmp[0][0]=j->bmp[0][0];
    k->bmp[0][scrwid-1]=j->bmp[0][scrwid-1];
    k->bmp[scrhei-1][0]=j->bmp[scrhei-1][0];
    k->bmp[scrhei-1][scrwid-1]=j->bmp[scrhei-1][scrwid-1];
    make(k,j,0,0,scrwid-1,scrhei-1);
    k->display();
    for (int x=0;x<scrwid;x++)
    for (int y=0;y<scrhei;y++) {
    }
  } while (!key[KEY_ESC]);
}
Ejemplo n.º 19
0
//
//	A lift
//
unsigned long CALLBACK lift_thread(void *p) {
    Lift_info l;
    int i;
    int no = (int)p;

    l.no = no;          /* set the no for this lift */
    l.position = 0;     /* set the initial position */
    l.direction = 1;    /* and direction */
    l.peopleinlift = 0; /* empty */
    randomise();
    for (i = 0; i < NFLOORS; i++) {
        l.stops[i] = 0;   /* nobody is waiting in the lift to go anywhere */
        l.stopsem[i] = create(0);
    }
    Sleep(rnd(1000)); /* wait for a while */
    while (1) {        /* do forever */
        char_at_xy(no * 4 + 1, NFLOORS - l.position, 0xdb); /* draw current position of lift */
        Sleep(LIFTSPEED);  /* wait a while */
        while (l.stops[l.position] != 0) {  /* drop off all passengers */
            l.peopleinlift--;        /* one less in lift */
            l.stops[l.position]--;   /* one less waiting */
            Sleep(GETOUTSPEED);      /* wait a while */
            ////////////////////////////////////////////////////////////////////////////
            // ---     /* tell them to get out */
            signal(l.stopsem[l.position]);
            ////////////////////////////////////////////////////////////////////////////
            if (!l.stops[l.position]) /* if it was the last one */
                char_at_xy(no * 4 + 1 + 2, NFLOORS - l.position, ' ');  /* remove the - */
        }
        if (l.direction == UP || !l.peopleinlift)  /* if the lift is going up or is empty */
            getintolift(&l, UP);      /* pick up passengers waiting to go up */
        if (l.direction == DOWN || !l.peopleinlift) /* if the lift is going down or is empty */
            getintolift(&l, DOWN);    /* pick up passengers waiting to go down */
        char_at_xy(no * 4 + 1, NFLOORS - l.position, (char)(l.direction + 1 ? ' ' : 0xb3));  /* erase the lift on the screen */
        l.position += l.direction;   /* move it */
        if (l.position == 0 || l.position == NFLOORS - 1)  /* if it is at the top or bottom */
            l.direction = -l.direction; /* change direction */
    }
}
Ejemplo n.º 20
0
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]);
}
Ejemplo n.º 21
0
//
//	A person
//
unsigned long CALLBACK person_thread(void *p) {
    int from = 0, to; /* start on the ground floor */
    Lift_info *l;

    randomise();
    while (1) {     /* stay in the building forever */
        Sleep(rnd(PEOPLESPEED)); /* work for a while */
        do
            to = rnd(NFLOORS);
        while (to == from);	/* pick a different floor to go to*/
        if (to > from) {	/* if we are going up */
            floor[from].waitingtogoup++;
            char_at_xy(NLIFTS * 4 + floor[from].waitingtogoup + floor[from].waitingtogodown, NFLOORS - from, 0xdc);
            ////////////////////////////////////////////////////////////////////////////
            // ---     /* wait for the lift to arrive */
            ////////////////////////////////////////////////////////////////////////////
        }
        else {  /* if we are going down */
            floor[from].waitingtogodown++;
            char_at_xy(NLIFTS * 4 + floor[from].waitingtogodown
                + floor[from].waitingtogoup, NFLOORS - from, 0xdc);
            ////////////////////////////////////////////////////////////////////////////
            // ---     /* wait for the lift to arrive */
           ////////////////////////////////////////////////////////////////////////////
        }
        ////////////////////////////////////////////////////////////////////////////
    // --- l=  /* which lift are we geting in to */
        ////////////////////////////////////////////////////////////////////////////
        l->stops[to]++;  /* press the button for the floor we want */
        if (l->stops[to] == 1)  /* light up the button if we were the first */
            char_at_xy(l->no * 4 + 1 + 2, NFLOORS - to, '-');
        ////////////////////////////////////////////////////////////////////////////
    // ---           /* wait until we get to the right floor */
        ////////////////////////////////////////////////////////////////////////////
        from = to;  /* we have reached our destination */
    }
}
Ejemplo n.º 22
0
Archivo: kips.c Proyecto: 10crimes/code
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();
}
Ejemplo n.º 23
0
void main() {
  int scrwid=320;
  int scrhei=200;
  int indent=(scrwid-scrhei)/2;
  float cenx=0;
  float ceny=0;
  float wid=1.0;
  float hei=1.0;
  float left=cenx-wid;
  float right=cenx+wid;
  float top=ceny-hei;
  float bottom=ceny+hei;
  float front=-1.0;
  float back=1.0;
  float scale=2.0/(2.0*front);
  float crazy=0.1234567;
  int steps=1000;
  int jump=1;
  JBmp *b=new JBmp(scrwid,scrhei);
  allegrosetup(scrwid,scrhei);
  makepalette(&greypalette);
  _farsetsel(screen->seg);
  randomise();
  Map2d<float> *map=new Map2d<float>(scrhei,scrhei);
  current=*new Quaternion(floatrnd(-.5,.5),floatrnd(-.5,.5),floatrnd(-.5,.5),floatrnd(-.5,.5));
  do {
    current=current*Quaternion(0.99,0,0,0)+Quaternion(floatrnd(-.05,.05),floatrnd(-.05,.05),floatrnd(-.05,.05),floatrnd(-.05,.05));
    
    float dslice=floatrnd(-.3,.3);
    current=*new Quaternion(floatrnd(-.5,.5),floatrnd(-.5,.5),floatrnd(-.5,.5),floatrnd(-.5,.5));
  current=*new Quaternion(-0.488193901,0.572800587,0,0);
    
    for (int i=0;i<scrhei;i+=jump) {
      for (int j=0;j<scrhei;j+=jump) {
        // b->setpixelud(indent+i,j,255);
        // b->writetoscreen();
        int col=0;
        V3d tmpnear=V3d(left+2.0*wid*i/(float)scrhei,top+2.0*hei*j/(float)scrhei,front);
        V3d tmpfar=V3d(tmpnear.x*2.0,tmpnear.y*2.0,back);
        tmpnear=V3d::rotate(tmpnear,V3d(0,1,0),rotation);
        tmpfar=V3d::rotate(tmpfar,V3d(0,1,0),rotation);
        tmpnear=V3d::rotate(tmpnear,V3d(1,0,0),elevation);
        tmpfar=V3d::rotate(tmpfar,V3d(1,0,0),elevation);
        Quaternion near=Quaternion(tmpnear.x,tmpnear.y,tmpnear.z,dslice);
        Quaternion far=Quaternion(tmpfar.x,tmpfar.y,tmpfar.z,dslice);
        map->pos[i][j]=crazy;
        Quaternion last=near-(far-near);
        for (int k=0;k<steps;k++) {
          float dk=(float)k/(float)steps;
          Quaternion next=near*(1.0-dk)+far*dk;
          if (julquat(next)==0) {
            Quaternion res=searchline(last,next);
            // col=255.0*(1.0-(res.c-front)/(forget-front));
            map->pos[i][j]=res.c;
            break;
          }
          last=next;
        }
        if (i>=jump && j>=jump) {
          if (map->pos[i-jump][j-jump]==crazy || map->pos[i-jump][j]==crazy || map->pos[i][j-jump]==crazy)
            col=0;
          else {
            float diff=2.0*map->pos[i-jump][j-jump]-map->pos[i-jump][j]-map->pos[i][j-jump];
            col=chop(128.0+diff*1600.0,0,255);
          }
          for (int x=0;x<jump;x++) {
            for (int y=0;y<jump;y++) {
              b->setpixel(indent+i+x,j+y,col);
            }
          }
        }
        if (key[KEY_SPACE])
          exit(0);
      }
      b->writetoscreen();
    }
    PALETTE pal;
    get_palette(pal);
    save_bitmap(getnextfilename("bmp"),screen,pal);
  } while (!key[KEY_SPACE]);
  allegro_exit();
}
Ejemplo n.º 24
0
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();
}
Ejemplo n.º 25
0
Archivo: last.c Proyecto: 10crimes/code
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();
}
Ejemplo n.º 26
0
void main() {
  int scrwid=320; int scrhei=200;
  int jump=10;
  allegrosetup(scrwid,scrhei);
  makepalette(&greypalette);
  List<S> xs=List<S>();
  List<S> ys=List<S>();
  List<S> xvs=List<S>();
  List<S> yvs=List<S>();
  randomise();
  for (int i=0;i<12;i++) {
    S s=S(myrnd()*scrwid,(1.0+myrnd()*4.0)*pi/(float)scrwid,myrnd()*1.0);
    S v=S(0,0,0);
    if (i%2) {
      xs+s;
      xvs+v;
    } else {
      ys+s;
      yvs+v;
    }
  }
  JBmp j=JBmp(scrwid,scrhei);
  do {
    for (int x=0;x<scrwid;x+=jump)
      for (int y=0;y<scrhei;y+=jump) {       
        float sum=0;
        for (int i=1;i<=xs.len;i++) {
          S s=xs.num(i);
          sum+=s.amp*sin(s.off+s.fre*x);
        }
        for (int i=1;i<=ys.len;i++) {
          S s=ys.num(i);
          sum+=s.amp*sin(s.off+s.fre*y);
        }
        sum=3.0*sum/(float)(xs.len+ys.len);
        int se=ucharchop(128+128*sum);
        j.bmp[y][x]=se;
        if (x>0 && y>0) {
          int nw=j.bmp[y-jump][x-jump];
          int ne=j.bmp[y-jump][x];
          int sw=j.bmp[y][x-jump];
          for (int i=0;i<=jump;i++)
            for (int k=0;k<=jump;k++) {
              float a=(float)i/(float)jump;
              float na=1.0-a;
              float b=(float)k/(float)jump;
              float nb=1.0-b;
              j.bmp[y-jump+k][x-jump+i]=na*nb*nw+a*nb*ne+na*b*sw+a*b*se;
            }
        }
      }
    j.writetoscreen();
    for (int i=1;i<=xs.len;i++) {
      xvs.p2num(i)->off+=magrnd(pi/128);
      xvs.p2num(i)->fre+=magrnd(pi/(float)10/(float)scrwid);
      xvs.p2num(i)->amp+=magrnd(0.005);
      xs.p2num(i)->add(xvs.num(i));
    }
    for (int i=1;i<=ys.len;i++) {
      yvs.p2num(i)->off+=magrnd(pi/128);
      yvs.p2num(i)->fre+=magrnd(pi/(float)10/(float)scrwid);
      yvs.p2num(i)->amp+=magrnd(0.005);
      ys.p2num(i)->add(yvs.num(i));
    }
  } while (!key[KEY_ESC]);
}
Ejemplo n.º 27
0
void randomise() {
#ifndef STUPIDUNIX
  int i=(int)time(NULL);
  randomise(i);
#endif
}
Ejemplo n.º 28
0
void main(int argc,String *argv) {

    randomise();

    ArgParser a=ArgParser(argc,argv);
    String fname=a.argafter("-i","GF lines filename","ls.gf");
    cdclip=a.floatafter("-ed","Maximum end distance of lines",30);
    creepintoline=a.floatafter("-ic","Intersection can creep in this much of the line",0.02);
    dotabove=a.floatafter("-pd","Parallelity: dot product must be above this",0.5);
    minlen=a.floatafter("-ml","Minimum length of a line",20);
    bool displaying=!a.argexists("nod","Don't display");
    String imname=a.argafter("-oi","Original image","none");
    oiscale=a.floatafter("-ois","Scale to original image",2);
    bool overlaylines=a.argexists("-ol","Overlay lines");
    int imwidth=a.intafter("-rqw","width of recovered quad images (pixels)",200);
//  float favourlarge=a.floatafter("-fl","Favour large by",0.8); // old method
    float favourlarge=a.floatafter("-fl","Favour large by",1.2);
    dividebyarea=!a.argexists("-dd","Don't divide V by area");
    oldmethod=a.argexists("-osm","Old stats method (area not sum mags, score reciprocal not -ve)");
    a.done();

    // Specific to my images
    printf("Auto scale? ");
    String tmp=imname;
    if (Sinstrlast(tmp,"/"))
        tmp=Sfrom(tmp,Sinstrlast(tmp,"/")+1);
    if (Sstarts(tmp,"image")) {
        printf("2.5");
        oiscale=2.5;
    }
    if (Sstarts(tmp,"img") || Slen(Sbefore(tmp,"."))==2) {
        printf("2.0");
        oiscale=2.0;
    }
    printf("\n");

    // Read list from file and find quads (looks easy!)
    List<QuadsLine2d> ls=readgfset(fname);
    helloworld();
    printf("Finding quads\n");
    List<Polygon2d> qs=findquads(ls);

    printf("df...");
    JFont coolfont=JFont(0.5);
    printf("fd...\n");

    if (!Seq(imname,"none")) {

        printf("Trying to read original file (%s)...",imname);
        oi=RGBmp::readfile(imname);
        Map2d<float> *gs=oi->getgreyscale();

        jbmp=JBmp(oi->width*0.5,oi->height*0.5);
        jbmp.clear(255);
        for (int i=1; i<=ls.len; i++) {
            QuadsLine2d l=ls.num(i)*oiscale*0.5;
            jbmp.line(l,0);
            //jbmp.thickline(l,1,255);
        }
        jbmp.writefile("lines.bmp");

        // Simple quad map
        Map2d<bool> jb=Map2d<bool>(oi->width*0.5,oi->height*0.5,255);
        for (int i=1; i<=qs.len; i++) {
            // jb.clear();
            Polygon2d p=qs.num(i);
            for (int j=1; j<=p.vs.len; j++) {
                jb.line(p.linefrom(j)*0.5*oiscale,0);
            }
        }
        jb.writefile("quads.bmp");

        // Edge detection
        printf("Doing edge detection\n");
        gs->edgedetection(Map2d<float>::sobel(),&mag,&angs);
        // angs->display();
        // exit(0);

        qs.applycall(&scalepoly); // No need for oiscale after this point

        for (int i=1; i<=qs.len; i++) {
            Polygon2d *quad=qs.p2num(i);
            quad->name=Schr(Sasc("A")+(i-1)%26);
        }

        // Overlay lines on original
        if (overlaylines) {
            RGBmp *linesover=oi->scaledby(0.5);
            for (int i=1; i<=ls.len; i++)
                linesover->thickline(0.5*oiscale*ls.num(i),myRGB(0,0,0),4);
            for (int i=1; i<=ls.len; i++)
                linesover->line(0.5*oiscale*ls.num(i),myRGB(255,255,255));
            linesover->writefile("linesover.bmp");
        }

        // Overlay quads on original
        RGBmp *rgbmp=oi->scaledby(0.5);
        for (int i=1; i<=qs.len; i++) {
            Polygon2d p=qs.num(i);
            for (int j=1; j<=p.vs.len; j++) {
                rgbmp->thickline(0.5*p.linefrom(j),myRGB(0,0,0),4);
            }
        }
        for (int i=1; i<=qs.len; i++) {
            Polygon2d p=qs.num(i);
            for (int j=1; j<=p.vs.len; j++) {
                rgbmp->line(0.5*p.linefrom(j),myRGB(255,255,255));
            }
        }
        rgbmp->writefile("overlay.bmp");

        RGBmp *detailed=new RGBmp(oi->width/2.0,oi->height/2.0,myRGB(255,255,255));//oi->scaledby(1);
        for (int i=1; i<=qs.len; i++) {
            Polygon2d p=qs.num(i);
            for (int j=1; j<=p.vs.len; j++) {
                detailed->line(p.linefrom(j)*0.5,myRGB(0,0,0));
            }
//      V2d t=(p.vs.num(1)+p.vs.num(2)+p.vs.num(3)+p.vs.num(4))/4.0/2.0+V2d::random()*100/2.0;
            V2d t=V2d(myrnd()*detailed->width,myrnd()*detailed->height);
            for (int k=1; k<=4; k++) {
                V2d c=p.vs.num(k)/2.0;
                detailed->line(c,t,myRGB(0,0,0));
            }
            String data=Sformat("%s",p.name);
            coolfont.centerString(data,detailed,t.x,t.y,8,myRGB(0,0,0));
        }
        detailed->writefile("data.bmp");

        List<String> left;
        List<String> right;
        for (int i=1; i<=qs.len; i++) {
            Polygon2d *p=qs.p2num(i);
            String s=Sformat("%s score %.3f, area %.3f",p->name,scorefor(p),p->area());
            if (p->centroid().x<oi->width/2.0)
                left.add(s);
            else
                right.add(s);
        }
        List<String> data;
//    data.add(Sformat("GF %s td=%.2f ti=%.2d tp=%.2f minlen=%.2f Image %s scale=%.2f  widthofrecquad=%.2f favourlarge=%.2f",fname,cdclip,creepintoline,dotabove,minlen,imname,oiscale,favourlarge));
        String tmp="";
        if (dividebyarea)
            tmp=Sconc(tmp,"Dividing V by area.  ");
        data.add(tmp);
        data.add("");
        data.add("-- Left:");
        data.add(left);
        data.add("-- Right:");
        data.add(right);
        writelinestofile(data,"data.txt");

        /* printf("Ordering\n");
           qs=qs.qsort(&offness);
           printf("Done ordering.\n");*/

        printf("Removing overlapping quads (%i) ...\n",qs.len);
        data.add("-- Rejection:");
        // Check all containers first
        for (int i=1; i<=qs.len; i++) {
            Polygon2d *quad=qs.p2num(i);
            bool done=false;
            for (int j=1; j<=qs.len && !done; j++) { // Compare to all others (one-directional)
                printf("Comparing (%i/%i) to %i : ",i,qs.len,j);
                if (i!=j) {

                    Polygon2d *oquad=qs.p2num(j);
                    data.add(Sformat("Comparing %s to %s %i %i",quad->name,oquad->name,i,j));

                    bool overlaps=quad->overlaps(oquad,0.99);
                    if (overlaps==Polygon2d::container) { // quad envelops oquad
                        if (scorefor(quad)>0.8*scorefor(oquad)) {
                            //          data.add(ql(&qs));
                            data.add(Sformat("%s contained %s and rejected it",quad->name,oquad->name));
                            qs.remnum(j);
                            j--;
                            if (i>j) {
                                i--;
                                done=true;
                            }
                            printf("Contained quad rejected");
                            //        data.add(ql(&qs));
                        }
                    }

                }

                printf("\n");
            }
        }
        // Then overlapping in general
        for (int i=1; i<=qs.len; i++) {
            Polygon2d *quad=qs.p2num(i);
            bool done=false;
            for (int j=i+1; j<=qs.len && !done; j++) { // bi-derectional
                printf("Comparing (%i/%i) to %i : ",i,qs.len,j);
                Polygon2d *oquad=qs.p2num(j);

                bool overlaps=quad->overlaps(oquad);
                if (overlaps) {
                    if (scorefor(quad)>scorefor(oquad)) {
                        //      data.add(ql(&qs));
                        data.add(Sformat("%s beat %s.",quad->name,oquad->name));
                        qs.remnum(j);
                        j--;
                        printf("Second quad rejected");
                        //    data.add(ql(&qs));
                    } else {
                        //  data.add(ql(&qs));
                        data.add(Sformat("%s beat %s,",oquad->name,quad->name));
                        qs.remnum(i);
                        i--;
                        done=true;
                        printf("First quad rejected");
                        //data.add(ql(&qs));
                    }
                }

                printf("\n");
            }
        }
        printf("Done: now (%i) quads.\n",qs.len);

        // Overlay again
        RGBmp *rgbmp2=oi->scaledby(0.5);
        for (int i=1; i<=qs.len; i++) {
            Polygon2d p=qs.num(i);
            for (int j=1; j<=p.vs.len; j++) {
                rgbmp2->thickline(0.5*p.linefrom(j),myRGB(0,0,0),4);
            }
        }
        for (int i=1; i<=qs.len; i++) {
            Polygon2d p=qs.num(i);
            for (int j=1; j<=p.vs.len; j++) {
                rgbmp2->line(0.5*p.linefrom(j),myRGB(255,255,255));
            }
            V2d t=0.5*p.centroid();
            // rgbmp2->line(oiscale*p.num(1),t,V3d(1,0,0));
            String data=Sformat("%.3f",scorefor(qs.p2num(i)));
            //coolfont.centerString(data,rgbmp2,t.x,t.y,9,myRGB(255,0,0));
        }
        rgbmp2->writefile("overlay2.bmp");

        // Simple quad map again
        Map2d<bool> jbq=Map2d<bool>(oi->width*0.5,oi->height*0.5,255);
        for (int i=1; i<=qs.len; i++) {
            // jb.clear();
            Polygon2d p=qs.num(i);
            for (int j=1; j<=p.vs.len; j++) {
                jbq.line(p.linefrom(j)*0.5,0);
            }
        }
        jbq.writefile("quads2.bmp");

        // Recover text
        List<RGBmp *> rec;
        // oi->display();
        for (int i=1; i<=qs.len && i<=5; i++) {
            List<V2d> *l=&qs.num(i).vs;
            RGBmp *n=oi->recoverquad(l,1,imwidth);
            n->writefile(getnextfilename("recquad","bmp"));
            rec.add(n);
        }

        if (displaying) {
//      waitforkeypress();
            jbmp.display();
            jb.display();
            for (int i=1; i<=rec.len; i++)
                rec.num(i)->display();
        }

        data.add("-- Final quads:");
        for (int i=1; i<=qs.len; i++) {
            Polygon2d *p=qs.p2num(i);
            String s=Sformat("%s %.3f",p->name,scorefor(p));
            data.add(s);
        }
        writelinestofile(data,"data.txt");

    }

//  allegroexit();
    printf("%i quadrilaterals found\n",qs.len);

}
Ejemplo n.º 29
0
void main() {
  allegrosetup(rscrwid,rscrhei);
  makepalette(&greypalette);
//  makepalette(&myRGB::hue);
  PPsetup(rscrwid,rscrhei,2);
  List<S> xs=List<S>();
  List<S> xvs=List<S>();
  randomise();
  for (int i=0;i<20;i++) {
    float amp=0;
    S s=S(myrnd()*scrwid,myrnd()*scrhei,radfromamp(amp),0);
    S v=S(0,0,0,0);
    xs+s;
    xvs+v;
  }
  for (int rndloop=0;rndloop<1000;rndloop++) {
  for (int i=0;i<20;i++) {
        S *v=xvs.p2num(i);
        S *x=xs.p2num(i);
        domovement(v,x);
      }
      }
  JBmp j=JBmp(rscrwid,rscrhei);
  intmap=Map2d<int>(scrwid,scrhei);
  int start=jump;
  do {
    j.clear();
    start-=3;
    if (start<=0)
      start=start+jump;
    for (int x=0;x<scrwid;x+=jump)
    for (int y=start;y<scrhei;y+=jump) {       
      float sum=0;
      for (int i=1;i<=xs.len;i++) {
        S s=xs.num(i);
        sum+=plusminus(i)*s.amp*gaussian(sqrt(mysquare(x-s.cx)+mysquare(y-s.cy))/s.rad);
      }
      sum=scale*sum/(float)(xs.len);
      int newcol=128+128*sum;
      intmap.pos[x][y]=newcol;
      if (x>0 && y>start) {
        int nwcol=intmap.pos[x-jump][y-jump];
        int wcol=intmap.pos[x-jump][y];
        int ncol=intmap.pos[x][y-jump];
        int xa,ya,xb,yb,xc,yc;
        PPgetscrpos(hillfor(x-jump,y-jump),&xa,&ya);
        PPgetscrpos(hillfor(x-jump,y),&xb,&yb);
//        printf("%i %i  ",xa,ya);
        j.line(xa,ya,xb,yb,255);
        PPgetscrpos(hillfor(x,y-jump),&xc,&yc);
        j.line(xa,ya,xc,yc,255);
//        PPgetscrpos(hillfor(x,y),&xa,&ya);
//        j.line(xa,ya,xb,yb,255);
//        j.line(xa,ya,xc,yc,255);
      }
    }
      for (int i=1;i<=xs.len;i++) {
//        j.line(myrnd()*scrwid,myrnd()*scrhei,myrnd()*scrwid,myrnd()*scrhei,myrnd()*255);
        S *v=xvs.p2num(i);
        S *x=xs.p2num(i);
        domovement(v,x);
        int c=j.point(x->cx,x->cy)+x->amp;
        if (debug) {
        j.vliner(x->cx,x->cy,plusminus(i)*x->amp,c);
        j.hliner(x->cx,x->cy,x->rad,c);
        j.setpixel(x->cx+radfromamp(x->amp),x->cy,c);
        }
      }
      j.writetoscreen();
    } while (!key[KEY_ESC]);
  }
Ejemplo n.º 30
0
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);

  }

}