Author Topic: One Piece Pie Chart Maker  (Read 5622 times)

0 Members and 1 Guest are viewing this topic.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
One Piece Pie Chart Maker
« on: October 29, 2019, 08:57:12 pm »
I decided to make this today because I've never made a pie chart maker. It makes one piece in the circle and the size depends on what percentage you give it (0-100). I used gradient colors to make it look right. I also made it so people can save it as a .BMP graphic file which is why I have the background white, so people can easily print it later on a graphics program.

Code: QB64: [Select]
  1. 'One Piece Pie Chart Maker by Ken G. on Oct. 29, 2019.
  2. 'Freeware
  3. _TITLE "One Piece Pie Chart Maker"
  4. again:
  5. SCREEN _NEWIMAGE(800, 600, 32)
  6. PAINT (1, 1), _RGB32(255, 255, 255)
  7. COLOR _RGB32(0, 0, 0), _RGB32(255, 255, 255)
  8.     _LIMIT 1000
  9.     LOCATE 1, 1: INPUT "Type Percentage Here (0-100):", p
  10.     IF p > 100 THEN p = 100
  11.     IF p < 0 THEN p = 0
  12.     sec = p * .6
  13.     c = 100
  14.     CLS
  15.     CIRCLE (400, 300), 180, _RGB32(255, 0, 0)
  16.     seconds = 0
  17.     DO
  18.         seconds = seconds + .01
  19.         s = (60 - seconds) * 6 + 180
  20.         x = INT(SIN(s / 180 * 3.141592) * 180) + 400
  21.         y = INT(COS(s / 180 * 3.141592) * 180) + 300
  22.         c = c + .025
  23.         IF seconds > sec THEN LINE (400, 300)-(x, y), _RGB32(c, 0, 255)
  24.         IF seconds > sec THEN GOTO two:
  25.         CIRCLE (x, y), 2, _RGB32(c, 0, 255)
  26.         PAINT (x, y), _RGB32(c, 0, 255)
  27.         LINE (400, 300)-(x, y), _RGB32(c, 0, 255)
  28.     LOOP
  29.     two:
  30.     LOCATE 1, 1: INPUT "Save (Y/N):", sv$
  31.     LINE (0, 0)-(800, 15), _RGB32(255, 255, 255), BF
  32.     IF LEFT$(sv$, 1) = "y" OR LEFT$(sv$, 1) = "Y" THEN GOSUB saving:
  33. saving:
  34. _LIMIT 500
  35. 'Now we call up the SUB to save the image to BMP.
  36. SaveImage 0, "temp.bmp"
  37. _DELAY .25
  38. LINE (0, 0)-(800, 600), _RGB32(0, 0, 0), BF
  39. COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  40. PRINT "                               Saving"
  41. PRINT "                  Your BMP file will be saved in the"
  42. PRINT "                  same directory as this program is."
  43. PRINT "                  It can be used with almost any"
  44. PRINT "                  other graphics program or website."
  45. PRINT "                  It is saved using:"
  46. PRINT "                  width: 800  height: 600 pixels."
  47. PRINT "                  Type a name to save your picture"
  48. PRINT "                  and press the Enter key. Do not"
  49. PRINT "                  add .bmp at the end, the program"
  50. PRINT "                  will do it automatically."
  51. PRINT "                  Also do not use the name temp"
  52. PRINT "                  because the program uses that name"
  53. PRINT "                  and it would be erased the next time"
  54. PRINT "                  you save a picture."
  55. PRINT "                  Example: MyPic"
  56. PRINT "                  Q and Enter goes to main screen."
  57. INPUT "         ->"; nm$
  58. IF nm$ = "Q" OR nm$ = "q" THEN GOTO again:
  59. nm$ = nm$ + ".bmp"
  60. 'Checking to see if the file already exists on your computer.
  61. theFileExists = _FILEEXISTS(nm$)
  62. IF theFileExists = -1 THEN
  63.     PRINT
  64.     PRINT "             File Already Exists"
  65.     PRINT "             Saving will delete your old"
  66.     PRINT "             bmp picture."
  67.     PRINT "             Would you like to still do it?"
  68.     PRINT "             (Y/N)."
  69.     PRINT "             Esc goes to start screen."
  70.     llloop:
  71.     _LIMIT 100
  72.     ag2$ = INKEY$
  73.     IF ag2$ = CHR$(27) THEN GOTO again:
  74.     IF ag2$ = "" THEN GOTO llloop:
  75.     IF ag2$ = "y" OR ag$ = "Y" THEN
  76.         SHELL _HIDE "DEL " + nm$
  77.         GOTO saving2:
  78.     END IF
  79.     GOTO llloop:
  80. saving2:
  81. SHELL _HIDE "REN " + "temp.bmp" + " " + nm$
  82. nm$ = ""
  83. FOR snd = 100 TO 500 STEP 100
  84.     SOUND snd, 2
  85. NEXT snd
  86. GOTO again:
  87. SUB SaveImage (image AS LONG, filename AS STRING)
  88.     bytesperpixel& = _PIXELSIZE(image&)
  89.     IF bytesperpixel& = 0 THEN PRINT "Text modes unsupported!": END
  90.     IF bytesperpixel& = 1 THEN bpp& = 8 ELSE bpp& = 24
  91.     x& = _WIDTH(image&)
  92.     y& = _HEIGHT(image&)
  93.     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)
  94.     IF bytesperpixel& = 1 THEN
  95.         FOR c& = 0 TO 255 ' read BGR color settings from JPG image + 1 byte spacer(CHR$(0))
  96.             cv& = _PALETTECOLOR(c&, image&) ' color attribute to read.
  97.             b$ = b$ + CHR$(_BLUE32(cv&)) + CHR$(_GREEN32(cv&)) + CHR$(_RED32(cv&)) + CHR$(0) 'spacer byte
  98.         NEXT
  99.     END IF
  100.     MID$(b$, 11, 4) = MKL$(LEN(b$)) ' image pixel data offset(BMP header)
  101.     lastsource& = _SOURCE
  102.     _SOURCE image&
  103.     IF ((x& * 3) MOD 4) THEN padder$ = STRING$(4 - ((x& * 3) MOD 4), 0)
  104.     FOR py& = y& - 1 TO 0 STEP -1 ' read JPG image pixel color data
  105.         r$ = ""
  106.         FOR px& = 0 TO x& - 1
  107.             c& = POINT(px&, py&) 'POINT 32 bit values are large LONG values
  108.             IF bytesperpixel& = 1 THEN r$ = r$ + CHR$(c&) ELSE r$ = r$ + LEFT$(MKL$(c&), 3)
  109.         NEXT px&
  110.         d$ = d$ + r$ + padder$
  111.     NEXT py&
  112.     _SOURCE lastsource&
  113.     MID$(b$, 35, 4) = MKL$(LEN(d$)) ' image size(BMP header)
  114.     b$ = b$ + d$ ' total file data bytes to create file
  115.     MID$(b$, 3, 4) = MKL$(LEN(b$)) ' size of data file(BMP header)
  116.     IF LCASE$(RIGHT$(filename$, 4)) <> ".bmp" THEN ext$ = ".bmp"
  117.     f& = FREEFILE
  118.     OPEN filename$ + ext$ FOR OUTPUT AS #f&: CLOSE #f& ' erases an existing file
  119.     OPEN filename$ + ext$ FOR BINARY AS #f&
  120.     PUT #f&, , b$
  121.     CLOSE #f&
  122.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: One Piece Pie Chart Maker
« Reply #1 on: October 29, 2019, 11:49:52 pm »
Ken you sure come up with interesting ideas!

Most people might have tried the CIRCLE's arc options. ;)

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: One Piece Pie Chart Maker
« Reply #2 on: October 29, 2019, 11:53:50 pm »
LOL I didn't even think of that. But I like my way, it goes with the same circle equation I've used on quite a few programs now. :)
Oh, one other thing is that using the CIRCLE command, I wouldn't have been able to have the colors change as it goes around. Instead they would change as it goes from center toward outer area.I like mine better. :)
« Last Edit: October 30, 2019, 12:02:45 am by SierraKen »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: One Piece Pie Chart Maker
« Reply #3 on: October 30, 2019, 12:07:02 am »
Well the CIRCLE arc drawing also leaks PAINT, so fills would often fill the whole screen.

I like your way better too except for the holes, I might have something of interest...

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: One Piece Pie Chart Maker
« Reply #4 on: October 30, 2019, 12:30:28 am »
I just made it so almost all the holes are filled. It just leaves some small streaks as a small X. I am adding 2 attachment pictures to show people 2 examples below.
Oh, and thanks! I had fun making it. The streaks make it look like a special design feature. :)

Here is what I have:

Code: QB64: [Select]
  1. 'One Piece Pie Chart Maker by Ken G. on Oct. 29, 2019.
  2. 'Freeware
  3. _TITLE "One Piece Pie Chart Maker"
  4. again:
  5. SCREEN _NEWIMAGE(800, 600, 32)
  6. PAINT (1, 1), _RGB32(255, 255, 255)
  7. COLOR _RGB32(0, 0, 0), _RGB32(255, 255, 255)
  8.     _LIMIT 1000
  9.     LOCATE 1, 1: INPUT "Type Percentage Here (0-100):", p
  10.     IF p > 100 THEN p = 100
  11.     IF p < 0 THEN p = 0
  12.     sec = p * .6
  13.     c = 100
  14.     CLS
  15.     CIRCLE (400, 300), 180, _RGB32(255, 0, 0)
  16.     seconds = 0
  17.     DO
  18.         seconds = seconds + .0001
  19.         s = (60 - seconds) * 6 + 180
  20.         x = INT(SIN(s / 180 * 3.14) * 180) + 400
  21.         y = INT(COS(s / 180 * 3.14) * 180) + 300
  22.         c = c + .00025
  23.         IF seconds > sec THEN LINE (400, 300)-(x, y), _RGB32(c, 0, 255)
  24.         IF seconds > sec THEN GOTO two:
  25.         LINE (400, 300)-(x, y), _RGB32(c, 0, 255)
  26.     LOOP
  27.     two:
  28.     LOCATE 1, 1: INPUT "Save (Y/N):", sv$
  29.     LINE (0, 0)-(800, 15), _RGB32(255, 255, 255), BF
  30.     IF LEFT$(sv$, 1) = "y" OR LEFT$(sv$, 1) = "Y" THEN GOSUB saving:
  31. saving:
  32. _LIMIT 1000
  33. 'Now we call up the SUB to save the image to BMP.
  34. SaveImage 0, "temp.bmp"
  35. _DELAY .25
  36. LINE (0, 0)-(800, 600), _RGB32(0, 0, 0), BF
  37. COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  38. PRINT "                               Saving"
  39. PRINT "                  Your BMP file will be saved in the"
  40. PRINT "                  same directory as this program is."
  41. PRINT "                  It can be used with almost any"
  42. PRINT "                  other graphics program or website."
  43. PRINT "                  It is saved using:"
  44. PRINT "                  width: 800  height: 600 pixels."
  45. PRINT "                  Type a name to save your picture"
  46. PRINT "                  and press the Enter key. Do not"
  47. PRINT "                  add .bmp at the end, the program"
  48. PRINT "                  will do it automatically."
  49. PRINT "                  Also do not use the name temp"
  50. PRINT "                  because the program uses that name"
  51. PRINT "                  and it would be erased the next time"
  52. PRINT "                  you save a picture."
  53. PRINT "                  Example: MyPic"
  54. PRINT "                  Q and Enter goes to main screen."
  55. INPUT "         ->"; nm$
  56. IF nm$ = "Q" OR nm$ = "q" THEN GOTO again:
  57. nm$ = nm$ + ".bmp"
  58. 'Checking to see if the file already exists on your computer.
  59. theFileExists = _FILEEXISTS(nm$)
  60. IF theFileExists = -1 THEN
  61.     PRINT
  62.     PRINT "             File Already Exists"
  63.     PRINT "             Saving will delete your old"
  64.     PRINT "             bmp picture."
  65.     PRINT "             Would you like to still do it?"
  66.     PRINT "             (Y/N)."
  67.     PRINT "             Esc goes to start screen."
  68.     llloop:
  69.     _LIMIT 100
  70.     ag2$ = INKEY$
  71.     IF ag2$ = CHR$(27) THEN GOTO again:
  72.     IF ag2$ = "" THEN GOTO llloop:
  73.     IF ag2$ = "y" OR ag$ = "Y" THEN
  74.         SHELL _HIDE "DEL " + nm$
  75.         GOTO saving2:
  76.     END IF
  77.     GOTO llloop:
  78. saving2:
  79. SHELL _HIDE "REN " + "temp.bmp" + " " + nm$
  80. nm$ = ""
  81. FOR snd = 100 TO 500 STEP 100
  82.     SOUND snd, 2
  83. NEXT snd
  84. GOTO again:
  85. SUB SaveImage (image AS LONG, filename AS STRING)
  86.     bytesperpixel& = _PIXELSIZE(image&)
  87.     IF bytesperpixel& = 0 THEN PRINT "Text modes unsupported!": END
  88.     IF bytesperpixel& = 1 THEN bpp& = 8 ELSE bpp& = 24
  89.     x& = _WIDTH(image&)
  90.     y& = _HEIGHT(image&)
  91.     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)
  92.     IF bytesperpixel& = 1 THEN
  93.         FOR c& = 0 TO 255 ' read BGR color settings from JPG image + 1 byte spacer(CHR$(0))
  94.             cv& = _PALETTECOLOR(c&, image&) ' color attribute to read.
  95.             b$ = b$ + CHR$(_BLUE32(cv&)) + CHR$(_GREEN32(cv&)) + CHR$(_RED32(cv&)) + CHR$(0) 'spacer byte
  96.         NEXT
  97.     END IF
  98.     MID$(b$, 11, 4) = MKL$(LEN(b$)) ' image pixel data offset(BMP header)
  99.     lastsource& = _SOURCE
  100.     _SOURCE image&
  101.     IF ((x& * 3) MOD 4) THEN padder$ = STRING$(4 - ((x& * 3) MOD 4), 0)
  102.     FOR py& = y& - 1 TO 0 STEP -1 ' read JPG image pixel color data
  103.         r$ = ""
  104.         FOR px& = 0 TO x& - 1
  105.             c& = POINT(px&, py&) 'POINT 32 bit values are large LONG values
  106.             IF bytesperpixel& = 1 THEN r$ = r$ + CHR$(c&) ELSE r$ = r$ + LEFT$(MKL$(c&), 3)
  107.         NEXT px&
  108.         d$ = d$ + r$ + padder$
  109.     NEXT py&
  110.     _SOURCE lastsource&
  111.     MID$(b$, 35, 4) = MKL$(LEN(d$)) ' image size(BMP header)
  112.     b$ = b$ + d$ ' total file data bytes to create file
  113.     MID$(b$, 3, 4) = MKL$(LEN(b$)) ' size of data file(BMP header)
  114.     IF LCASE$(RIGHT$(filename$, 4)) <> ".bmp" THEN ext$ = ".bmp"
  115.     f& = FREEFILE
  116.     OPEN filename$ + ext$ FOR OUTPUT AS #f&: CLOSE #f& ' erases an existing file
  117.     OPEN filename$ + ext$ FOR BINARY AS #f&
  118.     PUT #f&, , b$
  119.     CLOSE #f&
  120.  
100percentexample.bmp
* 100percentexample.bmp (Filesize: 1.37 MB, Dimensions: 800x600, Views: 234)
75percentexample.bmp
* 75percentexample.bmp (Filesize: 1.37 MB, Dimensions: 800x600, Views: 248)
« Last Edit: October 30, 2019, 12:35:25 am by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: One Piece Pie Chart Maker
« Reply #5 on: October 30, 2019, 12:40:16 am »
What I did (above) was I made 100x as many lines and I could do this because I removed the CIRCLE and PAINT commands for the outer edge of the pie piece and this made it go tons faster. There was no need for it anyway because the lines took up the space from the center to the circle anyways. This also smoothed out the outer edge a lot better. :)
So, I'm pretty sure I am done with this one. I'll put it on my website tomorrow (Wednesday).
« Last Edit: October 30, 2019, 12:42:52 am by SierraKen »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: One Piece Pie Chart Maker
« Reply #6 on: October 30, 2019, 12:44:55 am »
Well here is a hole filler, maybe you can figure out how to do the fraction part:

Code: QB64: [Select]
  1. _TITLE "Rainbow Circle" 'B+ 2019-10-30 trans from JB
  2. CONST xmax = 700, ymax = 700, pi = _PI, cx = xmax / 2, cy = ymax / 2, radius = 325
  3. SCREEN _NEWIMAGE(xmax, ymax, 32)
  4. _SCREENMOVE 400, 20
  5. FOR a = 0 TO 2 * pi STEP 1 / radius
  6.     x1 = cx + radius * COS(a): y1 = cy + radius * SIN(a)
  7.     thic cx, cy, x1, y1, 2, rainbow~&(a / (2 * pi))
  8.  
  9. FUNCTION rainbow~& (fraction)
  10.     radians = fraction * 2 * pi
  11.     r = SIN(radians) * 127 + 128
  12.     g = SIN(radians - 2 / 3 * pi) * 127 + 128
  13.     b = SIN(radians + 2 / 3 * pi) * 127 + 128
  14.     rainbow~& = _RGB32(r, g, b)
  15.  
  16. SUB thic (x1, y1, x2, y2, thick, K AS _UNSIGNED LONG)  'thick lines
  17.     PD2 = pi / 2
  18.     DIM t2 AS SINGLE, a AS SINGLE, x3 AS SINGLE, y3 AS SINGLE, x4 AS SINGLE, y4 AS SINGLE
  19.     DIM x5 AS SINGLE, y5 AS SINGLE, x6 AS SINGLE, y6 AS SINGLE
  20.     t2 = thick / 2
  21.     IF t2 < 1 THEN t2 = 1
  22.     a = _ATAN2(y2 - y1, x2 - x1)
  23.     x3 = x1 + t2 * COS(a + PD2)
  24.     y3 = y1 + t2 * SIN(a + PD2)
  25.     x4 = x1 + t2 * COS(a - PD2)
  26.     y4 = y1 + t2 * SIN(a - PD2)
  27.     x5 = x2 + t2 * COS(a + PD2)
  28.     y5 = y2 + t2 * SIN(a + PD2)
  29.     x6 = x2 + t2 * COS(a - PD2)
  30.     y6 = y2 + t2 * SIN(a - PD2)
  31.     ftri x6, y6, x4, y4, x3, y3, K
  32.     ftri x3, y3, x5, y5, x6, y6, K
  33.  
  34. SUB ftri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)  ;fill triangle
  35.     DIM a&
  36.     a& = _NEWIMAGE(1, 1, 32)
  37.     _DEST a&
  38.     PSET (0, 0), K
  39.     _DEST 0
  40.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  41.     _FREEIMAGE a& '<<< this is important!
  42.  
  43.  
  44.  

Rainbow Circle.PNG
* Rainbow Circle.PNG (Filesize: 101.61 KB, Dimensions: 702x726, Views: 188)

Offline codeguy

  • Forum Regular
  • Posts: 174
    • View Profile
Re: One Piece Pie Chart Maker
« Reply #7 on: October 30, 2019, 03:46:08 am »
Just a tiny change for origin of gradient fill for the original code.

Code: [Select]
_TITLE "Rainbow Circle" 'B+ 2019-10-30 trans from JB
CONST xmax = 700, ymax = 700, pi = _PI, cx = xmax / 2, cy = ymax / 2, radius = 325
SCREEN _NEWIMAGE(xmax, ymax, 32)
_SCREENMOVE 400, 20
f! = .5 '*  the fraction of the circle to fill in with a gradient -- tiny mod by CodeGuy
Rotate! = pi / 2
FOR a = 0 TO (2 * pi) * f! STEP 1 / radius
    x1 = cx + radius * COS(a - Rotate!): y1 = cy + radius * SIN(a - Rotate!)
    thic cx, cy, x1, y1, 2, rainbow~&(a / (2 * pi))
NEXT
SLEEP

FUNCTION rainbow~& (fraction)
    radians = fraction * 2 * pi
    r = SIN(radians) * 127 + 128
    g = SIN(radians - 2 / 3 * pi) * 127 + 128
    b = SIN(radians + 2 / 3 * pi) * 127 + 128
    rainbow~& = _RGB32(r, g, b)
END FUNCTION

SUB thic (x1, y1, x2, y2, thick, K AS _UNSIGNED LONG) 'thick lines
    PD2 = pi / 2
    DIM t2 AS SINGLE, a AS SINGLE, x3 AS SINGLE, y3 AS SINGLE, x4 AS SINGLE, y4 AS SINGLE
    DIM x5 AS SINGLE, y5 AS SINGLE, x6 AS SINGLE, y6 AS SINGLE
    t2 = thick / 2
    IF t2 < 1 THEN t2 = 1
    a = _ATAN2(y2 - y1, x2 - x1)
    x3 = x1 + t2 * COS(a + PD2)
    y3 = y1 + t2 * SIN(a + PD2)
    x4 = x1 + t2 * COS(a - PD2)
    y4 = y1 + t2 * SIN(a - PD2)
    x5 = x2 + t2 * COS(a + PD2)
    y5 = y2 + t2 * SIN(a + PD2)
    x6 = x2 + t2 * COS(a - PD2)
    y6 = y2 + t2 * SIN(a - PD2)
    ftri x6, y6, x4, y4, x3, y3, K
    ftri x3, y3, x5, y5, x6, y6, K
END SUB

SUB ftri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG) ' ;fill triangle
    DIM a&
    a& = _NEWIMAGE(1, 1, 32)
    _DEST a&
    PSET (0, 0), K
    _DEST 0
    _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
    _FREEIMAGE a& '<<< this is important!
END SUB

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: One Piece Pie Chart Maker
« Reply #8 on: October 30, 2019, 04:12:04 am »
BPlus based:

Code: QB64: [Select]
  1. _TITLE "Rainbow Circle" 'B+ 2019-10-30 trans from JB
  2. CONST xmax = 700, ymax = 700, pi = _PI, cx = xmax / 2, cy = ymax / 2, radius = 325
  3. SCREEN _NEWIMAGE(xmax, ymax, 32)
  4. _SCREENMOVE 400, 20
  5. INPUT "Insert percentage:"; per
  6.  
  7. FOR a = -_PI / 2 TO -_PI / 2 + _PI(2) / 100 * per STEP 1 / radius
  8.     x1 = cx + radius * COS(a): y1 = cy + radius * SIN(a)
  9.     thic cx, cy, x1, y1, 2, rainbow~&(a / (2 * pi))
  10.  
  11. FUNCTION rainbow~& (fraction)
  12.     radians = fraction * 2 * pi
  13.     r = SIN(radians) * 127 + 128
  14.     g = SIN(radians - 2 / 3 * pi) * 127 + 128
  15.     b = SIN(radians + 2 / 3 * pi) * 127 + 128
  16.     rainbow~& = _RGB32(r, g, b)
  17.  
  18. SUB thic (x1, y1, x2, y2, thick, K AS _UNSIGNED LONG) 'thick lines
  19.     PD2 = pi / 2
  20.     DIM t2 AS SINGLE, a AS SINGLE, x3 AS SINGLE, y3 AS SINGLE, x4 AS SINGLE, y4 AS SINGLE
  21.     DIM x5 AS SINGLE, y5 AS SINGLE, x6 AS SINGLE, y6 AS SINGLE
  22.     t2 = thick / 2
  23.     IF t2 < 1 THEN t2 = 1
  24.     a = _ATAN2(y2 - y1, x2 - x1)
  25.     x3 = x1 + t2 * COS(a + PD2)
  26.     y3 = y1 + t2 * SIN(a + PD2)
  27.     x4 = x1 + t2 * COS(a - PD2)
  28.     y4 = y1 + t2 * SIN(a - PD2)
  29.     x5 = x2 + t2 * COS(a + PD2)
  30.     y5 = y2 + t2 * SIN(a + PD2)
  31.     x6 = x2 + t2 * COS(a - PD2)
  32.     y6 = y2 + t2 * SIN(a - PD2)
  33.     ftri x6, y6, x4, y4, x3, y3, K
  34.     ftri x3, y3, x5, y5, x6, y6, K
  35.  
  36. SUB ftri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  37.     DIM a&
  38.     a& = _NEWIMAGE(1, 1, 32)
  39.     _DEST a&
  40.     PSET (0, 0), K
  41.     _DEST 0
  42.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  43.     _FREEIMAGE a& '<<< this is important!
  44.  
« Last Edit: October 30, 2019, 04:25:11 am by Petr »

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: One Piece Pie Chart Maker
« Reply #9 on: October 30, 2019, 11:12:55 am »
Hi! Nice work SierraKen, Bplus, Codeguy & Bplus!
I made this rainbow circles dance!
Code: QB64: [Select]
  1. _TITLE "Rainbow Circle" 'B+ 2019-10-30 trans from JB
  2. 'Dance MOD By Ashish
  3. CONST xmax = 700, ymax = 700, pi = _PI, cx = xmax / 2, cy = ymax / 2, radius = 325
  4. SCREEN _NEWIMAGE(xmax, ymax, 32)
  5.  
  6. TYPE balls
  7.     x AS SINGLE
  8.     y AS SINGLE
  9.     rotSpeed AS SINGLE
  10.     rad AS SINGLE
  11.     rot AS SINGLE
  12.  
  13. DIM SHARED ball(300) AS balls, glAllow
  14.  
  15. FOR i = 0 TO UBOUND(ball)
  16.     ball(i).x = RND * 2 - 1
  17.     ball(i).y = RND * 2 - 1
  18.     ball(i).rad = RND * 0.25 + 0.0625
  19.     ball(i).rotSpeed = RND * 0.1 + 0.01
  20. '_SCREENMOVE 400, 20
  21. 'INPUT "Insert percentage:"; per
  22.  
  23. 'FOR a = -_PI / 2 TO -_PI / 2 + _PI(2) / 100 * per STEP 1 / radius
  24. '    x1 = cx + radius * COS(a): y1 = cy + radius * SIN(a)
  25. '    thic cx, cy, x1, y1, 2, rainbow~&(a / (2 * pi))
  26. 'NEXT
  27. 'SLEEP
  28. glAllow = 1
  29.     _LIMIT 30
  30.  
  31. SUB _GL ()
  32.     IF NOT glAllow = 1 THEN EXIT SUB
  33.     STATIC glInit
  34.     IF glInit = 0 THEN
  35.         _glViewport 0, 0, _WIDTH, _HEIGHT
  36.         glInit = -1
  37.  
  38.     END IF
  39.     _glMatrixMode _GL_MODELVIEW
  40.  
  41.  
  42.  
  43.     FOR i = 0 TO UBOUND(ball)
  44.         _glPushMatrix
  45.         _glTranslatef ball(i).x, ball(i).y, 0
  46.         _glBegin _GL_TRIANGLE_FAN
  47.         FOR j = 0 TO _PI(2) STEP 0.05
  48.             rainbow j / _PI(2) + ball(i).rot
  49.             _glVertex2f COS(j) * ball(i).rad, SIN(j) * ball(i).rad
  50.         NEXT
  51.         _glEnd
  52.         ball(i).rot = ball(i).rot + ball(i).rotSpeed
  53.         _glPopMatrix
  54.     NEXT
  55.  
  56.     _glFlush
  57.  
  58. SUB rainbow (fraction)
  59.     'FUNCTION rainbow~& (fraction)
  60.     'MODED for OpenGL use
  61.     radians = fraction * 2 * pi
  62.     r = SIN(radians) * 127 + 128
  63.     g = SIN(radians - 2 / 3 * pi) * 127 + 128
  64.     b = SIN(radians + 2 / 3 * pi) * 127 + 128
  65.  
  66.     _glColor3f r / 255, g / 255, b / 255 'map values between 0 & 1
  67.     ' rainbow~& = _RGB32(r, g, b)
  68.     'END FUNCTION
  69.  
  70. SUB thic (x1, y1, x2, y2, thick, K AS _UNSIGNED LONG) 'thick lines
  71.     PD2 = pi / 2
  72.     DIM t2 AS SINGLE, a AS SINGLE, x3 AS SINGLE, y3 AS SINGLE, x4 AS SINGLE, y4 AS SINGLE
  73.     DIM x5 AS SINGLE, y5 AS SINGLE, x6 AS SINGLE, y6 AS SINGLE
  74.     t2 = thick / 2
  75.     IF t2 < 1 THEN t2 = 1
  76.     a = _ATAN2(y2 - y1, x2 - x1)
  77.     x3 = x1 + t2 * COS(a + PD2)
  78.     y3 = y1 + t2 * SIN(a + PD2)
  79.     x4 = x1 + t2 * COS(a - PD2)
  80.     y4 = y1 + t2 * SIN(a - PD2)
  81.     x5 = x2 + t2 * COS(a + PD2)
  82.     y5 = y2 + t2 * SIN(a + PD2)
  83.     x6 = x2 + t2 * COS(a - PD2)
  84.     y6 = y2 + t2 * SIN(a - PD2)
  85.     ftri x6, y6, x4, y4, x3, y3, K
  86.     ftri x3, y3, x5, y5, x6, y6, K
  87.  
  88. SUB ftri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  89.     DIM a&
  90.     a& = _NEWIMAGE(1, 1, 32)
  91.     _DEST a&
  92.     PSET (0, 0), K
  93.     _DEST 0
  94.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  95.     _FREEIMAGE a& '<<< this is important!
  96.  
  97.  
  98.  
  99.  
  100.  
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: One Piece Pie Chart Maker
« Reply #10 on: October 30, 2019, 11:55:25 am »
Ah Codeguy,

Code: QB64: [Select]
  1. f! = .5 '*  the fraction of the circle to fill in with a gradient -- tiny mod by CodeGuy

A clue to Ken, how he may show whole range of color for 50%, right?

Oh and you and Petr are shifting the start of the angle to 12 o'clock, too.

I was hoping Ken might figure these out, but I didn't think about the rotation to 12 o'clock.


Ha! Ashish, another good one for Diwali! :)
« Last Edit: October 30, 2019, 12:02:21 pm by bplus »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: One Piece Pie Chart Maker
« Reply #11 on: October 30, 2019, 02:03:10 pm »
Wow this is awesome you all found different ways! But guess what? Last night I thought of a much simpler way to fill all the holes. I tried it out this morning and it works perfectly! Here is the snippet of code that fills the holes and a 100% example picture below. Now I don't have to tear apart my code and learn a bunch of stuff. Just remember, we all program differently. :) Although some day I wish to keep learning more of course. And thank you everyone for all the examples you wrote out. I hope you all are learning like I do. I will first put the snippet of code and then I will put the whole program again so you can have it all.  Next, I'm going to make it so people can add text.

Snippet:
Code: QB64: [Select]
  1.     two:
  2.  
  3.     'Hole Filler
  4.     FOR xx = 0 TO 800
  5.         FOR yy = 20 TO 600
  6.             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
  7.                 cl& = POINT(xx + 1, yy)
  8.                 PSET (xx, yy), cl&
  9.             END IF
  10.         NEXT yy
  11.     NEXT xx
  12.  
  13.     LOCATE 1, 1: INPUT "Save (Y/N):", sv$
  14.     LINE (0, 0)-(800, 15), _RGB32(255, 255, 255), BF
  15.     IF LEFT$(sv$, 1) = "y" OR LEFT$(sv$, 1) = "Y" THEN GOSUB saving:
  16.  
  17.  

Code: QB64: [Select]
  1. 'One Piece Pie Chart Maker by Ken G. on Oct. 29, 2019.
  2. 'Freeware
  3. _TITLE "One Piece Pie Chart Maker"
  4. again:
  5. SCREEN _NEWIMAGE(800, 600, 32)
  6. PAINT (1, 1), _RGB32(255, 255, 255)
  7. COLOR _RGB32(0, 0, 0), _RGB32(255, 255, 255)
  8.     _LIMIT 1000
  9.     LOCATE 1, 1: INPUT "Type Percentage Here (0-100):", p
  10.     IF p > 100 THEN p = 100
  11.     IF p < 0 THEN p = 0
  12.     sec = p * .6
  13.     c = 100
  14.     CLS
  15.     CIRCLE (400, 300), 180, _RGB32(255, 0, 0)
  16.     seconds = 0
  17.     DO
  18.         seconds = seconds + .0001
  19.         s = (60 - seconds) * 6 + 180
  20.         x = INT(SIN(s / 180 * 3.14) * 180) + 400
  21.         y = INT(COS(s / 180 * 3.14) * 180) + 300
  22.         c = c + .00025
  23.         IF seconds > sec THEN LINE (400, 300)-(x, y), _RGB32(c, 0, 255)
  24.         IF seconds > sec THEN GOTO two:
  25.         LINE (400, 300)-(x, y), _RGB32(c, 0, 255)
  26.     LOOP
  27.     two:
  28.  
  29.     'Hole Filler
  30.     FOR xx = 0 TO 800
  31.         FOR yy = 20 TO 600
  32.             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
  33.                 cl& = POINT(xx + 1, yy)
  34.                 PSET (xx, yy), cl&
  35.             END IF
  36.         NEXT yy
  37.     NEXT xx
  38.  
  39.     LOCATE 1, 1: INPUT "Save (Y/N):", sv$
  40.     LINE (0, 0)-(800, 15), _RGB32(255, 255, 255), BF
  41.     IF LEFT$(sv$, 1) = "y" OR LEFT$(sv$, 1) = "Y" THEN GOSUB saving:
  42.  
  43. saving:
  44. _LIMIT 1000
  45. 'Now we call up the SUB to save the image to BMP.
  46. SaveImage 0, "temp.bmp"
  47. _DELAY .25
  48. LINE (0, 0)-(800, 600), _RGB32(0, 0, 0), BF
  49. COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  50. PRINT "                               Saving"
  51. PRINT "                  Your BMP file will be saved in the"
  52. PRINT "                  same directory as this program is."
  53. PRINT "                  It can be used with almost any"
  54. PRINT "                  other graphics program or website."
  55. PRINT "                  It is saved using:"
  56. PRINT "                  width: 800  height: 600 pixels."
  57. PRINT "                  Type a name to save your picture"
  58. PRINT "                  and press the Enter key. Do not"
  59. PRINT "                  add .bmp at the end, the program"
  60. PRINT "                  will do it automatically."
  61. PRINT "                  Also do not use the name temp"
  62. PRINT "                  because the program uses that name"
  63. PRINT "                  and it would be erased the next time"
  64. PRINT "                  you save a picture."
  65. PRINT "                  Example: MyPic"
  66. PRINT "                  Q and Enter goes to main screen."
  67. INPUT "         ->"; nm$
  68. IF nm$ = "Q" OR nm$ = "q" THEN GOTO again:
  69. nm$ = nm$ + ".bmp"
  70. 'Checking to see if the file already exists on your computer.
  71. theFileExists = _FILEEXISTS(nm$)
  72. IF theFileExists = -1 THEN
  73.     PRINT
  74.     PRINT "             File Already Exists"
  75.     PRINT "             Saving will delete your old"
  76.     PRINT "             bmp picture."
  77.     PRINT "             Would you like to still do it?"
  78.     PRINT "             (Y/N)."
  79.     PRINT "             Esc goes to start screen."
  80.     llloop:
  81.     _LIMIT 100
  82.     ag2$ = INKEY$
  83.     IF ag2$ = CHR$(27) THEN GOTO again:
  84.     IF ag2$ = "" THEN GOTO llloop:
  85.     IF ag2$ = "y" OR ag$ = "Y" THEN
  86.         SHELL _HIDE "DEL " + nm$
  87.         GOTO saving2:
  88.     END IF
  89.     GOTO llloop:
  90. saving2:
  91. SHELL _HIDE "REN " + "temp.bmp" + " " + nm$
  92. nm$ = ""
  93. FOR snd = 100 TO 500 STEP 100
  94.     SOUND snd, 2
  95. NEXT snd
  96. GOTO again:
  97. SUB SaveImage (image AS LONG, filename AS STRING)
  98.     bytesperpixel& = _PIXELSIZE(image&)
  99.     IF bytesperpixel& = 0 THEN PRINT "Text modes unsupported!": END
  100.     IF bytesperpixel& = 1 THEN bpp& = 8 ELSE bpp& = 24
  101.     x& = _WIDTH(image&)
  102.     y& = _HEIGHT(image&)
  103.     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)
  104.     IF bytesperpixel& = 1 THEN
  105.         FOR c& = 0 TO 255 ' read BGR color settings from JPG image + 1 byte spacer(CHR$(0))
  106.             cv& = _PALETTECOLOR(c&, image&) ' color attribute to read.
  107.             b$ = b$ + CHR$(_BLUE32(cv&)) + CHR$(_GREEN32(cv&)) + CHR$(_RED32(cv&)) + CHR$(0) 'spacer byte
  108.         NEXT
  109.     END IF
  110.     MID$(b$, 11, 4) = MKL$(LEN(b$)) ' image pixel data offset(BMP header)
  111.     lastsource& = _SOURCE
  112.     _SOURCE image&
  113.     IF ((x& * 3) MOD 4) THEN padder$ = STRING$(4 - ((x& * 3) MOD 4), 0)
  114.     FOR py& = y& - 1 TO 0 STEP -1 ' read JPG image pixel color data
  115.         r$ = ""
  116.         FOR px& = 0 TO x& - 1
  117.             c& = POINT(px&, py&) 'POINT 32 bit values are large LONG values
  118.             IF bytesperpixel& = 1 THEN r$ = r$ + CHR$(c&) ELSE r$ = r$ + LEFT$(MKL$(c&), 3)
  119.         NEXT px&
  120.         d$ = d$ + r$ + padder$
  121.     NEXT py&
  122.     _SOURCE lastsource&
  123.     MID$(b$, 35, 4) = MKL$(LEN(d$)) ' image size(BMP header)
  124.     b$ = b$ + d$ ' total file data bytes to create file
  125.     MID$(b$, 3, 4) = MKL$(LEN(b$)) ' size of data file(BMP header)
  126.     IF LCASE$(RIGHT$(filename$, 4)) <> ".bmp" THEN ext$ = ".bmp"
  127.     f& = FREEFILE
  128.     OPEN filename$ + ext$ FOR OUTPUT AS #f&: CLOSE #f& ' erases an existing file
  129.     OPEN filename$ + ext$ FOR BINARY AS #f&
  130.     PUT #f&, , b$
  131.     CLOSE #f&
  132.  
100percent-filled.bmp
* 100percent-filled.bmp (Filesize: 1.37 MB, Dimensions: 800x600, Views: 201)
« Last Edit: October 30, 2019, 02:06:44 pm by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: One Piece Pie Chart Maker
« Reply #12 on: October 30, 2019, 03:20:43 pm »
OK, I have the final version now I think. You can add text anywhere. It explains everything in the TITLE bar. You go to TEXT MODE by pressing T and then use the mouse and press Enter.  Each time you press Enter, it goes back to the main mode. So if you want to make more text, press T again. I also made it so the text stands out with a white font inside the filled pie and a black font on the empty areas. One trick I learned today was in order to see the cursor on a white background, you have to make the background of the COLOR anything except white. So I made a 100 green, even though for some reason it still shows a white background which is what I want, and the cursor shows up that way. I think the white is blending in with the green because I can still see a shade of green when I look carefully on it. But just barely.

Code: QB64: [Select]
  1. 'One Piece Pie Chart Maker by Ken G. on Oct. 30, 2019.
  2. 'Freeware
  3. _TITLE "One Piece Pie Chart Maker"
  4. again:
  5. SCREEN _NEWIMAGE(800, 600, 32)
  6. PAINT (1, 1), _RGB32(255, 255, 255)
  7. COLOR _RGB32(0, 0, 0), _RGB32(255, 255, 255)
  8.     _LIMIT 1000
  9.     LOCATE 1, 1: INPUT "Type Percentage Here (0-100):", p
  10.     IF p > 100 THEN p = 100
  11.     IF p < 0 THEN p = 0
  12.     sec = p * .6
  13.     c = 100
  14.     CLS
  15.     CIRCLE (400, 300), 180, _RGB32(255, 0, 0)
  16.     seconds = 0
  17.     DO
  18.         seconds = seconds + .0001
  19.         s = (60 - seconds) * 6 + 180
  20.         x = INT(SIN(s / 180 * 3.14) * 180) + 400
  21.         y = INT(COS(s / 180 * 3.14) * 180) + 300
  22.         c = c + .00025
  23.         IF seconds > sec THEN LINE (400, 300)-(x, y), _RGB32(c, 0, 255)
  24.         IF seconds > sec THEN GOTO two:
  25.         LINE (400, 300)-(x, y), _RGB32(c, 0, 255)
  26.     LOOP
  27. two:
  28. 'Hole Filler
  29. FOR xx = 0 TO 800
  30.     FOR yy = 20 TO 600
  31.         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
  32.             cl& = POINT(xx + 1, yy)
  33.             PSET (xx, yy), cl&
  34.         END IF
  35.     NEXT yy
  36. NEXT xx
  37. _TITLE "(T)ext, (S)ave, (D)elete, Esc to Quit"
  38.     a$ = INKEY$
  39.     IF a$ = CHR$(27) THEN END
  40.     IF a$ = "t" OR a$ = "T" THEN GOSUB Text:
  41.     IF a$ = "s" OR a$ = "S" THEN GOTO saving:
  42.     IF a$ = "d" OR a$ = "D" THEN GOTO again:
  43. Text:
  44. _TITLE "TEXT MODE - Use Mouse To Click Where You Want To Place Text Then Press Enter."
  45.     _LIMIT 500
  46.         mouseX = _MOUSEX
  47.         mouseY = _MOUSEY
  48.         mouseLeftButton = _MOUSEBUTTON(1)
  49.     LOOP
  50.     IF mouseLeftButton = -1 THEN
  51.         clr& = POINT(mouseX, mouseY)
  52.         IF clr& <> _RGB32(255, 255, 255) THEN COLOR _RGB32(255, 255, 255), clr&
  53.         IF clr& = _RGB32(255, 255, 255) THEN COLOR _RGB32(0, 100, 0), clr&
  54.         LOCATE mouseY / 16, mouseX / 8
  55.         INPUT "", txt$
  56.         _TITLE "(T)ext, (S)ave, (D)elete, Esc to Quit"
  57.         RETURN
  58.     END IF
  59. saving:
  60. _LIMIT 1000
  61. 'Now we call up the SUB to save the image to BMP.
  62. SaveImage 0, "temp.bmp"
  63. _DELAY .25
  64. LINE (0, 0)-(800, 600), _RGB32(0, 0, 0), BF
  65. COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  66. PRINT "                               Saving"
  67. PRINT "                  Your BMP file will be saved in the"
  68. PRINT "                  same directory as this program is."
  69. PRINT "                  It can be used with almost any"
  70. PRINT "                  other graphics program or website."
  71. PRINT "                  It is saved using:"
  72. PRINT "                  width: 800  height: 600 pixels."
  73. PRINT "                  Type a name to save your picture"
  74. PRINT "                  and press the Enter key. Do not"
  75. PRINT "                  add .bmp at the end, the program"
  76. PRINT "                  will do it automatically."
  77. PRINT "                  Also do not use the name temp"
  78. PRINT "                  because the program uses that name"
  79. PRINT "                  and it would be erased the next time"
  80. PRINT "                  you save a picture."
  81. PRINT "                  Example: MyPic"
  82. PRINT "                  Q and Enter goes to main screen."
  83. INPUT "                  ->"; nm$
  84. IF nm$ = "Q" OR nm$ = "q" THEN GOTO again:
  85. nm$ = nm$ + ".bmp"
  86. 'Checking to see if the file already exists on your computer.
  87. theFileExists = _FILEEXISTS(nm$)
  88. IF theFileExists = -1 THEN
  89.     PRINT
  90.     PRINT "             File Already Exists"
  91.     PRINT "             Saving will delete your old"
  92.     PRINT "             bmp picture."
  93.     PRINT "             Would you like to still do it?"
  94.     PRINT "             (Y/N)."
  95.     PRINT "             Esc goes to start screen."
  96.     llloop:
  97.     _LIMIT 100
  98.     ag2$ = INKEY$
  99.     IF ag2$ = CHR$(27) THEN GOTO again:
  100.     IF ag2$ = "" THEN GOTO llloop:
  101.     IF ag2$ = "y" OR ag$ = "Y" THEN
  102.         SHELL _HIDE "DEL " + nm$
  103.         GOTO saving2:
  104.     END IF
  105.     GOTO llloop:
  106. saving2:
  107. SHELL _HIDE "REN " + "temp.bmp" + " " + nm$
  108. nm$ = ""
  109. FOR snd = 100 TO 500 STEP 100
  110.     SOUND snd, 2
  111. NEXT snd
  112. GOTO again:
  113. SUB SaveImage (image AS LONG, filename AS STRING)
  114.     bytesperpixel& = _PIXELSIZE(image&)
  115.     IF bytesperpixel& = 0 THEN PRINT "Text modes unsupported!": END
  116.     IF bytesperpixel& = 1 THEN bpp& = 8 ELSE bpp& = 24
  117.     x& = _WIDTH(image&)
  118.     y& = _HEIGHT(image&)
  119.     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)
  120.     IF bytesperpixel& = 1 THEN
  121.         FOR c& = 0 TO 255 ' read BGR color settings from JPG image + 1 byte spacer(CHR$(0))
  122.             cv& = _PALETTECOLOR(c&, image&) ' color attribute to read.
  123.             b$ = b$ + CHR$(_BLUE32(cv&)) + CHR$(_GREEN32(cv&)) + CHR$(_RED32(cv&)) + CHR$(0) 'spacer byte
  124.         NEXT
  125.     END IF
  126.     MID$(b$, 11, 4) = MKL$(LEN(b$)) ' image pixel data offset(BMP header)
  127.     lastsource& = _SOURCE
  128.     _SOURCE image&
  129.     IF ((x& * 3) MOD 4) THEN padder$ = STRING$(4 - ((x& * 3) MOD 4), 0)
  130.     FOR py& = y& - 1 TO 0 STEP -1 ' read JPG image pixel color data
  131.         r$ = ""
  132.         FOR px& = 0 TO x& - 1
  133.             c& = POINT(px&, py&) 'POINT 32 bit values are large LONG values
  134.             IF bytesperpixel& = 1 THEN r$ = r$ + CHR$(c&) ELSE r$ = r$ + LEFT$(MKL$(c&), 3)
  135.         NEXT px&
  136.         d$ = d$ + r$ + padder$
  137.     NEXT py&
  138.     _SOURCE lastsource&
  139.     MID$(b$, 35, 4) = MKL$(LEN(d$)) ' image size(BMP header)
  140.     b$ = b$ + d$ ' total file data bytes to create file
  141.     MID$(b$, 3, 4) = MKL$(LEN(b$)) ' size of data file(BMP header)
  142.     IF LCASE$(RIGHT$(filename$, 4)) <> ".bmp" THEN ext$ = ".bmp"
  143.     f& = FREEFILE
  144.     OPEN filename$ + ext$ FOR OUTPUT AS #f&: CLOSE #f& ' erases an existing file
  145.     OPEN filename$ + ext$ FOR BINARY AS #f&
  146.     PUT #f&, , b$
  147.     CLOSE #f&
  148.  
  149.  
50-50-pie.bmp
* 50-50-pie.bmp (Filesize: 1.37 MB, Dimensions: 800x600, Views: 194)
« Last Edit: October 30, 2019, 03:34:58 pm by SierraKen »

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Re: One Piece Pie Chart Maker
« Reply #13 on: October 31, 2019, 01:20:11 pm »
Not my code but check this out!

Code: QB64: [Select]
  1. WIDTH 80, 25
  2. DIM slices(0 TO 4)
  3.  
  4. slices(0) = .33
  5. slices(1) = .33
  6. slices(2) = .2
  7. slices(3) = .09
  8. slices(4) = .05
  9.  
  10.  
  11. FOR X = 11 TO 70
  12.     TX = (X - 40.5) / 30
  13.     FOR Y = 1 TO 25
  14.         TY = ((Y - 13) * 2 - .5) / 25
  15.         GOSUB getc
  16.         BG = C
  17.  
  18.         TY = ((Y - 13) * 2 + .5) / 25
  19.         GOSUB getc
  20.         FG = C
  21.         COLOR FG, BG
  22.         LOCATE Y, X: PRINT CHR$(220);
  23. NEXT Y, X
  24.  
  25.  
  26. getc:
  27. 'Adapted from London's code
  28. turns = ATN(TY / TX) / ATN(1) / 8 - (TX < 0) / 2 - (TX > 0 AND TY < 0)
  29. IF SQR(TY * TY + TX * TX) > 1 THEN C = 0: RETURN
  30. Acc = 0
  31. C = 0
  32. FOR I = 0 TO UBOUND(slices)
  33.     Acc = Acc + slices(I)
  34.     IF Acc + .001 > turns THEN C = I + 1: EXIT FOR
  35.  
  36.  

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: One Piece Pie Chart Maker
« Reply #14 on: October 31, 2019, 01:52:24 pm »
Hi _Vince
fine ASCII pie slice!

 
Vincent ASCII PieSlice.jpg


Hey Pete where are you in these ASCII moments?
Programming isn't difficult, only it's  consuming time and coffee