_TITLE "Star Worlds" 'B+ 2019-11-26
CONST xmax
= 1200, ymax
= 700, nS
= 500
newStar i
drawStar i
stars(i).x = stars(i).x + stars(i).dx: stars(i).y = stars(i).y + stars(i).dy
IF stars
(i
).x
< -50 OR stars
(i
).x
> xmax
+ 50 OR stars
(i
).y
< -50 OR stars
(i
).y
> ymax
+ 50 THEN newStar i
stars(i).aOff = stars(i).aOff + stars(i).da
stars(i).x = irnd%(0, xmax)
stars(i).y = irnd%(0, ymax)
stars(i).ri = irnd%(1, 6)
stars
(i
).ro
= stars
(i
).ri
* (RND * 1 + 1.5) stars(i).nP = irnd%(3, 12)
stars(i).filled = irnd%(0, 1)
stars(i).dx = irnd%(-10, 10)
stars(i).dy = irnd%(-10, 10)
stars
(i
).cc
= _RGBA32(irnd%
(128, 255), irnd%
(128, 255), irnd%
(128, 255), irnd%
(1, 255))
FUNCTION irnd%
(n1
, n2
) 'return an integer between 2 numbers IF n1
> n2
THEN l%
= n2: h%
= n1
ELSE l%
= n1: h%
= n2
irnd%
= INT(RND * (h%
- l%
+ 1)) + l%
'this just draws a bunch of triangles according to x, y points in arr()
ox = arr(0): oy = arr(1) 'the first 2 items in arr() need to be center
ftri ox, oy, arr(i), arr(i + 1), arr(i + 2), arr(i + 3), c
' x, y are same as for circle,
' rInner is center circle radius
' rOuter is the outer most point of star
' nPoints is the number of points,
' angleOffset = angle offset in radians
' this is to allow us to spin the star
pAngle
= _PI(2) / stars
(i
).nP: radAngleOffset
= stars
(i
).aOff
- _PI(1 / 2) ar(0) = stars(i).x: ar(1) = stars(i).y
ar
(2) = stars
(i
).x
+ stars
(i
).ro
* COS(radAngleOffset
) ar
(3) = stars
(i
).y
+ stars
(i
).ro
* SIN(radAngleOffset
) idx = 4
FOR p
= 0 TO stars
(i
).nP
- 1 ar
(idx
) = stars
(i
).x
+ stars
(i
).ri
* COS(p
* pAngle
+ radAngleOffset
+ .5 * pAngle
) idx = idx + 1
ar
(idx
) = stars
(i
).y
+ stars
(i
).ri
* SIN(p
* pAngle
+ radAngleOffset
+ .5 * pAngle
) idx = idx + 1
ar
(idx
) = stars
(i
).x
+ stars
(i
).ro
* COS((p
+ 1) * pAngle
+ radAngleOffset
) idx = idx + 1
ar
(idx
) = stars
(i
).y
+ stars
(i
).ro
* SIN((p
+ 1) * pAngle
+ radAngleOffset
) idx = idx + 1
fIrrPoly ar(), stars(i).cc
IF p
> 2 THEN LINE (ar
(p
- 2), ar
(p
- 1))-(ar
(p
), ar
(p
+ 1)), stars
(i
).cc