Advertisement
Guest User

Untitled

a guest
Mar 25th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <time.h>
  5.  
  6. typedef
  7. struct point {
  8. int x;
  9. int y;
  10. } Point;
  11.  
  12. void appendNewpath(FILE * plik) {
  13. fprintf(plik, "newpath\n");
  14. }
  15. void movetoXY(FILE * plik, int x, int y) {
  16. fprintf(plik, "%d %d moveto\n", x, y);
  17. }
  18. void linetoXY(FILE * plik, int x, int y) {
  19. fprintf(plik, "%d %d lineto\n", x, y);
  20. }
  21. void setlinewidth(FILE * plik, int x) {
  22. fprintf(plik, "%d setlinewidth\n",x);
  23. }
  24. void linetopoint(FILE * plik, Point p) {
  25. fprintf(plik, "%d %d lineto\n", p.x, p.y);
  26. }
  27. void movetopoint(FILE * plik, Point p) {
  28. fprintf(plik, "%d %d moveto\n", p.x, p.y);
  29. }
  30. void stroke(FILE * plik) {
  31. fprintf(plik, "stroke\n");
  32. }
  33. int randX() {
  34. return rand() % 800 + 20;
  35. }
  36. int randY() {
  37. return rand() % 570 + 20;
  38. }
  39.  
  40. Point * createPoint() {
  41. Point * p = (Point *) malloc(sizeof(Point));
  42. p->x = rand() % 560 + 20;
  43. p->y = rand() % 800 + 20;
  44. return p;
  45. }
  46.  
  47. void drawcircle(FILE * plik,Point p) {
  48. fprintf(plik, "%d %d %d %d %d arc closepath fill\n",p.x,p.y,15,0,360);
  49. }
  50.  
  51. void drawnumber(FILE * plik, Point p, int x) {
  52. fprintf(plik, "%d %d moveto\n", p.x-6,p.y-8);
  53. fprintf(plik, "(%d) show\n", x);
  54. }
  55.  
  56. void setcolor(FILE * plik,int x) {
  57. fprintf(plik, "%d %d %d setrgbcolor\n", x, x, x);
  58. }
  59.  
  60. void setfont(FILE * plik) {
  61. fprintf(plik, "/Times-Roman findfont 25 scalefont setfont\n");
  62. }
  63.  
  64.  
  65. int main()
  66. {
  67. srand(time(NULL));
  68. int much;
  69. much = rand() % 8 + 3;
  70. int randX;
  71. int randY;
  72. FILE * output = fopen("final.ps", "w+");
  73. setcolor(output, 0);
  74. appendNewpath(output);
  75. printf("%d\n", much);
  76. Point ** tab;
  77. tab = (Point **) malloc(sizeof(Point *)*much);
  78.  
  79. for (int i = 0; i < much-1; i++) {
  80. tab[i] = createPoint();
  81. }
  82. for (int i = 0; i < much-1; i++) {
  83. drawcircle(output, *(tab[i]));
  84. }
  85. stroke(output);
  86. appendNewpath(output);
  87.  
  88. movetopoint(output,*(tab[0]));
  89. for (int i = 1; i < much-1; i++) {
  90. linetopoint(output, *(tab[i]));
  91. }
  92. linetopoint(output, *(tab[0]));
  93. stroke(output);
  94. setcolor(output, 1);
  95. setfont(output);
  96. for (int i = 0; i < much-1;i++) {
  97. drawnumber(output, *tab[i], i + 1);
  98. }
  99. stroke(output);
  100. return 0;
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement