static void enclosure(int npoints, double r, double height) { double thickness = r * THICKNESS_RADIUS; double angle = 2.0 * M_PI / (double) npoints; double ix, iy, x1, y1, x2, y2, a = 0; double dx, dy; int i; dx = randomn(r * WALL_VERTEX_RANDOMNESS * 2.0) - r * WALL_VERTEX_RANDOMNESS; dy = randomn(r * WALL_VERTEX_RANDOMNESS * 2.0) - r * WALL_VERTEX_RANDOMNESS; ix = x1 = cos(a) * r + dx; iy = y1 = sin(a) * r + dy; for (i = 0; i < npoints - 1; i++) { a += angle; dx = randomn(r * 0.3) - r * 0.15; dy = randomn(r * 0.3) - r * 0.15; x2 = cos(a) * r + dx; y2 = sin(a) * r + dy; wall(x1, y1, x2, y2, thickness, height); tower(x1, y1, thickness * 2.0, height * 1.25); x1 = x2; y1 = y2; } wall(x1, y1, ix, iy, thickness, height); tower(x1, y1, thickness * 2.0, height * 1.25); }
static void recursive_keep(double x, double y, double width, double length, double height, int level) { int i; if (irandomn(1000) < 300) { xlate(x, y, 0); keep_block(width, length, height); endxlate(); xlate(0, 0, height); recursive_keep(x, y, width, length, perturb(height, 0.2), level); endxlate(); return; } if (level == 0 || irandomn(1000) < 300) { xlate(x, y, 0); xkeep_topper(width, length, height, 1); endxlate(); return; } i = irandomn(100); xlate(x, y, 0); keep_block(width, length, height); endxlate(); xlate(0, 0, height); if ((level % 2) == 0) { double offset, nw1, nw2, x1, x2; offset = randomn(width * 0.2) - (0.1 * width); offset = 0.0; nw1 = (width / 2.0) + offset; nw2 = (width - nw1); x1 = x - offset / 2.0 -0.25 * width; x2 = x + 0.25 * width - offset / 2.0; printf("/* x/y = %lf,%lf, o=%lf nw1 = %lf, nw2 = %lf, x1 = %lf, x2 = %lf */\n", x, y, offset, nw1, nw2, x1, x2); recursive_keep(x1, y, nw1, length, perturb(height, 0.2), level - 1); recursive_keep(x2, y, nw2, length, perturb(height, 0.2), level - 1); } else { double offset, nl1, nl2, y1, y2; offset = randomn(length * 0.2) - (0.1 * length); offset = 0.0; nl1 = (length / 2.0) + offset; nl2 = (length - nl1); y1 = y - offset / 2.0 - 0.25 * length; y2 = y + 0.25 * length - offset / 2.0; printf("/* x/y = %lf,%lf, o=%lf nl1 = %lf, nl2 = %lf, y1 = %lf, y2 = %lf */\n", x, y, offset, nl1, nl2, y1, y2); recursive_keep(x, y1, width, nl1, perturb(height, 0.2), level - 1); recursive_keep(x, y2, width, nl2, perturb(height, 0.2), level - 1); } endxlate(); }
int main() { node* table[26]; int c = 0; while(c < 26) { table[c] = 0; c++; } srand(time(NULL)); printf("List function testing\n\n"); node *list = (node *)malloc(sizeof(node)); strcpy(list->name,"singing in the rain"); strcpy(list->artist,"john"); list->next = NULL; insert_lexic(list, "tomato sauce", "joshua"); insert_lexic(list, "potatoes", "joshua"); insert_lexic(list, "quiet", "joshua"); printf("List length (after adding 4 nodes in order): %d\n\n", list_len(list)); printf("Print list:\n"); print_list(list); printf("\nFind song (quiet):\n"); print_list(find_song(list, "quiet")); printf("\nFind artist (joshua):\n"); print_list(find_artist(list, "joshua")); printf("\nRandom Nodes:\n"); print_list(randomn(list)); print_list(randomn(list)); print_list(randomn(list)); print_list(randomn(list)); printf("\nSpecific Library Functions:\nAdding 5 songs:\n"); add_song(table, "hello", "john"); add_song(table, "goodbye", "james"); add_song(table, "fish", "john"); add_song(table, "star", "patrick"); add_song(table, "jean-luc", "picard"); printf("\nPrint letter function:\n"); print_let(table, 'p'); printf("\nPrint library function:\n"); print_lib(table); printf("\nPrint artist (john) function:\n"); print_art(table, "john"); del_song(findlib_song(table, "hello"), table); printf("Deleted hello by john\n"); print_art(table, "john"); printf("\nShuffle List (6 songs):\n"); shuffle(table, 6); printf("\nDelete library:\n"); del_lib(table); print_lib(table); return 0; }
static void add_windows(double tower_radius, double tower_height) { int i, nwindows; double h; double angle; nwindows = irandomn(3); for (i = 0; i < nwindows; i++) { h = randomn(tower_height / 4.0) + tower_height * 0.5; angle = (double) randomn(360.0); xlate(0, 0, h); rotate(angle, 0, 0, 1); arched_opening(5, 2, tower_radius * 3); endrotate(); endxlate(); } }
int main() { std::vector<double> tot(8,0), dtot(8,0); bool dens=true; unsigned nmols=200, dir; std::vector<double> com(3), dist(3), a1(3), a2(3), len(nmols); for(unsigned i=0;i<20;++i){ if(dens) std::cout<<1+nmols<<std::endl; else std::cout<<1+2*nmols<<std::endl; std::cout<<10.0<<" "<<10.0<<" "<<10.0<<std::endl; std::cout<<"Ar "<<5.0<<" "<<5.0<<" "<<5.0<<std::endl; for(unsigned j=0;j<nmols;++j){ com[0]=10.0*randomn(); com[1]=10.0*randomn(); com[2]=10.0*randomn(); for(unsigned k=0;k<3;++k) dist[k]=fabs(com[k]-5.0); len[j]=randomn(); dir=floor( 3*randomn() ); if( dist[0]<1.0 ){ tot[1]+=1.0; dtot[1]+=len[j]; } if( dist[1]<1.0 ){ tot[2]+=1.0; dtot[2]+=len[j]; } if( dist[2]<1.0 ){ tot[3]+=1.0; dtot[3]+=len[j]; } if( dist[0]<1.0 && dist[1]<1.0 ){ tot[4]+=1.0; dtot[4]+=len[j]; } if( dist[0]<1.0 && dist[2]<1.0 ){ tot[5]+=1.0; dtot[5]+=len[j]; } if( dist[1]<1.0 && dist[2]<1.0 ){ tot[6]+=1.0; dtot[6]+=len[j]; } if( dist[0]<1.0 && dist[1]<1.0 && dist[2]<1.0 ){ tot[7]+=1.0; dtot[7]+=len[j]; } a1[0]=com[0]; a1[1]=com[1]; a1[2]=com[2]; a2[0]=com[0]; a2[1]=com[1]; a2[2]=com[2]; a1[dir]-=0.5*len[j]; a2[dir]+=0.5*len[j]; if(dens){ std::cout<<"Ar "<<com[0]<<" "<<com[1]<<" "<<com[2]<<std::endl; } else { std::cout<<"Ar "<<a1[0]<<" "<<a1[1]<<" "<<a1[2]<<std::endl; std::cout<<"Ar "<<a2[0]<<" "<<a2[1]<<" "<<a2[2]<<std::endl; } } for(unsigned i=1;i<8;++i){ if(dens) std::cerr<<"CV "<<i<<" "<<tot[i]<<std::endl; else std::cerr<<"CV "<<i<<dtot[i] / static_cast<double>( nmols )<<std::endl; tot[i]=dtot[i]=0.0; } } return 1; }
long random(long from, long to) { return from + (randomn(to) % (to - from)); }
static double perturbup(double value, double amount) { value = value + randomn(value * amount); return value; }
static double perturb(double value, double amount) { value = value + randomn(value * amount) - (value * amount / 2.0); return value; }