|
Post by honkytonk on Apr 8, 2019 9:20:56 GMT
But no Google with my array
nomainwin haut=200: larg=150 WindowWidth = 205: WindowHeight = 350 UpperLeftX = 100: UpperLeftY = 20 STATICTEXT #w.pp, "N Data", 5, 10, 70, 25 TEXTBOX #w.p, 85, 10, 60, 25 BUTTON #w.new, "New ", [new], UL, 155, 10, 40, 20 BUTTON #w.go, "by array ", [drawback], UL, 10, 40, 80, 20 BUTTON #w.gogo, "by chains ", [chain], UL, 100, 40, 80, 20 STATICTEXT #w.tx, "Clic and move", 20, haut +80, 150, 25 GRAPHICBOX #w.m 10, 70, larg, haut OPEN "Test" FOR window_nf AS #w #w, "TRAPCLOSE [closetest]" [new] #w.p, "" ' p=0: pl=0: x$="": y$="" dim matr(2,haut+2) #w.m "down;fill darkgreen; color white;size 1" #w.m, "when leftButtonMove [keepdraw]" #w.m, "size 2" #w.tx, "!font courrier 14": #w.pp, "!font courrier 14" wait [keepdraw] x=MouseX: y= MouseY matr(1,x)=x: matr(2,x)=y x$=x$+str$(x)+" ": y$=y$+str$(y)+" " #w.m, "set ";matr(1,x);" ";matr(2,x) 'datas in box sure p=p +1: #w.p, str$(p) wait [drawback] #w.m "down;fill darkred; color yellow;size 2" for y=1 to haut for x=1 to larg if matr(1,x)<> 0 or matr(2,x) <> 0 then #w.m, "set ";matr(1,x);" ";matr(2,x) end if next x next y wait [chain] #w.m "down;fill darkpink; color black;size 2" for t=1 to p #w.m, "set ";val(word$(x$,t));" ";val(word$(y$,t)) next t wait [closetest] CLOSE #w END
|
|
|
Post by tsh73 on Apr 8, 2019 11:47:34 GMT
I have no idea what are you up to but
matr(1,x)=x: matr(2,x)=y stores ONE last point for any given X on a picture. (so any X have no more then ONE point. If you move back and forth, only last one is stored)
If you want (??) to store points in array you better use current point number, P, like in
nomainwin haut=200: larg=150 WindowWidth = 205: WindowHeight = 350 UpperLeftX = 100: UpperLeftY = 20 STATICTEXT #w.pp, "N Data", 5, 10, 70, 25 TEXTBOX #w.p, 85, 10, 60, 25 BUTTON #w.new, "New ", [new], UL, 155, 10, 40, 20 BUTTON #w.go, "by array ", [drawback], UL, 10, 40, 80, 20 BUTTON #w.gogo, "by chains ", [chain], UL, 100, 40, 80, 20 STATICTEXT #w.tx, "Clic and move", 20, haut +80, 150, 25 GRAPHICBOX #w.m 10, 70, larg, haut OPEN "Test" FOR window_nf AS #w #w, "TRAPCLOSE [closetest]" [new] #w.p, "" ' p=0: pl=0: x$="": y$="" 'dim matr(2,haut+2) dim matr(2,10000)'big number of points #w.m "down;fill darkgreen; color white;size 1" #w.m, "when leftButtonMove [keepdraw]" #w.m, "size 2" #w.tx, "!font courrier 14": #w.pp, "!font courrier 14" wait [keepdraw] x=MouseX: y= MouseY p=p +1: #w.p, str$(p) matr(1,p)=x: matr(2,p)=y x$=x$+str$(x)+" ": y$=y$+str$(y)+" " #w.m, "set ";matr(1,p);" ";matr(2,p) 'datas in box sure wait [drawback] #w.m "down;fill darkred; color yellow;size 2" for i=1 to p #w.m, "set ";matr(1,i);" ";matr(2,i) next i wait [chain] #w.m "down;fill darkpink; color black;size 2" for t=1 to p #w.m, "set ";val(word$(x$,t));" ";val(word$(y$,t)) next t wait [closetest] CLOSE #w END
|
|
|
Post by honkytonk on Apr 8, 2019 12:34:08 GMT
Oh big big thank you, it's been a week that I stumbled on this problem, your solution is wonderful.
|
|
|
Post by honkytonk on Apr 8, 2019 12:41:39 GMT
What I would like is the whole matrix (the whole window with the polygon drawn in it) and that in an array of the size of the window.
|
|
|
Post by honkytonk on Apr 8, 2019 12:50:08 GMT
In [drawback] when I read, anything that was not written is normally at zero. Why the test does not work well ?
|
|
|
Post by tsh73 on Apr 8, 2019 13:51:02 GMT
"size of the window" is rectangular (2d) array dim matr(larg, haut) So you either have a pont at (x,y) so matr(x,y)=1 or not - then matr(x,y) stays 0 Like this
nomainwin haut=200: larg=150 WindowWidth = 205: WindowHeight = 350 UpperLeftX = 100: UpperLeftY = 20 STATICTEXT #w.pp, "N Data", 5, 10, 70, 25 TEXTBOX #w.p, 85, 10, 60, 25 BUTTON #w.new, "New ", [new], UL, 155, 10, 40, 20 BUTTON #w.go, "by array ", [drawback], UL, 10, 40, 80, 20 BUTTON #w.gogo, "by chains ", [chain], UL, 100, 40, 80, 20 STATICTEXT #w.tx, "Clic and move", 20, haut +80, 150, 25 GRAPHICBOX #w.m 10, 70, larg, haut OPEN "Test" FOR window_nf AS #w #w, "TRAPCLOSE [closetest]" [new] #w.p, "" ' p=0: pl=0: x$="": y$="" dim matr(larg, haut) 'square matrix, dimension larg x haut (width height) #w.m "down;fill darkgreen; color white;size 1" #w.m, "when leftButtonMove [keepdraw]" #w.m, "size 2" #w.tx, "!font courrier 14": #w.pp, "!font courrier 14" wait [keepdraw] x=MouseX: y= MouseY if x<0 or x>larg or y <0 or y > haut then wait 'ot ot falls out of matrix matr(x,y)=1 x$=x$+str$(x)+" ": y$=y$+str$(y)+" " #w.m, "set ";x;" ";y 'datas in box sure p=p +1: #w.p, str$(p) wait [drawback] #w.m "down;fill darkred; color yellow;size 2" for y=1 to haut for x=1 to larg if matr(x,y)<> 0 then #w.m, "set ";x;" ";y end if next x next y wait [chain] #w.m "down;fill darkpink; color black;size 2" for t=1 to p #w.m, "set ";val(word$(x$,t));" ";val(word$(y$,t)) next t wait [closetest] CLOSE #w END
|
|
|
Post by honkytonk on Apr 8, 2019 14:20:54 GMT
Well well it's work fine. Thank you véry much. Now I would like to fill all the outside the polygon with black there's work
|
|
|
Post by tsh73 on Apr 8, 2019 14:27:35 GMT
|
|
|
Post by honkytonk on Apr 8, 2019 14:35:07 GMT
Yes, I have an algorithm in C, another in Pascal and another in unknown language. Transcription is not easy, I'm working on it.
|
|
|
Post by tenochtitlanuk on Apr 8, 2019 15:47:26 GMT
If you swap to JB's 'big brother' Liberty BASIC, you can call a dll easily for flood filling- it is very slow if you instead write your own routine in BASIC! JB code runs in LB and a lot of useful other things are added- and it is free with a few things disabled until you buy a licence. Everything you've learned in JB works exactly the same in LB See www.diga.me.uk/floodFill2.html for an example on my LB webpages. Also, I know a font called 'Courier' but not 'courrier'.
|
|
|
Post by honkytonk on Apr 8, 2019 16:30:15 GMT
Look at this Why does my code work in half?
nomainwin haut=200: larg=150 WindowWidth = 305: WindowHeight = 370 UpperLeftX = 300: UpperLeftY = 20 STATICTEXT #w.pp, "N Data", 5, 10, 70, 25 TEXTBOX #w.p, 85, 10, 60, 25 BUTTON #w.new, "New ", [new], UL, 155, 10, 40, 20 BUTTON #w.sto, "Stop ", [stop], UL, 210, 10, 40, 20 BUTTON #w.go, "by array ", [drawback], UL, 10, 40, 80, 20 STATICTEXT #w.tx, "Clic and move for polygon", 10, haut +80, 230, 25 STATICTEXT #w.txa, "And Try", 10, haut +100, 100, 25 BUTTON #w.try, "Try ", [palpe], UL, 100, 40, 80, 25 GRAPHICBOX #w.m 10, 70, larg, haut OPEN "Test" FOR window_nf AS #w #w, "TRAPCLOSE [closetest]" [new] #w.p, "" ' p=0: pl=0: x$="": y$="" dim matr(larg+1, haut+1) #w.m "down;fill darkgreen; color white;size 1" #w.m, "when leftButtonMove [keepdraw]" #w.m, "size 2" #w.tx, "!font courrier 14": #w.txa, "!font courrier 14" #w.pp, "!font courrier 12": #w.try, "!font courrier 12 bold" wait [keepdraw] x=MouseX: y= MouseY if x<0 or x>larg or y <0 or y > haut then wait 'ot ot falls out of matrix matr(x,y)=1 #w.m, "set ";x;" ";y 'datas in box sure p=p +1: #w.p, str$(p) wait [drawback] #w.m "down;fill darkred; color yellow;size 2" for y=1 to haut for x=1 to larg if matr(x,y)<> 0 then #w.m, "set ";x;" ";y end if next x next y wait '-------------------- [palpe] #w.m, "when mouseMove" #w.m "down;fill darkred" x=1 : y=1 for y=1 to haut if y>= haut then wait gosub [pause] yy=y x=1: scan [ret] scan if sto=1 then wait if x >= larg then next y
if matr(x,y) <> 0 then flag=1 gosub [draw] else gosub [draw] end if
if matr(x,y) <> 0 and flag=1 then flag=0 gosub [draw] else gosub [draw] end if
if matr(x,y) <> 0 and flag=0 then flag=1 gosub [draw] gosub [draw] else gosub [draw] end if ' gosub [draw] ' x=x+1 goto [ret] wait [draw] If flag=0 then #w.m, "down;color cyan;size 1" #w.m, "set ";x;" ";yy x=x+1 end if if flag=1 then x=x+1 return [stop] sto=1: goto [ret] wait [pause] timer 2, [temps] wait [temps] timer 0 return [closetest] CLOSE #w END
|
|
|
Post by Rod on Apr 8, 2019 17:17:43 GMT
You are putting a lot of random dots into the array and onto screen then expecting them to be "joined" without putting in any code to do that. So you must draw the "shape" as lines then fill in between lines. It is a lot more complicated than your code attempts and it will be very slow to draw.
There is some polygon filling code in the archives. One of the "old" gurus, UncleBen or AltBas.
|
|
|
Post by tsh73 on Apr 8, 2019 20:51:05 GMT
Why *should* it work? Wikipedia mentions three algorithms. First is recursive one You can implement it without recursion by explicitly using stack Second is algorithm using queue, ("Forest Fire algorithm") Third one is mase-traversing (right-hand fill method) Now, your code doesn't look like any of that.
EDIT There is a code in the archives comments say it implements Scanline fill It did worked - the problem is I do not remember how it works. jbfilesarchive.com/phpBB3/viewtopic.php?f=5&t=741&p=1163&hilit=flood#p1163
|
|
|
Post by tsh73 on Apr 8, 2019 21:17:22 GMT
Here is simple recursive implementation along Wikipedia en.wikipedia.org/wiki/Flood_fill Stack-based recursive implementation (four-way) size set to 1 - we should see where paint leaks edge is drawn with matr(x,y) =1 Area is filled with matr(x,y) =2 "by array" button draws points where matr(x,y) =1 and resets those points with matr(x,y) =2 to matr(x,y) =0 so it paint leaked we could press "by array" and fix (patch) gaps in the contour. nomainwin global larg, haut haut=200: larg=150 WindowWidth = 305: WindowHeight = 370 UpperLeftX = 300: UpperLeftY = 20 STATICTEXT #w.pp, "N Data", 5, 10, 70, 25 TEXTBOX #w.p, 85, 10, 60, 25 BUTTON #w.new, "New ", [new], UL, 155, 10, 40, 20 BUTTON #w.sto, "Stop ", [stop], UL, 210, 10, 40, 20 BUTTON #w.go, "by array ", [drawback], UL, 10, 40, 80, 20 STATICTEXT #w.tx, "Clic and move for polygon", 10, haut +80, 230, 25 STATICTEXT #w.txa, "And Try", 10, haut +100, 100, 25 BUTTON #w.try, "Try ", [palpe], UL, 100, 40, 80, 25 GRAPHICBOX #w.m 10, 70, larg, haut OPEN "Test" FOR window_nf AS #w #w, "TRAPCLOSE [closetest]" [new] #w.p, "" ' p=0: pl=0: x$="": y$="" dim matr(larg+1, haut+1) #w.m "down;fill darkgreen; color white;size 1" #w.m, "when leftButtonMove [keepdraw]" '#w.m, "size 2" 'leaves gaps!!! #w.tx, "!font courrier 14": #w.txa, "!font courrier 14" #w.pp, "!font courrier 12": #w.try, "!font courrier 12 bold" wait [keepdraw] x=MouseX: y= MouseY if x<0 or x>larg or y <0 or y > haut then wait 'or it falls out of matrix matr(x,y)=1 #w.m, "set ";x;" ";y 'datas in box sure p=p +1: #w.p, str$(p) wait [drawback] '#w.m "down;fill darkred; color yellow;size 2" #w.m "cls" #w.m "down;fill darkred; color yellow" 'no size 2 for y=1 to haut for x=1 to larg if matr(x,y)= 1 then #w.m, "set ";x;" ";y end if if matr(x,y)= 2 then matr(x,y)= 0 'so we can refill it next x next y wait sub FloodFill x,y 'simple recursive implementation 'along Wikipedia 'https://en.wikipedia.org/wiki/Flood_fill 'Stack-based recursive implementation (four-way) SCAN 'global larg, haut - w, h if x <0 or x > larg or y <0 or y >haut then exit sub if matr(x,y) <> 0 then exit sub 'else set colored matr(x,y) =2 'fills matr array - breaks it? #w.m, "set ";x;" ";y call FloodFill x+1,y call FloodFill x,y+1 call FloodFill x-1,y call FloodFill x,y-1 end sub '-------------------- [palpe] #w.m, "when mouseMove" #w.m "down;fill darkred" 'recursive flood fill #w.m, "down;color cyan;size 1" call FloodFill 1,1 wait [pause] timer 2, [temps] wait [temps] timer 0 return [closetest] CLOSE #w END
|
|
|
Post by honkytonk on Apr 9, 2019 7:52:34 GMT
@: tsh73 In your code copied / pasted / modified points in the handle have disappeared. Note: UncleBen, AltBas and Andy amaya are no longer in the membership list. @: Rod: I understand your argument. I work on the rest.
|
|