예제 #1
0
파일: koch.c 프로젝트: MiCHiLU/algo
void koch(void)
{
    if (d <= DMAX)
        draw_rel(d * costbl[a % 6], d * sintbl[a % 6]);
    else {
        d /= 3;  koch();  a++;  koch();
        a += 4;  koch();  a++;  koch();
        d *= 3;
    }
}
예제 #2
0
void kochFlake(Turtle * t, int depth, double length)
{
    t->penDown();
    t->setColour({255,128,128});
    koch(t, depth, length);
    t->setColour({128,255,128});
    t->turn(-120);
    koch(t, depth, length);
    t->setColour({128,128,255});
    t->turn(-120);
    koch(t, depth, length);
}
예제 #3
0
void koch(Turtle * t, int depth, double length)
{
    if(depth == 0) t->moveForward(length);
    else
    {
        koch(t, depth-1, length/3);
        t->turn(60);
        koch(t, depth-1, length/3);
        t->turn(-120);
        koch(t, depth-1, length/3);
        t->turn(60);
        koch(t, depth-1, length/3);
    }
}
예제 #4
0
파일: koch.c 프로젝트: 9Life42/cs
int main() 
{
 double j,r,q ;

 size = 600 ;
 G_init_graphics(size, size) ;
 G_rgb(0, 0, 0) ;
 G_clear() ;

 G_rgb(1.0, 0.0, 0.0) ;

 j = 0 ;
 while (j < 500000) {

   r = drand48() ;

   // diagonal_line(r) ;
   // filled_triangle(r) ;
   koch(r);

   G_point (x[0], y[0]) ;

   j=j+1 ;
 }

 q = G_wait_key() ;

}
예제 #5
0
void koch(double p0x, double p0y, double p1x, double p1y, int i)
{
  if (i == 0) return;
  double sx = (2.0 * p0x + p1x) / 3.0;
  double sy = (2.0 * p0y + p1y) / 3.0;
  double tx = (p0x + 2 * p1x) / 3.0;
  double ty = (p0y + 2 * p1y) / 3.0;
  double ux = (tx - sx) * cos(TH) - (ty - sy) * sin(TH) + sx;
  double uy = (tx - sx) * sin(TH) + (ty - sy) * cos(TH) + sy;

  koch(p0x, p0y, sx, sy, i - 1);
  printf("%.8f %.8f\n", sx, sy); /* s */
  koch(sx, sy, ux, uy, i - 1);
  printf("%.8f %.8f\n", ux, uy); /* u */
  koch(ux, uy, tx, ty, i - 1);
  printf("%.8f %.8f\n", tx, ty); /* t */
  koch(tx, ty, p1x, p1y, i - 1);
}
예제 #6
0
int main(int argc, char *argv[])
{
  int i;
  scanf("%d", &i);
  printf("%.8f %.8f\n", 0.0, 0.0);
  koch(0.0, 0.0, 100.0, 0.0, i);
  printf("%.8f %.8f\n", 100.0, 0.0);
  return 0;
}
예제 #7
0
void koch (int len, int level)
{
  int newlen;
  if (0 == level) {
    forwd (len);
    return;
  }
  else {
    newlen = (int) ceil (len / 3.0);
    koch (newlen, level - 1);
    turnleft (60);
    koch (newlen, level - 1);
    turnright (120);
    koch (newlen, level - 1);
    turnleft (60);
    koch (newlen, level - 1);
  }
}
예제 #8
0
파일: test.c 프로젝트: mimaun/Aizu
int main(){
    int n;
    double x1 = 0.0, x2 = 100.0;
    double y1 = 0.0, y2 = 0.0;

    scanf("%d", &n);
    printf("%f %f\n", x1, y1);
    koch(x1, y1, x2, y2, n);
    return 0;
}
예제 #9
0
void koch_start(int iter) {
  koch('F', iter);
  koch('p', iter);
  koch('p', iter);
  koch('F', iter);
  koch('p', iter);
  koch('p', iter);
  koch('F', iter);
}
예제 #10
0
파일: koch.c 프로젝트: MiCHiLU/algo
int main()
{
    gr_on();  gr_window(0, 0, 2, 1, 1, 0);
    for (a = 0; a < 6; a++) {
        costbl[a] = cos(a * PI / 3);
        sintbl[a] = sin(a * PI / 3);
    }
    move(0, 0);  d = 2;  a = 0;  koch();
    hitanykey();
    return EXIT_SUCCESS;
}
예제 #11
0
void render_drawing(turtle_t &turt)
{
	koch(turt, 2.0);
/*	turt.reset();
	turt.clear();
//	turt.set_pos(-0.3, 0.5);
	turt.turn_right(30);
	turt.forward(0.5);
	turt.turn_right(90);
	turt.forward(0.5);*/
}
예제 #12
0
파일: test.c 프로젝트: mimaun/Aizu
void koch(double x1, double y1, double x2, double y2, int n){
    double ax, ay, bx, by, cx, cy;

    if(n != 0){

        ax = (x2 - x1) / 3 + x1;
        ay = (y2 - y1) / 3 + y1;
        bx = 2 * (x2 - x1) / 3 + x1;
        by = 2 * (y2 - y1) / 3 + y1;

        cx = ((bx - ax)* cos(60) - (by - ay)* sin(60)) + ax;      // 60度回転
        cy = ((bx - ax)* sin(60) + (by - ay)* cos(60)) + ay;

        koch(x1, y1, ax, ay, n-1);
        koch(ax, ay, cx, cy, n-1);
        koch(cx, cy, bx, by, n-1);
        koch(bx, by, x2, y2, n-1);
    }
    else {
        printf("%f %f\n", x2, y2);

    }
}
예제 #13
0
void koch(char var, int iter) {
  if (iter < 0) {
    if (var == 'F') {
      turtle_forward(1);
    }
  } else {
    if(var == 'F') {
      koch('F', iter - 1);
      koch('m', iter - 1);
      koch('F', iter - 1);
      koch('p', iter - 1);
      koch('p', iter - 1);
      koch('F', iter - 1);
      koch('m', iter - 1);
      koch('F', iter - 1);
    }
    if (var == 'm') {
      turtle_turn_right(60);
    }
    if (var == 'p') {
      turtle_turn_left(60);
    }
  }
}
예제 #14
0
void snowflake(int depth, int side)
{
	koch(depth, side); turn(120);
	koch(depth, side); turn(120);
	koch(depth, side); turn(120);
}
예제 #15
0
int main (void)
{
  int i, l, x, y, xc, gd, gm;
  char s[32];

  gd = X11;
  gm = X11_1024x768;
  initgraph (&gd, &gm, "");

  setbkcolor (BLACK);

  /* Koch */
  for (i = 0; i < 6; i++) {
    cleardevice ();
    setcolor (GREEN);
    outtextxy (0, 0, "Standard Koch curve:");
    setposition (0, getmaxy () / 2);
    setheading (T_EAST);
    setcolor (i + 1);
    koch (getmaxx () + 1, i);
    usleep (500000);
  }
  setcolor (YELLOW);
  outtextxy (0, 20, "PRESS A KEY TO CONTINUE:");
  getch ();

  /* fractal tree */
  for (i = 0; i < 14; i++) {
    cleardevice ();
    setcolor (YELLOW);
    outtextxy (0, 0, "Tree:");
    setposition (getmaxx () *4/10, getmaxy ());
    setheading (T_NORTH);
    tree (getmaxy () / 3, i);
    usleep (500000);
  }
  setcolor (YELLOW);
  outtextxy (0, 20, "PRESS A KEY TO CONTINUE:");
  getch ();

  /* square Koch */
  for (i = 0; i < 6; i++) {
    cleardevice ();
    setcolor (RED);
    outtextxy (0, 0, "Square Koch curve:");
    setposition (0, getmaxy () / 2);
    setheading (T_EAST);
    setcolor (i + 1);
    sq_koch (getmaxx () + 1, i);
    usleep (500000);
  }
  setcolor (YELLOW);
  outtextxy (0, 20, "PRESS A KEY TO CONTINUE:");
  getch ();

  /* rotating square */
  cleardevice ();
  setcolor (RED);
  outtextxy (0, 0, "Rotating square:");
  home ();
  setheading (0);
  l = getmaxx () / 2;
  
  for (i = 1; i < l; i++) {
    setcolor (1 + i % 15);
    forwd (i);
    turnright (89);
    delay (10);
    if (kbhit ())
      break;
  }
  setcolor (YELLOW);
  outtextxy (0, 20, "PRESS A KEY TO CONTINUE:");
  getch ();

  /* Hilbert */
  setbkcolor (WHITE);
  cleardevice ();
  xc = getmaxx () / 2;
  x = xc;
  
  for (i = 1; i < 8; i++) {
    l = getmaxy () / powerof2 (i);
    x += l / 2;
    y = l / 2;
    setposition (x, y);
    setheading (T_WEST);
    setcolor (BLUE);
    hilbert_left (l, i);
    sprintf (s, "Hilbert curve at level %d", i);
    setcolor (BLUE);
    outtextxy (0, 0, s);
    getch ();
    cleardevice ();
  }
  outtextxy (0, 0, "PRESS A KEY TO EXIT:");
  
  /* stars */
  while (! kbhit ()) {
    setposition (random (getmaxx ()), random (getmaxy ()));
    setheading (random (360));
    setcolor (1 + random (15));
    star (random (80));
    star_6 (random (20));
    star_20 (random (40));
    usleep (50000);
  }
  
  closegraph ();
  return (0);
  
}