|
Post by honkytonk on Jul 1, 2019 8:09:19 GMT
Hello hello, I have a table containing x and y (coordinates). I have the screen dimension (xdisp, ydisp) I would like to render the x and y table relative to the size of the screen. xrelat = x xdisp ?; yrelat= y ydisp ? thank you for. EDIT: I propose for positions: posrelatx = DisplayWidth-DisplayWidth + x And for dimensions: dimrelatx = int(DisplayWidth / DisplayWidth * x) Is it good ?
|
|
|
Post by tsh73 on Jul 1, 2019 14:02:29 GMT
Resize this window by mouse. See if it good for you.
nomainwin open "Resize me by mouse" for graphics_nsb as #gr #gr "trapclose [quit]" #gr "down" #gr "home; posxy cx cy" 'size of client part is cx*2, cy*2 'draw box 75x50 at 100, 150 x0=100:y0=150:w0=75:h0=100 'initial cx cy for scaling cx0=cx:cy0=cy
gosub [draw] timer 300, [tick] wait
[tick] oldCx=cx oldCy=cy #gr "home; posxy cx cy" 'print time$("ms"), cx, cy, oldCx, oldCy if cx<>oldCx or cy <> oldCy then 'print "!!", time$("ms"), cx, cy, oldCx, oldCy gosub [draw] end if wait
[draw] 'calculate. Here we use different scale by x and by y x=x0*cx/cx0 y=y0*cy/cy0 w=w0*cx/cx0 h=h0*cy/cy0 'draw at new position #gr "cls" #gr "place ";x;" ";y #gr "box ";x+w;" ";y+h return
[quit] timer 0 close #gr
|
|
|
Post by B+ on Jul 1, 2019 15:35:05 GMT
As I understand the question, you want to exactly fill the screen with coordinates from table.
So need minX and maxX from table as well as minY and maxY from table.
scaleX = (screen_width / (maxX - minX))
screenX = (x from table - minX) * scaleX ' st minX = 0 and maxX = right edge of screen or screen_width
do likewise for Y's
Yeah it works after fudging WindowWidth and WindowHeight so edge dots are at least partly visible global SW, SH SW = 500 : SH = 300
nomainwin UpperLeftX = 100 UpperLeftY = 10
'fudge screen size to see all dots or their parts WindowWidth = SW + 20 'adjust +10 for screen frame plus slight white frame WindowHeight = SH + 40 'add +32 for screen frame plus slight white frame
open "Plot table - do you see 10 dots or parts?" for graphics_nsb as #gr #gr "trapclose [quit]" #gr "down" #gr "fill black" #gr "color white" #gr "size 10"
'make a fake table dim tableX(100), tableY(100) minX = 1000 : maxX = -1000 : minY = 1000 : maxY = -1000 for i = 1 to 10 tableX(i) = rnd(0)*100 - rnd(0)*50 if tableX(i) < minX then minX = tableX(i) if tableX(i) > maxX then maxX = tableX(i) tableY(i) = rnd(0)*50 - rnd(0)* 25 if tableY(i) < minY then minY = tableY(i) if tableY(i) > maxY then maxY = tableY(i) next
'plot table to fill screen xscale = SW/(maxX-minX) yscale = SH/(maxY-minY) for i = 1 to 10 x = (tableX(i)-minX)*xscale y = (tableY(i)-minY)*yscale #gr "set ";x;" ";y next wait
[quit] timer 0 close #gr end
|
|
|
Post by honkytonk on Jul 2, 2019 14:33:00 GMT
Thank you, your codes works well. But my problem is the different screen size. And as I only have one screen I can not test the screen change (DisplayWidth) posrelatx = DisplayWidth-DisplayWidth + x And for dimensions: dimrelatx = int(DisplayWidth / DisplayWidth * x) Is it good ? Or why not ?
|
|
|
Post by B+ on Jul 2, 2019 14:55:00 GMT
Thank you, your codes works well. But my problem is the different screen size. And as I only have one screen I can not test the screen change (DisplayWidth) posrelatx = DisplayWidth-DisplayWidth + x And for dimensions: dimrelatx = int(DisplayWidth / DisplayWidth * x) Is it good ? Or why not ? I honestly can't tell what you are talking about: DisplayWidth-DisplayWidth = 0 and DisplayWidth / DisplayWidth = 1 so ?? WTH? ;-)) You're spinning your wheels with those formulas. Ah maybe your table goes with DisplayWidth1 and you want to translate those to DisplayWidth2: x1 from table with DisplayWidth1 >>> x2 on DisplayWidth2 (box or screen) x2 = x1 * DisplayWidth2/DisplayWidth1 y2 = y1 * DisplayHeight2/DisplayHeight1 such that if DisplayWidth2 is 2 times DisplayWidth1, you double all the x1's to display on DisplayWidth2 screen or box.
|
|
|
Post by B+ on Jul 2, 2019 17:55:26 GMT
A demo, same data on 3 different screens (or boxes): global SW, SH SW = 500 : SH = 500
nomainwin UpperLeftX = 100 UpperLeftY = 10
'fudge screen size to see all dots or their parts WindowWidth = SW + 20 'adjust +10 for screen frame plus slight white frame WindowHeight = SH + 40 'add +32 for screen frame plus slight white frame
open "Plot the Same Data on Different Screen Sizes" for graphics_nsb as #gr #gr "trapclose [quit]" #gr "down" #gr "fill white" #gr "color black" #gr "size 1"
'make a fake table dim tableX(100), tableY(100) minX = 1000 : maxX = -1000 : minY = 1000 : maxY = -1000 for i = 1 to 20 tableX(i) = rnd(0)*100 + rnd(0)*50 if tableX(i) < minX then minX = tableX(i) if tableX(i) > maxX then maxX = tableX(i) tableY(i) = rnd(0)*50 + rnd(0)* 25 if tableY(i) < minY then minY = tableY(i) if tableY(i) > maxY then maxY = tableY(i) next
dim bx(3), by(3), bw(3), bh(3) bx(1) = 10:by(1) = 10 :bw(1) = 150: bh(1) = 75 bx(2) = 190: by(2) = 10: bw(2) = 300 : bh(2) = 150 bx(3) = 10: by(3) = 170: bw(3) = 480 : bh(3) = 310 call fore 0, 0, 255 call back 255, 0, 0 call fbox bx(1), by(1), bx(1) + bw(1), by(1) + bh(1) call fore 255, 255, 255 for i = 1 to 20 x = bx(1) + tableX(i) y = by(1) + tableY(i) #gr "set ";x;" ";y next #gr "size 2" call fore 255, 0, 0 call back 0, 0, 255 call fbox bx(2), by(2), bx(2) + bw(2), by(2) + bh(2) call fore 255, 255, 255 for i = 1 to 20 x = bx(2) + tableX(i) * bw(2)/bw(1) y = by(2) + tableY(i) * bh(2)/bh(1) #gr "set ";x;" ";y next #gr "size 3" call fore 128, 128, 128 call back 0, 0, 0 call fbox bx(3), by(3), bx(3) + bw(3), by(3) + bh(3) call fore 255, 255, 255 for i = 1 to 20 x = bx(3) + tableX(i) * bw(3)/bw(1) y = by(3) + tableY(i) * bh(3)/bh(1) #gr "set ";x;" ";y next wait
[quit] timer 0 close #gr end
sub fbox x0, y0, x1, y1 #gr "place ";x0;" ";y0 #gr "boxfilled ";x1+1;" ";y1+1 end sub
sub fore r, g, b #gr "color ";r;" ";g;" ";b end sub
sub back r, g, b 'backcolor is used for fills #gr "backcolor ";r;" ";g;" ";b end sub
|
|
|
Post by honkytonk on Jul 3, 2019 14:49:50 GMT
That's what I was looking for. Thank you.
|
|
|
Post by B+ on Jul 3, 2019 16:10:26 GMT
Ah good!
All our problems are solved...
for a second!
|
|