Author Topic: Pie Chart Maker 2 - With Up To 500 Pieces (Slices)  (Read 4177 times)

0 Members and 1 Guest are viewing this topic.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Pie Chart Maker 2 - With Up To 500 Pieces (Slices)
« on: October 31, 2019, 02:40:39 pm »
This morning I worked hard and made Pie Chart Maker 2. It lets you make many slices of the pie using random colors. I also added printer support to be able to print it on the printer. It uses bplus's graphic rotation to be able to print the screen vertically instead of the default landscape. Thanks! You can add up to 500 slices but I doubt anyone will make that many. lol
Thank you everyone for your support, it helps a lot because I don't have any forums or email or anything on my website that tells me people are using my programs.
Oh also, this program will tell you if you have gone past the 100% mark and ask you to type it in again, after the first slice.
As with the other one, it lets you save to a .bmp file as well to be used with other programs. 

(There is an updated version after this post.)

Code: QB64: [Select]
  1. 'One Piece Pie Chart Maker by Ken G. on Oct. 31. 2019.
  2. 'Thank you to bplus for the graphic rotation for printer support.
  3. 'Thank you also to everyone on the QB64.org forum for your support!
  4. 'Freeware
  5. _TITLE "One Piece Pie Chart Maker"
  6. again:
  7. SCREEN _NEWIMAGE(800, 600, 32)
  8. PAINT (1, 1), _RGB32(255, 255, 255)
  9. COLOR _RGB32(0, 0, 0), _RGB32(255, 255, 255)
  10. INPUT "How many slices for your chart (1-500):"; amount
  11. IF amount < 1 OR amount > 500 THEN GOTO again:
  12. p = 0
  13. pc = 100
  14. seconds = 0
  15. sec = 0
  16. FOR slice = 1 TO amount
  17.     c2 = INT(RND * 154) + 100
  18.     c3 = INT(RND * 154) + 100
  19.     c = INT(RND * 154) + 100
  20.     CIRCLE (400, 300), 180, _RGB32(255, 0, 0)
  21.     DO
  22.         _LIMIT 1000
  23.         pc = pc - p
  24.         again2:
  25.         LOCATE 1, 1: PRINT "                                                                                      "
  26.         LOCATE 1, 1: PRINT amount - slice + 1; ". Type Percentage Here (0 -"; pc; "):";
  27.         INPUT p
  28.         IF p > pc THEN LOCATE 1, 1: INPUT "That is over 100%. Press Enter and try again.", tg$: GOTO again2:
  29.         IF p > 100 THEN p = 100
  30.         IF p < 0 THEN p = 0
  31.         seconds = sec
  32.         sec = (p * .6) + seconds
  33.         DO
  34.             seconds = seconds + .0001
  35.             s = (60 - seconds) * 6 + 180
  36.             x = INT(SIN(s / 180 * _PI) * 180) + 400
  37.             y = INT(COS(s / 180 * _PI) * 180) + 300
  38.             c = c + .000125
  39.             IF seconds > sec THEN LINE (400, 300)-(x, y), _RGB32(c, c2, c3)
  40.             IF seconds > sec THEN GOTO two:
  41.             LINE (400, 300)-(x, y), _RGB32(c, c2, c3)
  42.         LOOP
  43.     LOOP
  44.     two:
  45. NEXT slice
  46. 'Erase the input line
  47. LINE (0, 0)-(800, 15), _RGB32(255, 255, 255), BF
  48. 'Hole Filler
  49. FOR xx = 0 TO 800
  50.     FOR yy = 20 TO 600
  51.         IF POINT(xx, yy) = _RGB32(255, 255, 255) AND POINT(xx - 1, yy) <> _RGB32(255, 255, 255) AND POINT(xx + 1, yy) <> _RGB32(255, 255, 255) THEN
  52.             cl& = POINT(xx + 1, yy)
  53.             PSET (xx, yy), cl&
  54.         END IF
  55.     NEXT yy
  56. NEXT xx
  57. _TITLE "(T)ext, (P)rint, (S)ave, (D)elete, Esc to Quit"
  58.     a$ = INKEY$
  59.     IF a$ = CHR$(27) THEN END
  60.     IF a$ = "t" OR a$ = "T" THEN GOSUB Text:
  61.     IF a$ = "s" OR a$ = "S" THEN GOTO saving:
  62.     IF a$ = "d" OR a$ = "D" THEN GOTO again:
  63.     IF a$ = "p" OR a$ = "P" THEN GOSUB printing:
  64. 'Print to your printer.
  65. printing:
  66. LOCATE 1, 1: INPUT "Are you sure you want to print to your printer (Y/N):"; yn$
  67. IF LEFT$(yn$, 1) = "y" OR LEFT$(yn$, 1) = "Y" THEN GOTO printing2:
  68. printing2:
  69. LINE (0, 0)-(800, 15), _RGB32(255, 255, 255), BF
  70. j& = _COPYIMAGE(0)
  71. _DELAY .25
  72. _DELAY .25
  73. 'printer prep (code copied and pasted from bplus Free Calendar Program)
  74. YMAX = _HEIGHT: XMAX = _WIDTH
  75. landscape& = _NEWIMAGE(YMAX, XMAX, 32)
  76. _MAPTRIANGLE (XMAX, 0)-(0, 0)-(0, YMAX), 0 TO(0, 0)-(0, XMAX)-(YMAX, XMAX), landscape&
  77. _MAPTRIANGLE (XMAX, 0)-(XMAX, YMAX)-(0, YMAX), 0 TO(0, 0)-(YMAX, 0)-(YMAX, XMAX), landscape&
  78. _PRINTIMAGE landscape&
  79. landscape& = 0
  80. j& = 0
  81. 'Add text to the picture.
  82. Text:
  83. _TITLE "TEXT MODE - Use Mouse To Click Where You Want To Place Text Then Type Text And Press Enter To Finish."
  84.     _LIMIT 500
  85.         mouseX = _MOUSEX
  86.         mouseY = _MOUSEY
  87.         mouseLeftButton = _MOUSEBUTTON(1)
  88.     LOOP
  89.     IF mouseLeftButton = -1 THEN
  90.         clr& = POINT(mouseX, mouseY)
  91.         IF clr& <> _RGB32(255, 255, 255) THEN COLOR _RGB32(255, 255, 255), clr&
  92.         IF clr& = _RGB32(255, 255, 255) THEN COLOR _RGB32(0, 100, 0), clr&
  93.         LOCATE mouseY / 16, mouseX / 8
  94.         INPUT "", txt$
  95.         _TITLE "(T)ext, (S)ave, (D)elete, Esc to Quit"
  96.         RETURN
  97.     END IF
  98. 'Save .bmp picture file to your computer.
  99. saving:
  100. _LIMIT 1000
  101. 'Now we call up the SUB to save the image to BMP.
  102. SaveImage 0, "temp.bmp"
  103. _DELAY .25
  104. LINE (0, 0)-(800, 600), _RGB32(0, 0, 0), BF
  105. COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  106. PRINT "                               Saving"
  107. PRINT "                  Your BMP file will be saved in the"
  108. PRINT "                  same directory as this program is."
  109. PRINT "                  It can be used with almost any"
  110. PRINT "                  other graphics program or website."
  111. PRINT "                  It is saved using:"
  112. PRINT "                  width: 800  height: 600 pixels."
  113. PRINT "                  Type a name to save your picture"
  114. PRINT "                  and press the Enter key. Do not"
  115. PRINT "                  add .bmp at the end, the program"
  116. PRINT "                  will do it automatically."
  117. PRINT "                  Also do not use the name temp"
  118. PRINT "                  because the program uses that name"
  119. PRINT "                  and it would be erased the next time"
  120. PRINT "                  you save a picture."
  121. PRINT "                  Example: MyPic"
  122. PRINT "                  Q and Enter goes to main screen."
  123. INPUT "                  ->"; nm$
  124. IF nm$ = "Q" OR nm$ = "q" THEN GOTO again:
  125. nm$ = nm$ + ".bmp"
  126. 'Checking to see if the file already exists on your computer.
  127. theFileExists = _FILEEXISTS(nm$)
  128. IF theFileExists = -1 THEN
  129.     PRINT
  130.     PRINT "             File Already Exists"
  131.     PRINT "             Saving will delete your old"
  132.     PRINT "             bmp picture."
  133.     PRINT "             Would you like to still do it?"
  134.     PRINT "             (Y/N)."
  135.     PRINT "             Esc goes to start screen."
  136.     llloop:
  137.     _LIMIT 100
  138.     ag2$ = INKEY$
  139.     IF ag2$ = CHR$(27) THEN GOTO again:
  140.     IF ag2$ = "" THEN GOTO llloop:
  141.     IF ag2$ = "y" OR ag$ = "Y" THEN
  142.         SHELL _HIDE "DEL " + nm$
  143.         GOTO saving2:
  144.     END IF
  145.     GOTO llloop:
  146. saving2:
  147. 'Rename temp.bmp to your chosen name.
  148. SHELL _HIDE "REN " + "temp.bmp" + " " + nm$
  149. nm$ = ""
  150. FOR snd = 100 TO 500 STEP 100
  151.     SOUND snd, 2
  152. NEXT snd
  153. INPUT "Do you wish to make another pie chart (Y/N):"; yesno$
  154. IF LEFT$(yesno$, 1) = "y" OR LEFT$(yesno$, 1) = "Y" THEN GOTO again:
  155.  
  156. SUB SaveImage (image AS LONG, filename AS STRING)
  157.     bytesperpixel& = _PIXELSIZE(image&)
  158.     IF bytesperpixel& = 0 THEN PRINT "Text modes unsupported!": END
  159.     IF bytesperpixel& = 1 THEN bpp& = 8 ELSE bpp& = 24
  160.     x& = _WIDTH(image&)
  161.     y& = _HEIGHT(image&)
  162.     b$ = "BM????QB64????" + MKL$(40) + MKL$(x&) + MKL$(y&) + MKI$(1) + MKI$(bpp&) + MKL$(0) + "????" + STRING$(16, 0) 'partial BMP header info(???? to be filled later)
  163.     IF bytesperpixel& = 1 THEN
  164.         FOR c& = 0 TO 255 ' read BGR color settings from JPG image + 1 byte spacer(CHR$(0))
  165.             cv& = _PALETTECOLOR(c&, image&) ' color attribute to read.
  166.             b$ = b$ + CHR$(_BLUE32(cv&)) + CHR$(_GREEN32(cv&)) + CHR$(_RED32(cv&)) + CHR$(0) 'spacer byte
  167.         NEXT
  168.     END IF
  169.     MID$(b$, 11, 4) = MKL$(LEN(b$)) ' image pixel data offset(BMP header)
  170.     lastsource& = _SOURCE
  171.     _SOURCE image&
  172.     IF ((x& * 3) MOD 4) THEN padder$ = STRING$(4 - ((x& * 3) MOD 4), 0)
  173.     FOR py& = y& - 1 TO 0 STEP -1 ' read JPG image pixel color data
  174.         r$ = ""
  175.         FOR px& = 0 TO x& - 1
  176.             c& = POINT(px&, py&) 'POINT 32 bit values are large LONG values
  177.             IF bytesperpixel& = 1 THEN r$ = r$ + CHR$(c&) ELSE r$ = r$ + LEFT$(MKL$(c&), 3)
  178.         NEXT px&
  179.         d$ = d$ + r$ + padder$
  180.     NEXT py&
  181.     _SOURCE lastsource&
  182.     MID$(b$, 35, 4) = MKL$(LEN(d$)) ' image size(BMP header)
  183.     b$ = b$ + d$ ' total file data bytes to create file
  184.     MID$(b$, 3, 4) = MKL$(LEN(b$)) ' size of data file(BMP header)
  185.     IF LCASE$(RIGHT$(filename$, 4)) <> ".bmp" THEN ext$ = ".bmp"
  186.     f& = FREEFILE
  187.     OPEN filename$ + ext$ FOR OUTPUT AS #f&: CLOSE #f& ' erases an existing file
  188.     OPEN filename$ + ext$ FOR BINARY AS #f&
  189.     PUT #f&, , b$
  190.     CLOSE #f&
  191.  
PieChartMaker2-Example.bmp
* PieChartMaker2-Example.bmp (Filesize: 1.37 MB, Dimensions: 800x600, Views: 214)
« Last Edit: October 31, 2019, 03:10:56 pm by SierraKen »

Marked as best answer by SierraKen on October 31, 2019, 01:30:54 pm

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Pie Chart Maker 2 - With Up To 500 Pieces (Slices)
« Reply #1 on: October 31, 2019, 03:10:31 pm »
LOL of course I left something out. I forgot that I use random colors so instead of using white text inside the pie, I am just going with black text everywhere because it stands out better.

Code: QB64: [Select]
  1. 'One Piece Pie Chart Maker by Ken G. on Oct. 31. 2019.
  2. 'Thank you to bplus for the graphic rotation for printer support.
  3. 'Thank you also to everyone on the QB64.org forum for your support!
  4. 'Freeware
  5. _TITLE "One Piece Pie Chart Maker"
  6. again:
  7. SCREEN _NEWIMAGE(800, 600, 32)
  8. PAINT (1, 1), _RGB32(255, 255, 255)
  9. COLOR _RGB32(0, 0, 0), _RGB32(255, 255, 255)
  10. INPUT "How many slices for your chart (1-500):"; amount
  11. IF amount < 1 OR amount > 500 THEN GOTO again:
  12. p = 0
  13. pc = 100
  14. seconds = 0
  15. sec = 0
  16. FOR slice = 1 TO amount
  17.     c2 = INT(RND * 154) + 100
  18.     c3 = INT(RND * 154) + 100
  19.     c = INT(RND * 154) + 100
  20.     CIRCLE (400, 300), 180, _RGB32(255, 0, 0)
  21.     DO
  22.         _LIMIT 1000
  23.         pc = pc - p
  24.         again2:
  25.         LOCATE 1, 1: PRINT "                                                                                      "
  26.         LOCATE 1, 1: PRINT amount - slice + 1; ". Type Percentage Here (0 -"; pc; "):";
  27.         INPUT p
  28.         IF p > pc THEN LOCATE 1, 1: INPUT "That is over 100%. Press Enter and try again.", tg$: GOTO again2:
  29.         IF p > 100 THEN p = 100
  30.         IF p < 0 THEN p = 0
  31.         seconds = sec
  32.         sec = (p * .6) + seconds
  33.         DO
  34.             seconds = seconds + .0001
  35.             s = (60 - seconds) * 6 + 180
  36.             x = INT(SIN(s / 180 * _PI) * 180) + 400
  37.             y = INT(COS(s / 180 * _PI) * 180) + 300
  38.             c = c + .000125
  39.             IF seconds > sec THEN LINE (400, 300)-(x, y), _RGB32(c, c2, c3)
  40.             IF seconds > sec THEN GOTO two:
  41.             LINE (400, 300)-(x, y), _RGB32(c, c2, c3)
  42.         LOOP
  43.     LOOP
  44.     two:
  45. NEXT slice
  46. 'Erase the input line
  47. LINE (0, 0)-(800, 15), _RGB32(255, 255, 255), BF
  48. 'Hole Filler
  49. FOR xx = 0 TO 800
  50.     FOR yy = 20 TO 600
  51.         IF POINT(xx, yy) = _RGB32(255, 255, 255) AND POINT(xx - 1, yy) <> _RGB32(255, 255, 255) AND POINT(xx + 1, yy) <> _RGB32(255, 255, 255) THEN
  52.             cl& = POINT(xx + 1, yy)
  53.             PSET (xx, yy), cl&
  54.         END IF
  55.     NEXT yy
  56. NEXT xx
  57. _TITLE "(T)ext, (P)rint, (S)ave, (D)elete, Esc to Quit"
  58.     a$ = INKEY$
  59.     IF a$ = CHR$(27) THEN END
  60.     IF a$ = "t" OR a$ = "T" THEN GOSUB Text:
  61.     IF a$ = "s" OR a$ = "S" THEN GOTO saving:
  62.     IF a$ = "d" OR a$ = "D" THEN GOTO again:
  63.     IF a$ = "p" OR a$ = "P" THEN GOSUB printing:
  64. 'Print to your printer.
  65. printing:
  66. LOCATE 1, 1: INPUT "Are you sure you want to print to your printer (Y/N):"; yn$
  67. IF LEFT$(yn$, 1) = "y" OR LEFT$(yn$, 1) = "Y" THEN GOTO printing2:
  68. printing2:
  69. LINE (0, 0)-(800, 15), _RGB32(255, 255, 255), BF
  70. j& = _COPYIMAGE(0)
  71. _DELAY .25
  72. _DELAY .25
  73. 'printer prep (code copied and pasted from bplus Free Calendar Program)
  74. YMAX = _HEIGHT: XMAX = _WIDTH
  75. landscape& = _NEWIMAGE(YMAX, XMAX, 32)
  76. _MAPTRIANGLE (XMAX, 0)-(0, 0)-(0, YMAX), 0 TO(0, 0)-(0, XMAX)-(YMAX, XMAX), landscape&
  77. _MAPTRIANGLE (XMAX, 0)-(XMAX, YMAX)-(0, YMAX), 0 TO(0, 0)-(YMAX, 0)-(YMAX, XMAX), landscape&
  78. _PRINTIMAGE landscape&
  79. landscape& = 0
  80. j& = 0
  81. 'Add text to the picture.
  82. Text:
  83. _TITLE "TEXT MODE - Use Mouse To Click Where You Want To Place Text Then Type Text And Press Enter To Finish."
  84.     _LIMIT 500
  85.         mouseX = _MOUSEX
  86.         mouseY = _MOUSEY
  87.         mouseLeftButton = _MOUSEBUTTON(1)
  88.     LOOP
  89.     IF mouseLeftButton = -1 THEN
  90.         clr& = POINT(mouseX, mouseY)
  91.         COLOR _RGB32(0, 100, 0), clr&
  92.         LOCATE mouseY / 16, mouseX / 8
  93.         INPUT "", txt$
  94.         _TITLE "(T)ext, (S)ave, (D)elete, Esc to Quit"
  95.         RETURN
  96.     END IF
  97. 'Save .bmp picture file to your computer.
  98. saving:
  99. _LIMIT 1000
  100. 'Now we call up the SUB to save the image to BMP.
  101. SaveImage 0, "temp.bmp"
  102. _DELAY .25
  103. LINE (0, 0)-(800, 600), _RGB32(0, 0, 0), BF
  104. COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  105. PRINT "                               Saving"
  106. PRINT "                  Your BMP file will be saved in the"
  107. PRINT "                  same directory as this program is."
  108. PRINT "                  It can be used with almost any"
  109. PRINT "                  other graphics program or website."
  110. PRINT "                  It is saved using:"
  111. PRINT "                  width: 800  height: 600 pixels."
  112. PRINT "                  Type a name to save your picture"
  113. PRINT "                  and press the Enter key. Do not"
  114. PRINT "                  add .bmp at the end, the program"
  115. PRINT "                  will do it automatically."
  116. PRINT "                  Also do not use the name temp"
  117. PRINT "                  because the program uses that name"
  118. PRINT "                  and it would be erased the next time"
  119. PRINT "                  you save a picture."
  120. PRINT "                  Example: MyPic"
  121. PRINT "                  Q and Enter goes to main screen."
  122. INPUT "                  ->"; nm$
  123. IF nm$ = "Q" OR nm$ = "q" THEN GOTO again:
  124. nm$ = nm$ + ".bmp"
  125. 'Checking to see if the file already exists on your computer.
  126. theFileExists = _FILEEXISTS(nm$)
  127. IF theFileExists = -1 THEN
  128.     PRINT
  129.     PRINT "             File Already Exists"
  130.     PRINT "             Saving will delete your old"
  131.     PRINT "             bmp picture."
  132.     PRINT "             Would you like to still do it?"
  133.     PRINT "             (Y/N)."
  134.     PRINT "             Esc goes to start screen."
  135.     llloop:
  136.     _LIMIT 100
  137.     ag2$ = INKEY$
  138.     IF ag2$ = CHR$(27) THEN GOTO again:
  139.     IF ag2$ = "" THEN GOTO llloop:
  140.     IF ag2$ = "y" OR ag$ = "Y" THEN
  141.         SHELL _HIDE "DEL " + nm$
  142.         GOTO saving2:
  143.     END IF
  144.     GOTO llloop:
  145. saving2:
  146. 'Rename temp.bmp to your chosen name.
  147. SHELL _HIDE "REN " + "temp.bmp" + " " + nm$
  148. nm$ = ""
  149. FOR snd = 100 TO 500 STEP 100
  150.     SOUND snd, 2
  151. NEXT snd
  152. INPUT "Do you wish to make another pie chart (Y/N):"; yesno$
  153. IF LEFT$(yesno$, 1) = "y" OR LEFT$(yesno$, 1) = "Y" THEN GOTO again:
  154.  
  155. SUB SaveImage (image AS LONG, filename AS STRING)
  156.     bytesperpixel& = _PIXELSIZE(image&)
  157.     IF bytesperpixel& = 0 THEN PRINT "Text modes unsupported!": END
  158.     IF bytesperpixel& = 1 THEN bpp& = 8 ELSE bpp& = 24
  159.     x& = _WIDTH(image&)
  160.     y& = _HEIGHT(image&)
  161.     b$ = "BM????QB64????" + MKL$(40) + MKL$(x&) + MKL$(y&) + MKI$(1) + MKI$(bpp&) + MKL$(0) + "????" + STRING$(16, 0) 'partial BMP header info(???? to be filled later)
  162.     IF bytesperpixel& = 1 THEN
  163.         FOR c& = 0 TO 255 ' read BGR color settings from JPG image + 1 byte spacer(CHR$(0))
  164.             cv& = _PALETTECOLOR(c&, image&) ' color attribute to read.
  165.             b$ = b$ + CHR$(_BLUE32(cv&)) + CHR$(_GREEN32(cv&)) + CHR$(_RED32(cv&)) + CHR$(0) 'spacer byte
  166.         NEXT
  167.     END IF
  168.     MID$(b$, 11, 4) = MKL$(LEN(b$)) ' image pixel data offset(BMP header)
  169.     lastsource& = _SOURCE
  170.     _SOURCE image&
  171.     IF ((x& * 3) MOD 4) THEN padder$ = STRING$(4 - ((x& * 3) MOD 4), 0)
  172.     FOR py& = y& - 1 TO 0 STEP -1 ' read JPG image pixel color data
  173.         r$ = ""
  174.         FOR px& = 0 TO x& - 1
  175.             c& = POINT(px&, py&) 'POINT 32 bit values are large LONG values
  176.             IF bytesperpixel& = 1 THEN r$ = r$ + CHR$(c&) ELSE r$ = r$ + LEFT$(MKL$(c&), 3)
  177.         NEXT px&
  178.         d$ = d$ + r$ + padder$
  179.     NEXT py&
  180.     _SOURCE lastsource&
  181.     MID$(b$, 35, 4) = MKL$(LEN(d$)) ' image size(BMP header)
  182.     b$ = b$ + d$ ' total file data bytes to create file
  183.     MID$(b$, 3, 4) = MKL$(LEN(b$)) ' size of data file(BMP header)
  184.     IF LCASE$(RIGHT$(filename$, 4)) <> ".bmp" THEN ext$ = ".bmp"
  185.     f& = FREEFILE
  186.     OPEN filename$ + ext$ FOR OUTPUT AS #f&: CLOSE #f& ' erases an existing file
  187.     OPEN filename$ + ext$ FOR BINARY AS #f&
  188.     PUT #f&, , b$
  189.     CLOSE #f&
  190.  
PieChart-MyExample.bmp
* PieChart-MyExample.bmp (Filesize: 1.37 MB, Dimensions: 800x600, Views: 252)
« Last Edit: October 31, 2019, 03:12:29 pm by SierraKen »