Advertisement
j0h

svgLib.svg

j0h
Jul 14th, 2023
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. #include <fcntl.h>
  2. #include <libfreenect.h>
  3. #include <libfreenect_sync.h>
  4. #include <string.h>
  5. #include <unistd.h>
  6.  
  7. #include <stdio.h>
  8. #include <math.h>
  9. #include <time.h>
  10. #include <stdlib.h>
  11.  
  12. #include"svg.h"
  13. //gcc k.c svg.c -std=c11 -o main
  14. #define WIDTH 640
  15. #define HEIGHT 480
  16. //--------------------------------------------------------
  17. // FUNCTION PROTOTYPES
  18. //--------------------------------------------------------
  19. void drawrectangles(void);
  20.  
  21. //--------------------------------------------------------
  22. // FUNCTION main
  23. //--------------------------------------------------------
  24. int main(void){
  25.  
  26. drawrectangles();
  27.  
  28. return EXIT_SUCCESS;
  29. }
  30.  
  31. // --------------------------------------------------------
  32. // FUNCTION drawrectangles
  33. // --------------------------------------------------------
  34. void drawrectangles(void){
  35. svg* psvg;
  36. psvg = svg_create(WIDTH, HEIGHT); //overall size
  37.  
  38. if(psvg == NULL){
  39. puts("psvg is NULL");
  40. } else {
  41.  
  42. char *RED="#FF0000";
  43. char *ORANGE="#FFA500";
  44. char *YELLOW="#FFFF00";
  45. char *GREEN="#00FF00";
  46. char *BLUE="#0000FF";
  47. char *INDIGO="FF00FF";
  48. char *VIOLET="#C0C0FF";
  49. char *WHITE="#FFFFFF";
  50. char *BLACK="#000000";
  51. int x = 0;
  52. int y = 0;
  53. int index = 0; //index 0 to 307840
  54.  
  55. for (x=0; x<=WIDTH; x++){ //I expect 640 numbers by 480
  56. //index = y * WIDTH+x;
  57. index = x;
  58. //printf(" %d %d ", x, y);
  59. printf(" Index: %d ",index);
  60. if(index<100){
  61. switch (index) {
  62. case 0 ... 5 :
  63. printf("White\n");
  64. //(svg* psvg, int width, int height, int x, int y, char* fill, char* stroke, int strokewidth, int radiusx, int radiusy)
  65. svg_rectangle(psvg, 1, 1, x, y, WHITE, WHITE, 1, 0, 0);
  66. break;
  67. case 6 ... 15:
  68. printf("red\n");
  69. svg_rectangle(psvg, 1, 1, x, y, RED, RED, 1, 0, 0);
  70. break;
  71. case 16 ... 30:
  72. printf("orange\n");
  73. svg_rectangle(psvg, 1, 1, x, y, ORANGE, ORANGE, 1, 0, 0);
  74. break;
  75. case 31 ... 51:
  76. printf("yellow\n");
  77. svg_rectangle(psvg, 1, 1, x, y, YELLOW,YELLOW, 1, 0, 0);
  78. break;
  79. case 52 ... 75:
  80. printf("green\n");
  81. svg_rectangle(psvg, 1, 1, x, y, GREEN,GREEN, 1, 0, 0);
  82. break;
  83. case 76 ... 80:
  84. printf("blue\n");
  85. svg_rectangle(psvg, 1, 1, x, y, BLUE,BLUE, 1, 0, 0);
  86. break;
  87. case 81 ... 90:
  88. printf("indigo\n");
  89. svg_rectangle(psvg, 1, 1, x, y, INDIGO,INDIGO, 1, 0, 0);
  90. break;
  91. case 91 ... 100:
  92. printf("violet\n");
  93. svg_rectangle(psvg, 1, 1, x, y, VIOLET,VIOLET, 1, 0, 0);
  94. break;
  95. default:
  96. printf("black\n");
  97. svg_rectangle(psvg, 1, 1, x, y, BLACK, BLACK, 1, 0, 0);
  98. break;
  99. }
  100. }
  101. }
  102. // svg_rectangle(psvg, 1, 1, 0, 0, RED, "black", 1, 0, 0);
  103. svg_finalize(psvg);
  104. svg_save(psvg, "balls.svg");
  105. svg_free(psvg);
  106. }
  107. }
  108.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement