Exemplo n.º 1
0
int main()
{
  char fractal;
  int x=width/2,y=height/2,radius=width/3;
  int margin=20;	
  int x1=margin,x2=width-margin,x3=width/2,y1=margin,y2=margin,y3=height-margin;	
  gfx_open(width,height,"Fractals");
  gfx_clear_color(0,0,0);
  gfx_clear();
  gfx_color(255,255,255);
  printf("Which fractal would you like to see?\n1: Sierpinski Triangles\n2: Shrinking Squares\n3: Spiral Squares\n4: Circular Lace\n5: Snowflake\n6: Tree\n7: Fern\n8: Spiral of Spirals\n\n"); 
  while(fractal!='q'){
    fractal=gfx_wait();
    gfx_clear();
    switch(fractal){
      case 'q':
	return 0;
	break;
      case '1':
        printf("Sierpinski Triangles\n\n");
	sierpTriangles(x1,y1,x2,y2,x3,y3);
	break;
      case '2':
        printf("Shrinking Squares\n\n");
	shrinkSquares(x,y,width/4);
	break;
      case '3':
	printf("Spiral Squares\n\n");
        spiralSquares(x,y,-M_PI/4,width*2/3);
	break;
      case '4':
        printf("Circular Lace\n\n");
	circularLace(x,y,width);
	break;
      case '5':
        printf("Snowflake\n\n");
	snowflake(x,y,radius);
	break;
      case '6':
        printf("Tree\n\n");
	tree(x,height,x,height*3/4,0,height/4);
	break;
      case '7':
        printf("Fern\n\n");
	fern(width/2,height-margin,2*height/3,0);
	break;
      case '8':
        printf("Spiral of Spirals\n\n");
	spiralSpirals(x,y,0,width);
	break;
      default:
	printf("Please enter a valid option\n\n");
	break;
    }
  }  
}
Exemplo n.º 2
0
void snowflake(int xcenter, int ycenter, int length){
  if(length<1) return;				//check for base case
 
  float angle=2*M_PI/5;				//drawing step
  int i,xnew[5],ynew[5];
  for(i=1;i<=5;i++){
    xnew[i-1]=xcenter+length*cos(i*angle+3*M_PI/2);
    ynew[i-1]=ycenter+length*sin(i*angle+3*M_PI/2);
    gfx_line(xcenter,ycenter,xnew[i-1],ynew[i-1]);
  }
 
  int newLength=length*.38;		//recursive step
  for(i=0;i<5;i++) snowflake(xnew[i],ynew[i],newLength);
}
Exemplo n.º 3
0
int main_snowflake(int argc, char **argv)
{
	if (argc < 3) {
		printf("Usage:\n");
		printf("%s [depth] [side]\n", argv[0]);
		exit(1);
	}

	startTurtle();
	snowflake(atoi(argv[1]), atoi(argv[2]));

	pause();

	return 0;
}
Exemplo n.º 4
0
void generateSnow() {
	double x = rand() % SCREEN_WIDTH + 1;
	double y = 0;
	dPoint velocity;
	velocity.x = ((rand() % 100) / 100.0) - 0.25;
	velocity.y = ((rand() % 10) / 10.0) + 1;
	Particle snowflake(x, y, velocity.x, velocity.y, 2, 2, 1.0);
	snowflakes.push_back(snowflake);
	
	for (unsigned int i = 0; i < snowflakes.size(); i++) {
		for (unsigned int j = 0; j < snowflakes.size(); j++) {
			if(!snowflakes.at(i).isConnectedToGround()) {
				if (snowflakes.at(j).isConnectedToGround()) {
					if (snowflakes.at(i).getPositionX() >= snowflakes.at(j).getPositionX() - 3) {
						if (snowflakes.at(i).getPositionY() >= snowflakes.at(j).getPositionY()- 3) {
								//snowflakes.at(i).connectToGround();
							snowflakes.at(i).set_to_be_deleted();
						}
					}//y position equality check
				}//connected to ground check
			}
		}
	}
}
Exemplo n.º 5
0
void Workspace::draw()
	{
	beginLocal();
	
	glBegin( GL_QUADS );
		glColor3f( 0.8, 0.9, 1 );
		glVertex2i( 0, 0 );

		glColor3f( 0.7, 0.8, 1 );
		glVertex2i( bounds.w, 0 );

		glColor3f( 0.2, 0.3, 0.5 );
		glVertex2i( bounds.w, bounds.h );

		glColor3f( 0.1, 0.2, 0.4 );
		glVertex2i( 0, bounds.h );
	glEnd();

#if defined(_WIN32)
	//<matt>: "pretty prettier snowflakes" 2-18-06
	const float SFSIZE = 4.0;
	  glColor4f( 1.0, 1.0, 1.0, 0.15 );
	if (snowflakes.size() == 0) //how many snowflakes?
	// 0 is not snowing, 20 enough, 50 too much, 200 blizzard
	{ for (int i = 0; i <= 50; i++)
	  snowflakes.push_back
	  (snowflake(rand()%bounds.w, rand()%bounds.h, rand()%360, ((rand()%2)-1.0)/5.0, ((rand()%2)-1.0)/5.0));
	}
	for (int i = 0; i < snowflakes.size(); i++)
	{
	 snowflakes[i].rz += SFSIZE;
	 if (snowflakes[i].rz >= 360.0) snowflakes[i].rz = 0.0;

	 snowflakes[i].px += 0.5 + snowflakes[i].dx;
	 if (snowflakes[i].px >= bounds.w) snowflakes[i].px = 0.0;

	 snowflakes[i].py += 0.5 + snowflakes[i].dy;
	 if (snowflakes[i].py >= bounds.h) snowflakes[i].py = 0.0;
	 
	 glPushMatrix();
	 glTranslatef(snowflakes[i].px, snowflakes[i].py, 0.0);
	 //which is pretier? I think the 2nd one is
	 //glRotatef(snowflakes[i].rz, 0.0, 0.0, 1.0);
	 glRotatef(snowflakes[i].rz, 1.0, 0.0, 1.0);
	 glBegin( GL_TRIANGLES );
	  glVertex2f( - SFSIZE, + SFSIZE);
	  glVertex2f( 0.0,  - SFSIZE);
	  glVertex2f( + SFSIZE, + SFSIZE);
	 glEnd();
	 glTranslatef(0.0, SFSIZE/2.0, 0.0);
	 glBegin( GL_TRIANGLES );
	  glVertex2f( + SFSIZE, - SFSIZE);
	  glVertex2f( 0.0,  + SFSIZE);
	  glVertex2f( - SFSIZE, - SFSIZE);
	 glEnd();
	 glPopMatrix();
	}
	//</matt> snowflakes
#endif

	endLocal();
	drawSubViews();
	}