Post by tsh73 on Nov 18, 2023 7:46:51 GMT -5
So
it started with desire to made cat-head shape from circle in polar coordinates
I made it with Excel, columns with fi, r(fi), x=r*cos(fi), ...
Scatter plot over x y
Initially all numbers in a formula were "5".
Then I start fiddling with r(fi). Changing numbers. Changing them in pairs.
You know, magic of Excel - you change single digit, it recalc/redraw on the fly.
Ear-things get bigger/smaller, nearer/far apart...
then I made a mistake
AND A CAT TURNED ITS HEAD
*WHOA*!!
So now it its translated to LB,
controlled using two virtual joysticks, just drag them with a mouse.
Move it!
it started with desire to made cat-head shape from circle in polar coordinates
I made it with Excel, columns with fi, r(fi), x=r*cos(fi), ...
Scatter plot over x y
Initially all numbers in a formula were "5".
Then I start fiddling with r(fi). Changing numbers. Changing them in pairs.
You know, magic of Excel - you change single digit, it recalc/redraw on the fly.
Ear-things get bigger/smaller, nearer/far apart...
then I made a mistake
AND A CAT TURNED ITS HEAD
*WHOA*!!
So now it its translated to LB,
controlled using two virtual joysticks, just drag them with a mouse.
Move it!
'cat graph
'tsh73 Nov 2023
nomainwin
global width, minX, maxX, height, minY, maxY
global pi
pi = acs(-1)
dim p(4) 'global params to be used in function, 2..9
For i = 1 To 4
p(i)=5
Next i
WindowHeight=400
WindowWidthg=300
open "Cat function. Drag the joysticks!" for graphics_nsb_nf as #gr
#gr "trapclose [trapcloseLabel]"
#gr "home ; down ; posxy cx cy"
'cx, cy give us width, height
'but we use lower part, so change it
cy = cy -50
width = 2*cx : height = 2*cy
'virtual joysticks setup
jr=cx*.6/2
jrr=10
jx(0)=cx/2:jy(0)=2*cy
jx(1)=0:jy(1)=0
jx(2)=3*cx/2:jy(2)=2*cy
jx(3)=0:jy(3)=0
'graph setup
'sample interval
a = 0-pi
b = pi
n = 300 'nPoints
h = (b-a)/n
minX = -2 : maxX = 2
minY = -2 : maxY = 2
'gosub [drawACat]
gosub [drawAll]
'virtual joysticks control
#gr "when leftButtonDown [down]"
#gr "when leftButtonMove [move]"
#gr "when leftButtonUp [up]"
#gr "flush"
wait
end
[drawAll]
#gr "cls"
'virtual joysticks
For jj = 0 To 2 step 2
#gr "place ";jx(jj);" ";jy(jj)
#gr "circle ";jr
#gr "place ";jx(jj)+jx(jj+1);" ";jy(jj)+jy(jj+1)
#gr "circle ";jrr
Next
gosub [drawACat]
return
[drawACat]
'first point
fi = a
r=(func(fi))
y = sy(r*sin(fi+pi/2))
x = sx(r*cos(fi+pi/2))
'#gr "place "; x; " "; y
command$="place "; x; " "; y;";"
for fi = a+h to b step h 'the rest
r=(func(fi))
y = int(sy(r*sin(fi+pi/2))) 'rotate by pi/2
x = int(sx(r*cos(fi+pi/2)))
'#gr "goto "; x; " "; y
command$=command$;"goto "; x; " "; y;";"
if len(command$)> 300 then
#gr command$
command$=""
end if
next
#gr command$
return
[down]
move=0
'is we in joystick point?
if distPug(0)<jrr then 'left joystick
'print "left joystick"
move=1
else
if distPug(2)<jrr then 'right joystick
'print "right joystick"
move=2
end if
end if
wait
[move]
if not(move) then wait
jj= (move=2)*2 '1->0, 2->2
'isn't too far?
if distJoy(jj)>jr then wait
'clear old pug
#gr "color white"
#gr "place ";jx(jj)+jx(jj+1);" ";jy(jj)+jy(jj+1)
#gr "circle ";jrr
'write new coord
jx(jj+1)=MouseX-jx(jj)
jy(jj+1)=MouseY-jy(jj)
'draw
#gr "color black"
#gr "place ";jx(jj)+jx(jj+1);" ";jy(jj)+jy(jj+1)
#gr "circle ";jrr
wait
[up]
if not(move) then wait
'convert yx jy -jr..jr to p(), 2..5..9 (5 is center)
p(jj+1)=5+4*jx(jj+1)/jr*(1-jj) 'x is inverted for jj=2
p(jj+2)=5+4*jy(jj+1)/jr
move=0
gosub [drawAll]
wait
[trapcloseLabel]
close #gr
end
'******************************************
function distPug(jj) 'MouseX, MouseY is global
distPug = sqr((jx(jj)+jx(jj+1)-MouseX)^2+((jy(jj)+jy(jj+1)-MouseY))^2)
end function
function distJoy(jj)
distJoy = sqr((jx(jj)-MouseX)^2+((jy(jj)-MouseY))^2)
end function
'sample function
function func(x)
func =1+EXP(0-min(ABS(x-pi/p(1))*p(2),ABS(x+pi/p(3))*p(4)))
end function
'conversions (logical coords to screen)
function sx(x)
'screen X. Depends on width, minX, maxX
sx = (x- minX)/(maxX-minX) * width
end function
function sy(y)
'screen Y. Depends on height, minY, maxY. Upside down.
sy = (1-(y- minY)/(maxY-minY)) * height
end function