General FreeBASIC programming questions.
albert
Posts: 6000 Joined: Sep 28, 2006 2:41
Location: California, USA
Post
by albert » Nov 10, 2019 20:30
Here's Abstract_0136.bas
Code: Select all
'===========================================================================
dim as single c1,c2
dim as single s1,s2
dim as single x1,x2
dim as single y1,y2
dim as single deg1,deg2
dim as single rad
dim as integer xctr, yctr, radius, divisions, fullcircle, toggle
dim as integer xres,yres
screeninfo xres,yres
screenres xres , yres , 8 , 1 , 8
xctr = xres / 2
yctr = yres / 2 -10
'radius = (xres*yres)/((xres+yres)*4)
radius = 3000
divisions = 45
rad = atn( 1 ) / divisions
fullcircle = atn( 1 ) * 8 / rad
for 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
next
Sleep
System
albert
Posts: 6000 Joined: Sep 28, 2006 2:41
Location: California, USA
Post
by albert » Nov 10, 2019 23:57
@EveryOne
How do you make a spiral in trigonometry?
Just a single loop ( for - next )
albert
Posts: 6000 Joined: Sep 28, 2006 2:41
Location: California, USA
Post
by albert » Nov 11, 2019 0:21
Making single loop doodles.. To create patterns for the double loop doodles.
Here's pat_009.bas
Code: Select all
' From galactic-chicken.bas
dim as single c2
dim as single s2
dim as single x2
dim as single y2
dim as single deg2
dim as single rad2
dim as integer xctr , yctr , radius , divisions , fullcircle
dim as integer xres , yres
'screen 19
screeninfo xres , yres
screenres xres , yres , 8 , 1 , 8
xctr = xres / 2
yctr = yres / 2
'radius = (xres*yres)/((xres+yres)*4)
radius = 200
divisions = 45
rad2 = atn( 1 ) / divisions
fullcircle = atn( 1 ) * 8 / rad2
do
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
next
loop until inkey <>""
albert
Posts: 6000 Joined: Sep 28, 2006 2:41
Location: California, USA
Post
by albert » Nov 11, 2019 0:25
Here's pat_010.bas
Code: Select all
' From galactic-chicken.bas
dim as single c2
dim as single s2
dim as single x2
dim as single y2
dim as single deg2
dim as single rad2
dim as integer xctr , yctr , radius , divisions , fullcircle
dim as integer xres , yres
'screen 19
screeninfo xres , yres
screenres xres , yres , 8 , 1 , 8
xctr = xres / 2
yctr = yres / 2
'radius = (xres*yres)/((xres+yres)*4)
radius = 200
divisions = 45
rad2 = atn( 1 ) / divisions
fullcircle = atn( 1 ) * 8 / rad2
do
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
next
loop until inkey <>""
albert
Posts: 6000 Joined: Sep 28, 2006 2:41
Location: California, USA
Post
by albert » Nov 11, 2019 0:32
Here's pat_011.bas
Code: Select all
' From galactic-chicken.bas
dim as single c2
dim as single s2
dim as single x2
dim as single y2
dim as single deg2
dim as single rad2
dim as integer xctr , yctr , radius , divisions , fullcircle
dim as integer xres , yres
'screen 19
screeninfo xres , yres
screenres xres , yres , 8 , 1 , 8
xctr = xres / 2
yctr = yres / 2
'radius = (xres*yres)/((xres+yres)*4)
radius = 200
divisions = 45
rad2 = atn( 1 ) / divisions
fullcircle = atn( 1 ) * 8 / rad2
do
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
next
loop until inkey <>""
albert
Posts: 6000 Joined: Sep 28, 2006 2:41
Location: California, USA
Post
by albert » Nov 11, 2019 0:40
Here's Pat_012.bas
Code: Select all
' From galactic-chicken.bas
dim as single c2
dim as single s2
dim as single x2
dim as single y2
dim as single deg2
dim as single rad2
dim as integer xctr , yctr , radius , divisions , fullcircle
dim as integer xres , yres
'screen 19
screeninfo xres , yres
screenres xres , yres , 8 , 1 , 8
xctr = xres / 2
yctr = yres / 2
'radius = (xres*yres)/((xres+yres)*4)
radius = 1500
divisions = 45
rad2 = atn( 1 ) / divisions
fullcircle = atn( 1 ) * 8 / rad2
do
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
next
loop until inkey <>""
albert
Posts: 6000 Joined: Sep 28, 2006 2:41
Location: California, USA
Post
by albert » Nov 11, 2019 0:44
Here's Pat_013.bas
Code: Select all
' From galactic-chicken.bas
dim as single c2
dim as single s2
dim as single x2
dim as single y2
dim as single deg2
dim as single rad2
dim as integer xctr , yctr , radius , divisions , fullcircle
dim as integer xres , yres
'screen 19
screeninfo xres , yres
screenres xres , yres , 8 , 1 , 8
xctr = xres / 2
yctr = yres / 2
'radius = (xres*yres)/((xres+yres)*4)
radius = 4000
divisions = 45
rad2 = atn( 1 ) / divisions
fullcircle = atn( 1 ) * 8 / rad2
do
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
next
loop until inkey <>""
albert
Posts: 6000 Joined: Sep 28, 2006 2:41
Location: California, USA
Post
by albert » Nov 11, 2019 0:47
Here's Pat_014.bas
( You can get some pretty cool doodles with a single loop. )
Code: Select all
' From galactic-chicken.bas
dim as single c2
dim as single s2
dim as single x2
dim as single y2
dim as single deg2
dim as single rad2
dim as integer xctr , yctr , radius , divisions , fullcircle
dim as integer xres , yres
'screen 19
screeninfo xres , yres
screenres xres , yres , 8 , 1 , 8
xctr = xres / 2
yctr = yres / 2
'radius = (xres*yres)/((xres+yres)*4)
radius = 3500
divisions = 45
rad2 = atn( 1 ) / divisions
fullcircle = atn( 1 ) * 8 / rad2
do
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
next
loop until inkey <>""
Richard
Posts: 3096 Joined: Jan 15, 2007 20:44
Location: Australia
Post
by Richard » Nov 11, 2019 1:12
Draw a spiral by increasing the radius with each step.
Changed radius to single.
Code: Select all
' spiral
Dim As Single c2
Dim As Single s2
Dim As Single x2
Dim As Single y2
Dim As Single deg2
Dim As Single rad2
Dim As single xctr, yctr, radius, divisions, fullcircle
' screen 19
Dim As Integer xres, yres
Screeninfo xres, yres
Screenres xres, yres, 4
xctr = xres / 2
yctr = yres / 2
'radius = (xres*yres)/((xres+yres)*4)
radius = 1
divisions = 45
rad2 = Atn( 1 ) / divisions
fullcircle = 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: 6000 Joined: Sep 28, 2006 2:41
Location: California, USA
Post
by albert » Nov 11, 2019 1:48
@Richard
Thanks for the code...
Here's Pat_015.bas ( close to a spiral )
Code: Select all
dim as single c2
dim as single s2
dim as single x2
dim as single y2
dim as single deg2
dim as single rad2
dim as integer xctr , yctr , radius , divisions , fullcircle
dim as integer xres , yres
'screen 19
screeninfo xres , yres
screenres xres , yres , 8 , 1 , 8
xctr = xres / 2
yctr = yres / 2
'radius = (xres*yres)/((xres+yres)*4)
radius = 150
divisions = 45
rad2 = atn( 1 ) / divisions
fullcircle = atn( 1 ) * 8 / rad2
do
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
next
loop until inkey <>""
albert
Posts: 6000 Joined: Sep 28, 2006 2:41
Location: California, USA
Post
by albert » Nov 11, 2019 1:59
@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
' spiral
Dim As Single c2
Dim As Single s2
Dim As Single x2
Dim As Single y2
Dim As Single deg2
Dim As Single rad2
Dim As single xctr, yctr, radius, divisions, fullcircle
' screen 19
Dim As Integer xres, yres
Screeninfo xres, yres
Screenres xres, yres, 4
xctr = xres / 2
yctr = yres / 2
'radius = (xres*yres)/((xres+yres)*4)
radius = 1
divisions = 45
rad2 = Atn( 1 ) / divisions
fullcircle = 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: 6000 Joined: Sep 28, 2006 2:41
Location: California, USA
Post
by albert » Nov 11, 2019 3:07
@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: 6000 Joined: Sep 28, 2006 2:41
Location: California, USA
Post
by albert » Nov 11, 2019 3:29
@Richard
I recreated the spiral formula....
Here's Pat_016.bas
Code: Select all
dim as single c2
dim as single s2
dim as single x2
dim as single y2
dim as single deg2
dim as single rad2
dim as integer xctr , yctr , radius , divisions , fullcircle
dim as integer xres , yres
'screen 19
screeninfo xres , yres
screenres xres , yres , 8 , 1 , 8
xctr = xres / 2
yctr = yres / 2
'radius = (xres*yres)/((xres+yres)*4)
radius = 100
divisions = 45
rad2 = atn( 1 ) / divisions
fullcircle = atn( 1 ) * 8 / rad2
do
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
next
loop until inkey <>""
albert
Posts: 6000 Joined: Sep 28, 2006 2:41
Location: California, USA
Post
by albert » Nov 11, 2019 4:02
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: 3096 Joined: Jan 15, 2007 20:44
Location: Australia
Post
by Richard » Nov 11, 2019 10:05
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, yctr
Screeninfo xres, yres
Screenres xres, yres, 4
xctr = xres \ 2
yctr = yres \ 2
'----------------------------------
Dim As Double turns, steps_per_turn, rate_of_growth
Dim As Double vx, vy, t, sint, cost, temp
'----------------------------------
' set the spiral parameters here
turns = 5
steps_per_turn = 90
rate_of_growth = 0.995 ' per step
' starting point is relative to origin
vx = yctr
vy = 0
'----------------------------------
' precompute
Const As Double TwoPi = 8 * Atn( 1 )
t = TwoPi / steps_per_turn ' radians per step
cost = Cos( t ) * rate_of_growth
sint = -Sin( t ) * rate_of_growth
'----------------------------------
' now go round in logarithmic spirals
Pset( vx + xctr, vy + yctr ), 0
For 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