## Squares

General FreeBASIC programming questions.
albert
Posts: 5676
Joined: Sep 28, 2006 2:41
Location: California, USA

### Re: Squares

Here's Abstract_0136.bas

Code: Select all

`'===========================================================================dim as single c1,c2dim as single s1,s2dim as single x1,x2dim as single y1,y2dim as single deg1,deg2dim as single raddim as integer xctr, yctr, radius, divisions, fullcircle, toggledim as integer xres,yresscreeninfo xres,yresscreenres xres , yres , 8 , 1 , 8xctr = xres / 2yctr = yres / 2 -10'radius = (xres*yres)/((xres+yres)*4)radius = 3000divisions = 45rad = atn( 1 ) / divisionsfullcircle = atn( 1 ) * 8 / radfor deg1 = 0 to fullcircle * 4 step 45                c1 = cos( deg1 * rad * 3 )            s1 = sin( deg1 * rad * 3 )               x1=radius * c1 * ( s1 ^ 4 ) * atan2( deg1 ,  deg2 ) / 3            y1=radius * s1 * ( c1 ^ 4 ) * atan2( deg1 ,  deg2 ) / 3                for deg2 = 0 to fullcircle step .1            c2 = cos( deg2 * rad * 5 )            s2 =  sin( deg2 * rad * 5 )               x2=radius * c2 * ( c1 ^ 2 ) * atan2( x1 , x2 ) * ( atn( c2 * s2 * deg2 * rad ) / 20 )            y2=radius * s2 * ( s1 ^ 2 ) * atan2( y1 , y2 ) * ( atn( s2 * c2 * deg2 * rad ) / 20 )        pset( xctr +x1 +x2 , yctr +y1 +y2 ) , 9        pset( xctr -x1 -x2 , yctr +y1 +y2 ) , 9        pset( xctr +x1 +x2 , yctr -y1 -y2 ) , 9        pset( xctr -x1 -x2 , yctr -y1 -y2 ) , 9               next   nextSleepSystem`
albert
Posts: 5676
Joined: Sep 28, 2006 2:41
Location: California, USA

### Re: Squares

@EveryOne

How do you make a spiral in trigonometry?

Just a single loop ( for - next )
albert
Posts: 5676
Joined: Sep 28, 2006 2:41
Location: California, USA

### Re: Squares

Making single loop doodles.. To create patterns for the double loop doodles.

Here's pat_009.bas

Code: Select all

`' From galactic-chicken.basdim as single c2dim as single s2dim as single x2dim as single y2dim as single deg2dim as single rad2dim as integer xctr , yctr , radius , divisions , fullcircledim as integer xres , yres'screen 19screeninfo xres , yresscreenres xres , yres , 8 , 1 , 8xctr = xres / 2yctr = yres / 2'radius = (xres*yres)/((xres+yres)*4)radius = 200divisions = 45rad2 = atn( 1 ) / divisionsfullcircle = atn( 1 ) * 8 / rad2do           for deg2 = 0 to fullcircle step .1               c2 = cos( deg2 * rad2 )            s2 =  sin( deg2 * rad2 )               x2 = radius * c2 + deg2            y2 = radius * s2 + deg2                        pset( xctr + x2 , yctr + y2 ) , 9            pset( xctr - x2 , yctr + y2 ) , 9            pset( xctr + x2 , yctr - y2 ) , 9            pset( xctr - x2 , yctr - y2 ) , 9                   nextloop until inkey <>""`
albert
Posts: 5676
Joined: Sep 28, 2006 2:41
Location: California, USA

### Re: Squares

Here's pat_010.bas

Code: Select all

`' From galactic-chicken.basdim as single c2dim as single s2dim as single x2dim as single y2dim as single deg2dim as single rad2dim as integer xctr , yctr , radius , divisions , fullcircledim as integer xres , yres'screen 19screeninfo xres , yresscreenres xres , yres , 8 , 1 , 8xctr = xres / 2yctr = yres / 2'radius = (xres*yres)/((xres+yres)*4)radius = 200divisions = 45rad2 = atn( 1 ) / divisionsfullcircle = atn( 1 ) * 8 / rad2do           for deg2 = 0 to fullcircle step .1               c2 = cos( deg2 * rad2 )            s2 =  sin( deg2 * rad2 )               x2 = radius * c2 + deg2 * c2 * c2            y2 = radius * s2 + deg2 * s2 * s2                        pset( xctr + x2 , yctr + y2 ) , 9            pset( xctr - x2 , yctr + y2 ) , 9            pset( xctr + x2 , yctr - y2 ) , 9            pset( xctr - x2 , yctr - y2 ) , 9                   nextloop until inkey <>""`
albert
Posts: 5676
Joined: Sep 28, 2006 2:41
Location: California, USA

### Re: Squares

Here's pat_011.bas

Code: Select all

`' From galactic-chicken.basdim as single c2dim as single s2dim as single x2dim as single y2dim as single deg2dim as single rad2dim as integer xctr , yctr , radius , divisions , fullcircledim as integer xres , yres'screen 19screeninfo xres , yresscreenres xres , yres , 8 , 1 , 8xctr = xres / 2yctr = yres / 2'radius = (xres*yres)/((xres+yres)*4)radius = 200divisions = 45rad2 = atn( 1 ) / divisionsfullcircle = atn( 1 ) * 8 / rad2do           for deg2 = 0 to fullcircle step .1               c2 = cos( deg2 * rad2 )            s2 =  sin( deg2 * rad2 )               x2 = radius * c2 * not s2            y2 = radius * s2 * not c2                        pset( xctr + x2 , yctr + y2 ) , 9            pset( xctr - x2 , yctr + y2 ) , 9            pset( xctr + x2 , yctr - y2 ) , 9            pset( xctr - x2 , yctr - y2 ) , 9                   nextloop until inkey <>""`
albert
Posts: 5676
Joined: Sep 28, 2006 2:41
Location: California, USA

### Re: Squares

Here's Pat_012.bas

Code: Select all

`' From galactic-chicken.basdim as single c2dim as single s2dim as single x2dim as single y2dim as single deg2dim as single rad2dim as integer xctr , yctr , radius , divisions , fullcircledim as integer xres , yres'screen 19screeninfo xres , yresscreenres xres , yres , 8 , 1 , 8xctr = xres / 2yctr = yres / 2'radius = (xres*yres)/((xres+yres)*4)radius = 1500divisions = 45rad2 = atn( 1 ) / divisionsfullcircle = atn( 1 ) * 8 / rad2do           for deg2 = 0 to fullcircle step .1               c2 = cos( deg2 * rad2 )            s2 =  sin( deg2 * rad2 )               x2 = radius * ( c2 * s2 ) / not ( c2 * 9 )            y2 = radius * ( s2 * c2 ) / not ( s2 * 9 )                        pset( xctr + x2 , yctr + y2 ) , 9            pset( xctr - x2 , yctr + y2 ) , 9            pset( xctr + x2 , yctr - y2 ) , 9            pset( xctr - x2 , yctr - y2 ) , 9                   nextloop until inkey <>""`
albert
Posts: 5676
Joined: Sep 28, 2006 2:41
Location: California, USA

### Re: Squares

Here's Pat_013.bas

Code: Select all

`' From galactic-chicken.basdim as single c2dim as single s2dim as single x2dim as single y2dim as single deg2dim as single rad2dim as integer xctr , yctr , radius , divisions , fullcircledim as integer xres , yres'screen 19screeninfo xres , yresscreenres xres , yres , 8 , 1 , 8xctr = xres / 2yctr = yres / 2'radius = (xres*yres)/((xres+yres)*4)radius = 4000divisions = 45rad2 = atn( 1 ) / divisionsfullcircle = atn( 1 ) * 8 / rad2do           for deg2 = 0 to fullcircle step .1               c2 = cos( deg2 * rad2 )            s2 =  sin( deg2 * rad2 )               x2 = radius * ( c2 * s2 ) / not ( c2 * 9 ) + deg2 * c2 / 10            y2 = radius * ( s2 * c2 ) / not ( s2 * 9 ) + deg2 * s2 / 10                        pset( xctr + x2 , yctr + y2 ) , 9            pset( xctr - x2 , yctr + y2 ) , 9            pset( xctr + x2 , yctr - y2 ) , 9            pset( xctr - x2 , yctr - y2 ) , 9                   nextloop until inkey <>""`
albert
Posts: 5676
Joined: Sep 28, 2006 2:41
Location: California, USA

### Re: Squares

Here's Pat_014.bas

( You can get some pretty cool doodles with a single loop. )

Code: Select all

`' From galactic-chicken.basdim as single c2dim as single s2dim as single x2dim as single y2dim as single deg2dim as single rad2dim as integer xctr , yctr , radius , divisions , fullcircledim as integer xres , yres'screen 19screeninfo xres , yresscreenres xres , yres , 8 , 1 , 8xctr = xres / 2yctr = yres / 2'radius = (xres*yres)/((xres+yres)*4)radius = 3500divisions = 45rad2 = atn( 1 ) / divisionsfullcircle = atn( 1 ) * 8 / rad2do           for deg2 = 0 to fullcircle step .01               c2 = cos( deg2 * rad2 * 3 )            s2 =  sin( deg2 * rad2 * 3 )               x2 = radius * ( c2 * s2 ) / not ( c2 * 9 ) + deg2 * c2 / 10            y2 = radius * ( s2 * c2 ) / not ( s2 * 9 ) + deg2 * s2 / 10                        pset( xctr + x2 , yctr + y2 ) , 9            pset( xctr - x2 , yctr + y2 ) , 9            pset( xctr + x2 , yctr - y2 ) , 9            pset( xctr - x2 , yctr - y2 ) , 9                   nextloop until inkey <>""`
Richard
Posts: 3013
Joined: Jan 15, 2007 20:44
Location: Australia

### Re: Squares

Draw a spiral by increasing the radius with each step.

Code: Select all

`' spiralDim As Single c2Dim As Single s2Dim As Single x2Dim As Single y2Dim As Single deg2Dim As Single rad2Dim As single xctr, yctr, radius, divisions, fullcircle' screen 19Dim As Integer xres, yresScreeninfo xres, yresScreenres xres, yres, 4xctr = xres / 2yctr = yres / 2'radius = (xres*yres)/((xres+yres)*4)radius = 1divisions = 45rad2 = Atn( 1 ) / divisionsfullcircle = Atn( 1 ) * 8 / rad2' Do    Pset( xctr, yctr ), 0       ' start in the middle    For deg2 = 0 To fullcircle Step .1                radius = radius + 0.1   ' increase radius of spiral each step        ' radius = radius * 1.002 ' log spiral                c2 = Cos( deg2 )        s2 = Sin( deg2 )                x2 = radius * c2        y2 = radius * s2                line -( xctr + x2 , yctr + y2 ), 14            Next    sleep' Loop Until Len( Inkey )`
albert
Posts: 5676
Joined: Sep 28, 2006 2:41
Location: California, USA

### Re: Squares

@Richard

Thanks for the code...

Here's Pat_015.bas ( close to a spiral )

Code: Select all

`dim as single c2dim as single s2dim as single x2dim as single y2dim as single deg2dim as single rad2dim as integer xctr , yctr , radius , divisions , fullcircledim as integer xres , yres'screen 19screeninfo xres , yresscreenres xres , yres , 8 , 1 , 8xctr = xres / 2yctr = yres / 2'radius = (xres*yres)/((xres+yres)*4)radius = 150divisions = 45rad2 = atn( 1 ) / divisionsfullcircle = atn( 1 ) * 8 / rad2do           for deg2 = 0 to fullcircle step .01               c2 = cos( deg2 * rad2 )            s2 =  sin( deg2 * rad2 )               x2 = radius * ( c2 * s2 ) / ( c2 * 3 ) * not (deg2 * rad2 )            y2 = radius * ( s2 * c2 ) / ( s2 * 3 ) * not (deg2 * rad2 )                        pset( xctr + x2 , yctr + y2 ) , 9            pset( xctr - x2 , yctr + y2 ) , 9            pset( xctr + x2 , yctr - y2 ) , 9            pset( xctr - x2 , yctr - y2 ) , 9                   nextloop until inkey <>""`
albert
Posts: 5676
Joined: Sep 28, 2006 2:41
Location: California, USA

### Re: Squares

@Richard

I played with your spiral code and adapted it to step by different values..

I can't figure out how to make it work , in a nested for - next loop?

Code: Select all

`' spiralDim As Single c2Dim As Single s2Dim As Single x2Dim As Single y2Dim As Single deg2Dim As Single rad2Dim As single xctr, yctr, radius, divisions, fullcircle' screen 19Dim As Integer xres, yresScreeninfo xres, yresScreenres xres, yres, 4xctr = xres / 2yctr = yres / 2'radius = (xres*yres)/((xres+yres)*4)radius = 1divisions = 45rad2 = Atn( 1 ) / divisionsfullcircle = Atn( 1 ) * 8 / rad2' Do    Pset( xctr, yctr ), 0       ' start in the middle    For deg2 = 0 To fullcircle * 16 Step 10               radius = radius + .65   ' increase radius of spiral each step        ' radius = radius * 1.002 ' log spiral               c2 = Cos( deg2 * rad2 )        s2 = Sin( deg2 * rad2 )               x2 = radius * c2        y2 = radius * s2                line -( xctr + x2 , yctr + y2 ), 14           Next   sleep' Loop Until Len( Inkey )`
albert
Posts: 5676
Joined: Sep 28, 2006 2:41
Location: California, USA

### Re: Squares

@Richard

There's a trig formula to create a spiral , without modifying the radius..
It's a formula similar to Abstract_0003.bas

I can't remember the formula.. I'll have to play around , and try to recreate it....
albert
Posts: 5676
Joined: Sep 28, 2006 2:41
Location: California, USA

### Re: Squares

@Richard

I recreated the spiral formula....

Here's Pat_016.bas

Code: Select all

`dim as single c2dim as single s2dim as single x2dim as single y2dim as single deg2dim as single rad2dim as integer xctr , yctr , radius , divisions , fullcircledim as integer xres , yres'screen 19screeninfo xres , yresscreenres xres , yres , 8 , 1 , 8xctr = xres / 2yctr = yres / 2'radius = (xres*yres)/((xres+yres)*4)radius = 100divisions = 45rad2 = atn( 1 ) / divisionsfullcircle = atn( 1 ) * 8 / rad2do           for deg2 = 0 to fullcircle * 8 step .1               c2 = cos( deg2 * rad2 )            s2 =  sin( deg2 * rad2 )               x2 = radius * c2 * atn( deg2 / fullcircle )  / 2 * deg2 * rad2 / 10            y2 = radius * s2 * atn( deg2 / fullcircle )  / 2 * deg2 * rad2 / 10                        pset( xctr + x2 , yctr + y2 ) , 9                    nextloop until inkey <>""`
albert
Posts: 5676
Joined: Sep 28, 2006 2:41
Location: California, USA

### Re: Squares

Someone could make a book of my trig doodles..
Have a glossy picture of the doodle on one page , and the source code on the next page.
Call it "Monster-Trig" or something...
Richard
Posts: 3013
Joined: Jan 15, 2007 20:44
Location: Australia

### Re: Squares

Here is a spiral without lots of sin, cos and atn inside the loop...

Code: Select all

`'----------------------------------' Log spiral'----------------------------------Dim As Integer xres, yres, xctr, yctrScreeninfo xres, yresScreenres xres, yres, 4xctr = xres \ 2yctr = yres \ 2'----------------------------------Dim As Double turns, steps_per_turn, rate_of_growthDim As Double vx, vy, t, sint, cost, temp'----------------------------------' set the spiral parameters hereturns = 5steps_per_turn = 90rate_of_growth = 0.995  ' per step' starting point is relative to originvx = yctrvy = 0'----------------------------------' precomputeConst As Double TwoPi = 8 * Atn( 1 )t = TwoPi / steps_per_turn  ' radians per stepcost = Cos( t ) * rate_of_growthsint = -Sin( t ) * rate_of_growth'----------------------------------' now go round in logarithmic spiralsPset( vx + xctr, vy + yctr ), 0For t = 0 To turns * steps_per_turn    temp = vx    vx = temp * cost - vy * sint     vy = temp * sint + vy * cost        Line -( vx + xctr, vy + yctr ), 12    Next t'----------------------------------Sleep`