|
Post by honky on Feb 15, 2024 12:52:59 GMT
Good morning, Either an array of "N" datas "d" from Dmini to Dmaxi I am looking for a generic way to display this data in a window of dimensions: xx, yy And I get lost in N / xx and 1 / dmaxi / yy A means which works for any N, d, xx, and yy. Thank you for.
|
|
|
Post by tsh73 on Feb 15, 2024 13:47:16 GMT
Post some example of data
|
|
|
Post by tenochtitlanuk on Feb 15, 2024 15:38:50 GMT
Inventing some data... nomainwin
xx =1000 ' Your decision on window size yy = 600
N =250 dim dataa( N) ' 'data' is a reserved word
dMax =-1E10 ' used to find largest and smallest datum dMin = 1E10
for i =1 to N dataa( i) =100 *sin( i /20) +30 *sin( i /6) +10 *sin( i /4) dMax =max( dMax, dataa( i)) dMin =min( dMin, dataa( i)) next i
WindowWidth =xx +40 ' Graphics window with allowance for title bar and edge margins WindowHeight =yy +60
open "Data display" for graphics_nsb as #wg
#wg "trapclose quit"
#wg "fill cyan ; color darkblue"
for i =1 to N scrX = 10 +xx *i /N scrY =yy +20 -yy *( dataa( i) -dMin) /( dMax -dMin) #wg "goto "; int( scrX); " "; int( scrY) #wg "down" next i
wait
sub quit h$ close #wg end end sub
|
|
|
Post by honky on Feb 15, 2024 15:50:15 GMT
Ah, okay, we must fix the dimensions of the window Thank you tenochtitlanuk
|
|
|
Post by tsh73 on Feb 15, 2024 17:56:08 GMT
|
|
|
Post by tenochtitlanuk on Feb 15, 2024 18:01:58 GMT
This is slightly expanded to display at random one of 8 pre-defined data-generators. It also shows the max and min it found.Anyone got any other fun Cartesian ( x, y) functions? Makes a pretty attention-grabbing display!
nomainwin
xx =1000 ' Your decision on window size yy = 600
N =250 dim dataa( N) ' 'data' is a reserved word
WindowWidth =xx +40 ' Graphics window with allowance for title bar and edge margins WindowHeight =yy +60
open "Data display" for graphics_nsb as #wg
#wg "trapclose quit"
[again] dMax =-1E10 ' used to find largest and smallest datum dMin = 1E10
#wg "fill cyan ; color darkblue"
choice =int( 1 +8 *rnd( 1)) ' so each time you run it you get a random choice of supplied curve ' choice =8 for i =1 to N select case choice case 1 dataa( i) =300 +50 *rnd( 1) case 2 dataa( i) =100 *sin( i /20) case 3 dataa( i) =100 *sin( i /20) +30 *sin( i /6) +10 *sin( i /4) case 4 dataa( i) =100 *sin( i /20) +5 *sin( i) case 5 dataa( i) =200 +400 *int( i /20) case 6 dataa( i) =200 +400 *( i mod 30) case 7 dataa( i) =exp( ( i -1)/40) case 8 dataa( i) =exp( ( 1 -i)/40) end select
dMax =max( dMax, dataa( i)) dMin =min( dMin, dataa( i)) next i
for i =1 to N scrX = 10 +xx *i /N scrY =yy +20 -yy *( dataa( i) -dMin) /( dMax -dMin) #wg "goto "; int( scrX); " "; int( scrY) #wg "down" next i
#wg "color red ; font 12 ; backcolor cyan" #wg "up ; goto "; xx /2 -30; " 40; down" #wg "\"; "dMax = "; dMax #wg "up ; goto "; xx /2 -30; " "; yy; " down" #wg "\"; "dMin = "; dMin #wg "color darkblue" #wg "up ; goto "; 30; " "; yy; " down" #wg "\"; "Number of samples = "; N
timer 4000, [on] wait [on] timer 0
goto [again]
wait
sub quit h$ close #wg end end sub
|
|
|
Post by tsh73 on Feb 16, 2024 8:07:10 GMT
Re: other fun Cartesian ( x, y) functions ABS(x)^(2/3)+SQR(1-X^2) ABS(x)^(2/3)-SQR(1-X^2) from -1 to 1 looks pretty nice. But it needs 2 functions (+ and - branches) drawn at single plane. Also, x*sin(1/x) from -0.4 to 0.4 Also, constructing square wave of sine waves www.mathsisfun.com/calculus/fourier-series.html
|
|
|
Post by honky on Feb 16, 2024 10:30:32 GMT
.@: tenochtitlanuk: Wow, it's masterful. @: tsh73: Thank you for the very goods links. But, dataa= ABS(x)^(2/3)+SQR(1-X^2) return "divide by 0". dataa= ABS(x)^(2/3)-SQR(1-X^2) return "divide by 0". dataa= x*sin(1/x) from -0.4 to 0.4 return "syntax error"
|
|
|
Post by tsh73 on Feb 16, 2024 11:30:52 GMT
Honky, formulas I posted need a bit of work to be pasted into John's (tenochtitlanuk) code Mainly he plots over "i" but functions want "x" (and I mixed up x and X - because I typed it by hand and did not run in JB which makes case distinction)
Here I tweaked it
nomainwin
xx =1000 ' Your decision on window size yy = 600
N =250 dim dataa( N) ' 'data' is a reserved word
WindowWidth =xx +40 ' Graphics window with allowance for title bar and edge margins WindowHeight =yy +60
open "Data display" for graphics_nsb as #wg
#wg "trapclose quit"
[again] dMax =-1E10 ' used to find largest and smallest datum dMin = 1E10
#wg "fill cyan ; color darkblue"
choice =int( 1 +8 *rnd( 1)) ' so each time you run it you get a random choice of supplied curve 'use only first 3 choice =int( 1 +3 *rnd( 1)) ' choice =8 for i =1 to N select case choice case 1 'N=250, 1..N -> -1..1 x=-1+2*(i/N) dataa( i) =ABS(x)^(2/3)+SQR(1-x^2) 'Heart-shape top case 2 x=-1+2*(i/N) dataa( i) =ABS(x)^(2/3)-SQR(1-x^2) 'Heart-shape top case 3 'N=250, 1..N -> -0.4..0.4 x=-0.4+0.8*(i/N) '0 is not valid (1/0), so change it if x=0 then x=1e-10 dataa( i) =x*sin(1/x) case 4 dataa( i) =100 *sin( i /20) +5 *sin( i) case 5 dataa( i) =200 +400 *int( i /20) case 6 dataa( i) =200 +400 *( i mod 30) case 7 dataa( i) =exp( ( i -1)/40) case 8 dataa( i) =exp( ( 1 -i)/40) end select
dMax =max( dMax, dataa( i)) dMin =min( dMin, dataa( i)) next i
for i =1 to N scrX = 10 +xx *i /N scrY =yy +20 -yy *( dataa( i) -dMin) /( dMax -dMin) #wg "goto "; int( scrX); " "; int( scrY) #wg "down" next i
#wg "color red ; font 12 ; backcolor cyan" #wg "up ; goto "; xx /2 -30; " 40; down" #wg "\"; "dMax = "; dMax #wg "up ; goto "; xx /2 -30; " "; yy; " down" #wg "\"; "dMin = "; dMin #wg "color darkblue" #wg "up ; goto "; 30; " "; yy; " down" #wg "\"; "Number of samples = "; N
timer 4000, [on] wait [on] timer 0
goto [again]
wait
sub quit h$ close #wg end end sub
|
|
|
Post by honky on Feb 16, 2024 13:38:01 GMT
@: tsh73: Good, very good.
|
|