Post by johnno56 on May 29, 2019 2:11:01 GMT -6
Here is a little demo that serves little to no purpose... Not mine... Enjoy...
'*******************************************************
' Pliant Grid
'Code found in the LOVECodea wrapper demo programs that
'can be found in SiENEcE's Blog on
' https://github.com/SiENcE/lovecodify/zipball/master
'Converted from LUA to BASIC-256 by UglyMike (12/2011)
'Modified for SDLBasic Johnno56 20.Aug.14
'Modified for RCBasic Johnno56 29.May.19
'*******************************************************
' Graphical Setup
'*******************************************************
canvas_x = 800
canvas_y = 600
WindowOpen(0,"Pliant Grid",0,0,canvas_x,canvas_y,0)
Window(0)
CanvasOpen(0,canvas_x,canvas_y,0,0,canvas_x,canvas_y,0)
Canvas(0)
clearcanvas
'*******************************************************
'Tunable parameters
'*******************************************************
' 1. number & size of cells (lower = better performance)
' when multiplied, they must fit in the window
' grida*cellsizea =< canvas_x
' gridb*cellsizeb =< canvas_y
grida=40
gridb=30
cellsizea=20
cellsizeb=20
' 2. Size of a node (best between 1 and 10)
nodesize=2
' 3. Speed of relaxation (best between 0.5 and 2)
relax=1
' 4. Speed of color fading (best between 0.95 and 0.99)
fade=0.99
' 5. strenght of attraction to mouse (between 10 and 50)
vel=15
' 6. Fall-off of influence (best between 100 and 3000)
dist=800
b = 0
a = 0
'*******************************************************
'Storage reservation & initialisation
'*******************************************************
dim point_origa[grida,gridb]
dim point_origb[grida,gridb]
dim point_worka[grida,gridb]
dim point_workb[grida,gridb]
dim point_dir[grida,gridb]
dim point_vel[grida,gridb]
dim point_dir2[grida,gridb]
dim point_vel2[grida,gridb]
for a=1 to grida-1
for b=1 to gridb-1
point_origa[a,b]=cellsizea*a
point_origb[a,b]=cellsizeb*b
point_worka[a,b]=cellsizea*a
point_workb[a,b]=cellsizeb*b
point_vel[a,b]=0
point_dir[a,b]=0
point_vel2[a,b]=0
point_dir2[a,b]=0
next
next
'*******************************************************
' Variable initialization
'*******************************************************
oldmousey=0
oldmousex=0
newmousex = 0
newmousey = 0
fpstimer=0
'*******************************************************
' Grid update
'*******************************************************
sub updating()
fpstimer=fpstimer+1
if fpstimer>1/75 then
fpstimer=fpstimer-1/75
for a=1 to grida-1
for b=1 to gridb-1
newmousex=mousex
newmousey=mousey
if newmousex<>oldmousex or newmousey<>oldmousey then
xb=newmousey - point_workb[a,b]
ya=newmousex - point_worka[a,b]
if xb<>0 then
point_dir[a,b]= 2*atan ((sqrt(ya*ya+xb*xb)-ya)/xb)
point_vel[a,b]=dist/sqrt(( oldmousey - point_workb[a,b] )^2 + ( oldmousex - (point_worka[a,b]))^2 )
if point_vel[a,b]>vel then
point_vel[a,b]=vel
end if
else
point_dir2[a,b]=0
end if
end if
xb=point_origb[a,b]-point_workb[a,b]
ya=point_origa[a,b]-point_worka[a,b]
if xb<>0 then
point_dir2[a,b]=2*atan((sqrt(ya*ya+xb*xb)-ya)/xb)
point_vel2[a,b]=sqrt((point_origb[a,b]-point_workb[a,b])^2+(point_origa[a,b]-point_worka[a,b])^2)*0.08
else
point_dir2[a,b]=0
end if
if newmousex<>oldmousex or newmousey<>oldmousey then
point_worka[a,b]=point_worka[a,b]+point_vel[a,b]*cos(point_dir[a,b])+point_vel2[a,b]*cos(point_dir2[a,b])
point_workb[a,b]=point_workb[a,b]+point_vel[a,b]*sin(point_dir[a,b])+point_vel2[a,b]*sin(point_dir2[a,b])
else
point_worka[a,b]=point_worka[a,b]+point_vel2[a,b]*cos(point_dir2[a,b])*relax
point_workb[a,b]=point_workb[a,b]+point_vel2[a,b]*sin(point_dir2[a,b])*relax
point_vel[a,b]=point_vel[a,b]*fade
end if
next
next
end if
end sub
'*******************************************************
' Main drawing loop (endless)
'*******************************************************
do
' update the grid
updating()
oldmousex=newmousex
oldmousey=newmousey
' paint the window black
setColor(rgb(0,0,0)) 'color black
RectFill(0,0,canvas_x,canvas_y)
' draw the nodes
for a=1 to grida -1
for b=1 to gridb-1
setColor(rgb(55,55,(55+200*point_vel[a,b]/vel)))
circle(point_worka[a,b],point_workb[a,b],nodesize)
next
next
' draw the connecting lines
for a=1 to grida-2
for b=1 to gridb-2
setColor(rgb(55,55,(55+200*point_vel[a,b]/vel)))
line(point_worka[a,b],point_workb[a,b],point_worka[a+1,b],point_workb[a+1,b])
line(point_worka[a,b],point_workb[a,b],point_worka[a,b+1],point_workb[a,b+1])
next
next
for a = 1 to grida-2
setColor(rgb(55,55,(55+200*point_vel[a,b]/vel)))
line(point_worka[a,b],point_workb[a,b],point_worka[a+1,b],point_workb[a+1,b])
next
for b = 1 to gridb-2
setColor(rgb(55,55,(55+200*point_vel[a,b]/vel)))
line(point_worka[a,b],point_workb[a,b],point_worka[a,b+1],point_workb[a,b+1])
next
update()
loop until key(k_escape) = 1