Exemplo n.º 1
0
int spi_hello_test(int iteration)
{
	int i, j, xv, sz;
	struct spi_comm_packet *cmd = (struct spi_comm_packet *)out_msg;
	const struct spi_comm_packet *resp;

	for (i = 0; i < iteration; ++i) {
		xv = myrnd() & 0xff;
		cmd->cmd_sts = TS_CMD_HELLO;
		sz = myrnd() % (sizeof(out_msg) - 10) + 1;
		cmd->size = sz + 2;
		cmd->data[0] = sz;
		cmd->data[1] = xv;
		for (j = 0; j < sz; ++j)
			cmd->data[j + 2] = myrnd() & 0xff;
		if (spi_master_send_command(cmd))
			return EC_ERROR_UNKNOWN;

		resp = spi_master_wait_response();
		if (resp == NULL || resp->size != sz)
			return EC_ERROR_UNKNOWN;
		for (j = 0; j < sz; ++j)
			if (cmd->data[j + 2] != resp->data[j])
				return EC_ERROR_UNKNOWN;
		resp = spi_master_wait_response();
		if (resp == NULL || resp->size != sz)
			return EC_ERROR_UNKNOWN;
		for (j = 0; j < sz; ++j)
			if ((cmd->data[j + 2] ^ xv) != resp->data[j])
				return EC_ERROR_UNKNOWN;
	}

	return EC_SUCCESS;
}
Exemplo n.º 2
0
Arquivo: hue1.c Projeto: 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]);
}
Exemplo n.º 3
0
Arquivo: last.c Projeto: 10crimes/code
 Wave() {
   f=intrnd(1,15);
   line=V3d::random();
   if (planar)
     line.y=0;
   o=myrnd()*2.0*pi;
   a=myrnd()*3.0;
 }
Exemplo n.º 4
0
void newripple(int i) {
        ripples[i].st=mytime;
        ripples[i].x=myrnd()*scrwid;
        ripples[i].y=myrnd()*scrhei;
        ripples[i].w=50+myrnd()*150;
        ripples[i].v=1+myrnd()*4;
        ripples[i].n=2+myrnd()*7;
//        printf("%f\n",myrnd());
}
Exemplo n.º 5
0
  Wave() {
    int k=intrnd(1,5);
    Wave(k,V3d::random(),myrnd()*2.0*pi,myrnd()*0.2);

    f=intrnd(1,5);
    line=V3d::random();
    o=myrnd()*2.0*pi;
    a=myrnd()*3.0;

  }
Exemplo n.º 6
0
  Wave() {
    int k=intrnd(1,40);
    Wave(k,V3d::random(),myrnd()*2.0*pi,myrnd()*0.1);

    f=intrnd(1,10);
    line=V3d::random();
    o=myrnd()*2.0*pi;
    a=myrnd()*7.0;

  }
Exemplo n.º 7
0
int main() {
    List<V3d> l;
    List<float> m;
    allegrosetup(scrwid,scrhei);
    makepalette(&greypalette);
//  List<V3d> l(5);
    for (int i=1; i<=numps; i++) {
        V3d r=sqrt(myrnd())*(V3d::random());
        l.add(r);
        m.add(r.mod());
    }

    JBmp j=JBmp(scrwid,scrhei);
    int time=0;
    while (!key[KEY_ESC]) {
        time++;
        V3d rotaxis=V3d::rotate(V3d(0,1,0),V3d(1,0,0),time*pi/500);
        V3d rotaxis2=V3d::rotate(V3d(0,1,0),V3d(1,0,0),time*pi/500);
        j.clear();
        for (int i=1; i<=l.length(); i++) {
//      V3d t=(V3d)(l.num(i));
//      t.changeto(V3d::rotate(t,rotaxis,pi/40));
//      l.replace(i,t);
            V3d v=(V3d)(l.num(i));
            V3d t=(V3d::rotate((V3d::rotate(v,V3d(1,0,0),pi/700*time)),V3d(0,1,0),pi/40*time));
            j.setpixel(scrwid/2+scrhei/2*t.x,scrhei/2*(1+t.y),127*(1-t.z));
        }
        j.writetoscreen();
    }
}
Exemplo n.º 8
0
int lifefrom(int x,int y) {
    int c=countneighbourschecking(x,y)/8;
    if (c==0)
        return myrnd()*255;
    if (c>255-crowded || c<lonely)
        return 0;
    return c;
}
Exemplo n.º 9
0
 Stripey() {
   Radial::Radial();
   pos=V2d(floatrnd(0,scrwid),floatrnd(0,scrhei));
   vel=V2d::o;
   // rad=floatrnd(20,40);
   radvel=0;
   ang=myrnd(2*pi);
   angvel=0;
 }
Exemplo n.º 10
0
void plotsomeshapes() {

  for (int i=0;i<2;i++)
  	if (myrnd()<0.4) {
			V2d cen=V2d((float)scrwid*myrnd(),(float)scrhei*myrnd());
			V2d dir=V2d::random();
			V2d a=cen-dir*(scrwid);			
			V2d b=cen+dir*(scrwid);			
      // img.line(a.x,a.y,b.x,b.y,255);
      img.thickline(a.x,a.y,b.x,b.y,1,255);
			// float oth=sqrt(myrnd())*5.0;
			// V2d perp=oth*dir.perp();
			// img.filltri((a-perp).x,(a-perp).y,(a+perp).x,(a+perp).y,b.x,b.y,myrnd()*255);
			
			// img.line(a.x,a.y,b.x,b.y,255);
		}
			
}
Exemplo n.º 11
0
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]);
}
Exemplo n.º 12
0
Arquivo: zoom.c Projeto: 10crimes/code
void mycircle(int cx,int cy,int r,int c) {
  int x,h,y,px,py;
  for (x=-r;x<=r;x++) {
    h=sqrt(mysquare(r)-mysquare(x));
    for (y=-h;y<=h;y++) {
      px=cx+x; py=cy+y;
      if (px>=0 && px<scrwid && py>=0 && py<scrhei)
        img[py][px]=myrnd()*256;
    }
  }
}
Exemplo n.º 13
0
void newpart(Part *p) {
    p->pos=V3d(magrnd(1),magrnd(1),1);
    p->rad=0.02+myrnd(0.04);
    p->sgn=plusminus();
    if (p->sgn>0) {
      p->inc=127;
      p->outc=63;
    } else {
      p->inc=255;
      p->outc=128+63;
    }
}
Exemplo n.º 14
0
int main(int argc,String *argv) {
  Jargsetup(argc,argv);
  String fname=Jgetargafter("-o","noise.bmp");
  int width,height;
  sscanf(Jgetargafter("-w","320"),"%i",&width);
  sscanf(Jgetargafter("-h","200"),"%i",&height);
  Map2d<int> *n=new Map2d<int>(width,height);
  for (int i=0;i<n->width;i++)
    for (int j=0;j<=n->height;j++)
      n->pos[i][j]=myrnd()*255;
  n->writefile(fname);
  printf(Sformat("noise: written file %s w %i h %i\n",fname,width,height));
}
Exemplo n.º 15
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]);
}
Exemplo n.º 16
0
void main(int argc,String *argv) {
  
  ArgParser a=ArgParser(argc,argv);
  int w=a.intafter("-w","width",275);
  int h=a.intafter("-h","height",116);
  int numpts=a.intafter("-n","number of points",100);
  a.done();


  FILE *file=fopen("region.txt","wa");
  fprintf(file,"[Normal]\n");
  fprintf(file,"Numpoints=%i\n",numpts);

  V2d cen=V2d((float)w/2.0,(float)h/2.0);

  for (int i=0;i<numpts;i++) {

    V2d a=10.0*(w+h)*V2d::angle(-pi/4.0+2.0*pi*(float)i/(float)numpts);

    a=a+cen;

    if (a.x<0)
      a=Line2d(cen,a).intersect(Line2d(V2d(0,0),V2d(0,1)));
    if (a.y<0)
      a=Line2d(cen,a).intersect(Line2d(V2d(0,0),V2d(1,0)));
    if (a.x>w)
      a=Line2d(cen,a).intersect(Line2d(V2d(w,0),V2d(w,1)));
    if (a.y>h)
      a=Line2d(cen,a).intersect(Line2d(V2d(0,h),V2d(1,h)));

    a=a-cen;
    float rnd=myrnd();
    a=a*rnd;

    a=a+cen;

    fprintf(file,"%i,%i",(int)a.x,(int)a.y);
    if (i<numpts-1)
      fprintf(file,", ");

  }

  fprintf(file,"\n");

  fclose(file);

}
Exemplo n.º 17
0
/* Turns a forcefield on, and ensures its vars are suitable. */
static void turn_on_field(struct state *st, int ff)
{
  if (!st->fon[ff]) {
    /* acc[ff]=0.0; */
    st->acc[ff]=0.02 * myrnd();
    st->vel[ff]=0.0;
    st->var[ff]=st->op[ff];
  }
  st->fon[ff] = 1;
  if (ff == 10) {
    turn_on_field(st, 11);
    turn_on_field(st, 12);
  }
  if (ff == 13) {
    turn_on_field(st, 14);
    turn_on_field(st, 15);
  }
}
Exemplo n.º 18
0
void newparts(List<Part> *l) {
  V3d a=V3d(magrnd(1),magrnd(1),1+magrnd(2));
  V3d b=a+V3d(magrnd(1),magrnd(1),magrnd(0.4));;
  float sgn=plusminus();
  float rad=0.005+myrnd(0.01);
  for (int i=1;i<=line;i++) {
    Part p;
    float thru=(float)(i-1)/(line-1);
    p.pos=a+thru*(b-a);
    p.rad=rad;
    p.sgn=sgn;
    if (p.sgn>0) {
      p.inc=127;
      p.outc=63;
    } else {
      p.inc=255;
      p.outc=128+63;
    }
    l->add(p);
  }
}
Exemplo n.º 19
0
void movepart(int i) {
  int j;
  //xor_mode(0);
  if (plotpart(i,0)==0 || part[i].pos.z<znear || part[i].pos.z>zfar)
    newpart(i);
  // Brownian motion
  if (myrnd()<pbrownian) {
  part[i].vel.x=part[i].vel.x+floatrnd(-brownian,brownian);
  part[i].vel.y=part[i].vel.y+floatrnd(-brownian,brownian);
  part[i].vel.z=part[i].vel.z+floatrnd(-brownian,brownian);
  }
  if (part[i].gwell<0.5) {
    // Pulled by gravity wells
    for (j=0;j<gwells;j++) {
      // Gravity well j affects particle i
      if (gwell[j]!=i)
        part[i].vel=V3dadd(part[i].vel,V3dmult(part[gwell[j]].gwell/(V3ddist(part[gwell[j]].pos,part[i].pos)+1)*gwellstr,V3dnorm(V3dsub(part[gwell[j]].pos,part[i].pos))));
    }
  } else {
    // Warping towards user
    part[i].vel.z=part[i].vel.z-warpvel;
  }
  // Damping
  part[i].vel=V3dmult(dampening,part[i].vel);
  // Movement
  part[i].pos=V3dadd(part[i].pos,part[i].vel);
  /* Bouncing off the walls
  if (myabs(part[i].pos.x)>1)
    part[i].vel.x=-part[i].vel.x;
  if (myabs(part[i].pos.y)>1)
    part[i].vel.y=-part[i].vel.y;
  if (myabs(part[i].pos.z)>1)
    part[i].vel.z=-part[i].vel.z;*/
  //xor_mode(1);
  plotpart(i,255);
}
Exemplo n.º 20
0
void newpart(int i) {
  float x,y;
  int j;
  //part[i].pos=(V3d)newV3d(floatrnd(-1,1),floatrnd(-1,1),floatrnd(znear,zfar));
  x=floatrnd(-1,1); y=floatrnd(-1,1);
  part[i].pos.z=floatrnd(zcreatenear,zfar);
  // scrx/pd=x/z
  part[i].pos.x=part[i].pos.z*x/planedist;
  part[i].pos.y=part[i].pos.z*y/planedist;
  part[i].vel=newV3d(0,0,0);
  if (myrnd()<pgwell) {
    part[i].gwell=floatrnd(1,3);
    gwell[gwells]=i; gwells++;
  } else {
    // Ensure not in the gwell list
    for (j=0;j<gwells;j++) {
      if (gwell[j]==i) {
        gwell[j]=gwell[gwells];
        gwells--;
      }
    }
    part[i].gwell=0;
  }
}
Exemplo n.º 21
0
void stars_newp(int p) {
  cx[p]=myrnd();
  cy[p]=myrnd();
}
Exemplo n.º 22
0
static void do_twinkle(Display *dpy, Window window) {
  Colormap cmap;
  XWindowAttributes xgwa;
  int got_color = 0;
  XColor color[maxps];
  XColor bgcolor;
  int p,f,nt, sx,sy, resets,lastresets,cnt;

  XClearWindow (dpy, window);
  XGetWindowAttributes (dpy, window, &xgwa);
  cmap = xgwa.colormap;
  scrwid = xgwa.width;
  scrhei = xgwa.height;

  /* Setup colours */
  hsv_to_rgb (0.0, 0.0, 0.0, &bgcolor.red, &bgcolor.green, &bgcolor.blue);
  got_color = XAllocColor (dpy, cmap, &bgcolor);
  for (p=0;p<ps;p++) {
        if (!mono_p)
          hsv_to_rgb (random()%360, .6+.4*myrnd(), .6+.4*myrnd(), &color[p].red, &color[p].green, &color[p].blue);
          /* hsv_to_rgb (random()%360, 1.0, 1.0, &color[p].red, &color[p].green, &color[p].blue);   for stronger colours! */
        if ((!mono_p) && (got_color = XAllocColor (dpy, cmap, &color[p]))) {
        } else {
          if (p>0)
            color[p]=color[0];
          else
            color[p].pixel=default_fg_pixel;
        }
  }

  /* Set up parameter movements for the different forcefields */
  name[1] = "Velocity";
  op[1] = 1; damp[1] = .999; force[1] = .002;
  name[2] = "Rotation";
  op[2] = 0; damp[2] = .999; force[2] = .002;
  name[3] = "Drip";
  op[3] = 1; damp[3] = .999; force[3] = .005;
  name[4] = "Dribble";
  op[4] = 1; damp[4] = .999; force[4] = .005;
  name[5] = "Slide";
  op[5] = 0; damp[5] = .999; force[5] = .002;
  name[6] = "Accelerate";
  op[6] = 1.0; damp[6] = .999; force[6] = .005;
  name[7] = "xDisplace";
  op[7] = 0; damp[7] = .999; force[7] = .005;
  name[8] = "yDisplace";
  op[8] = 0; damp[8] = .999; force[8] = .005;
  /* 0 and 9 are options for splitting displacements [no var] */
  name[0] = "Split";
  op[0] = 0; damp[0] = 0; force[0] = 0;
  name[9] = "2d/3d split";
  op[9] = 0; damp[9] = 0; force[9] = 0;

  /* Initialise parameters to optimum, all off */
  for (f=0;f<fs;f++) {
    var[f]=op[f];
    fon[f]=0;
  }

  /* Initialise stars */
  for (p=0;p<ps;p++)
    stars_newp(p);

  /* tx[nt],ty[nt] remeber earlier screen plots (tails of stars)
     which are deleted when nt comes round again */
  nt=0;
  resets=0;

  while (1) {

      /* Move current points */
      lastresets=resets;
      resets=0;
      for (p=0;p<ps;p++) {
        /* Erase old */
        XSetForeground (dpy, draw_gc, bgcolor.pixel);
        XDrawPoint(dpy,window,draw_gc,tx[nt],ty[nt]);

        /* Move */
        stars_move(p);
        /* If moved off screen, create a new one */
        if (cx[p]<-1.0 || cx[p]>+1.0 ||
            cy[p]<-1.0 || cy[p]>+1.0 ||
            fabs(cx[p])<.001 || fabs(cy[p])<.001) {
          stars_newp(p);
          resets++;
        } else if (myrnd()>0.99) /* Reset at random */
          stars_newp(p);

        /* Draw point */
        sx=stars_scrpos_x(p);
        sy=stars_scrpos_y(p);
        XSetForeground (dpy, draw_gc, color[p].pixel);
        XDrawPoint(dpy,window,draw_gc,sx,sy);

        /* Remember it for removal later */
        tx[nt]=sx;
        ty[nt]=sy;
        nt=(nt+1)%(ps*ts);
      }

      /* Adjust force fields */
      cnt=0;
      for (f=0;f<fs;f++) {

        if (meters) { /* Remove meter from display */
          XSetForeground(dpy, draw_gc, bgcolor.pixel);
          stars_draw_meter(dpy,window,draw_gc,f);
        }

        /* Adjust forcefield's parameter */
        var[f]=stars_perturb(var[f],op[f],damp[f],force[f]);

        if (myrnd()>0.998) /* Turn it on/off ? */
          fon[f]=(myrnd()<0.0);
          /* fon[f]=!fon[f]; */

        if (meters) { /* Redraw the meter */
          XSetForeground(dpy, draw_gc, color[f].pixel);
          stars_draw_meter(dpy,window,draw_gc,f);
        }

        if (fon[f])
          cnt++;
      }
      if (cnt==0) { /* Ensure at least one is on! */
        f=random() % fs;
        fon[f]=1;
      }
      if (meters) {
        XSetForeground(dpy, draw_gc, bgcolor.pixel);
        XDrawRectangle(dpy,window,draw_gc,0,0,lastresets*5,3);
        XSetForeground(dpy, draw_gc, default_fg_pixel);
        XDrawRectangle(dpy,window,draw_gc,0,0,resets*5,3);
      }
/*      if (resets*5>scrwid) {
       Turn one off a field if too many points are flying off screen */
      /* This was a problem when one of the force-fields was acting wrong,
         but not really needed any more unless we need to debug new ones ...! */
        /* for (f=0;f<fs;f++)
            if (fon[f])
            printf("%i",f);
          printf("\n");
          XSync (dpy, False);
          screenhack_handle_events (dpy);
         sleep(1);
        do { // In fact this bit might go wrong if
          f=random() % fs; // we have not ensured at least one is on (above)
        } while (!fon[f]);
        fon[f]=0;
      }            */

        XSync (dpy, False);
        screenhack_handle_events (dpy);

  }

}
Exemplo n.º 23
0
/* Adjust a variable var about optimum op,
     with damp = dampening about op
         force = force of random perturbation */
float stars_perturb(float var,float op,float damp,float force) {
  var=op+damp*(var-op)+force*myrnd()/4.0;
/*  if (fabs(var-op)>0.1)  // (to keep within bounds)
    var=op+0.1*mysgn(var-op);*/
  return var;
}
Exemplo n.º 24
0
void newpart(Part *p) {
    p->pos=V3d(magrnd(1),magrnd(1),1);
    p->rad=0.02+myrnd(0.04);
    p->c=16;
    p->sgn=plusminus();
}
Exemplo n.º 25
0
void main(void) {
    
    int i,j,k,c,x,y;
    RGB rgb;

    srand((int)time(NULL));

    for (x=0;x<scrwid;x++) {
    for (y=0;y<scrhei;y++) {
        rx=(float)x/scrwid*2-1;
        ry=(float)(y-scrhei/2)/scrwid*2;

        px=(qx+1)/2*scrwid;
        py=scrhei/2+(qy)/2*scrwid;
        ix=(int)px;
        iy=(int)py;
        amount[x][y][0][0]=((float)ix+1-(float)px)*((float)(iy+1)-(float)py);
        amount[x][y][1][0]=((float)px-(float)ix)*((float)(iy+1)-(float)py);
        amount[x][y][0][1]=((float)ix+1-(float)px)*((float)py-(float)iy);
        amount[x][y][1][1]=((float)px-(float)ix)*((float)py-(float)iy);
        pix[x][y]=ix;
        piy[x][y]=iy;
    }
    }

    allegro_init ();
    install_keyboard ();
    install_timer ();
    set_gfx_mode (GFX_AUTODETECT, scrwid, scrhei, 0, 0);
    set_pallete (desktop_palette);
    _farsetsel(screen->seg);
    for (c=0;c<=255;c++) {
        if (c<128) {
            rgb.r=c*63/127;
            rgb.g=0;
            rgb.b=0;
        } else {
            rgb.r=127;
            rgb.g=(c-128)*63/127;
            rgb.b=rgb.g;
        }
        set_color(c,&rgb);
    }
    
    while(!key[KEY_ESC]) {
        for (y=0; y<scrhei; y++) {
            movedata(screen->seg, bmp_read_line(screen,y), _my_ds(), map[y], scrwid);
        }
        for (x=0; x<scrwid; x++) {
        for (y=0; y<scrhei; y++) {
            c=0;
            for (i=0;i<=1;i++) {
            for (j=0;j<=1;j++) {
                c=c+amount[x][y][i][j]*map[piy[x][y]+j][pix[x][y]+i];
            }
            }
            c--;
            map2[y][x]=c;
        }
        }
        for (y=0; y<scrhei; y++) {
            movedata(_my_ds(), map2[y], screen->seg, bmp_write_line(screen,y), scrwid);
        }
        for (i=1;i<=10;i++) {
            circlefill(screen,myrnd()*scrwid,myrnd()*scrhei,8,myrnd()*255);
        }
    }

}
Exemplo n.º 26
0
void main(void) {
    
    int xy,i,j,c,x,y,front,back,n,minc,maxc;
    int ix,iy,k,address,jx,jy,kx,ky;
    float dzdx,dzdy,a,b,dot,norm;
    float rx,ry,sx,sy,px,py;
    long p,q;
    RGB rgb;

    for (x=0;x<scrwid;x++) {
    for (y=0;y<scrhei;y++) {
        rx=(float)x/scrwid*2-1;
        ry=(float)y/scrhei*2-1;
        sx=rx*.8;
        sy=ry*.8;
        px=(sx+1)/2*scrwid;
        py=(sy+1)/2*scrhei;
        ix=(int)px;
        iy=(int)py;
        amount[x][y][0][0]=((float)ix+1-(float)px)*((float)(iy+1)-(float)py);
        amount[x][y][1][0]=((float)px-(float)ix)*((float)(iy+1)-(float)py);
        amount[x][y][0][1]=((float)ix+1-(float)px)*((float)py-(float)iy);
        amount[x][y][1][1]=((float)px-(float)ix)*((float)py-(float)iy);
        pix[x][y]=ix;
        piy[x][y]=iy;
//        printf("%f",amount[x][y][0][0]+amount[x][y][1][0]+amount[x][y][0][1]+amount[x][y][1][1]);
        if (mysquare(amount[x][y][0][0]+amount[x][y][1][0]+amount[x][y][0][1]+amount[x][y][1][1]-1)>0.00001) {
            printf("%d %d %f %f ",ix,iy,px,py);
            printf("%f+%f(%f*%f)+%f+%f=%f? \n",amount[x][y][0][0],amount[x][y][1][0],(float)px-(float)ix,(float)(iy+1)-(float)py,amount[x][y][0][1],amount[x][y][1][1],amount[x][y][0][0]+amount[x][y][1][0]+amount[x][y][0][1]+amount[x][y][1][1]);
        }
    }
    }

//    srand(456789);
        srand((int)time(NULL));
        //printf("%d\n",(int)time(NULL));


  allegro_init ();
  install_keyboard ();
  install_timer ();
  set_gfx_mode (GFX_AUTODETECT, scrwid, scrhei, 0, 0);
  set_pallete (desktop_palette);
  buffer = create_bitmap (scrwid, scrhei);
      clear (buffer);

//      textout_centre (buffer, font, "Press SPACE!", 60, 220, 4);


    // Set up grayscale colours
    for (c=0;c<=255;c++) {
        i=0;
        rgb.r=c*63/255;
        rgb.g=0;
        rgb.b=0;
        set_color(c,&rgb);
//        colors[c]=GrAllocColor(c,i,i);
    }
    
        for (x=0; x<scrwid; x++) {
        for (y=0; y<scrhei; y++) {
            putpixel(buffer,x,y,128);
        }
        }

      blit (buffer, screen, 0, 0, 0, 0, scrwid, scrhei);

   _farsetsel(screen->seg);

    while(!key[KEY_ESC]) {
        for (y=0; y<scrhei; y++) {
     movedata(screen->seg, bmp_read_line(screen,y), _my_ds(), tmp[y], scrwid);
     }
        for (x=0; x<scrwid; x++) {
        for (y=0; y<scrhei; y++) {
        c=0;
        kx=x-scrwid/2;
        ky=y-scrhei/2;
        jx=kx*cos(ang)+ky*sin(ang);
        jy=-kx*sin(ang)+ky*cos(ang);
        ix=scrwid/2+0.9*jx;
        iy=scrhei/2+0.9*jy;
        k=0;
        i=0;j=0;
//        for (i=-1;i<=1;i++) {
//        for (j=-1;j<=1;j++) {
//            c=c+getpixel(screen, ix+i, iy+j);
//     address = bmp_read_line(screen, iy)+ix;
            c=c+tmp[iy][ix];
            k++;
//        }
//        }
        c=c/k;
        c--;
//     address = bmp_write_line(buffer, y)+x;
//        _farnspokeb(address, c);
        tmp2[y][x]=c;
//        putpixel(buffer, x, y, c);
        }
        }
        for (y=0; y<scrhei; y++) {
     movedata(_my_ds(), tmp2[y], screen->seg, bmp_write_line(screen,y), scrwid);
     }
for (i=1;i<=10;i++)
        circlefill(screen,myrnd()*scrwid,myrnd()*scrhei,8,myrnd()*255);
//        putpixel(buffer,scrwid/2,scrhei/2,255);

//      blit (buffer, screen, 0, 0, 0, 0, scrwid, scrhei);
    }

destroy_bitmap(buffer);
exit(0);
    getch();

//    GrSetMode(GR_default_text);
    printf("max col %d\n",maxc);
    printf("min col %d\n",minc);
  
}
Exemplo n.º 27
0
float classifyrnd(List<Pixel> *ps) {
  return myrnd();
}
Exemplo n.º 28
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]);
}
Exemplo n.º 29
0
void main(void) {
    
    int xy,i,j,c,x,y,front,back,n,minc,maxc;
    int ix,iy;
    float dzdx,dzdy,a,b,dot,norm,tmp;
    float rx,ry,sx,sy,px,py;
    long p,q;
    RGB rgb;

    for (x=0;x<scrwid;x++) {
    for (y=0;y<scrhei;y++) {
        rx=(float)x/scrwid*2-1;
        ry=(float)y/scrhei*2-1;
        sx=rx*.99;
        sy=ry*.99;
        px=(sx+1)/2*scrwid;
        py=(sy+1)/2*scrhei;
        ix=(int)px;
        iy=(int)py;
        amount[x][y][0][0]=((float)ix+1-px)*((float)iy+1-py);
        amount[x][y][1][0]=(px-(float)ix)*((float)iy+1-py);
        amount[x][y][0][1]=((float)ix+1-px)*(py-(float)iy);
        amount[x][y][1][1]=(px-(float)ix)*(py-(float)iy);
        pix[x][y]=ix;
        piy[x][y]=iy;
        printf("%d %d %f %f ",x,y,px,py);
        printf("%f=1? \n",amount[x][y][0][0]+amount[x][y][1][0]+amount[x][y][0][1]+amount[x][y][1][1]);
    }
    }

//    srand(456789);
        srand((int)time(NULL));
        //printf("%d\n",(int)time(NULL));


  allegro_init ();
  install_keyboard ();
  install_timer ();
  set_gfx_mode (GFX_AUTODETECT, scrwid, scrhei, 0, 0);
  set_pallete (desktop_palette);
  buffer = create_bitmap (scrwid, scrhei);
      clear (buffer);

//      textout_centre (buffer, font, "Press SPACE!", 60, 220, 4);

      blit (buffer, screen, 0, 0, 0, 0, scrwid, scrhei);

    // Set up grayscale colours
    for (c=0;c<=255;c++) {
        i=0;
        rgb.r=c*63/255;
        rgb.g=0;
        rgb.b=0;
        set_color(c,&rgb);
//        colors[c]=GrAllocColor(c,i,i);
    }
    

    while(!key[KEY_ESC]) {
        for (x=0; x<scrwid; x=x+res) {
        for (y=0; y<scrhei; y=y+res) {
        c=0;
        for (i=0;i<1;i++) {
        for (j=0;j<1;j++) {
        c=c+getpixel(buffer, pix[x][y]+i, piy[x][y]+j)*amount[x][y][i][j];
        }
        }
        putpixel(buffer, x, y, c);
        }
        }
        putpixel(buffer,myrnd()*scrwid,myrnd()*scrhei,myrnd()*255);
      blit (buffer, screen, 0, 0, 0, 0, scrwid, scrhei);
    }

destroy_bitmap(buffer);
exit(0);
    getch();

//    GrSetMode(GR_default_text);
    printf("max col %d\n",maxc);
    printf("min col %d\n",minc);
  
}
Exemplo n.º 30
0
bool boolrnd() {
  return (myrnd()>0.5);
}