void dessinArbre2(int lg, int x, int y, int angle){ int nx, ny, feuille=10; if(lg<feuille*2) fruits_rouges(x,y); lg+= (int) 0.1*aleat(lg); avance(lg,x,y,angle,&nx,&ny); lg=2*lg/3; if(lg>feuille+4){ int n=3+aleat(3); int i; for(i=1;i<=n;i++){ dessinArbre2(lg,nx,ny,angle-70+i*25); } } else if(lg>feuille-4){ setcolor(newcolor(0,1,0)); int n=3+aleat(3); int i; for(i=1;i<=n;i++){ dessinArbre2(lg,nx,ny,angle-70+i*25); } setcolor(newcolor(0.5,0.3,0.08)); } }
int cubilete (int lados) { float tirada; tirada = ((float) aleat () / ESCALA + 1.0) * lados / 2.0 + 1.0; return ((int) (tirada)); }
void fruits_rouges(int x,int y){ int chance_fruit=6; if (aleat(100)<chance_fruit){ setcolor(newcolor(0.8,0.07,0.05)); disque(x,y,3); setcolor(newcolor(0.5,0.3,0.08)); } }
static vpnode buildvpt (vpt *tree, Tod *od, int nobjs) { int i,per; Tdist max,min; vpnode node; node.hoja = (nobjs <= tree->bsize); if (node.hoja) { node.u.hoja.bucket = createbucket(); node.u.hoja.size = 0; for (i=0; i<nobjs; i++) { node.u.hoja.bucket = addbucket (node.u.hoja.bucket, node.u.hoja.size, od[i].obj); node.u.hoja.size++; } } else { #ifdef P1 int j = aleat (nobjs); #endif #ifdef P2 int j = 0; #endif #ifdef P3 int j = nobjs-1; #endif #ifdef P4 int j = 0,jj; for (jj=1; jj<nobjs; jj++) if (od[jj].tdist < od[j].tdist) j = jj; #endif #ifdef P5 int j = 0,jj; for (jj=1; jj<nobjs; jj++) if (od[jj].tdist > od[j].tdist) j = jj; #endif node.u.interno.query = od[j].obj; od[j] = od[--nobjs]; for (i=0; i<nobjs; i++) { od[i].dist = distance (node.u.interno.query, od[i].obj); od[i].tdist += od[i].dist; } qsort (od,nobjs,sizeof(Tod),compar); min = od[0].dist; max = od[nobjs-1].dist; per = tree->bsize; node.u.interno.dist = od[per].dist; while ((per > 0) && (od[per+1].dist == node.u.interno.dist)) per--; node.u.interno.child1 = malloc (sizeof(vpnode)); *node.u.interno.child1 = buildvpt (tree,od,per); node.u.interno.child2 = malloc (sizeof(vpnode)); *node.u.interno.child2 = buildvpt (tree,od+per,nobjs-per); } return node; }
main(int argc, char** argv) { int n,m,J,t; struct stat sdata; FILE* ifile,*ofile; unsigned char* buff; if (argc < 5) { fprintf(stderr, "Usage: %s <file> <length> <number> <intervals file>\n" " randomly extracts <number> intervals of length <length> from <file>.\n" " The output file, <intervals file> has a first line of the form:\n" " # number=<number> length=<length> file=<file>\n" " and then <number> lines of the form <from>,<to>.\n",argv[0] ); exit(1); } if (stat(argv[1],&sdata) != 0) { fprintf(stderr,"Error: cannot stat file %s\n",argv[1]); fprintf(stderr," errno = %i\n",errno); exit(1); } n = sdata.st_size; m = atoi(argv[2]); if ((m <= 0) || (m > n)) { fprintf(stderr,"Error: length must be >= 1 and <= file length" " (%i)\n",n); exit(1); } J = atoi(argv[3]); if (J < 1) { fprintf(stderr,"Error: number of intervals must be >= 1\n"); exit(1); } ifile = fopen(argv[1],"r"); if (ifile == NULL) { fprintf(stderr,"Error: cannot open file %s for reading\n",argv[1]); fprintf(stderr," errno = %i\n",errno); exit(1); } buff = (unsigned char*) malloc(n); if (buff == NULL) { fprintf(stderr,"Error: cannot allocate %i bytes\n",n); fprintf(stderr," errno = %i\n",errno); exit(1); } if (fread(buff,n,1,ifile) != 1) { fprintf(stderr,"Error: cannot read file %s\n",argv[1]); fprintf(stderr," errno = %i\n",errno); exit(1); } fclose(ifile); ofile = fopen(argv[4],"w"); if (ofile == NULL) { fprintf(stderr,"Error: cannot open file %s for writing\n",argv[4]); fprintf(stderr," errno = %i\n",errno); exit(1); } if (fprintf(ofile,"# number=%i length=%i file=%s\n", J,m,argv[1]) <= 0) { fprintf(stderr,"Error: cannot write file %s\n",argv[4]); fprintf(stderr," errno = %i\n",errno); exit(1); } for (t=0; t<J; t++) { int j,l; j = aleat(n-m+1); if (fprintf(ofile,"%i,%i\n",j,j+m-1) <= 0) { fprintf(stderr,"Error: cannot write file %s\n",argv[4]); fprintf(stderr," errno = %i\n",errno); exit(1); } } if (fclose(ofile) != 0) { fprintf(stderr,"Error: cannot write file %s\n",argv[4]); fprintf(stderr," errno = %i\n",errno); exit(1); } fprintf(stderr,"File %s successfully generated\n",argv[4]); exit(0);// SG: Replaced 1 by 0. }
void main(void) { while(!kbhit()) printf("\n%d", aleat()); }