Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
N-pointed star
#6
I did this a while back.  Every once in a while it doesn't make a complete star (not sure why). Someone might find this useful.   
Code: (Select All)
Screen _NewImage(600, 500, 256)
Dim st(100, 10)
Const sx = 1: Const sy = 2: Const pnts = 3: Const sr1 = 4: Const sr2 = 5: Const klr = 6: Const styl = 7
Const hdg = 8: Const mr = 9: Const rtn = 10
Randomize Timer
For st = 0 To 9
    Print "starpoly: a variation of the polygon drawing routine I've posted earlier"
    Print
    Print "Style "; st
    Print "(press any key to continue)"

    starpoly 300, 250, 160, 82, 5, 180, 12, st

    any$ = Input$(1)
    Cls
Next
For s = 1 To 100
    st(s, sr1) = Int(Rnd * 100) + 20
    st(s, sr2) = Int(st(s, sr1) / (1.5 + Rnd * 4))
    st(s, klr) = Int(Rnd * 256)
    st(s, pnts) = Int(5 + Rnd * 10)
    st(s, sx) = Int(Rnd * 700) + 50
    st(s, sy) = Int(Rnd * 400) + 50
    st(s, styl) = Int(Rnd * 13) - 3
    If st(s, styl) < 1 Then st(s, styl) = 0
    st(s, hdg) = Int(Rnd * 360)
    st(s, rtn) = Int(1 + Rnd * 360)
    st(s, mr) = Rnd * 4
Next
Do
    Cls
    _Limit 60

    For s = 1 To 100
        starpoly st(s, sx), st(s, sy), st(s, sr1), st(s, sr2), st(s, pnts), st(s, rtn), st(s, klr), st(s, styl)
        st(s, sx) = st(s, sx) + st(s, mr) * Sin(0.01745329 * st(s, hdg))
        st(s, sy) = st(s, sy) + st(s, mr) * Cos(0.01745329 * st(s, hdg))
        st(s, rtn) = st(s, rtn) + Int(Rnd * 3) + Int(Rnd * 3)
        If st(s, sx) < -50 Or st(s, sx) > 850 Or st(s, sy) < -50 Or st(s, sy) > 550 Then
            st(s, sr1) = Int(Rnd * 100) + 20
            st(s, sr2) = Int(st(s, sr1) / (1.5 + Rnd * 4))
            st(s, klr) = Int(Rnd * 256)
            st(s, pnts) = Int(5 + Rnd * 10)
            st(s, sx) = Int(Rnd * 700) + 50
            st(s, sy) = Int(Rnd * 400) + 50
            st(s, styl) = Int(Rnd * 13) - 3
            If st(s, styl) < 1 Then st(s, styl) = 0

            st(s, hdg) = Int(Rnd * 360)
            st(s, rtn) = Int(1 + Rnd * 360)
            st(s, mr) = Rnd * 4
        End If
        st(s, mr) = st(s, mr) + 0.001
    Next s
    Locate 1, 1: Print "<ESC> to exit"
    _Display
    kk$ = InKey$
Loop Until kk$ = Chr$(27)
End


Sub starpoly (cx, cy, rr, r2, points, turn, klr As _Unsigned Long, style)
    'rr is outer radius
    'r2 is inner radius
    'points= how many points the star has
    'turn is how many degrees to rotate the sta, a turn of 0 will result in a stabdard star point "down"
    'style 0 = star outline
    'style 1 = star outline with line from center to outer radius
    'style 2 = star outline with  line from center to inner radius
    'style 3 = star outline with lines from center to oouter and inner radius
    'styles 4 and up will double the number of points
    'style 4 and up will created variated starbursts , mode 5 and up adding accent lines.
    shapedeg = 360 / points
    Select EveryCase style
        Case 0 To 3
            n = 0
            x = rr * Sin(0.01745329 * turn)
            y = rr * Cos(0.01745329 * turn)
            Line (cx + x, cy + y)-(cx + x, cy + y), klr
            For deg = turn To turn + 360 Step shapedeg / 2
                If n = 0 Then
                    x2 = rr * Sin(0.01745329 * deg)
                    y2 = rr * Cos(0.01745329 * deg)
                End If
                If n = 1 Then
                    x2 = r2 * Sin(0.01745329 * deg)
                    y2 = r2 * Cos(0.01745329 * deg)
                End If
                Line -(cx + x2, cy + y2), klr
                n = n + 1
                If n = 2 Then n = 0
            Next
        Case 1, 3
            n = 0
            For deg = turn To turn + 360 Step shapedeg / 2
                If n = 0 Then
                    x2 = rr * Sin(0.01745329 * deg)
                    y2 = rr * Cos(0.01745329 * deg)
                    Line (cx, cy)-(cx + x2, cy + y2), klr
                End If
                n = n + 1
                If n = 2 Then n = 0
            Next
        Case 2, 3
            n = 0
            For deg = turn To turn + 360 Step shapedeg / 2
                If n = 0 Then
                Else
                    x2 = r2 * Sin(0.01745329 * deg)
                    y2 = r2 * Cos(0.01745329 * deg)
                    Line (cx, cy)-(cx + x2, cy + y2), klr
                End If
                n = n + 1
                If n = 2 Then n = 0
            Next
        Case 4 To 9
            shapedeg = shapedeg / 2
            x = rr * Sin(0.01745329 * turn)
            y = rr * Cos(0.01745329 * turn)
            Line (cx + x, cy + y)-(cx + x, cy + y), klr
            n = 0
            For deg = turn To turn + 360 Step shapedeg / 2
                If n = 0 Then
                    x2 = rr * Sin(0.01745329 * deg)
                    y2 = rr * Cos(0.01745329 * deg)
                End If
                If n = 2 Or n = 4 Then
                    x2 = ((r2 + rr) / 2) * Sin(0.01745329 * deg)
                    y2 = ((r2 + rr) / 2) * Cos(0.01745329 * deg)
                End If
                If n = 1 Or n = 3 Then
                    x2 = r2 * Sin(0.01745329 * deg)
                    y2 = r2 * Cos(0.01745329 * deg)
                End If
                Line -(cx + x2, cy + y2), klr
                n = n + 1
                If n = 4 Then n = 0
            Next
        Case 5, 8, 9
            n = 0
            For deg = turn To turn + 360 Step shapedeg / 2
                If n = 0 Then
                    x2 = rr * Sin(0.01745329 * deg)
                    y2 = rr * Cos(0.01745329 * deg)
                    Line (cx, cy)-(cx + x2, cy + y2), klr
                End If

                n = n + 1
                If n = 4 Then n = 0
            Next
        Case 6, 9
            n = 0
            For deg = turn To turn + 360 Step shapedeg / 2
                If n = 1 Or n = 3 Then
                    x2 = r2 * Sin(0.01745329 * deg)
                    y2 = r2 * Cos(0.01745329 * deg)
                    Line (cx, cy)-(cx + x2, cy + y2), klr
                End If
                n = n + 1
                If n = 4 Then n = 0
            Next
        Case 7, 8, 9
            n = 0
            For deg = turn To turn + 360 Step shapedeg / 2
                If n = 2 Or n = 4 Then
                    x2 = ((r2 + rr) / 2) * Sin(0.01745329 * deg)
                    y2 = ((r2 + rr) / 2) * Cos(0.01745329 * deg)
                    Line (cx, cy)-(cx + x2, cy + y2), klr
                End If
                n = n + 1
                If n = 4 Then n = 0
            Next
    End Select
End Sub
Reply


Messages In This Thread
N-pointed star - by macalwen - 12-09-2024, 05:12 AM
RE: N-pointed star - by macalwen - 12-09-2024, 05:18 AM
RE: N-pointed star - by bplus - 12-09-2024, 12:26 PM
RE: N-pointed star - by bplus - 12-09-2024, 02:09 PM
RE: N-pointed star - by SierraKen - 12-09-2024, 09:44 PM
RE: N-pointed star - by James D Jarvis - 12-09-2024, 10:01 PM
RE: N-pointed star - by NakedApe - 12-10-2024, 12:26 AM
RE: N-pointed star - by macalwen - 12-10-2024, 10:57 AM



Users browsing this thread: 1 Guest(s)