Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <time.h>
- typedef
- struct point {
- int x;
- int y;
- } Point;
- void appendNewpath(FILE * plik) {
- fprintf(plik, "newpath\n");
- }
- void movetoXY(FILE * plik, int x, int y) {
- fprintf(plik, "%d %d moveto\n", x, y);
- }
- void linetoXY(FILE * plik, int x, int y) {
- fprintf(plik, "%d %d lineto\n", x, y);
- }
- void setlinewidth(FILE * plik, int x) {
- fprintf(plik, "%d setlinewidth\n",x);
- }
- void linetopoint(FILE * plik, Point p) {
- fprintf(plik, "%d %d lineto\n", p.x, p.y);
- }
- void movetopoint(FILE * plik, Point p) {
- fprintf(plik, "%d %d moveto\n", p.x, p.y);
- }
- void stroke(FILE * plik) {
- fprintf(plik, "stroke\n");
- }
- int randX() {
- return rand() % 800 + 20;
- }
- int randY() {
- return rand() % 570 + 20;
- }
- Point * createPoint() {
- Point * p = (Point *) malloc(sizeof(Point));
- p->x = rand() % 560 + 20;
- p->y = rand() % 800 + 20;
- return p;
- }
- void drawcircle(FILE * plik,Point p) {
- fprintf(plik, "%d %d %d %d %d arc closepath fill\n",p.x,p.y,15,0,360);
- }
- void drawnumber(FILE * plik, Point p, int x) {
- fprintf(plik, "%d %d moveto\n", p.x-6,p.y-8);
- fprintf(plik, "(%d) show\n", x);
- }
- void setcolor(FILE * plik,int x) {
- fprintf(plik, "%d %d %d setrgbcolor\n", x, x, x);
- }
- void setfont(FILE * plik) {
- fprintf(plik, "/Times-Roman findfont 25 scalefont setfont\n");
- }
- int main()
- {
- srand(time(NULL));
- int much;
- much = rand() % 8 + 3;
- int randX;
- int randY;
- FILE * output = fopen("final.ps", "w+");
- setcolor(output, 0);
- appendNewpath(output);
- printf("%d\n", much);
- Point ** tab;
- tab = (Point **) malloc(sizeof(Point *)*much);
- for (int i = 0; i < much-1; i++) {
- tab[i] = createPoint();
- }
- for (int i = 0; i < much-1; i++) {
- drawcircle(output, *(tab[i]));
- }
- stroke(output);
- appendNewpath(output);
- movetopoint(output,*(tab[0]));
- for (int i = 1; i < much-1; i++) {
- linetopoint(output, *(tab[i]));
- }
- linetopoint(output, *(tab[0]));
- stroke(output);
- setcolor(output, 1);
- setfont(output);
- for (int i = 0; i < much-1;i++) {
- drawnumber(output, *tab[i], i + 1);
- }
- stroke(output);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement