Post by tsh73 on Nov 17, 2023 11:50:26 GMT
Actually cat's head. Lookalike.
Will try to make it interactive, lust add 4 sliders for those p1..p4...
Will try to make it interactive, lust add 4 sliders for those p1..p4...
'cat graph; in progress
'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..10
For i = 1 To 4
p(i)=5
Next i
open "cat function" for graphics_nsb_nf as #grFunc
print #grFunc, "trapclose [trapcloseLabel]"
print #grFunc, "home ; down ; posxy cx cy"
'cx, cy give us width, height
width = 2*cx : height = 2*cy
'sample interval
a = 0-pi
b = pi
'
n = 300 'nPoints
h = (b-a)/n
'minX = a : maxX = b
minX = -2 : maxX = 2
' 'get y bounds
' minY = 1e10
' maxY = -1e10
' for x = a to b step h
' y = func(x)
' if y< minY then minY = y
' if y> maxY then maxY = y
' next x
minY = -2 : maxY = 2
print "ymin, ymax ", minY, maxY
'axes
xxmin = sx(a) : xxmax = sx(b) : y0 = sy(0)
print #grFunc, "line ";xxmin;" ";y0;" "; xxmax;" ";y0 'horiz from A to B
print #grFunc, "place ";xxmax-15;" ";y0-5
print #grFunc, "\X"
yymin = sy(minY) : yymax = sy(maxY) : x0 = sx(0)
print #grFunc, "line ";x0;" ";yymin;" "; x0;" ";yymax 'vert ymin to ymax
print #grFunc, "place ";x0-15;" ";yymax+15
print #grFunc, "\Y"
fi = a
r=(func(fi))
y = sy(r*sin(fi+pi/2))
x = sx(r*cos(fi+pi/2))
print #grFunc, "place "; x; " "; y
for fi = a to b step h
r=(func(fi))
y = sy(r*sin(fi+pi/2)) 'rotate by pi/2
x = sx(r*cos(fi+pi/2))
print #grFunc, "goto "; x; " "; y
next
print #grFunc, "flush"
wait
end
[trapcloseLabel]
close #grFunc
end
'******************************************
'sample function
function func(x)
'func = sin(x)-3*cos(3*x)
'func = sin(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