Liberty BASIC Community Forum
« RC Polyspirals »

Welcome Guest. Please Login or Register.
Jun 24th, 2017, 2:10pm


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: RC Polyspirals  (Read 352 times)
tenochtitlanuk
Moderator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 1154
xx RC Polyspirals
« Thread started on: Jul 11th, 2016, 2:38pm »

Rosetta Code- polyspiral

A fun one, this! Only run the code if you can face flashing screens! Shown here are just some stills from an actual run... spent a fun hour on this one.

There are still quite a few Rosetta Code examples that can be coded in LB, although the 'low hanging fruit' ones are mostly done. I'd encourage people to look and try one!

User Image

There's lots of scope for varying colour, line width, etc- try making modifications.


Code:
'A Polyspiral is a spiral made of multiple line segments, whereby each segment is
'   larger (or smaller) than the previous one by a given amount.
'   Each segment also changes direction at a given angle.

'The task: animate a series of polyspirals, by drawing a complete spiral then incrementing the angle,
'   and (after clearing the background) drawing the next, and so on.
'   Every spiral will be a frame of the animation.
'   The animation may stop as it goes full circle or continue indefinitely.
'   The given input values may be varied.


nomainwin

WindowWidth  =500
WindowHeight =500

global sScreens: sScreens =0


open "Polyspiral- let me run for a while!!" for graphics_nsb as #wg

    #wg "trapclose [quit]"
    #wg "down ; fill 180 180 250 ; color darkblue ; size 4"
    #wg "when leftButtonDown saveScreen"

    incr        =   0.0


    for iteration =0 to 9999

        #wg "cls ; fill 180 180 250"
        R       = iteration mod 256
        G       = 50
        B       = 255 -R
        #wg "color "; str$( R) +" " +str$( G) +" " +str$( B)

        x1          = 250
        y1          = 250

        incr    = (incr + 0.05) mod 360

        length  = 5
        angle   = incr

        for i = 1 to 150
            x2          = x1 + cos( angle *3.14159265 /180) * length
            y2          = y1 + sin( angle *3.14159265 /180) * length
            #wg "line "; x1; " "; y1; " "; x2; " "; y2
            x1          = x2
            y1          = y2
            length      = length + 3
            angle       = ( angle + incr) mod 360
        next i

        scan

    next iteration

    wait

  [quit]
    close #wg
    end

    sub saveScreen h$, x, y
        #wg "getbmp scr 1 1 500 500"
        'bmpsave "scr", "poly" +right$( "000" +str$( sScreens), 3) + ".bmp" 'un-rem to save screens
        sScreens    = sScreens +1
    end sub
 
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls