Remake Star Maker

OMG! so much better! Now 0 angleOffset will have the star pointing North.

Append: Allot of this is happened because Ted got me rethinking Star Making.
Thank Ted for the stars all pointing North when angleOffset = 0 degrees and for starArr being a function that returns the star Array points but you will still need to track x, r, inner radius and outer radius and angleOffset to make wire frame over star.


' Remake Star Maker.bas SmallBASIC 0.12.8 [B+=MGA] 2017-03-26
' attempt to use DRAWPOLY for Star Maker that has built-in fill

cx=xmax/2 : cy=ymax/2
star = starArr(cx, cy, 100, 300, 7, 0, 0)
for
i in star : ? i : next
input "press enter for next test ";enter
n = 3
while asc(inkey) <> 32
cls
? "press spacebar to quit.."
star = starArr(cx, cy, 100, 300, n, a, 1)
if a = 0 then delay 200
showpage
delay 20
a +=1
if a = 45 then n += 1 : a = 0
wend
pause

func
starArr(x, y, rInner, rOuter, nPoints, angleOffset, fillTF)
' 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 DEGREES, it will be converted to radians in sub
' this is to allow us to spin the polygon of n sides
' TFfill filled True or False (1 or 0)
local p_angle, rad_angle_offset, x1, y1, i, arr
dim arr()
p_angle = rad(360 / nPoints) : rad_angle_offset = rad(angleOffset - 90)
x1 = x + rOuter * cos(rad_angle_offset)
y1 = y + rOuter * sin(rad_angle_offset)
arr << x1 : arr << y1
for i = 0 to nPoints - 1
x1 = x + rInner * cos(i * p_angle + rad_angle_offset + .5 * p_angle)
y1 = y + rInner * sin(i * p_angle + rad_angle_offset + .5 * p_angle)
arr << x1 : arr << y1
x1 = x + rOuter * cos((i + 1) * p_angle + rad_angle_offset)
y1 = y + rOuter * sin((i + 1) * p_angle + rad_angle_offset)
arr << x1 : arr << y1
next
if fillTF then drawpoly arr filled else drawpoly arr
starArr = arr
end



It's a function now so you can save the array eg for wire framing or whatever.

No more bulky triangleFill to have to add to graphics programs.

Wow! For sure, what an improvement in code-readability! I gave it a quick run in SB, and all looks good there too. Gotta hustle to work, back this evening. - Ted

quote from
https://en.wikipedia.org/wiki/2001:_A_Space_Odyssey_(novel)

'remake Star Worlds.bas for SmallBASIC [B+=MGA] 2017-03-29
'using Chris method in Triangles to create what Johnno calls Particle Programs
'and shian's LOCAL method, and new plasma/flasher method

func
rand(n1, n2)
local l
if n1 > n2 then l.hi = n1 : l.lo = n2 else l.hi = n2 : l.lo = n1
rand = (rnd * (l.hi - l.lo + 1)) \ 1 + l.lo
end


func
starArr(byref star)
' 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 DEGREES, it will be converted to radians in sub
' this is to allow us to spin the polygon of n sides
' TFfill filled True or False (1 or 0)

'use l. method for tracking what is local
local l 'p_angle, rad_angle_offset, x1, y1, i, arr
dim l.arr()
l.p_angle = rad(360 / star.n) : l.rad_angle_offset = rad(star.a - 90)
l.x1 = star.x + star.ro * cos(l.rad_angle_offset)
l.y1 = star.y + star.ro * sin(l.rad_angle_offset)
l.arr << l.x1 : l.arr << l.y1
for l.i = 0 to star.n - 1
l.x1 = star.x + star.ri * cos(l.i * l.p_angle + l.rad_angle_offset + .5 * l.p_angle)
l.y1 = star.y + star.ri * sin(l.i * l.p_angle + l.rad_angle_offset + .5 * l.p_angle)
l.arr << l.x1 : l.arr << l.y1
l.x1 = star.x + star.ro * cos((l.i + 1) * l.p_angle + l.rad_angle_offset)
l.y1 = star.y + star.ro * sin((l.i + 1) * l.p_angle + l.rad_angle_offset)
l.arr << l.x1 : l.arr << l.y1
next
if star.f then drawpoly l.arr filled else drawpoly l.arr
starArr = l.arr
end

func
makeStarProperties
local p
p.x = rand(0, xmax)
p.y = rand(0, ymax)
p.ri = rand(5, 20)
p.m = rand(1.2, 3.5)
p.ro = p.ri * p.m
p.n = rand(3, 17)
p.a = rand(0, 360)
p.f = rand(0, 1)
p.dx = rand(-5, 5)
p.dy = rand(-5, 5)
p.sp = rand(-10, 10)
p.z = rand(-3, 3)
p.c = rgb(rand(128, 255), rand(128, 255), rand(128, 255))
makeStarProperties = p
end

dim StarWorlds
n = 50
for
i = 0 to n
StarWorlds << makeStarProperties
next

while 1
cls
for i = 0 to n
color StarWorlds(i).c
istar = starArr(StarWorlds(i))
StarWorlds(i).c = StarWorlds(i).c * .999
StarWorlds(i).a = (StarWorlds(i).a + StarWorlds(i).sp) mod 360
StarWorlds(i).ri = StarWorlds(i).ri + StarWorlds(i).z
if StarWorlds(i).ri > 50 then
StarWorlds(i).ri = 50 : StarWorlds(i).z = -1 * StarWorlds(i).z
elif StarWorlds(i).ri < 5
StarWorlds(i).ri = 5 : StarWorlds(i).z = -1 * StarWorlds(i).z
end if
StarWorlds(i).ro = StarWorlds(i).m * StarWorlds(i).ri
StarWorlds(i).x = (StarWorlds(i).x + StarWorlds(i).dx)
if StarWorlds(i).x < -50 or StarWorlds(i).x > xmax + 50 then
StarWorlds(i) = makeStarProperties
end if
StarWorlds(i).y = (StarWorlds(i).y + StarWorlds(i).dy)
if StarWorlds(i).y < -50 or StarWorlds(i).y > ymax + 50 then
StarWorlds(i) = makeStarProperties
end if
next
showpage
delay 10
wend

Very cool. Also fortunately this uncovered a bug with some recent changes I made to MAP variable handling. I will release the update soon; It has some changes you should like.

(battening down the hatches for ex-tropical cyclone debbie)

FUNC is earning its franshise here. The DIMensioned ARRay and DRAWPOLY are making the assist. "And they score!!" Congrats, MGA, very nice work! :)

... "coming ashore as a Category 4 storm, packing gusts to 161 mph". Gulp. Batten it down good, Mate.

Did you make it through hurricane OK?

You have me wondering what I might like in next update... great teaser!

#1 on my list is to continue seeing updates. : )

#2 is nothing compared to that!

I live in Brisbane. It was just a "tropical low" when we got our turn but still enough that they closed all the Schools for a couple of days. The system is now heading to NZ which seems pretty amazing.

Here's the current list of changes:
https://github.com/smallbasic/SmallBASIC/pull/51

It's mostly just subtle changes and minor fixes.

Cheers,
Chris