<< | к задаче | главная | печатать | обсудить(0 сообщений) >>
Задача: Рисование Фрактала (листьев папоротника)
Исходник: 123 [C++, code #674, hits: 404, рейтинг: 3/6,4.63(129)] +
автор: - [добавлен: 02.05.2018] управление:
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <dos.h>
  4. #include <graphics.h>
  5. #include <conio.h>
  6. // this function initializes graphics mode
  7. // it will work only if you're using Borland C++ compiler & BGI drivers
  8. // if you're using another compiler you should overwrite body of this function
  9. void init_gr(void)
  10. {
  11. /* request autodetection */
  12. int gdriver = DETECT, gmode, errorcode;
  13. /* initialize graphics mode */
  14. initgraph(&gdriver, &gmode, "");
  15. /* read result of initialization */
  16. errorcode = graphresult();
  17. if (errorcode != grOk) /* an error occurred */
  18. {
  19. printf("Graphics error: %s\n", grapherrormsg(errorcode));
  20. printf("Press any key to halt:");
  21. getch();
  22. exit(1); /* return with error code */
  23. }
  24. }
  25. // this function shuts graphics mode down
  26. // it will work only if you're using Borland C++ compiler & BGI drivers
  27. // if you're using another compiler you should overwrite body of this function
  28. void end_gr(void)
  29. {
  30. closegraph();
  31. }
  32. // this function puts pixel on the screen in (x,y) position using color 'color'
  33. // it will work only if you're using Borland C++ compiler & BGI drivers
  34. // if you're using another compiler you should overwrite body of this function
  35. void PutPixel(int x, int y, int color)
  36. {
  37. putpixel(x,y,color);
  38. }
  39. #define N 200000L // number of points
  40. float x=0, y=0; // iteration variables (are global)
  41. // a b c d e f probability
  42. float coeff[4][6] = {{ 0.00, 0.00, 0.00,0.16,0.00,0.00,}, // 01%
  43. { 0.85, 0.04,-0.04,0.85,0.00,1.60,}, // 85%
  44. { 0.05,-0.26, 0.23,0.22,0.00,1.60,}, // 07%
  45. {-0.15, 0.30, 0.26,0.24,0.00,0.44,},}; // 07%
  46. int colors[5]={10,11,2,3,2};
  47. void iterate(char i,int c)
  48. {
  49. float x1,y1;
  50. x1=x*coeff[i][0]+y*coeff[i][1]+coeff[i][4];
  51. y1=x*coeff[i][2]+y*coeff[i][3]+coeff[i][5];
  52. x=x1;
  53. y=y1;
  54. putpixel ((int)(y*64),240-(int)(x*48),c);
  55. }
  56. int main (void)
  57. {
  58. int leaf,color;
  59. // initializing graphics mode
  60. init_gr();
  61. // drawing leafs
  62. for (long int i=0;i<N;i++)
  63. {
  64. color=colors[random(5)]; // random color
  65. leaf=random(1000); // selecting leaf to draw
  66. if (leaf<=10) iterate(0,color);
  67. else if (leaf<=860) iterate(1,color);
  68. else if (leaf<=930) iterate(2,color);
  69. else iterate(3,color);
  70. }
  71. /* clean up */
  72. getch();
  73. end_gr();
  74. return 0;
  75. }

+добавить реализацию
 
каталог | задачи | паттерны | исходники | стат | форумы | карта сайта | контакты | ссылки 
© 2000-2018 CodeLAB Group
  Все права защищены
Страница сгенерирована за 0.002842 секунд
Количество запросов к БД: 8, gzip: 4.4kb/20.2kb(79%)