|
Post by honkytonk on Jun 21, 2022 10:32:04 GMT
Hello friends, The goal is to put a red dot on the light spots, above and to the left of the trace. Ideally left and right. And I can't get away with it. And it's insanely complicated. A little (a lot) of help would be appreciated. Many thanks.
NOMAINWIN mapw=800: maph= 500 WindowWidth=mapw+15: WindowHeight=maph+40 UpperLeftX = 10: UpperLeftY = 20 BUTTON #w.n1, "Go !", [go], UL, 440, 440, 40, 25 GRAPHICBOX #w.g, 5, 5, mapw, maph OPEN "Help" FOR window_nf AS #w #w, "TRAPCLOSE [closeHelp]" #w.g, "when leftButtonDown [point]" #w.g, "down;fill darkgray;color black;backcolor darkgray" #w.g, "font courrier 12 bold" #w.g, "place 20 450": #w.g, "\ Left clic and trace from bottom to top for 5 cm and--->" #w.g, "place 485 450": #w.g, "\ and wait...and see the disaster !!" dim pointx(805), pointy(505), tagx(805), tagy(505) #w.g, "color lightgray;backcolor darkgray" for x=1 to 15 px=int(rnd(1)*790)+1: py=int(rnd(1)*490)+1 [ret] siz=int(rnd(1)*20)+1 if siz < 5 then [ret] #w.g, "size ";siz: #w.g, "set ";px;" ";py pointx(px)=1: pointy(py)=1': pointx(px+1)=1: pointy(py+1)=1 ' pointx(px+2)=1: pointy(py+2)=1': pointx(px+3)=1: pointy(py+3)=1 next x #w.g, "flush" wait [point] #w.g, "when leftButtonMove [trace]" wait [trace] mx=MouseX: my=MouseY #w.g, "color yellow;backcolor darkgray" #w.g, "place ";mx;" ";my: #w.g, "size 1;set" wait [go] #w.g, "color red;backcolor darkgray" g=0 for x=mx-2 to 0 step -1 for y=my-2 to 3 step -1 if pointy(y)=1 and pointx(x)=1 then g=g+1: tagx(g)=x: tagy(g)=y ' pointy(y-1)=0 end if next y next x for x=1 to g #w.g, "size 10": #w.g, "set ";tagx(x);" ";tagy(x) next x wait [closeHelp] CLOSE #w END
|
|
|
Post by tsh73 on Jun 21, 2022 11:26:44 GMT
Your check
if pointy(y)=1 and pointx(x)=1 then makes you all Y for every X and vice versa So you see a grid. It just can't work this way
So instead of big array of points for each pixel store 15 points you actually marked BTW checking just these 15 points is easier and likely faster.
NOMAINWIN mapw=800: maph= 500 WindowWidth=mapw+15: WindowHeight=maph+40 UpperLeftX = 10: UpperLeftY = 20 BUTTON #w.n1, "Go !", [go], UL, 440, 440, 40, 25 GRAPHICBOX #w.g, 5, 5, mapw, maph OPEN "Help" FOR window_nf AS #w #w, "TRAPCLOSE [closeHelp]" #w.g, "when leftButtonDown [point]" #w.g, "down;fill darkgray;color black;backcolor darkgray" #w.g, "font courrier 12 bold" #w.g, "place 20 450": #w.g, "\ Left clic and trace from bottom to top for 5 cm and--->" #w.g, "place 485 450": #w.g, "\ and wait...and see the disaster !!" dim pointx(805), pointy(505), tagx(805), tagy(505) #w.g, "color lightgray;backcolor darkgray" for x=1 to 15 px=int(rnd(1)*790)+1: py=int(rnd(1)*490)+1 [ret] siz=int(rnd(1)*20)+1 if siz < 5 then [ret] #w.g, "size ";siz: #w.g, "set ";px;" ";py 'now x just number of a pont pointx(x)=px: pointy(x)=py 'pointx(px)=1: pointy(py)=1': pointx(px+1)=1: pointy(py+1)=1 ' pointx(px+2)=1: pointy(py+2)=1': pointx(px+3)=1: pointy(py+3)=1 next x #w.g, "flush" wait [point] #w.g, "when leftButtonMove [trace]" wait [trace] mx=MouseX: my=MouseY #w.g, "color yellow;backcolor darkgray" #w.g, "place ";mx;" ";my: #w.g, "size 1;set" wait [go] #w.g, "color red;backcolor darkgray" g=0 'check that 15 points instead for k = 1 to 15 'left top? if pointx(k)<mx and pointy(k)<my then g=g+1: tagx(g)= pointx(k): tagy(g)= pointy(k) end if next
' for x=mx-2 to 0 step -1 ' for y=my-2 to 3 step -1 ' if pointy(y)=1 and pointx(x)=1 then ' g=g+1: tagx(g)=x: tagy(g)=y ' ' pointy(y-1)=0 ' end if ' next y ' next x for x=1 to g #w.g, "size 10": #w.g, "set ";tagx(x);" ";tagy(x) next x wait [closeHelp] CLOSE #w END
|
|
|
Post by honkytonk on Jun 21, 2022 12:25:49 GMT
Oh la la, I've been struggling in all directions with my "1" arrays for a week. And it was so simple. But in fact I wanted to "FIND the light spots by SEARCHING for them, hence the arrays of "1". Your method works on fire, but it's a bit cheating.
|
|
|
Post by tsh73 on Jun 21, 2022 13:18:28 GMT
The problem is, you have array of "x" and array of "y", just two lines But you need matrix of (x,y) - whole plane *then* you could search for (x,y) set to 1.
|
|
|
Post by honkytonk on Jun 21, 2022 13:29:58 GMT
But the full matrix does exist, it is full of "0", right? Is the map
EDIT: But no, I'm stupid. To consider the map as a matrix, I would have had to test the pixels. Or fulling an array with ""0"s
|
|
|
Post by tsh73 on Jun 21, 2022 13:54:54 GMT
New array (or array after REDIM) is filled with 0 allright. But you really need
dim points(805, 505) instead of
dim pointx(805), pointy(505)
|
|
|
Post by tsh73 on Jun 21, 2022 14:00:29 GMT
BTW testing pixels just as possible, though slow just searched this forum: (and search show that you know this function)
'***************************************************** 'GetPixelValue$ returns a string with the RGB values of the pixel 'in coordinates x and y in window/graphicbox names handle$ (e.g, "#main.graph") function GetPixelValue$(x, y, handle$)
'Grab a 1*1 bitmap #handle$, "getbmp gpv "; x; " "; y; " "; 1; " "; 1
'Save in a bmp file bmpsave "gpv", "getpvaluetemp.bmp"
'Open the file for string input and get it's full contents open "getpvaluetemp.bmp" for input as #gpv s$ = input$(#gpv, lof(#gpv)) close #gpv
'Check if user's display is 32-bit, and read the red-green-blue values 'If display 16 bit, then colors are masked. So some last (3 for red, 2 for green, 3 for blue) bits always 0 'That means that you did not get 255 255 255 for white - (248 252 248) instead. You have to experiment 'otherwise function returns nothing (support for other display types could be added (?)) bpp = asc(mid$(s$, 29, 1)) select case bpp case 32 red = asc(mid$(s$, 69, 1)) green = asc(mid$(s$, 68, 1)) blue = asc(mid$(s$, 67, 1)) case 24 '(censored): 24 bit, no palette red = asc(mid$(s$, 57, 1)) green = asc(mid$(s$, 56, 1)) blue = asc(mid$(s$, 55, 1)) 'print red,green, blue case 16 bytes = asc(mid$( s$, 67, 1)) + 256*asc(mid$( s$, 68, 1)) red = (bytes AND 63488) /256 '0xF800 green = (bytes AND 2016) / 32 * 4 '0x7E0 blue = (bytes AND 31) * 8 '0x1F end select
'concatenate the return value, delete temporary file and free memory GetPixelValue$ = using("###",red)+using("####",green)+using("####",blue) kill "getpvaluetemp.bmp" unloadbmp "gpv" end function
|
|
|
Post by honkytonk on Jun 21, 2022 14:09:18 GMT
Continued from . that's it, it works as I want. thank you for opening my eyes
NOMAINWIN mapw=800: maph= 500 WindowWidth=mapw+15: WindowHeight=maph+40 UpperLeftX = 10: UpperLeftY = 20 BUTTON #w.n1, "Go !", [go], UL, 440, 440, 40, 25 GRAPHICBOX #w.g, 5, 5, mapw, maph OPEN "Help" FOR window_nf AS #w #w, "TRAPCLOSE [closeHelp]" #w.g, "when leftButtonDown [point]" #w.g, "down;fill darkgray;color black;backcolor darkgray" #w.g, "font courrier 12 bold" #w.g, "place 20 450": #w.g, "\ Left clic and trace from bottom to top for 5 cm and--->" #w.g, "place 485 450": #w.g, "\ and wait..." dim tagx(805), tagy(505) dim map(800,500) #w.g, "color white;backcolor darkgray" for x=1 to 800 for y=1 to 500 map(x,y)=0 next y #w.g, "place 20 20": #w.g, "\ "; str$(x) next x #w.g, "color lightgray;backcolor darkgray" for x=1 to 15 px=int(rnd(1)*790)+1: py=int(rnd(1)*490)+1 [ret] siz=int(rnd(1)*20)+1 if siz < 5 then [ret] #w.g, "size ";siz: #w.g, "set ";px;" ";py map(px,py)=1 next x #w.g, "flush" wait [point] #w.g, "when leftButtonMove [trace]" wait [trace] mx=MouseX: my=MouseY #w.g, "color yellow;backcolor darkgray" #w.g, "place ";mx;" ";my: #w.g, "size 1;set" wait [go] #w.g, "color white;backcolor darkgray" g=0 #w.g, "color white;backcolor darkgray" for x=1 to 800 for y=my-2 to 3 step -1 if map(x,y)=1 then g=g+1: tagx(g)=x: tagy(g)=y ' pointy(y-1)=0 end if next y #w.g, "place 20 40": #w.g, "\ "; str$(x) next x #w.g, "color red;backcolor darkgray" for x=1 to g #w.g, "size 5": #w.g, "set ";tagx(x);" ";tagy(x) next x wait [closeHelp] CLOSE #w END
|
|
|
Post by honkytonk on Jun 21, 2022 14:17:47 GMT
Continued Yes, I know this method of pixels which saves a lot of time. But my thing was exercise for the brain. I was not likely to get there with my "out of no where" reasoning.
|
|
|
Post by honkytonk on Jun 21, 2022 15:05:45 GMT
Continued Now I want to find the light spot closest to the end of the trace. Would there be a flamboyant method for that? Or will I spend another week there
|
|
|
Post by tsh73 on Jun 21, 2022 15:50:20 GMT
You just count a distance then keep point with minimum distance
nomainwin mapw=800: maph= 500 WindowWidth=mapw+15: WindowHeight=maph+40 UpperLeftX = 10: UpperLeftY = 20 BUTTON #w.n1, "Go !", [go], UL, 440, 440, 40, 25 GRAPHICBOX #w.g, 5, 5, mapw, maph OPEN "Help" FOR window_nf AS #w #w, "TRAPCLOSE [closeHelp]" #w.g, "when leftButtonDown [point]" #w.g, "down;fill darkgray;color black;backcolor darkgray" #w.g, "font courrier 12 bold" #w.g, "place 20 450": #w.g, "\ Left clic and trace from bottom to top for 5 cm and--->" #w.g, "place 485 450": #w.g, "\ and wait..." dim tagx(805), tagy(505) dim map(800,500) #w.g, "color white;backcolor darkgray" for x=1 to 800 for y=1 to 500 map(x,y)=0 next y #w.g, "place 20 20": #w.g, "\ "; str$(x) next x #w.g, "color lightgray;backcolor darkgray" for x=1 to 15 px=int(rnd(1)*790)+1: py=int(rnd(1)*490)+1 [ret] siz=int(rnd(1)*20)+1 if siz < 5 then [ret] #w.g, "size ";siz: #w.g, "set ";px;" ";py map(px,py)=1 next x #w.g, "flush" wait [point] #w.g, "when leftButtonMove [trace]" wait [trace] mx=MouseX: my=MouseY #w.g, "color yellow;backcolor darkgray" #w.g, "place ";mx;" ";my: #w.g, "size 1;set" wait [go] #w.g, "color white;backcolor darkgray" g=1 #w.g, "color white;backcolor darkgray" minDist=1e10 'overly big for x=1 to 800 for y=my-2 to 3 step -1 if map(x,y)=1 then dist = sqr((x-mx)^2+(y-my)^2) 'print mx, my, x, y, dist, minDist if dist < minDist then minDist= dist tagx(g)=x: tagy(g)=y end if ' pointy(y-1)=0 end if next y #w.g, "place 20 40": #w.g, "\ "; str$(x) next x #w.g, "color red;backcolor darkgray" for x=1 to g #w.g, "size 5": #w.g, "set ";tagx(x);" ";tagy(x) next x wait [closeHelp] CLOSE #w END
|
|
|
Post by honkytonk on Jun 21, 2022 16:01:48 GMT
Thanks, I'll look into that. I started with left, right, and vertical distances With a sorting sub. I will see how far I am from the truth.
|
|
|
Post by honkytonk on Jun 21, 2022 16:38:12 GMT
Great shot of the hypotenuse! I was far from the truth and I was determined to get further away from it. I did well to come. Thanks again, big thanks.
|
|
|
Post by honkytonk on Jun 21, 2022 16:57:07 GMT
Continued Gloups ! what is that --->: "minDist=1e10" ? Why minDist=10000000000 ?
EDIT: It's work with 10000
|
|
|
Post by davidk64 on Jun 21, 2022 21:19:39 GMT
Strange sequence. I browsed this post about tracing. Ate some more porridge then thought I'd search JB Archive on joystick since I'd like to use mine on next project. Found this game: Mayhem!It has an arc of the tank shell on it's way! Edit: Tank images from my game since they are not packaged with archive!
|
|