Author Topic: Need a little help.  (Read 5257 times)

0 Members and 1 Guest are viewing this topic.

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Need a little help.
« on: July 31, 2018, 01:23:02 pm »
Okay so I'm trying to finish up some stuff for my eRATication Mark II and I just can't get my cheese wedge shaped shooter to rotate correctly. or more precisely the 'holes' in the wedge to stay put as the wedge spins. I can get them to work in very specific locations but not in a random look that I want.
Code: QB64: [Select]
  1. 'cheese wedge ship design spin test.
  2. CONST TRUE = -1, FALSE = NOT TRUE
  3. SCREEN _NEWIMAGE(800, 600, 32)
  4.  
  5. x = 400: y = 300
  6.  FOR i! = 0 TO 6.28 STEP .01
  7.   RadianAngle = i!
  8.   LINE (300, 200)-(500, 400), _RGB(0, 0, 0), BF 'erase spin area
  9.  
  10.   x1 = x + 60 * COS(RadianAngle) 'the wedge points
  11.   y1 = y + 60 * SIN(RadianAngle)
  12.   x2 = x + 30 * COS(RadianAngle + _PI(2 / 3))
  13.   y2 = y + 30 * SIN(RadianAngle + _PI(2 / 3))
  14.   x3 = x + 30 * COS(RadianAngle - _PI(2 / 3))
  15.   y3 = y + 30 * SIN(RadianAngle - _PI(2 / 3))
  16.  
  17.   fTri x1, y1, x2, y2, x3, y3, _RGB(252, 221, 37) 'draw the wedge
  18.  
  19.   'try to add some 'holes' to the wedge and have them stay in place while spining
  20.   fcirc x + 15 * COS(RadianAngle + _PI(2 / 3)), y + 15 * SIN(RadianAngle + _PI(2 / 3)), 4, _RGB(148, 76, 36)
  21.   fcirc x + 10 * COS(RadianAngle), y + 15 * SIN(RadianAngle), 3, _RGB(148, 76, 36)
  22.   fcirc x + 20 * COS(RadianAngle - _PI(2 / 3)), y - 8 * SIN(RadianAngle - _PI(2 / 3)), 2, _RGB(148, 76, 36)
  23.  
  24.   'mark the main points of the triangle
  25.   PSET (x1, y1), _RGB(255, 0, 0)
  26.   PSET (x2, y2), _RGB(0, 255, 0)
  27.   PSET (x3, y3), _RGB(0, 0, 255)
  28.   'mark the rotational center of the triangle
  29.   PSET (x, y), _RGB(255, 0, 255): DRAW "ud2url2"
  30.  
  31.   _DELAY .01
  32.   IF INKEY$ <> "" THEN exitflag% = TRUE: i! = 6.30
  33.  NEXT i!
  34. LOOP UNTIL exitflag%
  35.  
  36. SUB fTri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  37.  a& = _NEWIMAGE(1, 1, 32)
  38.  _DEST a&
  39.  PSET (0, 0), K
  40.  _DEST 0
  41.  _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  42.  _FREEIMAGE a& '<<< this is important!
  43.  
  44. 'vince version
  45. SUB fcirc (x AS LONG, y AS LONG, R AS LONG, C AS _UNSIGNED LONG)
  46.  x0 = R
  47.  y0 = 0
  48.  e = 0
  49.  DO WHILE y0 < x0
  50.   IF e <= 0 THEN
  51.    y0 = y0 + 1
  52.    LINE (x - x0, y + y0)-(x + x0, y + y0), C, BF
  53.    LINE (x - x0, y - y0)-(x + x0, y - y0), C, BF
  54.    e = e + 2 * y0
  55.   ELSE
  56.    LINE (x - y0, y - x0)-(x + y0, y - x0), C, BF
  57.    LINE (x - y0, y + x0)-(x + y0, y + x0), C, BF
  58.    x0 = x0 - 1
  59.    e = e - 2 * x0
  60.   END IF
  61.  LINE (x - R, y)-(x + R, y), C, BF
  62.  

the back of the wedge is a little flat yet but I'm not overly concerned with that at this time. I just need to find a way to keep the 'hole' circles in place on the wedge while having a random pattern of them. you guys have any ideas?
Granted after becoming radioactive I only have a half-life!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Need a little help.
« Reply #1 on: July 31, 2018, 01:44:44 pm »
Hi. I would do it otherwise. I would make a cheese wallpaper and then cut out the cheese triangle using the _maptriangle and turn it over RotoZoom.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Need a little help.
« Reply #2 on: July 31, 2018, 02:28:51 pm »
....wallpaper.... i meant texture.... i now write, how do it.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Need a little help.
« Reply #3 on: July 31, 2018, 03:08:53 pm »
Hi Cobalt,

You need to use the same coefficient for  y for sin multiplier as you used for x cos multiplier

x = cx + m * sin(...)
y = cy + m * cos(...)

Here is code modified with a draw sub for shooter with some more holes added.
The shooter angle (which is shared for sub access) is not converted to radians until inside the sub.
Also the shooter x, y location is also shared.

Code: QB64: [Select]
  1. 'cheese wedge ship design spin test.
  2. CONST TRUE = -1, FALSE = NOT TRUE
  3. SCREEN _NEWIMAGE(800, 600, 32)
  4. DIM SHARED shooterX, shooterY, shooterA
  5. shooterX = 400: shooterY = 300
  6.  
  7. FOR shooterA = 0 TO 360 STEP 1
  8.     IF _KEYDOWN(32) THEN END
  9.     LINE (300, 200)-(500, 400), _RGB(0, 0, 0), BF 'erase spin area
  10.  
  11.     drawShooter
  12.     _DISPLAY
  13.     _LIMIT 60
  14.  
  15.  
  16. SUB fTri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  17.     a& = _NEWIMAGE(1, 1, 32)
  18.     _DEST a&
  19.     PSET (0, 0), K
  20.     _DEST 0
  21.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  22.     _FREEIMAGE a& '<<< this is important!
  23.  
  24. 'vince version
  25. SUB fcirc (x AS LONG, y AS LONG, R AS LONG, C AS _UNSIGNED LONG)
  26.     x0 = R
  27.     y0 = 0
  28.     e = 0
  29.     DO WHILE y0 < x0
  30.         IF e <= 0 THEN
  31.             y0 = y0 + 1
  32.             LINE (x - x0, y + y0)-(x + x0, y + y0), C, BF
  33.             LINE (x - x0, y - y0)-(x + x0, y - y0), C, BF
  34.             e = e + 2 * y0
  35.         ELSE
  36.             LINE (x - y0, y - x0)-(x + y0, y - x0), C, BF
  37.             LINE (x - y0, y + x0)-(x + y0, y + x0), C, BF
  38.             x0 = x0 - 1
  39.             e = e - 2 * x0
  40.         END IF
  41.     LOOP
  42.     LINE (x - R, y)-(x + R, y), C, BF
  43.  
  44. SUB drawShooter ()
  45.     'calculate 3 points of triangle shooter
  46.     'dim shared ShooterX, ShooterY, ShooterA
  47.     rA = _D2R(shooterA)
  48.     x1 = shooterX + 60 * COS(rA) 'main point of shooter according to heading
  49.     y1 = shooterY + 60 * SIN(rA)
  50.     x2 = shooterX + 30 * COS(rA + _PI(2 / 3)) 'next two points are 120 degrees off main point in direction
  51.     y2 = shooterY + 30 * SIN(rA + _PI(2 / 3))
  52.     x3 = shooterX + 30 * COS(rA - _PI(2 / 3))
  53.     y3 = shooterY + 30 * SIN(rA - _PI(2 / 3))
  54.     fTri x1, y1, x2, y2, x3, y3, _RGB32(252, 221, 37)
  55.     ''try to add some 'holes' to the wedge and have them stay in place while spining
  56.  
  57.     fcirc shooterX + 15 * COS(rA + _PI(2 / 3)), shooterY + 15 * SIN(rA + _PI(2 / 3)), 4, _RGB(148, 76, 36)
  58.     fcirc shooterX + 10 * COS(rA), shooterY + 10 * SIN(rA), 3, _RGB(148, 76, 36)
  59.     fcirc shooterX + 8 * COS(rA - _PI(2 / 3)), shooterY + 8 * SIN(rA - _PI(2 / 3)), 2, _RGB(148, 76, 36)
  60.     fcirc shooterX + 5 * COS(rA + _PI(1 / 3)), shooterY + 5 * SIN(rA + _PI(1 / 3)), 1, _RGB(148, 76, 36)
  61.     fcirc shooterX + 20 * COS(rA + _PI(1 / 20)), shooterY + 20 * SIN(rA + _PI(1 / 20)), 3, _RGB(148, 76, 36)
  62.     fcirc shooterX + 40 * COS(rA - _PI(1 / 36)), shooterY + 40 * SIN(rA - _PI(1 / 36)), 4, _RGB(148, 76, 36)
  63.     fcirc shooterX + 20 * COS(rA + _PI(1 / 20)), shooterY + 20 * SIN(rA + _PI(1 / 20)), 3, _RGB(148, 76, 36)
  64.     fcirc shooterX + 40 * COS(rA - _PI(1 / 36)), shooterY + 40 * SIN(rA - _PI(1 / 36)), 4, _RGB(148, 76, 36)
  65.  
  66.     ''mark the main points of the triangle
  67.     fcirc x1, y1, 1, _RGB32(255, 0, 0)
  68.     fcirc x2, y2, 1, _RGB32(0, 255, 0)
  69.     fcirc x3, y3, 1, _RGB32(0, 0, 255)
  70.     ''mark the rotational center of the triangle
  71.     fcirc shooterX, shooterY, 2, _RGB(255, 0, 255)
  72.  
  73.  
  74.  

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Need a little help.
« Reply #4 on: July 31, 2018, 03:28:35 pm »
Again, hello. Perhaps this way is easier:

Code: QB64: [Select]
  1. 'cheese wedge ship design spin test.
  2. CONST TRUE = -1, FALSE = NOT TRUE, Cheese& = _RGB32(148, 76, 36), Wedge& = _RGB32(252, 221, 37)
  3. SCREEN _NEWIMAGE(800, 600, 32)
  4. REDIM ch(0) AS LONG
  5.  
  6. CheeseTexture ch()
  7. x = 400: y = 300
  8.  
  9.  
  10. 'all textures coordinate preload
  11. DIM ssx(20), ssy(20)
  12. FOR f = 1 TO 20
  13.     ssx(f) = sx: ssy(f) = sy
  14.     sx = sx + 120: IF sx > 800 - 120 THEN sx = 0: sy = sy + 120
  15.  
  16.  
  17.  
  18.  
  19.     'rotation:
  20.     CLS
  21.     FOR i = 1 TO 20
  22.         RotoZoom ssx(i) + 75, ssy(i) + 75, ch(i), _DEST, 1, f!, 1, 1
  23.     NEXT i
  24.     _DISPLAY
  25.     f! = f! + .01
  26.  
  27.  
  28.  
  29.     '    FOR i! = 0 TO 6.28 STEP .01
  30.     '    RadianAngle = i!
  31.     '   LINE (300, 200)-(500, 400), _RGB(0, 0, 0), BF 'erase spin area
  32.  
  33.     '  x1 = x + 60 * COS(RadianAngle) 'the wedge points
  34.     '  y1 = y + 60 * SIN(RadianAngle)
  35.     '  x2 = x + 30 * COS(RadianAngle + _PI(2 / 3))
  36.     '  y2 = y + 30 * SIN(RadianAngle + _PI(2 / 3))
  37.     '  x3 = x + 30 * COS(RadianAngle - _PI(2 / 3))
  38.     '  y3 = y + 30 * SIN(RadianAngle - _PI(2 / 3))
  39.  
  40.     '    fTri x1, y1, x2, y2, x3, y3, _RGB(252, 221, 37) 'draw the wedge
  41.  
  42.     'try to add some 'holes' to the wedge and have them stay in place while spining
  43.     '  fcirc x + 15 * COS(RadianAngle + _PI(2 / 3)), y + 15 * SIN(RadianAngle + _PI(2 / 3)), 4, _RGB(148, 76, 36)
  44.     '  fcirc x + 10 * COS(RadianAngle), y + 15 * SIN(RadianAngle), 3, _RGB(148, 76, 36)
  45.     '   REM        fcirc x + 20 * COS(RadianAngle - _PI(2 / 3)), y - 8 * SIN(RadianAngle - _PI(2 / 3)), 2, _RGB(148, 76, 36)
  46.     '   fcirc x + 20 * COS(RadianAngle + _PI(2 / 3)), y + 20 * SIN(RadianAngle + _PI(2 / 3)), 2, _RGB(148, 76, 36)
  47.  
  48.  
  49.     'mark the main points of the triangle
  50.     '  PSET (x1, y1), _RGB(255, 0, 0)
  51.     '  PSET (x2, y2), _RGB(0, 255, 0)
  52.     '  PSET (x3, y3), _RGB(0, 0, 255)
  53.     '  'mark the rotational center of the triangle
  54.     '  PSET (x, y), _RGB(255, 0, 255): DRAW "ud2url2"
  55.  
  56.     '  _DELAY .01
  57.     IF INKEY$ <> "" THEN exitflag% = TRUE: i! = 6.30
  58.     ' NEXT i!
  59.  
  60.  
  61.     '  _LIMIT 30
  62. LOOP UNTIL exitflag%
  63.  
  64.  
  65.  
  66.  
  67. SUB CheeseTexture (ch() AS LONG)
  68.     REDIM ch(20) AS LONG
  69.     V& = _NEWIMAGE(150, 150, 32)
  70.     curr& = _DEST
  71.     _DEST V&
  72.     FOR TextureGen = 0 TO 20
  73.         CLS , Wedge&
  74.         FOR w = 1 TO 10 'how much circles
  75.             x = RND * 150
  76.             y = RND * 150
  77.             radius = RND * 15
  78.             fcirc x, y, radius, Cheese&
  79.         NEXT w
  80.  
  81.         'generate random cheese size:
  82.         gen:
  83.         x1 = RND * 20
  84.         y1 = RND * 20
  85.         x2 = RND * 130
  86.         y2 = RND * 130
  87.         x3 = RND * 130
  88.         y3 = RND * 20
  89.         IF ABS(x3 - x1) < 30 OR ABS(x2 - x1) < 30 OR ABS(y2 - y1) < 30 THEN GOTO gen
  90.  
  91.  
  92.         ch(TextureGen) = _NEWIMAGE(150, 150, 32)
  93.         _MAPTRIANGLE (x1, y1)-(x2, y2)-(x3, y3), V& TO(x1, y1)-(x2, y2)-(x3, y3), ch(TextureGen)
  94.     NEXT
  95.     _DEST curr&
  96.     _FREEIMAGE V&
  97.  
  98.  
  99. 'SUB fTri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  100. '    a& = _NEWIMAGE(1, 1, 32)
  101. '    _DEST a&
  102. '    PSET (0, 0), K
  103. '    _DEST 0
  104. '    _MAPTRIANGLE (0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  105. '    _FREEIMAGE a& '<<< this is important!
  106. 'END SUB
  107.  
  108.  
  109.  
  110. 'vince version
  111.  
  112.  
  113. SUB RotoZoom (X AS INTEGER, Y AS INTEGER, Image AS LONG, cil AS LONG, Scale AS SINGLE, RotationR AS SINGLE, direction AS INTEGER, speed AS INTEGER)
  114.     DIM px(3) AS SINGLE: DIM py(3) AS SINGLE
  115.     W& = _WIDTH(Image&): h& = _HEIGHT(Image&)
  116.     px(0) = -W& / 2: py(0) = -h& / 2: px(1) = -W& / 2: py(1) = h& / 2
  117.     px(2) = W& / 2: py(2) = h& / 2: px(3) = W& / 2: py(3) = -h& / 2
  118.     IF direction = 1 THEN
  119.         sinr! = COS(-RotationR / 3.1415927): cosr! = SIN(-RotationR / 3.1415927 * speed)
  120.     ELSE
  121.         sinr! = SIN(-RotationR / 3.1415927): cosr! = COS(-RotationR / 3.1415927 * speed)
  122.     END IF
  123.     '  _limit 60 - speed
  124.     FOR i& = 0 TO 3
  125.         x2& = (px(i&) * cosr! + sinr! * py(i&)) * Scale + X: y2& = (py(i&) * cosr! - px(i&) * sinr!) * Scale + Y
  126.         px(i&) = x2&: py(i&) = y2&
  127.     NEXT
  128.     _DEST cil&
  129.     _MAPTRIANGLE (0, 0)-(0, h& - 1)-(W& - 1, h& - 1), Image& TO(px(0), py(0))-(px(1), py(1))-(px(2), py(2)), 0, _SMOOTH
  130.     _MAPTRIANGLE (0, 0)-(W& - 1, 0)-(W& - 1, h& - 1), Image& TO(px(0), py(0))-(px(3), py(3))-(px(2), py(2)), 0, _SMOOTH
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137. SUB fcirc (x AS LONG, y AS LONG, R AS LONG, C AS _UNSIGNED LONG)
  138.     x0 = R
  139.     y0 = 0
  140.     e = 0
  141.     DO WHILE y0 < x0
  142.         IF e <= 0 THEN
  143.             y0 = y0 + 1
  144.             LINE (x - x0, y + y0)-(x + x0, y + y0), C, BF
  145.             LINE (x - x0, y - y0)-(x + x0, y - y0), C, BF
  146.             e = e + 2 * y0
  147.         ELSE
  148.             LINE (x - y0, y - x0)-(x + y0, y - x0), C, BF
  149.             LINE (x - y0, y + x0)-(x + y0, y + x0), C, BF
  150.             x0 = x0 - 1
  151.             e = e - 2 * x0
  152.         END IF
  153.     LOOP
  154.     LINE (x - R, y)-(x + R, y), C, BF
  155.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Need a little help.
« Reply #5 on: July 31, 2018, 03:34:52 pm »
oops! I repeated holes here are 8 different ones:
Code: QB64: [Select]
  1.     fcirc shooterX + 15 * COS(rA + _PI(2 / 3)), shooterY + 15 * SIN(rA + _PI(2 / 3)), 3, _RGB(148, 76, 36)
  2.     fcirc shooterX + 10 * COS(rA), shooterY + 10 * SIN(rA), 2, _RGB(148, 76, 36)
  3.     fcirc shooterX + 8 * COS(rA - _PI(2 / 3)), shooterY + 8 * SIN(rA - _PI(2 / 3)), 2, _RGB(148, 76, 36)
  4.     fcirc shooterX + 5 * COS(rA + _PI(1 / 3)), shooterY + 5 * SIN(rA + _PI(1 / 3)), 3, _RGB(148, 76, 36)
  5.     fcirc shooterX + 20 * COS(rA + _PI(1 / 20)), shooterY + 20 * SIN(rA + _PI(1 / 20)), 2, _RGB(148, 76, 36)
  6.     fcirc shooterX + 40 * COS(rA - _PI(1 / 36)), shooterY + 40 * SIN(rA - _PI(1 / 36)), 3, _RGB(148, 76, 36)
  7.     fcirc shooterX + 10 * COS(rA + _PI(.8)), shooterY + 10 * SIN(rA + _PI(.8)), 4, _RGB(148, 76, 36)
  8.     fcirc shooterX + 12 * COS(rA - _PI(7 / 16)), shooterY + 12 * SIN(rA - _PI(7 / 16)), 4, _RGB(148, 76, 36)
  9.  
  10.  
  11.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Need a little help.
« Reply #6 on: July 31, 2018, 07:36:32 pm »
A different construction of the shooter wedge that makes it easier for random patterns of holes:
Code: QB64: [Select]
  1. 'cheese wedge shooter 2
  2.  
  3. 'try a different construction of wedge for easier random holes in it
  4.  
  5. CONST TRUE = -1, FALSE = NOT TRUE
  6. CONST nHoles = 9
  7. TYPE holeType
  8.     mult AS SINGLE
  9.     angle AS SINGLE
  10.     radius AS INTEGER
  11.  
  12. SCREEN _NEWIMAGE(800, 600, 32)
  13.  
  14. DIM SHARED shooterX, shooterY, shooterA
  15. DIM SHARED holes(nHoles) AS holeType
  16. shooterX = 400: shooterY = 300
  17.  
  18. 'show different patterns of holes
  19.     'new set of holes
  20.     initHoles
  21.     FOR shooterA = 0 TO 360 STEP 1
  22.         IF _KEYDOWN(27) THEN EXIT FOR
  23.         CLS
  24.         drawShooter
  25.         _DISPLAY
  26.         _LIMIT 60
  27.     NEXT
  28.  
  29. SUB fTri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  30.     a& = _NEWIMAGE(1, 1, 32)
  31.     _DEST a&
  32.     PSET (0, 0), K
  33.     _DEST 0
  34.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  35.     _FREEIMAGE a& '<<< this is important!
  36.  
  37. 'vince version
  38. SUB fcirc (x AS LONG, y AS LONG, R AS LONG, C AS _UNSIGNED LONG)
  39.     x0 = R
  40.     y0 = 0
  41.     e = 0
  42.     DO WHILE y0 < x0
  43.         IF e <= 0 THEN
  44.             y0 = y0 + 1
  45.             LINE (x - x0, y + y0)-(x + x0, y + y0), C, BF
  46.             LINE (x - x0, y - y0)-(x + x0, y - y0), C, BF
  47.             e = e + 2 * y0
  48.         ELSE
  49.             LINE (x - y0, y - x0)-(x + y0, y - x0), C, BF
  50.             LINE (x - y0, y + x0)-(x + y0, y + x0), C, BF
  51.             x0 = x0 - 1
  52.             e = e - 2 * x0
  53.         END IF
  54.     LOOP
  55.     LINE (x - R, y)-(x + R, y), C, BF
  56.  
  57. SUB drawShooter ()
  58.     'calculate 2 points of wedge, the pointer is at shooterX, shooterY
  59.     'dim shared ShooterX, ShooterY, ShooterA
  60.     rA = _D2R(shooterA)
  61.     x1 = shooterX + 80 * COS(rA + _PI(11 / 12))
  62.     y1 = shooterY + 80 * SIN(rA + _PI(11 / 12))
  63.     x2 = shooterX + 80 * COS(rA + _PI(13 / 12))
  64.     y2 = shooterY + 80 * SIN(rA + _PI(13 / 12))
  65.     fTri shooterX, shooterY, x1, y1, x2, y2, _RGB32(252, 221, 37)
  66.     ''try to add some 'holes' to the wedge and have them stay in place while spining
  67.     FOR i = 1 TO nHoles
  68.         fcirc shooterX + holes(i).mult * COS(rA + holes(i).angle), shooterY + holes(i).mult * SIN(rA + holes(i).angle), holes(i).radius, _RGB32(0, 0, 0)
  69.     NEXT
  70.  
  71.  
  72. SUB initHoles ()
  73.     FOR i = 1 TO nHoles
  74.         holes(i).mult = 17 + RND * 63
  75.         holes(i).angle = _PI(45 / 48) + RND * _PI(7 / 48)
  76.         holes(i).radius = INT(RND * 4) + 1
  77.     NEXT
  78.  
  79.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Need a little help.
« Reply #7 on: August 01, 2018, 01:27:54 pm »
Spent the morning making cheese to employ some of Petr's idea for a wedge of cheese shooter:
Everything depends upon radius of hole size, for shooter need a pretty small radius but some excellent cheese textures could be made with larger radii but the other variables then have to be tweaked. (Hi Petr, did not need rotozoom).

Anyway, here is best cheese I could come up for smallish shooter wedge:
Code: QB64: [Select]
  1. _TITLE "Cheese Factory"
  2. 'QB64 X 64 version 1.2 20180228/86  from git b301f92
  3.  
  4. '2018-08-01 started from idea I had while trying to fix holes in Colbalt's cheese wedge shooter
  5.  
  6. CONST wW = 800
  7. CONST wH = 600
  8. CONST maxHoleLife = 10
  9. CONST maxHoleRadius = 4
  10. CONST sSz = 100
  11. TYPE holeType
  12.     x AS SINGLE
  13.     y AS SINGLE
  14.     life AS INTEGER
  15.  
  16.  
  17. SCREEN _NEWIMAGE(wW, wH, 32)
  18. _SCREENMOVE 360, 60
  19.  
  20. DIM SHARED nHoles 'this might change
  21. nHoles = 2000
  22.  
  23. DIM SHARED h(nHoles) AS holeType
  24. FOR i = 1 TO nHoles
  25.     newHole i, 1
  26.  
  27. DIM SHARED slice&
  28. slice& = 1
  29.  
  30. growCheese 0
  31. COLOR _RGB32(0, 0, 0), _RGB32(255, 255, 0)
  32. _PRINTSTRING (20, 280), "Here is a sample of the cheese from which we are taking a wedge, press any to rotate shooter..."
  33. COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  34.  
  35. DIM SHARED shooterX, shooterY, shooterA
  36. shooterX = 400: shooterY = 300
  37.  
  38. 'show different patterns of holes
  39.     growCheese slice& 'try different batches of cheese
  40.     FOR shooterA = 0 TO 360 STEP 1
  41.         IF _KEYDOWN(27) THEN EXIT FOR
  42.         CLS
  43.         drawShooter
  44.         _DISPLAY
  45.         _LIMIT 60
  46.     NEXT
  47.  
  48. SUB drawShooter ()
  49.     'calculate 2 points of wedge, the pointer is at shooterX, shooterY
  50.     'dim shared ShooterX, ShooterY, ShooterA
  51.     rA = _D2R(shooterA)
  52.     x1 = shooterX + sSz * COS(rA + _PI(11 / 12)) 'next two points are 120 degrees off main point in direction
  53.     y1 = shooterY + sSz * SIN(rA + _PI(11 / 12))
  54.     x2 = shooterX + sSz * COS(rA + _PI(13 / 12))
  55.     y2 = shooterY + sSz * SIN(rA + _PI(13 / 12))
  56.     _MAPTRIANGLE (400 + sSz * COS(_PI(11 / 12)), 300 + sSz * SIN(_PI(11 / 12)))-(400 + sSz * COS(_PI(13 / 12)), 300 + sSz * SIN(_PI(13 / 12)))-(400, 300), slice& TO(x1, y1)-(x2, y2)-(shooterX, shooterY)
  57.  
  58.  
  59. SUB newHole (i, tfStart)
  60.     h(i).x = wW * RND
  61.     h(i).y = wH * RND
  62.     IF tfStart THEN h(i).life = INT(RND * maxHoleLife) ELSE h(i).life = 1
  63.  
  64. SUB growCheese (destHandle&)
  65.     curr& = _DEST
  66.     l& = _NEWIMAGE(wW, wH, 32)
  67.     _DEST l&
  68.     FOR layr = 40 TO 80
  69.         LINE (0, 0)-(wW, wH), _RGBA32(255, 255, 0, .3 * layr), BF 'layer of cheese
  70.         FOR i = 1 TO nHoles 'holes in layer
  71.             IF h(i).life + 1 > maxHoleLife THEN newHole i, 0 ELSE h(i).life = h(i).life + 1
  72.             h(i).x = h(i).x + RND * 2 - 1
  73.             h(i).y = h(i).y + RND * 2 - 1
  74.             IF h(i).life < maxHoleRadius THEN
  75.                 radius = h(i).life
  76.             ELSEIF maxHoleLife - h(i).life < maxHoleRadius THEN
  77.                 radius = maxHoleLife - h(i).life
  78.             ELSE
  79.                 radius = maxHoleRadius
  80.             END IF
  81.             COLOR _RGBA32(0, 0, 0, .3 * layr)
  82.             fcirc h(i).x, h(i).y, radius
  83.         NEXT
  84.     NEXT
  85.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, wH)-(wW, 0), l& TO(0, 0)-(0, wH)-(wW, 0), destHandle&
  86.     'only using small slice of cheese
  87.     _MAPTRIANGLE _SEAMLESS(wW, 0)-(wW, wH)-(0, wH), l& TO(wW, 0)-(wW, wH)-(0, wH), destHandle&
  88.     _DEST curr&
  89.     _FREEIMAGE l& '<<< this is important!
  90.  
  91. 'Steve McNeil's  copied from his forum   note: Radius is too common a name
  92. SUB fcirc (CX AS LONG, CY AS LONG, R AS LONG)
  93.     DIM subRadius AS LONG, RadiusError AS LONG
  94.     DIM X AS LONG, Y AS LONG
  95.  
  96.     subRadius = ABS(R)
  97.     RadiusError = -subRadius
  98.     X = subRadius
  99.     Y = 0
  100.  
  101.     IF subRadius = 0 THEN PSET (CX, CY): EXIT SUB
  102.  
  103.     ' Draw the middle span here so we don't draw it twice in the main loop,
  104.     ' which would be a problem with blending turned on.
  105.     LINE (CX - X, CY)-(CX + X, CY), , BF
  106.  
  107.     WHILE X > Y
  108.         RadiusError = RadiusError + Y * 2 + 1
  109.         IF RadiusError >= 0 THEN
  110.             IF X <> Y + 1 THEN
  111.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), , BF
  112.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), , BF
  113.             END IF
  114.             X = X - 1
  115.             RadiusError = RadiusError - X * 2
  116.         END IF
  117.         Y = Y + 1
  118.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), , BF
  119.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), , BF
  120.     WEND
  121.  
« Last Edit: August 01, 2018, 01:29:06 pm by bplus »

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Need a little help.
« Reply #8 on: August 01, 2018, 02:47:48 pm »
Does not matter if is rotozoom used, the principle is still the same. Good luck with other cheese orgies, I will no longer participate in them.

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Need a little help.
« Reply #9 on: August 01, 2018, 10:16:26 pm »
Sorry to highlight myself as being immensely immature, but this line is farking hilarious:

Quote
Good luck with other cheese orgies, I will no longer participate in them.
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: Need a little help.
« Reply #10 on: August 02, 2018, 03:44:42 am »
I do not know what you mean, of course, I'm writing about programming orgies - four, five or more examples for the same thema. I understand it's summer and someone can understand it differently...

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Need a little help.
« Reply #11 on: August 02, 2018, 06:45:08 am »
^ That's why I love ya Petr. (Puns never intended!)

Begin your education on the topic here then: https://www.urbandictionary.com/define.php?term=cheese%20orgy

(Anyone who wants a kid-friendly Internet has to wait for Walt to finish his site.)
« Last Edit: August 02, 2018, 06:48:56 am by STxAxTIC »
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: Need a little help.
« Reply #12 on: August 02, 2018, 07:40:41 am »
I love you not :-D

Thank you for the link, definition of this word in Czech is different. Means, among other things, brazenness, ceremony or festivity, or eccentric entertainment.