Author Topic: Simple coordinates equation or impossible coordinates equation?  (Read 6408 times)

0 Members and 1 Guest are viewing this topic.

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Simple coordinates equation or impossible coordinates equation?
« Reply #15 on: December 15, 2019, 01:59:37 pm »
Hey bplus,

You're welcome to try to tweak that busted function if you find the time. I remember that whole development arc well - and judging the lion by his claw, whoever put the finishing touches on ellipsetiltfill was definitely not me. On the other hand, ellipsetilt and ellipsefill still look like my handywork. In other words, that error started with someone else. I'll try to find it if you don't get there first.
You're not done when it works, you're done when it's right.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Simple coordinates equation or impossible coordinates equation?
« Reply #16 on: December 15, 2019, 04:40:04 pm »
I didn't really understand too much, about what you and STxAxTIC are talking about here. Is it about drawing a cone? Or to fill in an ellipse? I tried a simple program to fill the cone. I had to use the trick to get the right bottom diameter. When I wanted to calculate it (we will not lie, mathematics is my death), so it just did not work. The angle to be entered is the angle at the top of the cone. I tried to count it all through the sinus theorem. Unfortunately, probably because of the sum of the angles in the triangle, where their sum is 180 degrees, the angle at the vertex cannot be greater than 90 degrees. (Or, again, bug is here between keyboard and chair)  :)

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 600, 256)
  2.  
  3. tm = 1
  4.     t = t + tm
  5.     CLS
  6.     R 400, 50, 300, t
  7.     LOCATE 1: PRINT t
  8.     SLEEP
  9.     IF t > 90 OR t < 1 THEN tm = tm * -1
  10.  
  11.  
  12. SUB R (hx, hy, v, u)
  13.     uu = _D2R(u) '                       angle on top vertex
  14.     y = hy + v '                         lower y = upper y + v (v = height)
  15.     polomer = SIN(uu) * v '              radius on bottom
  16.  
  17.  
  18.     nx1 = hx - (polomer * SIN(uu)) '     left X point on radius
  19.     nx2 = hx + (polomer * SIN(uu)) '     right X point on radius
  20.  
  21.     de = (nx2 - nx1) / 2 '              radius for ellipse
  22.     CIRCLE (hx, y), de, 14, _PI, _PI(2), .1
  23.     LINE (nx1, y)-(hx, hy), 14
  24.     LINE (nx2, y)-(hx, hy), 14
  25.     PAINT (hx, hy + v / 2), 14, 14
  26.  
« Last Edit: December 15, 2019, 04:41:30 pm by Petr »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Simple coordinates equation or impossible coordinates equation?
« Reply #17 on: December 15, 2019, 04:51:19 pm »
That's neat Petr, that draws cones similar to what bplus made. But what I am going for is probably even harder. I want 2 open ended circles, one on each end. Like the second one bplus made which is really good and he calls them megaphones.  A circle on each end, like a tube. But one circle is a different size than the other. And not just filled in like with PAINT or something, but with a 3D effect using low to high shades of color. Like a megaphone. I apologize for saying 2D earlier, I was wrong. Here is the first way I made it earlier using my circle code and LINE commands for each point. But using the full circles draws just too much I think, or the shade is off. I added the Save feature when I was wanting to save these to .bmp.

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 600, 32)
  2. start:
  3. _TITLE "Cone Maker - by Ken G."
  4. _LIMIT 1000
  5. x1:
  6. INPUT "X1 (0-800) = ", x1
  7. IF x1 < 0 OR x1 > 800 THEN PRINT "Out of range, try again.": GOTO x1:
  8. y1:
  9. INPUT "Y1 (0-600) = ", y1
  10. IF y1 < 0 OR y1 > 600 THEN PRINT "Out of range, try again.": GOTO y1:
  11. r1:
  12. INPUT "Radius (1-400) = ", r1
  13. IF r1 < 1 OR r1 > 400 THEN PRINT "Out of range, try again.": GOTO r1:
  14. x2:
  15. INPUT "X2 (0-800) = ", x2
  16. IF x2 < 0 OR x2 > 800 THEN PRINT "Out of range, try again.": GOTO x2:
  17. y2:
  18. INPUT "Y2 (0-600) = ", y2
  19. IF y2 < 0 OR y2 > 600 THEN PRINT "Out of range, try again.": GOTO y2:
  20. r2:
  21. INPUT "Radius (1-400) = ", r2
  22. IF r2 < 1 OR r2 > 400 THEN PRINT "Out of range, try again.": GOTO r2:
  23. gaps:
  24. INPUT "Gap Space (.01-5) = ", gap
  25. IF gap < .01 THEN PRINT "Gap is too small, try again.": GOTO gaps:
  26. one:
  27. _LIMIT 1000
  28. seconds = seconds + gap
  29. s = (60 - seconds) * 6 + 180
  30. xx1 = INT(SIN(s / 180 * 3.141592) * r1) + x1
  31. xx2 = INT(SIN(s / 180 * 3.141592) * r2) + x2
  32. yy1 = INT(COS(s / 180 * 3.141592) * r1) + y1
  33. yy2 = INT(COS(s / 180 * 3.141592) * r2) + y2
  34.  
  35. CIRCLE (xx1, yy1), 2, _RGB32(127, 216, 127)
  36. CIRCLE (xx2, yy2), 2, _RGB32(127, 216, 127)
  37. LINE (xx1, yy1)-(xx2, yy2), _RGB32(0, seconds * 4, 0)
  38. IF seconds > 60 THEN
  39.     seconds = 0
  40.     _TITLE "Press S to Save to .bmp file, or do again press Y or N."
  41.     GOTO again:
  42. GOTO one:
  43. again:
  44. ag$ = INKEY$
  45. IF ag$ = "y" OR ag$ = "Y" THEN GOTO start:
  46. IF ag$ = "n" OR ag$ = "N" THEN END
  47. IF ag$ = "s" OR ag$ = "S" THEN GOTO saving:
  48. GOTO again:
  49.  
  50. 'This section saves the calendar to a BMP file along with the SUB at the end of this program.
  51. saving:
  52. 'Saving
  53. 'This section first saves your picture as temp.bmp and then
  54. 'asks you a name for your picture and then renames temp.bmp to your name.
  55. _TITLE "Saving"
  56. 'Now we call up the SUB to save the image to BMP.
  57. SaveImage 0, "temp.bmp"
  58. _DELAY .25
  59. PRINT "                       Saving"
  60. PRINT "         Your bmp file will be saved in the"
  61. PRINT "         same directory as this program is."
  62. PRINT "         It can be used with almost any"
  63. PRINT "         other graphics program or website."
  64. PRINT "         It is saved using:"
  65. PRINT "         width: 800  height: 600 pixels."
  66. PRINT "         Type a name to save your picture"
  67. PRINT "         and press the Enter key. Do not"
  68. PRINT "         add .bmp at the end, the program"
  69. PRINT "         will do it automatically."
  70. PRINT "         Also do not use the name temp"
  71. PRINT "         because the program uses that name"
  72. PRINT "         and it would be erased the next time"
  73. PRINT "         you save a picture."
  74. PRINT "         Example: MyPic"
  75. PRINT "         Quit and Enter key ends program."
  76. INPUT "         ->"; nm$
  77. IF nm$ = "Quit" OR nm$ = "quit" OR nm$ = "QUIT" THEN END
  78. nm$ = nm$ + ".bmp"
  79. 'Checking to see if the file already exists on your computer.
  80. theFileExists = _FILEEXISTS(nm$)
  81. IF theFileExists = -1 THEN
  82.     PRINT
  83.     PRINT "       File Already Exists"
  84.     PRINT "       Saving will delete your old"
  85.     PRINT "       bmp picture."
  86.     PRINT "       Would you like to still do it?"
  87.     PRINT "       (Y/N)."
  88.     PRINT "       Esc goes to start screen."
  89.     llloop:
  90.     _LIMIT 100
  91.     ag2$ = INKEY$
  92.     IF ag2$ = CHR$(27) THEN GOTO start:
  93.     IF ag2$ = "" THEN GOTO llloop:
  94.     IF ag2$ = "y" OR ag$ = "Y" THEN
  95.         SHELL _HIDE "DEL " + nm$
  96.         GOTO saving2:
  97.     END IF
  98.     GOTO llloop:
  99. saving2:
  100. SHELL _HIDE "REN " + "temp.bmp" + " " + nm$
  101. nm$ = ""
  102. FOR snd = 100 TO 700 STEP 100
  103.     SOUND snd, 2
  104. NEXT snd
  105. m = 0
  106. _TITLE "Cone Maker - by Ken G."
  107. GOTO start:
  108.  
  109.  
  110. 'This section saves the .bmp picture file.
  111. SUB SaveImage (image AS LONG, filename AS STRING)
  112.     bytesperpixel& = _PIXELSIZE(image&)
  113.     IF bytesperpixel& = 0 THEN PRINT "Text modes unsupported!": END
  114.     IF bytesperpixel& = 1 THEN bpp& = 8 ELSE bpp& = 24
  115.     x& = _WIDTH(image&)
  116.     y& = _HEIGHT(image&)
  117.     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)
  118.     IF bytesperpixel& = 1 THEN
  119.         FOR c& = 0 TO 255 ' read BGR color settings from JPG image + 1 byte spacer(CHR$(0))
  120.             cv& = _PALETTECOLOR(c&, image&) ' color attribute to read.
  121.             b$ = b$ + CHR$(_BLUE32(cv&)) + CHR$(_GREEN32(cv&)) + CHR$(_RED32(cv&)) + CHR$(0) 'spacer byte
  122.         NEXT
  123.     END IF
  124.     MID$(b$, 11, 4) = MKL$(LEN(b$)) ' image pixel data offset(BMP header)
  125.     lastsource& = _SOURCE
  126.     _SOURCE image&
  127.     IF ((x& * 3) MOD 4) THEN padder$ = STRING$(4 - ((x& * 3) MOD 4), 0)
  128.     FOR py& = y& - 1 TO 0 STEP -1 ' read JPG image pixel color data
  129.         r$ = ""
  130.         FOR px& = 0 TO x& - 1
  131.             c& = POINT(px&, py&) 'POINT 32 bit values are large LONG values
  132.             IF bytesperpixel& = 1 THEN r$ = r$ + CHR$(c&) ELSE r$ = r$ + LEFT$(MKL$(c&), 3)
  133.         NEXT px&
  134.         d$ = d$ + r$ + padder$
  135.     NEXT py&
  136.     _SOURCE lastsource&
  137.     MID$(b$, 35, 4) = MKL$(LEN(d$)) ' image size(BMP header)
  138.     b$ = b$ + d$ ' total file data bytes to create file
  139.     MID$(b$, 3, 4) = MKL$(LEN(b$)) ' size of data file(BMP header)
  140.     IF LCASE$(RIGHT$(filename$, 4)) <> ".bmp" THEN ext$ = ".bmp"
  141.     f& = FREEFILE
  142.     OPEN filename$ + ext$ FOR OUTPUT AS #f&: CLOSE #f& ' erases an existing file
  143.     OPEN filename$ + ext$ FOR BINARY AS #f&
  144.     PUT #f&, , b$
  145.     CLOSE #f&
  146.  
  147.  


Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Simple coordinates equation or impossible coordinates equation?
« Reply #18 on: December 15, 2019, 05:05:24 pm »
Wow has this test code revealed allot of messed up things:
First tiltedEllipseFill then
fTri: Steves recent mods adding STATIC and removing _FREEIMAGE, do not work with transparencies specially in my quad function which merely calls fTri twice.
RotoZoom2, tried and true was leaving seams in the rotozoomed rotated filled ellipsii

So all those fixed now, I left transparencies in to show the nice seamless tilted ellipsii fills, Ken just replace with solid colors for 3D faking, just replace 2x's in the &Hxx.... with &HFF:
Code: QB64: [Select]
  1. _TITLE "fTiltEllipse tests" 'b+ 2019-12-15
  2. 'test code from "Draw megaphone Test, click 4 points in clockwise direction first pair is one opening and 2nd is 2nd." 'B+ 2019-12-15
  3.  
  4. CONST xmax = 800, ymax = 600
  5. SCREEN _NEWIMAGE(xmax, ymax, 32)
  6. _SCREENMOVE 300, 40
  7.  
  8.     CLS
  9.     WHILE pi < 4 'get 4 mouse clicks
  10.         _PRINTSTRING (5, 5), SPACE$(20)
  11.         _PRINTSTRING (5, 5), "Need 4 clicks, have" + STR$(pi)
  12.         WHILE _MOUSEINPUT: WEND
  13.         IF _MOUSEBUTTON(1) AND oldMouse = 0 THEN 'new mouse down
  14.             pi = pi + 1
  15.             mx(pi) = _MOUSEX: my(pi) = _MOUSEY
  16.             CIRCLE (mx(pi), my(pi)), 2
  17.         END IF
  18.         oldMouse = _MOUSEBUTTON(1)
  19.         _DISPLAY
  20.         _LIMIT 60
  21.     WEND
  22.     LINE (mx(2), my(2))-(mx(3), my(3))
  23.     LINE (mx(4), my(4))-(mx(1), my(1))
  24.     ang1 = _ATAN2(my(2) - my(1), mx(2) - mx(1))
  25.     maj1 = (_HYPOT(mx(1) - mx(2), my(1) - my(2))) / 2
  26.     min1 = .1 * maj1
  27.     cx1 = (mx(1) + mx(2)) / 2
  28.     cy1 = (my(1) + my(2)) / 2
  29.     EllipseTilt cx1, cy1, maj1, min1, ang1, &HFFFFFFFF
  30.     ang2 = _ATAN2(my(3) - my(4), mx(3) - mx(4))
  31.     maj2 = (_HYPOT(mx(3) - mx(4), my(3) - my(4))) / 2
  32.     min2 = .1 * maj2
  33.     cx2 = (mx(3) + mx(4)) / 2
  34.     cy2 = (my(3) + my(4)) / 2
  35.     EllipseTilt cx2, cy2, maj2, min2, ang2, &HFFFFFFFF
  36.     _DISPLAY
  37.     _DELAY 3
  38.     CLS
  39.     _PRINTSTRING (5, 5), "Sleeping, wake with click or keypress..."
  40.     fTiltEllipse 0, cx2, cy2, maj2, min2, ang2, &H880000FF 'check trnasparency
  41.     fquad mx(1), my(1), mx(2), my(2), mx(3), my(3), mx(4), my(4), &H880000FF
  42.     fTiltEllipse 0, cx1, cy1, maj1, min1, ang1, &H88FFFF00
  43.     _DISPLAY
  44.     cSleep 45
  45.  
  46.     pi = 0 'point index
  47.  
  48.  
  49.  
  50. 'thanks STxAxTIC from Toolbox
  51. SUB EllipseTilt (CX, CY, a, b, ang, C AS _UNSIGNED LONG)
  52.     DIM k, i, j
  53.     '  CX = center x coordinate
  54.     '  CY = center y coordinate
  55.     '   a = semimajor axis  major radius
  56.     '   b = semiminor axis  minor radius
  57.     ' ang = clockwise orientation of semimajor axis in radians (0 default)
  58.     '   C = fill color
  59.     FOR k = 0 TO 6.283185307179586 + .025 STEP .025
  60.         i = a * COS(k) * COS(ang) + b * SIN(k) * SIN(ang)
  61.         j = -a * COS(k) * SIN(ang) + b * SIN(k) * COS(ang)
  62.         i = i + CX
  63.         j = -j + CY
  64.         IF k <> 0 THEN
  65.             LINE -(i, j), C
  66.         ELSE
  67.             PSET (i, j), C
  68.         END IF
  69.     NEXT
  70.  
  71. 'relace broken toolbax code
  72. 'this needs RotoZoom3 to rotate image BUT it can now scale it also!
  73. SUB fTiltEllipse (destH AS LONG, ox AS INTEGER, oy AS INTEGER, majorRadius AS INTEGER, minorRadius AS INTEGER, radianAngle AS SINGLE, c AS _UNSIGNED LONG)
  74.     'setup isolated area, draw fFlatEllipse and then RotoZoom the image into destination
  75.     'ox, oy is center of ellipse
  76.     'majorRadius is 1/2 the lonest axis
  77.     'minorRadius is 1/2 the short axis
  78.     'radianAngle is the Radian Angle of Tilt
  79.     'c is of course color
  80.     sd& = _DEST
  81.     temp& = _NEWIMAGE(2 * majorRadius, 2 * minorRadius, 32)
  82.     _DEST temp&
  83.     fEllipse majorRadius, minorRadius, majorRadius, minorRadius, c
  84.     _DEST destH
  85.     RotoZoom3 ox, oy, temp&, 1, 1, radianAngle
  86.     _FREEIMAGE temp&
  87.     _DEST sd&
  88.  
  89. 'modified 2019-12-15 _seamless added, rotation convert to radians
  90. SUB RotoZoom3 (X AS LONG, Y AS LONG, Image AS LONG, xScale AS SINGLE, yScale AS SINGLE, radianRotation AS SINGLE) ' 0 at end means no scaling of x or y
  91.     DIM px(3) AS SINGLE: DIM py(3) AS SINGLE
  92.     W& = _WIDTH(Image&): H& = _HEIGHT(Image&)
  93.     px(0) = -W& / 2: py(0) = -H& / 2: px(1) = -W& / 2: py(1) = H& / 2
  94.     px(2) = W& / 2: py(2) = H& / 2: px(3) = W& / 2: py(3) = -H& / 2
  95.     sinr! = SIN(-radianRotation): cosr! = COS(-radianRotation)
  96.     FOR i& = 0 TO 3
  97.         x2& = (px(i&) * cosr! + sinr! * py(i&)) + X * xScale: y2& = (py(i&) * cosr! - px(i&) * sinr!) + Y * yScale
  98.         px(i&) = x2&: py(i&) = y2&
  99.     NEXT
  100.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, H& - 1)-(W& - 1, H& - 1), Image& TO(px(0), py(0))-(px(1), py(1))-(px(2), py(2))
  101.     _MAPTRIANGLE _SEAMLESS(0, 0)-(W& - 1, 0)-(W& - 1, H& - 1), Image& TO(px(0), py(0))-(px(3), py(3))-(px(2), py(2))
  102.  
  103. 'this seems to work as well as any
  104. SUB fEllipse (CX AS LONG, CY AS LONG, xRadius AS LONG, yRadius AS LONG, c AS _UNSIGNED LONG)
  105.     DIM scale AS SINGLE, x AS LONG, y AS LONG
  106.     scale = yRadius / xRadius
  107.     LINE (CX, CY - yRadius)-(CX, CY + yRadius), c, BF
  108.     FOR x = 1 TO xRadius
  109.         y = scale * SQR(xRadius * xRadius - x * x)
  110.         LINE (CX + x, CY - y)-(CX + x, CY + y), c, BF
  111.         LINE (CX - x, CY - y)-(CX - x, CY + y), c, BF
  112.     NEXT
  113.  
  114. ' found at [abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]:    http://www.[abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]/forum/index.php?topic=14425.0
  115. SUB ftri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  116.     DIM D AS LONG
  117.     D = _DEST
  118.     a& = _NEWIMAGE(1, 1, 32)
  119.     _DEST a&
  120.     PSET (0, 0), K
  121.     _DEST D
  122.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  123.     _FREEIMAGE a& '<<< this is important!
  124.  
  125. '2019-11-20 Steve saves some time with STATIC and saves and restores last dest
  126. SUB ftri1 (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  127.     DIM D AS LONG
  128.     STATIC a&
  129.     D = _DEST
  130.     IF a& = 0 THEN a& = _NEWIMAGE(1, 1, 32)
  131.     _DEST a&
  132.     PSET (0, 0), K
  133.     _DEST D
  134.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  135.  
  136. 'need 4 non linear points (not all on 1 line) list them clockwise so x2, y2 is opposite of x4, y4
  137. SUB fquad (x1, y1, x2, y2, x3, y3, x4, y4, K AS _UNSIGNED LONG)
  138.     ftri x1, y1, x2, y2, x4, y4, K
  139.     ftri x3, y3, x2, y2, x4, y4, K
  140.  
  141. SUB cSleep (secsWait AS DOUBLE) 'wait for keypress or mouseclick, solves midnight problem nicely I think
  142.     DIM wayt AS INTEGER, oldMouse AS INTEGER, k AS LONG, startTime AS DOUBLE
  143.  
  144.     startTime = TIMER
  145.     wayt = 1
  146.     _KEYCLEAR
  147.     WHILE wayt
  148.         WHILE _MOUSEINPUT: WEND
  149.         IF _MOUSEBUTTON(1) AND oldMouse = 0 THEN wayt = 0
  150.         oldMouse = _MOUSEBUTTON(1) ' <<< this is Steve's cool way to get clear of mouse click
  151.         k = _KEYHIT: IF k > 0 THEN _KEYCLEAR: wayt = 0
  152.         IF TIMER - startTime < 0 THEN 'past midnight
  153.             IF TIMER + 24 * 60 * 60 - startTime > secsWait THEN wayt = 0
  154.         ELSE
  155.             IF TIMER - startTime >= secsWait THEN wayt = 0
  156.         END IF
  157.         _LIMIT 30
  158.     WEND
  159.  
  160.  

Test with Solid colors.PNG
* Test with Solid colors.PNG (Filesize: 11.36 KB, Dimensions: 805x630, Views: 189)
test with Steve's modified fTri in Quad sub.PNG
* test with Steve's modified fTri in Quad sub.PNG (Filesize: 12.67 KB, Dimensions: 801x625, Views: 202)

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Simple coordinates equation or impossible coordinates equation?
« Reply #19 on: December 15, 2019, 05:42:09 pm »
Bplus, that works great!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Simple coordinates equation or impossible coordinates equation?
« Reply #20 on: December 16, 2019, 12:55:09 am »
Isn't this simple little demo what you were trying to accomplish?

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 600, 32)
  2.  
  3. LINE (100, 100)-(200, 300)
  4. Cone 100, 100, 10, 200, 300, 30, &H77FFFFFF
  5. LINE (100, 300)-(300, 100)
  6. Cone 100, 300, 30, 300, 100, 120, &H337700FF
  7.  
  8.  
  9.  
  10.  
  11. SUB Cone (x1, y1, r1, x2, y2, r2, kolor AS _UNSIGNED LONG)
  12.     rise = y2 - y1
  13.     runn = x2 - x1
  14.     slope = rise / runn
  15.     rchange = r2 - r1
  16.     RateOfRadiusChange = rchange / runn
  17.     FOR i = 0 TO runn
  18.         CircleFill x1 + i, y1 + i * slope, r1 + RateOfRadiusChange * i, kolor
  19.         SLEEP
  20.     NEXT
  21.  
  22. SUB CircleFill (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  23.     ' CX = center x coordinate
  24.     ' CY = center y coordinate
  25.     '  R = radius
  26.     '  C = fill color
  27.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  28.     DIM X AS INTEGER, Y AS INTEGER
  29.     Radius = ABS(R)
  30.     RadiusError = -Radius
  31.     X = Radius
  32.     Y = 0
  33.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  34.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  35.     WHILE X > Y
  36.         RadiusError = RadiusError + Y * 2 + 1
  37.         IF RadiusError >= 0 THEN
  38.             IF X <> Y + 1 THEN
  39.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  40.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  41.             END IF
  42.             X = X - 1
  43.             RadiusError = RadiusError - X * 2
  44.         END IF
  45.         Y = Y + 1
  46.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  47.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  48.     WEND
  49.  

There's one stray SLEEP statement in there, so you can watch as it works, so feel free to take it out if it's not something you're interested in having in your own code.  ;)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Simple coordinates equation or impossible coordinates equation?
« Reply #21 on: December 16, 2019, 09:53:38 am »
Nice one Steve, that is simpler. ;)

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Simple coordinates equation or impossible coordinates equation?
« Reply #22 on: December 16, 2019, 12:33:18 pm »
Yes Steve, thank you. But every single time I try to make subs they don't work unless I copy other people's code. I am brand new at SUB's, so please tell me why this has a Syntax Error. I'm trying to let the user define the variables instead. Thanks.

Cone x1, y1, r1, x2, y2, r2


Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Simple coordinates equation or impossible coordinates equation?
« Reply #23 on: December 16, 2019, 12:46:33 pm »
Yes Steve, thank you. But every single time I try to make subs they don't work unless I copy other people's code. I am brand new at SUB's, so please tell me why this has a Syntax Error. I'm trying to let the user define the variables instead. Thanks.

Cone x1, y1, r1, x2, y2, r2

Can you share the rest of the code and the error message?  By itself, I can’t see any reason why it’d fail.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Simple coordinates equation or impossible coordinates equation?
« Reply #24 on: December 16, 2019, 01:14:15 pm »
Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 600, 32)
  2.  
  3. INPUT "X1 = ", x1
  4. INPUT "Y1 = ", y1
  5. INPUT "Radius = ", r1
  6. INPUT "X2 = ", x2
  7. INPUT "Y2 = ", y2
  8. INPUT "Radius = ", r2
  9.  
  10. Cone x1, y1, r1, x2, y2, r2
  11.  
  12.  
  13. 'LINE (100, 100)-(200, 300)
  14. 'Cone 100, 100, 10, 200, 300, 30, &H77FFFFFF
  15. 'LINE (100, 300)-(300, 100)
  16. 'Cone 100, 300, 30, 300, 100, 120, &H337700FF
  17.  
  18.  
  19.  
  20.  
  21. SUB Cone (x1, y1, r1, x2, y2, r2, kolor AS _UNSIGNED LONG)
  22.     kcolor = kcolor + 1
  23.     rise = y2 - y1
  24.     runn = x2 - x1
  25.     slope = rise / runn
  26.     rchange = r2 - r1
  27.     RateOfRadiusChange = rchange / runn
  28.     FOR i = 0 TO runn
  29.         CircleFill x1 + i, y1 + i * slope, r1 + RateOfRadiusChange * i, kolor
  30.         SLEEP
  31.     NEXT
  32.  
  33. SUB CircleFill (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  34.     ' CX = center x coordinate
  35.     ' CY = center y coordinate
  36.     '  R = radius
  37.     '  C = fill color
  38.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  39.     DIM X AS INTEGER, Y AS INTEGER
  40.     Radius = ABS(R)
  41.     RadiusError = -Radius
  42.     X = Radius
  43.     Y = 0
  44.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  45.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  46.     WHILE X > Y
  47.         RadiusError = RadiusError + Y * 2 + 1
  48.         IF RadiusError >= 0 THEN
  49.             IF X <> Y + 1 THEN
  50.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  51.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  52.             END IF
  53.             X = X - 1
  54.             RadiusError = RadiusError - X * 2
  55.         END IF
  56.         Y = Y + 1
  57.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  58.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  59.     WEND
  60.  
  61.  

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Simple coordinates equation or impossible coordinates equation?
« Reply #25 on: December 16, 2019, 01:17:15 pm »
Here is a picture of the screen with the error message.

Sub Error Message For Forum.jpg
* Sub Error Message For Forum.jpg (Filesize: 358.21 KB, Dimensions: 1920x1039, Views: 220)

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Simple coordinates equation or impossible coordinates equation?
« Reply #26 on: December 16, 2019, 01:27:38 pm »
You’re missing a parameter; you aren’t sending the sub a color value. 

Cone x1, Y1, r1, X2, Y2, R2, kolor <— the last parameter is missing.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Simple coordinates equation or impossible coordinates equation?
« Reply #27 on: December 16, 2019, 02:43:59 pm »
Thanks Steve. It works now.