[ratkaistu] pikselille lukuarvo

Voit pyytää apua ohjelmointiongelmiin täältä.
Post Reply
User avatar
duck
Member
Posts: 80
Joined: Sun Sep 09, 2007 4:41 pm

[ratkaistu] pikselille lukuarvo

Post by duck »

terve!

minulla on kuva labyrintti.png, ja siihen pitäisi tehdä wavefront tyyppinen lyhimmän reitin selvittäminen.
mustat pikselit ovat seinää ja valkoiset vapaata aluetta.

eli kysymys olis että miten coolbasicissa vois antaa tietylle pikselille lukuarvon? vai voiko? ja miten voin määrittää esim. labyrintin alkupisteeksi pikselin x10,y10 tms.
lisäksi en ole ihan varma miten voin muuttaa kuvan matriksi muotoon?

jos johonkin osaisi joku vastata, olisin kiitollinen :D
tämä liittyy yhteen koulutyöhön, olisin voinut tehdä projektin myös c++:lla mutta siitä ei ole kokemusta ja opetteluun ei ole aikaa.
Last edited by duck on Mon Oct 20, 2014 11:01 am, edited 2 times in total.
Lentäjä-ässä:
lentäjä-ässä
MrMonday
Advanced Member
Posts: 378
Joined: Fri Oct 10, 2008 2:35 pm

Re: pikselille lukuarvo (wavefront algorytmiä varten)

Post by MrMonday »

Itselle tulisi mieleen luoda kaksiulotteinen taulukko kuvan mittojen pohjalta, ja sitten käydä loopilla läpi kuvan pikseleiden väriarvot, joiden mukaan taulukkoon merkittäisiin esim. mustan kohdalle 0 ja valkoisen kohdalle 1, ja siten jokaisella pikselillä olisi tavallaan oma lukuarvonsa..
User avatar
CCE
Artist
Artist
Posts: 650
Joined: Mon Aug 27, 2007 9:53 pm

Re: pikselille lukuarvo (wavefront algorytmiä varten)

Post by CCE »

Voit luoda kaksiulotteisen taulukon, tai sitten lukea kuvan pikseleitä suoraan. CoolBasicin näyttöpuskurin pikseliformaatti on perus kahdeksanbittinen ARGB, joka tarkoittaa että jokaista pikseliä kohden on varattu neljä tavua muistia. Näistä A on alpha-kanava joka on tässä tapauksessa aina arvoltaan 255.

Alla on esimerkki eri kanavien erottamisesta pikseliarvosta. Jokainen pikseli voidaan esittää 32-bittisenä etumerkillisenä kokonaislukuna, josta yksittäiset värikanavat kaivellaan bittioperaatioiden avulla.

Code: Select all

img = loadImage("media/map.bmp")

repeat
	drawImage img, 0, 0

	lock image(img)
	pikkels = getPixel2(mouseX(), mouseY(), image(img))
	unlock image(img)
	
	// shr on bittisiirto oikealle, ja shl vasemmalle
	a = (pikkels shr 24) mod 256 
	r = (pikkels shr 16) mod 256
	g = (pikkels shr 8) mod 256
	b = ((pikkels shl 24) shr 24) mod 256 
		
	text 0,0,"Pikseli kokonaislukuna " + pikseli
	text 0,12,"A: " + a + " R: " + r + " G: " + g + " B: " + b
		
	drawScreen	
forever
Jos haluat käyttää kuvaa vain taulukkona, voit kylmästi kirjoittaa pikselin arvoksi esim. nollan tai ykkösen myöhempää lukemista varten. Tällöin tietenkin sen väriarvo menetetään.
Latexi95
Guru
Posts: 1166
Joined: Sat Sep 20, 2008 5:10 pm
Location: Lempäälä

Re: pikselille lukuarvo (wavefront algorytmiä varten)

Post by Latexi95 »

Itse erottaisin väriarvot pikselistä näin:

Code: Select all

a = pixel Shr 24
r = (pixel Shl 8) Shr 24
g = (pixel Shl 16) Shr 24
b = (pixel Shl 24) Shr 24
User avatar
duck
Member
Posts: 80
Joined: Sun Sep 09, 2007 4:41 pm

Re: pikselille lukuarvo (wavefront algorytmiä varten)

Post by duck »

Code: Select all

img = LoadImage("media/map.bmp")

mapsize_x = 400
mapsize_y = 300
Dim array(mapsize_x,mapsize_y)

Repeat
   DrawImage img, 0, 0

   Lock Image(img)
   
      For x = 0 To x = mapsize_x
    For y = 0 To y = mapsize_y        
           
        pikkels = GetPixel2(x, y, Image(img))
        array (x,y) = pikkels
                
    Next y
   Next x

   unlock Image(img)
   
   // shr on bittisiirto oikealle, ja shl vasemmalle
   a = (pikkels shr 24) mod 256 
   r = (pikkels shr 16) mod 256
   g = (pikkels shr 8) mod 256
   b = ((pikkels shl 24) shr 24) mod 256 
      
   Text 0,0,"Pikseli kokonaislukuna " + array (MouseX(),MouseY())
   Text 0,12,"A: " + a + " R: " + r + " G: " + g + " B: " + b
      
   DrawScreen   
Forever
eikö tämän nyt pitäis tehdä taulukon jonka leveys on mapsize_x ja korkeus mapsize_y, ja antaa taulukolle sitten arvon pikkels?
miksi taulukon arvo hiiren sijainnissa ei tulostu ruudulle. :( vai onko taulukko edes nyt saanut mitään eri pikkels:n arvoja.
Lentäjä-ässä:
lentäjä-ässä
Latexi95
Guru
Posts: 1166
Joined: Sat Sep 20, 2008 5:10 pm
Location: Lempäälä

Re: pikselille lukuarvo (wavefront algorytmiä varten)

Post by Latexi95 »

duck wrote: eikö tämän nyt pitäis tehdä taulukon jonka leveys on mapsize_x ja korkeus mapsize_y, ja antaa taulukolle sitten arvon pikkels?
miksi taulukon arvo hiiren sijainnissa ei tulostu ruudulle. :( vai onko taulukko edes nyt saanut mitään eri pikkels:n arvoja.
Sinulla oli For-To loopin syntaksi väärin (ihme että kääntäjä päästi tämän läpi). Siitä syystä taulukkoa ei täytetty. Taulukon täyttämienen muutenkin kannattaa siirtää pois main loopista.
Tämä versio ainakin toimii:

Code: Select all

img = LoadImage("media/map.bmp")

mapsize_x = 400
mapsize_y = 300
Dim array(mapsize_x,mapsize_y)
Lock Image(img)

For x = 0 To mapsize_x
	For y = 0 To mapsize_y        
		pikkels = GetPixel2(x, y, Image(img))
		array (x,y) = pikkels	
	Next y
Next x
Unlock Image(img)

Repeat
   DrawImage img, 0, 0

   
   
   
   // shr on bittisiirto oikealle, ja shl vasemmalle
	pixel = array (MouseX(),MouseY())
	a = pixel Shr 24
	r = (pixel Shl 8) Shr 24
	g = (pixel Shl 16) Shr 24
	b = (pixel Shl 24) Shr 24
      
   Text 0,0,"Pikseli kokonaislukuna " + pixel
   Text 0,12,"A: " + a + " R: " + r + " G: " + g + " B: " + b
      
   DrawScreen   
Forever
User avatar
duck
Member
Posts: 80
Joined: Sun Sep 09, 2007 4:41 pm

Re: pikselille lukuarvo (wavefront algorytmiä varten)

Post by duck »

jep kiitos :D pitäis olla vähä huolellisempi.

osaattekos auttaa sitten sellasessa, kun mun pitäs saada pikselien numerot juoksemaan lähtökohdasta eteenpäin joka suuntaan labyrinttiäni.
tässä kuvassa näette mitä tarkoitan:
Image

nyt koodini tekee niin, että numerot lähtevät yläkulmasta laajenemaan oikealle sekä alas, mutta heti kun tulee mutkia, numerojuoksu loppuu.
ei ajatus kulje ollenkaan miten tän vois toteuttaa järkevästi.

labyrintin tilalle voi laittaa minkä vaan mustavalkosen kuvan.

Code: Select all

SCREEN 900,855 //screen size

img = loadImage("C:\uge3_labyrinth.png")

Const mapsize_x = 900 //here we tell how large is map
Const mapsize_y = 885
Const goalpoint_x = 0 //goalpoint
Const goalpoint_y = 0

Dim array(mapsize_x,mapsize_y) //we make array

Lock Image(img) //we lock image for faster calculation
   For x = 0 To mapsize_x //for loop for whole map
    For y = 0 To mapsize_y            
        pixel = GetPixel2(x, y, Image(img)) //we measure value from pixel located x,y
        If pixel = -1 Then //if loop. white pixel = -1 -> 1, others 0
        pixel = 1
        Else
        pixel = 0
        EndIf
        array (x,y) = pixel //we tell to array that at location x,y pixel value is 1 or 0     
    Next y //ends for loop
   Next x
Unlock Image(img)

array(goalpoint_x,goalpoint_y)=2

x=0
y=0
old_x=0

Repeat


    Repeat
    
		While x<mapsize_x
            old_x = x
            x = x + 1
            If array(x,y) = 1 And array(old_x,y)>1 Then 
                array(x,y)=array(old_x,y)+1
            EndIf
        Wend
        if y<mapsize_y Then 
            y = y + 1
            x = 0
            array(x,y) = y + 1
        EndIf
    Until y>mapsize_y-2 And x>mapsize_x-2

   DrawImage img, 0, 0 //we draw image of labyrinth to location 0,0  
   
   Text 250,10,"array " + array(MouseX(), MouseY()) +", location x " + MouseX()+ "y " + MouseY()
   DrawScreen   
Forever

Attachments
uge3_labyrinth.png
uge3_labyrinth.png (7.51 KiB) Viewed 27628 times
Lentäjä-ässä:
lentäjä-ässä
Latexi95
Guru
Posts: 1166
Joined: Sat Sep 20, 2008 5:10 pm
Location: Lempäälä

Re: pikselille lukuarvo (wavefront algorytmiä varten)

Post by Latexi95 »

En nyt rupea koodia kirjoittamaan, mutta ehdota, että teet Tyypin tätä varten. Tyyppi pitäisi sisällään listan seuraavista käsiveltävistä pisteistä (ja nykyisestä numerosta). Lisäisit ensiksi tyyppiin jäsenen joka merkkaa aloituspistettä. Sen jälkeen teet for-each loopin jossa joka kierroksella tarkistat nykyisen jäsenen ympärillä olevat ruudut ja mikäli niissä ei ole vielä numeroa taulukossa, lisäät sen ja teet niitä pisteitä vastaavat uudet tyypin jäsenet. Tämän jälkeen poistat käsitellyn jäsenen. Loopin pitäisi pyöriä ja käsitellä kaikki ruudut ja kun vapaat ruudut loppuvat myös tyyppi tyhjenee ja loopista poistutaan.
User avatar
CCE
Artist
Artist
Posts: 650
Joined: Mon Aug 27, 2007 9:53 pm

Re: pikselille lukuarvo (wavefront algorytmiä varten)

Post by CCE »

Tarvitset flood fill algoritmin. Kätevin tapa toteuttaa tämä on äskeisellä Wikipedian sivullakin esitelty neljään suuntaan etenevä rekursiivinen täyttö. Ideana on siis tehdä funktio joka täyttää yhden solun (koordinaatit annettu kutsun yhteydessä parametreinä) ja sen jälkeen kutsuu samaa funktiota neljään eri suuntaan, eli koordinaateille (x+1, y), (x-1, y), (x, y-1), (x, y+1). Funktiolla on myös "sukupolven" kertova parametri jota kasvatetaan aina rekursiivisen kutsun yhteydessä.

Oleellista on että funktio terminoituu heti alussa jos annettuissa koordinaateissa on seinätile, tai jo aikaisemmin täytetty ruutu.
Funktion määritelmä voisi näyttää jotakuinkin tälläiseltä:

Code: Select all

Function floodfill(x, y, generation)
// kutsu täällä neljästi floodfill(x+jotain, y+jotain, generation+1)
Endfunction
Edit: CoolBasicista voi tietenkin loppua pino aika nopeaan vähänkään isommilla labyrinteillä, joten Latexi95:n idea on luultavasti parempi.
User avatar
duck
Member
Posts: 80
Joined: Sun Sep 09, 2007 4:41 pm

Re: pikselille lukuarvo (wavefront algorytmiä varten)

Post by duck »

no lähdin tuolla latexin esimerkillä liikkeelle, sen mitä osasin.

Code: Select all

SCREEN 900,855 //screen size

Type wavefront
    Field left_
    Field right_
    Field up_
    Field down_
    Field location_x //location now
    Field location_y
End Type

img = loadImage("C:\uge3_labyrinth.png")

Const mapsize_x = 900 //here we tell how large is map
Const mapsize_y = 885
Const goalpoint_x = 10 //goalpoint
Const goalpoint_y = 85

Dim array(mapsize_x,mapsize_y) //we make array

Lock Image(img) //we lock image for faster calculation
   For x = 0 To mapsize_x //for loop for whole map
    For y = 0 To mapsize_y            
        pixel = GetPixel2(x, y, Image(img)) //we measure value from pixel located x,y
        If pixel = -1 Then //if loop. white pixel = -1 -> 1, others 0
        pixel = 1
        Else
        pixel = 0
        EndIf
        array (x,y) = pixel //we tell to array that at location x,y pixel value is 1 or 0     
    Next y //ends for loop
   Next x
Unlock Image(img)

array(goalpoint_x,goalpoint_y)=2

x=goalpoint_x
y=goalpoint_y


Repeat

wave.wavefront = New (wavefront)
wave\location_x = x
wave\location_y = y
wave\left_ = wave\location_x - 1
wave\right_ = wave\location_x + 1
wave\up_ = wave\location_y - 1
wave\down_ = wave\location_y + 1

For wave.wavefront = Each wavefront
    Text 10,10,"loc"+wave\location_x+" "+wave\location_y
    If array(wave\right_,wave\location_y) = 1 Then array(wave\right_,wave\location_y) = array(wave\location_x,wave\location_y)+1 //jos ollaan "vapaalla" alueella
    If array(wave\left_,wave\location_y) = 1 Then array(wave\left_,wave\location_y) = array(wave\location_x,wave\location_y)+1
    If array(wave\location_x,wave\up_) = 1 Then array(wave\location_x,wave\up_) = array(wave\location_x,wave\location_y)+1
    If array(wave\location_x,wave\down_) = 1 Then array(wave\location_x,wave\down_) = array(wave\location_x,wave\location_y)+1
    
    If array(wave\location_x+2,wave\location_y) = 1 Then //jos edessä on vapaata tilaa, liiku suunnassa x
    x + 1
    ElseIf array(wave\location_x,wave\location_y+2) = 1 Then 
    y + 1
    ElseIf array(wave\location_x-2,wave\location_y) = 1 Then 
    x - 1
    ElseIf array(wave\location_x,wave\location_y-2) = 1 Then 
    y - 1
    EndIf
    
    Delete wave
Next wave


   DrawImage img, 0, 0 //we draw image of labyrinth to location 0,0  
   
   Text 250,10,"array " + array(MouseX(), MouseY()) +", location x " + MouseX()+ "y " + MouseY()
   DrawScreen   
Forever
en täysin hanskaa tätä, nyt mulla tää ohjelma tekee niin että laskee arvoja suuntaan x kunnes törmää seinään, maalaa mennessään 4 vieruskaverille lukuarvot.
kun törmänny, kääntyy ja alkaa eri suuntaan jatkamaan. Ongelma on että se ajaa ittensä umpikujaan, eikä pääse pois. miten vois tämän ratkaista? tuo mun koodi ei varmaankaan oo ihan lähelle sitä mitä haettiin.. pitäis jotenki päästä joka suuntaan yhtäaikaa levittäytymään.

ideoita miten jatkaa tästä?
Lentäjä-ässä:
lentäjä-ässä
Latexi95
Guru
Posts: 1166
Joined: Sat Sep 20, 2008 5:10 pm
Location: Lempäälä

Re: pikselille lukuarvo (wavefront algorytmiä varten)

Post by Latexi95 »

Koodailin ajankuluksi tuon kuvaamani algorithmin:

Code: Select all

SCREEN 900,855 //screen size

Type wavefront
    Field location_x //location now
    Field location_y
End Type
Global img
img = loadImage("C:\uge3_labyrinth.png")

Const mapsize_x = 900 //here we tell how large is map
Const mapsize_y = 885
Const goalpoint_x = 10 //goalpoint
Const goalpoint_y = 85

Dim array(mapsize_x,mapsize_y) //we make array

Lock Image(img) //we lock image for faster calculation
   For x = 0 To mapsize_x //for loop for whole map
    For y = 0 To mapsize_y            
        pixel = GetPixel2(x, y, Image(img)) //we measure value from pixel located x,y
        If pixel = -1 Then //if loop. white pixel = -1 -> 1, others 0
			pixel = 1
        Else
			pixel = 0
        EndIf
        array (x,y) = pixel //we tell to array that at location x,y pixel value is 1 or 0     
    Next y //ends for loop
   Next x
Unlock Image(img)



x=goalpoint_x
y=goalpoint_y


Repeat

	If MouseHit(1) Then
		FloodFillArray(MouseX(), MouseY())
	EndIf




   DrawImage img, 0, 0 //we draw image of labyrinth to location 0,0  
   
   Text 250,10,"array " + array(MouseX(), MouseY()) +", location x " + MouseX()+ "y " + MouseY()
   DrawScreen   
Forever

Function FloodFillArray(startX, startY)
	Lock Image(img)
	array(startX,startY) = 2
	wave.wavefront = New (wavefront)
	wave\location_x = startX
	wave\location_y = startY
	
	For wave.wavefront = Each wavefront
		x = wave\location_x
		y = wave\location_y
		
		//Poista tämä ja lukitukset jos haluat poistaa värjäyksen
		PutPixel2 x, y, 255, Image(img)
		
		num = array(x, y) + 1
		//Tarkistetaan joka suunta
		If x > 0 Then
			//Tyhjä ruutu
			If array(x - 1, y) = 0 Then
				array(x - 1, y) = num
				newWave.wavefront = New (wavefront)
				newWave\location_x = x - 1
				newWave\location_y = y
			EndIf
		EndIf
		If x < mapsize_x - 1 Then
			//Tyhjä ruutu
			If array(x + 1, y) = 0 Then
				array(x + 1, y) = num
				newWave.wavefront = New (wavefront)
				newWave\location_x = x + 1
				newWave\location_y = y
			EndIf
		EndIf
		If y > 0 Then
			//Tyhjä ruutu
			If array(x, y - 1) = 0 Then
				array(x, y - 1) = num
				newWave.wavefront = New (wavefront)
				newWave\location_x = x
				newWave\location_y = y - 1
			EndIf
		EndIf
		If y < mapsize_y - 1 Then
			//Tyhjä ruutu
			If array(x, y + 1) = 0 Then
				array(x, y + 1) = num
				newWave.wavefront = New (wavefront)
				newWave\location_x = x
				newWave\location_y = y + 1
			EndIf
		EndIf
		Delete wave
	Next wave
	Unlock Image(img)
EndFunction
Kannattaisi olla tuo kuva, niin että käytävät ovat pikselin levyisiä, niin flood fill olisi paljon nopeampi.
User avatar
duck
Member
Posts: 80
Joined: Sun Sep 09, 2007 4:41 pm

Re: pikselille lukuarvo (wavefront algorytmiä varten)

Post by duck »

Latexi95 wrote:Koodailin ajankuluksi tuon kuvaamani algorithmin:

Code: Select all

koodi 
Kannattaisi olla tuo kuva, niin että käytävät ovat pikselin levyisiä, niin flood fill olisi paljon nopeampi.
Kiitos todella paljon! Nyt vaan tutustumaan periaatteeseen miten teit sen.
Seuraavaksi mun pitää tehdä lyhimmän reitin piirto alkupisteestä maaliin. mutta enköhän saa tehtyä itse :)
Labyrintin kokoon en voi oikeen vaikuttaa, koska tämä liittyy yhteen projektiin jossa on käytössä kyseinen labyrintti.

Muuten onko coolbasicilla mitenkään mahdollista aukasta .pmg muotoisia kuvia?
EDIT:

laitanpa sen valmiin koodinki tänne jos joku joskus tarvii:

Code: Select all

//WAVEFRONT ALGORITHM
//----------------------------------------------------------------------
//SETUP

    SCREEN 900,855 //screen size that we want to use.

    Type wavefront//we make collections called wavefront
        Field location_x//data we want use, when we call wavefront
        Field location_y//data here is wavefront's location
    End Type//type is ready

    //we load image uge3_labyrinth from this location
    //now location is in the same folder where this program is
    //we call our labyrinth with name img
    img = LoadImage("uge3_labyrinth.png")

    Const mapsize_x = 900 //here we tell how large is map
    Const mapsize_y = 885 
    Const goalpoint_x = 5 //goalpoint
    Const goalpoint_y = 405
    Const startpoint_x = 890 //startpoint
    Const startpoint_y = 450
    robot_x = startpoint_x //robot's location (first startpoint)
    robot_y = startpoint_y
    
    //WE MAKE ARRAY WHERE WE CHANGE PIXELS FROM LABYRINTH TO  NUMBERS
    Dim array(mapsize_x,mapsize_y) //we make array (or is better english word sheet?)
    Lock Image(img) //we lock image for faster calculation
    For x = 0 To mapsize_x //for loop to the whole map
        For y = 0 To mapsize_y     
            //getpixel2 reads value from 32-bit pixel
            pixel = GetPixel2(x, y, Image(img)) //value from labyrinth located x,y
            If pixel = -1 Then //if loop. white pixel = -1
                pixel = 0 //if white -> pixel = 0
            Else
                pixel = 1//if other than white -> pixel = 1
            EndIf//ends if loop
            array (x,y) = pixel //we tell to array that at location x,y pixel value is 1 or 0     
        Next y //return to for loop, until y = mapsize_y
    Next x
    Unlock Image(img)//unlock image, so it can be used in other places also

//---------------------------------------------------------------------------
//MAIN LOOP

    Repeat //repeat starts main loop, repeat it until...

        //FILL NUMBERS TO ARRAY
        FloodFillArray(goalpoint_x, goalpoint_y)//we call function which fills numbers, starting from goal
        
        //START MOVING ROBOT
        If array(startpoint_x,startpoint_y) > 0 Then //first we check that robot's startpoint is not empty 
            Color 255,0,0 //red color for text
            //text location 10,10 where we tell array's number at startpoint -2 (because we start wavefront from 2)
            Text 10,10,"path from start to goal: " + (array(startpoint_x,startpoint_y)-2)
            
            Lock Image(img)//again lock image, so it's faster to draw in it
            While array(robot_x, robot_y) > 2 //loop until robot is in the goalpoint
                //we check if array's number is smaller at right and we are not going to wall
                //if not true, we check left. If that's not true, we check down and if that is not true we check up
                If array(robot_x + 1, robot_y)<array(robot_x, robot_y) And array(robot_x + 1, robot_y) > 1 Then 
                    robot_x + 1 //if true -> move robot right
                ElseIf array(robot_x - 1, robot_y)<array(robot_x, robot_y) And array(robot_x - 1, robot_y) > 1 Then 
                    robot_x - 1 //move robot left
                ElseIf array(robot_x, robot_y + 1)<array(robot_x, robot_y) And array(robot_x, robot_y + 1) > 1 Then 
                    robot_y + 1 //move robot down
                ElseIf array(robot_x, robot_y - 1)<array(robot_x, robot_y) And array(robot_x, robot_y - 1) > 1 Then 
                    robot_y - 1 //move robot up
                EndIf //end for if loop
                PutPixel2 robot_x, robot_y, 255, Image(img)//draw one pixel al robot's location
            Wend //end for while loop
            Unlock Image(img)//unlock image
            
        Else//if happens so badly that robot's loc is still free space
            Text 10,10,"WE DID NOT FIND ANY PATH!"
        EndIf//ends if loop


       DrawImage img, 0, 0 //we draw image of labyrinth to location 0,0 
       
       //if we want to look over labyrinth and see all distances to goalpoint, we call this text, otherwise it can be set as comment
       //mouseX() is location of mouse
       Text 250,10,"array: " + (array(MouseX(), MouseY())-2) +", location x: " + MouseX()+ "y: " + MouseY()
       DrawScreen   //draw everything to screen and clear all what happened before in mainloop 
    Forever //we tell to repeat main loop forever

//---------------------------------------------------------------------------------
//FUNCTION

    Function FloodFillArray(startX, startY)//Function to fill numbers to array. 

       array(startX,startY) = 2 //fill's starting point must be different than free space
       wave.wavefront = New (wavefront)//first wave
       wave\location_x = startX//first wave's starting points
       wave\location_y = startY
       
       For wave.wavefront = Each wavefront//loop where we check every wave
          x = wave\location_x //location x is same as wave's location
          y = wave\location_y
          num = array(x, y) + 1//number in array located x,y +1
          
          //we check every location from x,y: left, right, up, down
          
          If x > 0 Then//check if x is more than zero, so we can't go over map
             If array(x - 1, y) = 0 Then//if location in left is free
                array(x - 1, y) = num//location in left is num (=before location +1)
                newWave.wavefront = New (wavefront)//we make new wave for next round(old wave is deleted in the end)
                newWave\location_x = x - 1//we move our new location to left
                newWave\location_y = y//location in y axel stays
             EndIf//we end if..then loop
          EndIf
          If x < mapsize_x - 1 Then//check if x is less than mapsize
             If array(x + 1, y) = 0 Then//if free pixel in right
                array(x + 1, y) = num
                newWave.wavefront = New (wavefront)//we make new wave also to left
                newWave\location_x = x + 1
                newWave\location_y = y
             EndIf
          EndIf
          If y > 0 Then
             If array(x, y - 1) = 0 Then//if free pixel in up
                array(x, y - 1) = num
                newWave.wavefront = New (wavefront)
                newWave\location_x = x
                newWave\location_y = y - 1
             EndIf
          EndIf
          If y < mapsize_y - 1 Then
             If array(x, y + 1) = 0 Then//if free pixel in down
                array(x, y + 1) = num
                newWave.wavefront = New (wavefront)
                newWave\location_x = x
                newWave\location_y = y + 1
             EndIf
          EndIf
          Delete wave//we delete this wave
       Next wave//next wave, so we return for..each loop again and start with newWave's
    EndFunction//when all possible waves are checked, we end function
[/edit]
Lentäjä-ässä:
lentäjä-ässä
Post Reply