|
Post by honky on Feb 17, 2024 14:28:30 GMT
Good morning, How to make the curve continue continuously? Continue scrolling. thank you for.
nomainwin xx =1000 ' Your decision on window size yy = 600 N =500 dim dataa( N) ' 'data' is a reserved word for i =1 to N ' dataa( i)=100*sin(i/20)+30*sin(i/6)+10*sin(i/4) dataa( i)=100*sin(i/20) dMax=max(dMax,dataa(i)) dMin=min(dMin,dataa(i)) next i WindowWidth=xx+40: WindowHeight=yy+60 UpperLeftX=10: UpperLeftY=10 open "Data display" for graphics_nsb as #wg #wg "trapclose [quit]" #wg "fill cyan ; color darkblue" tx=0 while t=0 scan if tx >=1000 then tx=tx-1000 #wg "set ";tx;" ";int (rY) for i =1 to N scan rX=10+xx*i/N rY=yy+20-yy*(dataa(i)-dMin)/(dMax-dMin) #wg "goto ";int(rX)+tx;" ";int (rY) #wg "down" next i #wg "cls" tx=tx+5 wend wait [quit] close #wg end
|
|
|
Post by tsh73 on Feb 17, 2024 17:53:16 GMT
As they say, there is more then one way to skin a cat One of ways
EDIT Interesting it looks working because
dataa( i)=100*sin(i/20) 500/20/3.14 is almost integer (7.96, ~ 8) Or we would get "step" where function plot is wrapped by MOD So for example
dataa( i)=100*sin(i/25) will not do.
nomainwin xx =1000 ' Your decision on window size yy = 600 N =500 dim dataa( N) ' 'data' is a reserved word for i =1 to N ' dataa( i)=100*sin(i/20)+30*sin(i/6)+10*sin(i/4) dataa( i)=100*sin(i/20) 'this way of scrolling works because N/20/pi is ALMOST integer (!!) dMax=max(dMax,dataa(i)) dMin=min(dMin,dataa(i)) next i
WindowWidth=xx+40: WindowHeight=yy+60 UpperLeftX=10: UpperLeftY=10 open "Data display" for graphics_nsb as #wg #wg "trapclose [quit]" #wg "fill cyan ; color darkblue" #wg "down"
cX=xx/N 'actually intger as 1000/500 = 2 cY=yy/(dMax-dMin) while 1 scan
i=1 j = (i+k+N) mod N +1 rX=10+xx*i/N rY=yy+20-yy*(dataa(j)-dMin)/(dMax-dMin) #wg "set ";rX;" ";int (rY) for i =1 to N j = (i+k+N) mod N +1 scan 'rX=10+xx*i/N ''rX=10+cX*i 'rY=yy+20-yy*(dataa(j)-dMin)/(dMax-dMin) ''rY=yy+20-cY*(dataa(j)-dMin) '#wg "goto ";int(rX);" ";int (rY) #wg "goto ";10+cX*i;" ";int(yy+20-cY*(dataa(j)-dMin)) next i
timer 30, [wait] wait [wait] timer 0
'#wg "cls" #wg "discard" #wg "fill cyan" k=(k-3+N) mod N wend
wait
[quit] close #wg end
|
|
|
Post by tenochtitlanuk on Feb 17, 2024 20:08:09 GMT
Dredged this up from previous forum stuff- when it 'runs out of space' on the rhs it starts scrolling. The delay is needed 'cos LB/JB is a bit slow on graphics in some ways...
Example uses a decaying sin wave. Another good one is 'sin( x) +sin( 1.05 *x)... just change to
if t >599 then #w.g "goto 599 "; 200 -int( 100 *sin( t /5) +100 *sin( 1.1 *t /5)) #w.g "getbmp scr 1 1 599 400" #w.g "cls ; down ; fill cyan ; drawbmp scr 0 1 ; discard" unloadbmp "scr" else #w.g "goto "; int( t); " "; 200 -int( 100 *sin( t /5) +100 *sin( 1.1 *t /5)) end if
nomainwin
WindowWidth =660 WindowHeight =620
graphicbox #w.g, 40, 10, 604, 400
open "y-t scrolling window " for window_nf as #w
t =1
#w "trapclose [quit]"
#w.g "down ; fill cyan ; color darkblue ; size 1 ; flush ; up"
#w.g "goto 1 "; 200 -int( exp( 0 -t /500) *200 *sin( t /10)) #w.g "down"
while 1 =1 if t >599 then #w.g "goto 599 "; 200 -int( exp( 0 -t /500) *200 *sin( t /10)) #w.g "getbmp scr 1 1 599 400" #w.g "cls ; down ; fill cyan ; drawbmp scr 0 1 ; discard" unloadbmp "scr" else #w.g "goto "; int( t); " "; 200 -int( exp( 0 -t /500) *200 *sin( t /10)) end if
t =t +1
timer 100, [goOn] wait [goOn] timer 0 scan wend
[quit] close #w end
|
|
|
Post by plus on Feb 18, 2024 1:43:32 GMT
Can you make a giant bmp sprite and just show parts of it down to point you can repeat it at the start again?
b = b + ...
|
|
|
Post by honky on Feb 18, 2024 10:01:35 GMT
Thank you very much tsh73 and tenochtitlanuk, great experts. I saw what's going on with "i/30". The case is not easy.
|
|
|
Post by honky on Feb 18, 2024 10:02:10 GMT
Can you make a giant bmp sprite and just show parts of it down to point you can repeat it at the start again? b = b + ... The difficulty will be to link the sprite to the variation of the real parameter whose curve is the representation.
|
|
|
Post by plus on Feb 18, 2024 12:09:15 GMT
Actually John is already doing better! what I had in mind. I only suggest changing the timer 100, [goOn] to timer 10, [goOn] because it's too darn slow at 100. Nice work John! b = b + ...
|
|
|
Post by honky on Feb 18, 2024 16:33:50 GMT
It's slow, but it's so beautiful.
|
|
|
Post by tsh73 on Feb 19, 2024 9:13:04 GMT
Somehow initial decaying sin() line desappear then changes became small. Adding
#w.g "posxy xxxx yyyy" #w.g "set ";xxxx;" "; yyyy
in branch "if t >599 then" kind of fixes that.
|
|
|
Post by tenochtitlanuk on Feb 19, 2024 18:06:42 GMT
Here's a version showing assembling a square wave from the Fourier series 'sin x +1/3sin 3x +1 /5 sin 5x .... Easily changed to make triangular or other shapes. See my Fourier pages on my LB website. EDIT ..and synthesizing a triangular ramp function
nomainwin
WindowWidth =660 WindowHeight =460
graphicbox #w.g, 40, 10, 604, 400
open "y-t scrolling window " for window_nf as #w
global t,pi
n =1 t =0 pi =3.14159265
#w "trapclose [quit]"
#w.g "down ; fill cyan ; color darkblue ; size 1 ; flush ; up"
#w.g "goto 1 "; 200 -int( exp( 0 -t /500) *200 *sin( t /10)) #w.g "down"
while 1 =1 funct =fourier( t, n) if t >599 then #w.g "goto 599 "; funct #w.g "getbmp scr 1 1 599 400" #w.g "cls ; down ; fill cyan ; drawbmp scr 0 1 ; discard" unloadbmp "scr" else #w.g "goto "; int( t); " "; funct end if
t =t +1
if int( t mod( 8 *pi *5)) =0 then n =n +2
timer 50, [goOn] wait [goOn] timer 0 scan wend
function fourier( t, n) fourier =0 for k =1 to n step 2 fourier =fourier +sin( k *t /20) /k next k fourier =200 -int( 100 *fourier) end function
[quit] close #w end
|
|
|
Post by tsh73 on Feb 19, 2024 18:53:22 GMT
Wow. Way of adding these waves up is really interesting.
|
|
|
Post by honky on Feb 20, 2024 9:21:08 GMT
@: tenochtitlanuk: One of these days you will create us a sound synthesizer by dint of tinkering with waves.
|
|
|
Post by tenochtitlanuk on Feb 20, 2024 10:51:48 GMT
|
|
|
Post by honky on Feb 20, 2024 13:27:57 GMT
We are not yet in phase distortion, but it's a good start.
|
|
|
Post by tenochtitlanuk on Feb 22, 2024 17:24:35 GMT
If you are into sound effects, this is an LB-generated ring-modulation of a single pure note/tone. I'll put code and link soon to an explanatory page on the LB forum. link to sound produced
|
|