рдПрдл # + рдУрдкрдирдЬреАрдПрд▓ рдкрд░ рдХреЙрдирд╡реЗ рдХрд╛ рдЬреАрд╡рди

рдХреНрдпреЛрдВ рдЪ #?



рд╕рд┐рд░реНрдл рдЗрд╕рд▓рд┐рдП рдХрд┐ рдореИрдВ рдЙрд╕реЗ рдкрд╕рдВрдж рдХрд░рддрд╛ рд╣реВрдВред рдкреНрд░реЛрдЬреЗрдХреНрдЯрдпреВрд▓рд░ рдкрд░ рдХреБрдЫ рджрд░реНрдЬрди рдХрд╛рд░реНрдпреЛрдВ рдХреЛ рд╣рд▓ рдХрд░рдиреЗ рдХреЗ рдмрд╛рдж , рдореИрдВрдиреЗ рдЬреНрдЮрд╛рди рдХрд╛ рдПрдХ рдЕрдзрд┐рдХ рд╡реНрдпрд╛рд╡рд╣рд╛рд░рд┐рдХ рдЕрдиреБрдкреНрд░рдпреЛрдЧ рдЦреЛрдЬрдиреЗ рдФрд░ рдХреБрдЫ рдЬрдЯрд┐рд▓ рдирд╣реАрдВ, рдмрд▓реНрдХрд┐ рдореВрд░реНрдд рд▓рд┐рдЦрдиреЗ рдХрд╛ рдлреИрд╕рд▓рд╛ рдХрд┐рдпрд╛ред

рдХреМрди рдкрд░рд╡рд╛рд╣ рдХрд░рддрд╛ рд╣реИ - рдмрд┐рд▓реНрд▓реА рдореЗрдВ рдЖрдкрдХрд╛ рд╕реНрд╡рд╛рдЧрдд рд╣реИред

рдореИрдВ рддреБрд░рдВрдд рдЖрд░рдХреНрд╖рдг рдХрд░ рджреВрдВрдЧрд╛ред рдореИрдВ рдХрд╛рд░реНрдпрд╛рддреНрдордХ рдкреНрд░реЛрдЧреНрд░рд╛рдорд┐рдВрдЧ рдпрд╛ рдУрдкрдирдЬреАрдПрд▓ рдХреЗ рдХреНрд╖реЗрддреНрд░ рдореЗрдВ рд╡рд┐рд╢реЗрд╖рдЬреНрдЮ рдирд╣реАрдВ рд╣реВрдВ, рдЗрд╕рд▓рд┐рдП рдореБрдЭреЗ рдХрд┐рд╕реА рднреА рд╕рд╛рд░реНрдердХ рдЯрд┐рдкреНрдкрдгреА рдФрд░ рд╕реБрдЭрд╛рд╡реЛрдВ рдкрд░ рдЦреБрд╢реА рд╣реЛрдЧреА рдХрд┐ рдЗрд╕реЗ рдмреЗрд╣рддрд░ / рддреЗрдЬ / рдЕрдзрд┐рдХ рд╕реБрдВрджрд░ рдХреИрд╕реЗ рдмрдирд╛рдпрд╛ рдЬрд╛рдПред

рднрд╛рд╖рд╛ рдХрд╛ рд╡рд░реНрдгрди рдХрд░рдиреЗ рдХрд╛ рдорддрд▓рдм рд╣реА рдирд╣реАрдВ рд╣реИред рдкрд╣рд▓реЗ рд╕реЗ рд╣реА рд╡рд┐рд╖рдп рдкрд░ рдмрд╣реБрдд рд╕рд╛рд░реА рд╕рд╛рдордЧреНрд░реА рд╣реИред
рдЖрдк рд╢реБрд░реБрдЖрдд рдХреЗ рд▓рд┐рдП, рд╡рд┐рдХреА , рдПрдл # рд╡рд┐рдХрд╛рд╕ рдХреЗрдВрджреНрд░ , рдПрдл # 3.0 рдореЗрдВ рдирдпрд╛ рдХреНрдпрд╛ рд╣реИ рджреЗрдЦ рд╕рдХрддреЗ рд╣реИрдВ ред

рддреЛ рдЪрд▓рд┐рдП рд╢реБрд░реВ рдХрд░рддреЗ рд╣реИрдВ


рд╕рдмрд╕реЗ рдкрд╣рд▓реЗ, рд╣рдо рдЕрдкрдиреЗ рд╕реЗрд▓ рдХреЗ рдкреНрд░рдХрд╛рд░ рдирд┐рд░реНрдзрд╛рд░рд┐рдд рдХрд░реЗрдВрдЧреЗ:
type Sex = |Male|Female type Cell = { Sex: Sex; Age: int; Position: (int * int)} 


рд╣рдо рдХреЛрд╢рд┐рдХрд╛рдУрдВ рдХрд╛ рдкреНрд░рддрд┐рдкрд╛рджрди рдХрд░рддреЗ рд╕рдордп рдлрд░реНрд╢ рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд░реЗрдВрдЧреЗред рднрд╡рд┐рд╖реНрдп рдореЗрдВ, рдореИрдВ рдЗрд╕реЗ рдПрд▓реНрдЧреЛрд░рд┐рдереНрдо рдХреЗ рд╕рд╛рде рдкреНрд░рдпреЛрдЧреЛрдВ рдХреЗ рд▓рд┐рдП рдЙрдкрдпреЛрдЧ рдХрд░рдиреЗ рдХреА рдпреЛрдЬрдирд╛ рдмрдирд╛ рд░рд╣рд╛ рд╣реВрдВред
рдЦреЗрд▓ рдХреЗ рд╡реИрд╢реНрд╡рд┐рдХ рдЪрд░ рдШреЛрд╖рд┐рдд рдХрд░реЗрдВ:
 //Globals let mutable (field:Cell[]) = [||] //   let mutable pause = false //   let mutable isInProc = false // ,    let mutable generation = 0 //  let mutable ftime = DateTime.Now // let mutable fps = 0.0 //     fps //   openGL let mutable modelview = Matrix4.LookAt(Vector3.UnitZ, Vector3.Zero, Vector3.UnitY) let mutable Size = 100 //  let mutable CellCount = 2000 //   let mutable LifeLength = 50 //   let mutable ScreenWidth = 500 //    


рдЧреЗрдордкреНрд▓реЗ рдХреЗ рд▓рд┐рдП рдореБрдЦреНрдп рд╡рд░реНрдЧ рдЬрд┐рдореНрдореЗрджрд╛рд░ рд╣реИ


рд╕рдмрд╕реЗ рдкрд╣рд▓реЗ, рд╣рдо рдирдИ рдХреЛрд╢рд┐рдХрд╛рдПрдБ рдмрдирд╛рдиреЗ рдХреЗ рд▓рд┐рдП рддрд░реАрдХреЗ рд▓рд┐рдЦреЗрдВрдЧреЗ:
 type Life() = member this.genCell (rnd:Random) = { Sex = match rnd.Next(2) with |0 -> Sex.Male |_ -> Sex.Female Age=0 Position=(rnd.Next(Size), rnd.Next(Size))} member this.genCells = let rnd = new System.Random() let rec lst (l:list<Cell>) = match l.Length with |c when c = CellCount -> l |_ -> match this.genCell rnd with |c when not (this.existCell (l |> List.toArray) c.Position) -> lst (c::l) |_ -> lst l List.Empty |> lst |> List.toArray 

genCell рд░реИрдВрдбрдо рдСрдмреНрдЬреЗрдХреНрдЯ рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд░рдХреЗ рдПрдХ рдирдпрд╛ рд╕реЗрд▓ рдмрдирд╛рддрд╛ рд╣реИред
genCells рдирдИ рдХреЛрд╢рд┐рдХрд╛рдУрдВ рдХреЗ рд╕рд╛рде рд╕реВрдЪреА рдХреЛ рдкреЙрдкреНрдпреБрд▓реЗрдЯ рдХрд░рддрд╛ рд╣реИред
рдкреБрдирд░рд╛рд╡рд░реНрддреА рдХрд╛рд░реНрдп
 let rec lst (l:list)        ,   . 

:
member this.allNeighbourCells (position:int*int) = let nCells (point:int*int) = let x,y = point [| (x-1, y-1); (x-1, y); (x-1, y+1); (x, y-1); (x, y+1); (x+1, y-1); (x+1, y); (x+1, y+1); |] let (!) pos = let tx = match fst pos with |x when x < 0 -> Size - 1 |x when x >= Size -> 0 |_ -> fst pos let ty = match snd pos with |y when y < 0 -> Size - 1 |y when y >= Size -> 0 |_ -> snd pos (tx, ty) nCells position |> Array.map ((!))

2 :
nCells point
! , , , ┬л┬╗ .

:
member this.existCell field c = field |> Array.exists (fun af -> c = af.Position)
.

member this.partitionfield field = this.allNeighbourCells >> Array.partition(fun c -> this.existCell field c) member this.pFree field = this.partitionfield field >> snd member this.pExist field = this.partitionfield field >> fst
Partitionfield tuple .
pFree, pExist

, :
member this.Iterate (field:Cell[]) = // let freeNeighb = field |> PSeq.collect (fun c -> this.pFree field c.Position) |> Seq.distinct let born = freeNeighb |> Seq.filter (fun c -> this.pExist field c |> Array.length = 3) |> Seq.map(fun c -> let rnd = new System.Random() {this.genCell(rnd) with Position = c}) let alive = field |> PSeq.filter(fun c -> let neighb = this.pExist field c.Position |> Array.length neighb <= 3 && neighb >= 2) |> PSeq.map (fun c -> {c with Age = (c.Age + 1)}) let res = alive |> Seq.append born |> Seq.toArray res
:
, (freeNeighb) , (- = 3) (born) , 2

, OpenGL , .. .
2 :
doNextStep
, :
member this.doNextStep = async{ let res = (this.life.Iterate field) field <- res |> Array.filter(fun c -> c.Age < LifeLength) isInProc <- false generation <- generation + 1 let delta = DateTime.Now - ftime ftime <- DateTime.Now fps <- Math.Round ((fps + 1000.0 / delta.TotalMilliseconds) / 2.0, 1) }
OnRenderFrame
OpenGL, :
override o.OnRenderFrame(e) = base.OnRenderFrame e match (pause, isInProc) with | (false, false) -> isInProc <- true; Async.Start(o.doNextStep) | _ -> () GL.Clear(ClearBufferMask.ColorBufferBit ||| ClearBufferMask.DepthBufferBit) GL.MatrixMode(MatrixMode.Modelview) GL.LoadMatrix(&modelview) field |> Seq.iter (fun c -> o.DrawCell c) if not pause then base.Title <- String.Format("F# Life cell count: {0} Generation: {1} FPS: {2}", (field |> Seq.length), generation, fps) else base.Title <- String.Format("F# Life cell count: {0} Generation: {1} Paused", (field |> Seq.length), generation) base.SwapBuffers()

, , LifeLength:
member this.doNextStep = .... field <- res |> Array.filter(fun c -> c.Age < LifeLength ...

. , :
member this.DrawCell (cell:Cell) = let cellWidth = float32(this.ClientSize.Width) / float32 Size let alpha = match (1.f - float32 cell.Age / float32 LifeLength) with |c when c < 0.f -> 0.f | c -> c let color = match cell.Sex with |Male -> [|0.5f; 0.f; 0.f; alpha|] |Female -> [|0.7f; 0.f; 0.f; alpha|] let pos = (float32 (fst cell.Position) * cellWidth, float32 (snd cell.Position) * cellWidth) GL.Begin(BeginMode.Triangles) GL.Color4 (color) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.End()

:
рдЫрд╡рд┐
- :



.
:)
"" , /

bitbucket
!.

Upd: . :)

let rec lst (l:list) , .

:
member this.allNeighbourCells (position:int*int) = let nCells (point:int*int) = let x,y = point [| (x-1, y-1); (x-1, y); (x-1, y+1); (x, y-1); (x, y+1); (x+1, y-1); (x+1, y); (x+1, y+1); |] let (!) pos = let tx = match fst pos with |x when x < 0 -> Size - 1 |x when x >= Size -> 0 |_ -> fst pos let ty = match snd pos with |y when y < 0 -> Size - 1 |y when y >= Size -> 0 |_ -> snd pos (tx, ty) nCells position |> Array.map ((!))

2 :
nCells point
! , , , ┬л┬╗ .

:
member this.existCell field c = field |> Array.exists (fun af -> c = af.Position)
.

member this.partitionfield field = this.allNeighbourCells >> Array.partition(fun c -> this.existCell field c) member this.pFree field = this.partitionfield field >> snd member this.pExist field = this.partitionfield field >> fst
Partitionfield tuple .
pFree, pExist

, :
member this.Iterate (field:Cell[]) = // let freeNeighb = field |> PSeq.collect (fun c -> this.pFree field c.Position) |> Seq.distinct let born = freeNeighb |> Seq.filter (fun c -> this.pExist field c |> Array.length = 3) |> Seq.map(fun c -> let rnd = new System.Random() {this.genCell(rnd) with Position = c}) let alive = field |> PSeq.filter(fun c -> let neighb = this.pExist field c.Position |> Array.length neighb <= 3 && neighb >= 2) |> PSeq.map (fun c -> {c with Age = (c.Age + 1)}) let res = alive |> Seq.append born |> Seq.toArray res
:
, (freeNeighb) , (- = 3) (born) , 2

, OpenGL , .. .
2 :
doNextStep
, :
member this.doNextStep = async{ let res = (this.life.Iterate field) field <- res |> Array.filter(fun c -> c.Age < LifeLength) isInProc <- false generation <- generation + 1 let delta = DateTime.Now - ftime ftime <- DateTime.Now fps <- Math.Round ((fps + 1000.0 / delta.TotalMilliseconds) / 2.0, 1) }
OnRenderFrame
OpenGL, :
override o.OnRenderFrame(e) = base.OnRenderFrame e match (pause, isInProc) with | (false, false) -> isInProc <- true; Async.Start(o.doNextStep) | _ -> () GL.Clear(ClearBufferMask.ColorBufferBit ||| ClearBufferMask.DepthBufferBit) GL.MatrixMode(MatrixMode.Modelview) GL.LoadMatrix(&modelview) field |> Seq.iter (fun c -> o.DrawCell c) if not pause then base.Title <- String.Format("F# Life cell count: {0} Generation: {1} FPS: {2}", (field |> Seq.length), generation, fps) else base.Title <- String.Format("F# Life cell count: {0} Generation: {1} Paused", (field |> Seq.length), generation) base.SwapBuffers()

, , LifeLength:
member this.doNextStep = .... field <- res |> Array.filter(fun c -> c.Age < LifeLength ...

. , :
member this.DrawCell (cell:Cell) = let cellWidth = float32(this.ClientSize.Width) / float32 Size let alpha = match (1.f - float32 cell.Age / float32 LifeLength) with |c when c < 0.f -> 0.f | c -> c let color = match cell.Sex with |Male -> [|0.5f; 0.f; 0.f; alpha|] |Female -> [|0.7f; 0.f; 0.f; alpha|] let pos = (float32 (fst cell.Position) * cellWidth, float32 (snd cell.Position) * cellWidth) GL.Begin(BeginMode.Triangles) GL.Color4 (color) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.End()

:
рдЫрд╡рд┐
- :



.
:)
"" , /

bitbucket
!.

Upd: . :)

 let rec lst (l:list)        ,   . 

:
member this.allNeighbourCells (position:int*int) = let nCells (point:int*int) = let x,y = point [| (x-1, y-1); (x-1, y); (x-1, y+1); (x, y-1); (x, y+1); (x+1, y-1); (x+1, y); (x+1, y+1); |] let (!) pos = let tx = match fst pos with |x when x < 0 -> Size - 1 |x when x >= Size -> 0 |_ -> fst pos let ty = match snd pos with |y when y < 0 -> Size - 1 |y when y >= Size -> 0 |_ -> snd pos (tx, ty) nCells position |> Array.map ((!))

2 :
nCells point
! , , , ┬л┬╗ .

:
member this.existCell field c = field |> Array.exists (fun af -> c = af.Position)
.

member this.partitionfield field = this.allNeighbourCells >> Array.partition(fun c -> this.existCell field c) member this.pFree field = this.partitionfield field >> snd member this.pExist field = this.partitionfield field >> fst
Partitionfield tuple .
pFree, pExist

, :
member this.Iterate (field:Cell[]) = // let freeNeighb = field |> PSeq.collect (fun c -> this.pFree field c.Position) |> Seq.distinct let born = freeNeighb |> Seq.filter (fun c -> this.pExist field c |> Array.length = 3) |> Seq.map(fun c -> let rnd = new System.Random() {this.genCell(rnd) with Position = c}) let alive = field |> PSeq.filter(fun c -> let neighb = this.pExist field c.Position |> Array.length neighb <= 3 && neighb >= 2) |> PSeq.map (fun c -> {c with Age = (c.Age + 1)}) let res = alive |> Seq.append born |> Seq.toArray res
:
, (freeNeighb) , (- = 3) (born) , 2

, OpenGL , .. .
2 :
doNextStep
, :
member this.doNextStep = async{ let res = (this.life.Iterate field) field <- res |> Array.filter(fun c -> c.Age < LifeLength) isInProc <- false generation <- generation + 1 let delta = DateTime.Now - ftime ftime <- DateTime.Now fps <- Math.Round ((fps + 1000.0 / delta.TotalMilliseconds) / 2.0, 1) }
OnRenderFrame
OpenGL, :
override o.OnRenderFrame(e) = base.OnRenderFrame e match (pause, isInProc) with | (false, false) -> isInProc <- true; Async.Start(o.doNextStep) | _ -> () GL.Clear(ClearBufferMask.ColorBufferBit ||| ClearBufferMask.DepthBufferBit) GL.MatrixMode(MatrixMode.Modelview) GL.LoadMatrix(&modelview) field |> Seq.iter (fun c -> o.DrawCell c) if not pause then base.Title <- String.Format("F# Life cell count: {0} Generation: {1} FPS: {2}", (field |> Seq.length), generation, fps) else base.Title <- String.Format("F# Life cell count: {0} Generation: {1} Paused", (field |> Seq.length), generation) base.SwapBuffers()

, , LifeLength:
member this.doNextStep = .... field <- res |> Array.filter(fun c -> c.Age < LifeLength ...

. , :
member this.DrawCell (cell:Cell) = let cellWidth = float32(this.ClientSize.Width) / float32 Size let alpha = match (1.f - float32 cell.Age / float32 LifeLength) with |c when c < 0.f -> 0.f | c -> c let color = match cell.Sex with |Male -> [|0.5f; 0.f; 0.f; alpha|] |Female -> [|0.7f; 0.f; 0.f; alpha|] let pos = (float32 (fst cell.Position) * cellWidth, float32 (snd cell.Position) * cellWidth) GL.Begin(BeginMode.Triangles) GL.Color4 (color) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.End()

:
рдЫрд╡рд┐
- :



.
:)
"" , /

bitbucket
!.

Upd: . :)

let rec lst (l:list) , .

:
member this.allNeighbourCells (position:int*int) = let nCells (point:int*int) = let x,y = point [| (x-1, y-1); (x-1, y); (x-1, y+1); (x, y-1); (x, y+1); (x+1, y-1); (x+1, y); (x+1, y+1); |] let (!) pos = let tx = match fst pos with |x when x < 0 -> Size - 1 |x when x >= Size -> 0 |_ -> fst pos let ty = match snd pos with |y when y < 0 -> Size - 1 |y when y >= Size -> 0 |_ -> snd pos (tx, ty) nCells position |> Array.map ((!))

2 :
nCells point
! , , , ┬л┬╗ .

:
member this.existCell field c = field |> Array.exists (fun af -> c = af.Position)
.

member this.partitionfield field = this.allNeighbourCells >> Array.partition(fun c -> this.existCell field c) member this.pFree field = this.partitionfield field >> snd member this.pExist field = this.partitionfield field >> fst
Partitionfield tuple .
pFree, pExist

, :
member this.Iterate (field:Cell[]) = // let freeNeighb = field |> PSeq.collect (fun c -> this.pFree field c.Position) |> Seq.distinct let born = freeNeighb |> Seq.filter (fun c -> this.pExist field c |> Array.length = 3) |> Seq.map(fun c -> let rnd = new System.Random() {this.genCell(rnd) with Position = c}) let alive = field |> PSeq.filter(fun c -> let neighb = this.pExist field c.Position |> Array.length neighb <= 3 && neighb >= 2) |> PSeq.map (fun c -> {c with Age = (c.Age + 1)}) let res = alive |> Seq.append born |> Seq.toArray res
:
, (freeNeighb) , (- = 3) (born) , 2

, OpenGL , .. .
2 :
doNextStep
, :
member this.doNextStep = async{ let res = (this.life.Iterate field) field <- res |> Array.filter(fun c -> c.Age < LifeLength) isInProc <- false generation <- generation + 1 let delta = DateTime.Now - ftime ftime <- DateTime.Now fps <- Math.Round ((fps + 1000.0 / delta.TotalMilliseconds) / 2.0, 1) }
OnRenderFrame
OpenGL, :
override o.OnRenderFrame(e) = base.OnRenderFrame e match (pause, isInProc) with | (false, false) -> isInProc <- true; Async.Start(o.doNextStep) | _ -> () GL.Clear(ClearBufferMask.ColorBufferBit ||| ClearBufferMask.DepthBufferBit) GL.MatrixMode(MatrixMode.Modelview) GL.LoadMatrix(&modelview) field |> Seq.iter (fun c -> o.DrawCell c) if not pause then base.Title <- String.Format("F# Life cell count: {0} Generation: {1} FPS: {2}", (field |> Seq.length), generation, fps) else base.Title <- String.Format("F# Life cell count: {0} Generation: {1} Paused", (field |> Seq.length), generation) base.SwapBuffers()

, , LifeLength:
member this.doNextStep = .... field <- res |> Array.filter(fun c -> c.Age < LifeLength ...

. , :
member this.DrawCell (cell:Cell) = let cellWidth = float32(this.ClientSize.Width) / float32 Size let alpha = match (1.f - float32 cell.Age / float32 LifeLength) with |c when c < 0.f -> 0.f | c -> c let color = match cell.Sex with |Male -> [|0.5f; 0.f; 0.f; alpha|] |Female -> [|0.7f; 0.f; 0.f; alpha|] let pos = (float32 (fst cell.Position) * cellWidth, float32 (snd cell.Position) * cellWidth) GL.Begin(BeginMode.Triangles) GL.Color4 (color) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.End()

:
рдЫрд╡рд┐
- :



.
:)
"" , /

bitbucket
!.

Upd: . :)

 let rec lst (l:list)        ,   . 

:
member this.allNeighbourCells (position:int*int) = let nCells (point:int*int) = let x,y = point [| (x-1, y-1); (x-1, y); (x-1, y+1); (x, y-1); (x, y+1); (x+1, y-1); (x+1, y); (x+1, y+1); |] let (!) pos = let tx = match fst pos with |x when x < 0 -> Size - 1 |x when x >= Size -> 0 |_ -> fst pos let ty = match snd pos with |y when y < 0 -> Size - 1 |y when y >= Size -> 0 |_ -> snd pos (tx, ty) nCells position |> Array.map ((!))

2 :
nCells point
! , , , ┬л┬╗ .

:
member this.existCell field c = field |> Array.exists (fun af -> c = af.Position)
.

member this.partitionfield field = this.allNeighbourCells >> Array.partition(fun c -> this.existCell field c) member this.pFree field = this.partitionfield field >> snd member this.pExist field = this.partitionfield field >> fst
Partitionfield tuple .
pFree, pExist

, :
member this.Iterate (field:Cell[]) = // let freeNeighb = field |> PSeq.collect (fun c -> this.pFree field c.Position) |> Seq.distinct let born = freeNeighb |> Seq.filter (fun c -> this.pExist field c |> Array.length = 3) |> Seq.map(fun c -> let rnd = new System.Random() {this.genCell(rnd) with Position = c}) let alive = field |> PSeq.filter(fun c -> let neighb = this.pExist field c.Position |> Array.length neighb <= 3 && neighb >= 2) |> PSeq.map (fun c -> {c with Age = (c.Age + 1)}) let res = alive |> Seq.append born |> Seq.toArray res
:
, (freeNeighb) , (- = 3) (born) , 2

, OpenGL , .. .
2 :
doNextStep
, :
member this.doNextStep = async{ let res = (this.life.Iterate field) field <- res |> Array.filter(fun c -> c.Age < LifeLength) isInProc <- false generation <- generation + 1 let delta = DateTime.Now - ftime ftime <- DateTime.Now fps <- Math.Round ((fps + 1000.0 / delta.TotalMilliseconds) / 2.0, 1) }
OnRenderFrame
OpenGL, :
override o.OnRenderFrame(e) = base.OnRenderFrame e match (pause, isInProc) with | (false, false) -> isInProc <- true; Async.Start(o.doNextStep) | _ -> () GL.Clear(ClearBufferMask.ColorBufferBit ||| ClearBufferMask.DepthBufferBit) GL.MatrixMode(MatrixMode.Modelview) GL.LoadMatrix(&modelview) field |> Seq.iter (fun c -> o.DrawCell c) if not pause then base.Title <- String.Format("F# Life cell count: {0} Generation: {1} FPS: {2}", (field |> Seq.length), generation, fps) else base.Title <- String.Format("F# Life cell count: {0} Generation: {1} Paused", (field |> Seq.length), generation) base.SwapBuffers()

, , LifeLength:
member this.doNextStep = .... field <- res |> Array.filter(fun c -> c.Age < LifeLength ...

. , :
member this.DrawCell (cell:Cell) = let cellWidth = float32(this.ClientSize.Width) / float32 Size let alpha = match (1.f - float32 cell.Age / float32 LifeLength) with |c when c < 0.f -> 0.f | c -> c let color = match cell.Sex with |Male -> [|0.5f; 0.f; 0.f; alpha|] |Female -> [|0.7f; 0.f; 0.f; alpha|] let pos = (float32 (fst cell.Position) * cellWidth, float32 (snd cell.Position) * cellWidth) GL.Begin(BeginMode.Triangles) GL.Color4 (color) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.End()

:
рдЫрд╡рд┐
- :



.
:)
"" , /

bitbucket
!.

Upd: . :)

let rec lst (l:list) , .

:
member this.allNeighbourCells (position:int*int) = let nCells (point:int*int) = let x,y = point [| (x-1, y-1); (x-1, y); (x-1, y+1); (x, y-1); (x, y+1); (x+1, y-1); (x+1, y); (x+1, y+1); |] let (!) pos = let tx = match fst pos with |x when x < 0 -> Size - 1 |x when x >= Size -> 0 |_ -> fst pos let ty = match snd pos with |y when y < 0 -> Size - 1 |y when y >= Size -> 0 |_ -> snd pos (tx, ty) nCells position |> Array.map ((!))

2 :
nCells point
! , , , ┬л┬╗ .

:
member this.existCell field c = field |> Array.exists (fun af -> c = af.Position)
.

member this.partitionfield field = this.allNeighbourCells >> Array.partition(fun c -> this.existCell field c) member this.pFree field = this.partitionfield field >> snd member this.pExist field = this.partitionfield field >> fst
Partitionfield tuple .
pFree, pExist

, :
member this.Iterate (field:Cell[]) = // let freeNeighb = field |> PSeq.collect (fun c -> this.pFree field c.Position) |> Seq.distinct let born = freeNeighb |> Seq.filter (fun c -> this.pExist field c |> Array.length = 3) |> Seq.map(fun c -> let rnd = new System.Random() {this.genCell(rnd) with Position = c}) let alive = field |> PSeq.filter(fun c -> let neighb = this.pExist field c.Position |> Array.length neighb <= 3 && neighb >= 2) |> PSeq.map (fun c -> {c with Age = (c.Age + 1)}) let res = alive |> Seq.append born |> Seq.toArray res
:
, (freeNeighb) , (- = 3) (born) , 2

, OpenGL , .. .
2 :
doNextStep
, :
member this.doNextStep = async{ let res = (this.life.Iterate field) field <- res |> Array.filter(fun c -> c.Age < LifeLength) isInProc <- false generation <- generation + 1 let delta = DateTime.Now - ftime ftime <- DateTime.Now fps <- Math.Round ((fps + 1000.0 / delta.TotalMilliseconds) / 2.0, 1) }
OnRenderFrame
OpenGL, :
override o.OnRenderFrame(e) = base.OnRenderFrame e match (pause, isInProc) with | (false, false) -> isInProc <- true; Async.Start(o.doNextStep) | _ -> () GL.Clear(ClearBufferMask.ColorBufferBit ||| ClearBufferMask.DepthBufferBit) GL.MatrixMode(MatrixMode.Modelview) GL.LoadMatrix(&modelview) field |> Seq.iter (fun c -> o.DrawCell c) if not pause then base.Title <- String.Format("F# Life cell count: {0} Generation: {1} FPS: {2}", (field |> Seq.length), generation, fps) else base.Title <- String.Format("F# Life cell count: {0} Generation: {1} Paused", (field |> Seq.length), generation) base.SwapBuffers()

, , LifeLength:
member this.doNextStep = .... field <- res |> Array.filter(fun c -> c.Age < LifeLength ...

. , :
member this.DrawCell (cell:Cell) = let cellWidth = float32(this.ClientSize.Width) / float32 Size let alpha = match (1.f - float32 cell.Age / float32 LifeLength) with |c when c < 0.f -> 0.f | c -> c let color = match cell.Sex with |Male -> [|0.5f; 0.f; 0.f; alpha|] |Female -> [|0.7f; 0.f; 0.f; alpha|] let pos = (float32 (fst cell.Position) * cellWidth, float32 (snd cell.Position) * cellWidth) GL.Begin(BeginMode.Triangles) GL.Color4 (color) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.End()

:
рдЫрд╡рд┐
- :



.
:)
"" , /

bitbucket
!.

Upd: . :)

 let rec lst (l:list)        ,   . 

:
member this.allNeighbourCells (position:int*int) = let nCells (point:int*int) = let x,y = point [| (x-1, y-1); (x-1, y); (x-1, y+1); (x, y-1); (x, y+1); (x+1, y-1); (x+1, y); (x+1, y+1); |] let (!) pos = let tx = match fst pos with |x when x < 0 -> Size - 1 |x when x >= Size -> 0 |_ -> fst pos let ty = match snd pos with |y when y < 0 -> Size - 1 |y when y >= Size -> 0 |_ -> snd pos (tx, ty) nCells position |> Array.map ((!))

2 :
nCells point
! , , , ┬л┬╗ .

:
member this.existCell field c = field |> Array.exists (fun af -> c = af.Position)
.

member this.partitionfield field = this.allNeighbourCells >> Array.partition(fun c -> this.existCell field c) member this.pFree field = this.partitionfield field >> snd member this.pExist field = this.partitionfield field >> fst
Partitionfield tuple .
pFree, pExist

, :
member this.Iterate (field:Cell[]) = // let freeNeighb = field |> PSeq.collect (fun c -> this.pFree field c.Position) |> Seq.distinct let born = freeNeighb |> Seq.filter (fun c -> this.pExist field c |> Array.length = 3) |> Seq.map(fun c -> let rnd = new System.Random() {this.genCell(rnd) with Position = c}) let alive = field |> PSeq.filter(fun c -> let neighb = this.pExist field c.Position |> Array.length neighb <= 3 && neighb >= 2) |> PSeq.map (fun c -> {c with Age = (c.Age + 1)}) let res = alive |> Seq.append born |> Seq.toArray res
:
, (freeNeighb) , (- = 3) (born) , 2

, OpenGL , .. .
2 :
doNextStep
, :
member this.doNextStep = async{ let res = (this.life.Iterate field) field <- res |> Array.filter(fun c -> c.Age < LifeLength) isInProc <- false generation <- generation + 1 let delta = DateTime.Now - ftime ftime <- DateTime.Now fps <- Math.Round ((fps + 1000.0 / delta.TotalMilliseconds) / 2.0, 1) }
OnRenderFrame
OpenGL, :
override o.OnRenderFrame(e) = base.OnRenderFrame e match (pause, isInProc) with | (false, false) -> isInProc <- true; Async.Start(o.doNextStep) | _ -> () GL.Clear(ClearBufferMask.ColorBufferBit ||| ClearBufferMask.DepthBufferBit) GL.MatrixMode(MatrixMode.Modelview) GL.LoadMatrix(&modelview) field |> Seq.iter (fun c -> o.DrawCell c) if not pause then base.Title <- String.Format("F# Life cell count: {0} Generation: {1} FPS: {2}", (field |> Seq.length), generation, fps) else base.Title <- String.Format("F# Life cell count: {0} Generation: {1} Paused", (field |> Seq.length), generation) base.SwapBuffers()

, , LifeLength:
member this.doNextStep = .... field <- res |> Array.filter(fun c -> c.Age < LifeLength ...

. , :
member this.DrawCell (cell:Cell) = let cellWidth = float32(this.ClientSize.Width) / float32 Size let alpha = match (1.f - float32 cell.Age / float32 LifeLength) with |c when c < 0.f -> 0.f | c -> c let color = match cell.Sex with |Male -> [|0.5f; 0.f; 0.f; alpha|] |Female -> [|0.7f; 0.f; 0.f; alpha|] let pos = (float32 (fst cell.Position) * cellWidth, float32 (snd cell.Position) * cellWidth) GL.Begin(BeginMode.Triangles) GL.Color4 (color) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.End()

:
рдЫрд╡рд┐
- :



.
:)
"" , /

bitbucket
!.

Upd: . :)

let rec lst (l:list) , .

:
member this.allNeighbourCells (position:int*int) = let nCells (point:int*int) = let x,y = point [| (x-1, y-1); (x-1, y); (x-1, y+1); (x, y-1); (x, y+1); (x+1, y-1); (x+1, y); (x+1, y+1); |] let (!) pos = let tx = match fst pos with |x when x < 0 -> Size - 1 |x when x >= Size -> 0 |_ -> fst pos let ty = match snd pos with |y when y < 0 -> Size - 1 |y when y >= Size -> 0 |_ -> snd pos (tx, ty) nCells position |> Array.map ((!))

2 :
nCells point
! , , , ┬л┬╗ .

:
member this.existCell field c = field |> Array.exists (fun af -> c = af.Position)
.

member this.partitionfield field = this.allNeighbourCells >> Array.partition(fun c -> this.existCell field c) member this.pFree field = this.partitionfield field >> snd member this.pExist field = this.partitionfield field >> fst
Partitionfield tuple .
pFree, pExist

, :
member this.Iterate (field:Cell[]) = // let freeNeighb = field |> PSeq.collect (fun c -> this.pFree field c.Position) |> Seq.distinct let born = freeNeighb |> Seq.filter (fun c -> this.pExist field c |> Array.length = 3) |> Seq.map(fun c -> let rnd = new System.Random() {this.genCell(rnd) with Position = c}) let alive = field |> PSeq.filter(fun c -> let neighb = this.pExist field c.Position |> Array.length neighb <= 3 && neighb >= 2) |> PSeq.map (fun c -> {c with Age = (c.Age + 1)}) let res = alive |> Seq.append born |> Seq.toArray res
:
, (freeNeighb) , (- = 3) (born) , 2

, OpenGL , .. .
2 :
doNextStep
, :
member this.doNextStep = async{ let res = (this.life.Iterate field) field <- res |> Array.filter(fun c -> c.Age < LifeLength) isInProc <- false generation <- generation + 1 let delta = DateTime.Now - ftime ftime <- DateTime.Now fps <- Math.Round ((fps + 1000.0 / delta.TotalMilliseconds) / 2.0, 1) }
OnRenderFrame
OpenGL, :
override o.OnRenderFrame(e) = base.OnRenderFrame e match (pause, isInProc) with | (false, false) -> isInProc <- true; Async.Start(o.doNextStep) | _ -> () GL.Clear(ClearBufferMask.ColorBufferBit ||| ClearBufferMask.DepthBufferBit) GL.MatrixMode(MatrixMode.Modelview) GL.LoadMatrix(&modelview) field |> Seq.iter (fun c -> o.DrawCell c) if not pause then base.Title <- String.Format("F# Life cell count: {0} Generation: {1} FPS: {2}", (field |> Seq.length), generation, fps) else base.Title <- String.Format("F# Life cell count: {0} Generation: {1} Paused", (field |> Seq.length), generation) base.SwapBuffers()

, , LifeLength:
member this.doNextStep = .... field <- res |> Array.filter(fun c -> c.Age < LifeLength ...

. , :
member this.DrawCell (cell:Cell) = let cellWidth = float32(this.ClientSize.Width) / float32 Size let alpha = match (1.f - float32 cell.Age / float32 LifeLength) with |c when c < 0.f -> 0.f | c -> c let color = match cell.Sex with |Male -> [|0.5f; 0.f; 0.f; alpha|] |Female -> [|0.7f; 0.f; 0.f; alpha|] let pos = (float32 (fst cell.Position) * cellWidth, float32 (snd cell.Position) * cellWidth) GL.Begin(BeginMode.Triangles) GL.Color4 (color) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.End()

:
рдЫрд╡рд┐
- :



.
:)
"" , /

bitbucket
!.

Upd: . :)

  1. let rec lst (l:list) , .

    :
    member this.allNeighbourCells (position:int*int) = let nCells (point:int*int) = let x,y = point [| (x-1, y-1); (x-1, y); (x-1, y+1); (x, y-1); (x, y+1); (x+1, y-1); (x+1, y); (x+1, y+1); |] let (!) pos = let tx = match fst pos with |x when x < 0 -> Size - 1 |x when x >= Size -> 0 |_ -> fst pos let ty = match snd pos with |y when y < 0 -> Size - 1 |y when y >= Size -> 0 |_ -> snd pos (tx, ty) nCells position |> Array.map ((!))

    2 :
    nCells point
    ! , , , ┬л┬╗ .

    :
    member this.existCell field c = field |> Array.exists (fun af -> c = af.Position)
    .

    member this.partitionfield field = this.allNeighbourCells >> Array.partition(fun c -> this.existCell field c) member this.pFree field = this.partitionfield field >> snd member this.pExist field = this.partitionfield field >> fst
    Partitionfield tuple .
    pFree, pExist

    , :
    member this.Iterate (field:Cell[]) = // let freeNeighb = field |> PSeq.collect (fun c -> this.pFree field c.Position) |> Seq.distinct let born = freeNeighb |> Seq.filter (fun c -> this.pExist field c |> Array.length = 3) |> Seq.map(fun c -> let rnd = new System.Random() {this.genCell(rnd) with Position = c}) let alive = field |> PSeq.filter(fun c -> let neighb = this.pExist field c.Position |> Array.length neighb <= 3 && neighb >= 2) |> PSeq.map (fun c -> {c with Age = (c.Age + 1)}) let res = alive |> Seq.append born |> Seq.toArray res
    :
    , (freeNeighb) , (- = 3) (born) , 2

    , OpenGL , .. .
    2 :
    doNextStep
    , :
    member this.doNextStep = async{ let res = (this.life.Iterate field) field <- res |> Array.filter(fun c -> c.Age < LifeLength) isInProc <- false generation <- generation + 1 let delta = DateTime.Now - ftime ftime <- DateTime.Now fps <- Math.Round ((fps + 1000.0 / delta.TotalMilliseconds) / 2.0, 1) }
    OnRenderFrame
    OpenGL, :
    override o.OnRenderFrame(e) = base.OnRenderFrame e match (pause, isInProc) with | (false, false) -> isInProc <- true; Async.Start(o.doNextStep) | _ -> () GL.Clear(ClearBufferMask.ColorBufferBit ||| ClearBufferMask.DepthBufferBit) GL.MatrixMode(MatrixMode.Modelview) GL.LoadMatrix(&modelview) field |> Seq.iter (fun c -> o.DrawCell c) if not pause then base.Title <- String.Format("F# Life cell count: {0} Generation: {1} FPS: {2}", (field |> Seq.length), generation, fps) else base.Title <- String.Format("F# Life cell count: {0} Generation: {1} Paused", (field |> Seq.length), generation) base.SwapBuffers()

    , , LifeLength:
    member this.doNextStep = .... field <- res |> Array.filter(fun c -> c.Age < LifeLength ...

    . , :
    member this.DrawCell (cell:Cell) = let cellWidth = float32(this.ClientSize.Width) / float32 Size let alpha = match (1.f - float32 cell.Age / float32 LifeLength) with |c when c < 0.f -> 0.f | c -> c let color = match cell.Sex with |Male -> [|0.5f; 0.f; 0.f; alpha|] |Female -> [|0.7f; 0.f; 0.f; alpha|] let pos = (float32 (fst cell.Position) * cellWidth, float32 (snd cell.Position) * cellWidth) GL.Begin(BeginMode.Triangles) GL.Color4 (color) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.End()

    :
    рдЫрд╡рд┐
    - :



    .
    :)
    "" , /

    bitbucket
    !.

    Upd: . :)

  2. let rec lst (l:list) , .

    :
    member this.allNeighbourCells (position:int*int) = let nCells (point:int*int) = let x,y = point [| (x-1, y-1); (x-1, y); (x-1, y+1); (x, y-1); (x, y+1); (x+1, y-1); (x+1, y); (x+1, y+1); |] let (!) pos = let tx = match fst pos with |x when x < 0 -> Size - 1 |x when x >= Size -> 0 |_ -> fst pos let ty = match snd pos with |y when y < 0 -> Size - 1 |y when y >= Size -> 0 |_ -> snd pos (tx, ty) nCells position |> Array.map ((!))

    2 :
    nCells point
    ! , , , ┬л┬╗ .

    :
    member this.existCell field c = field |> Array.exists (fun af -> c = af.Position)
    .

    member this.partitionfield field = this.allNeighbourCells >> Array.partition(fun c -> this.existCell field c) member this.pFree field = this.partitionfield field >> snd member this.pExist field = this.partitionfield field >> fst
    Partitionfield tuple .
    pFree, pExist

    , :
    member this.Iterate (field:Cell[]) = // let freeNeighb = field |> PSeq.collect (fun c -> this.pFree field c.Position) |> Seq.distinct let born = freeNeighb |> Seq.filter (fun c -> this.pExist field c |> Array.length = 3) |> Seq.map(fun c -> let rnd = new System.Random() {this.genCell(rnd) with Position = c}) let alive = field |> PSeq.filter(fun c -> let neighb = this.pExist field c.Position |> Array.length neighb <= 3 && neighb >= 2) |> PSeq.map (fun c -> {c with Age = (c.Age + 1)}) let res = alive |> Seq.append born |> Seq.toArray res
    :
    , (freeNeighb) , (- = 3) (born) , 2

    , OpenGL , .. .
    2 :
    doNextStep
    , :
    member this.doNextStep = async{ let res = (this.life.Iterate field) field <- res |> Array.filter(fun c -> c.Age < LifeLength) isInProc <- false generation <- generation + 1 let delta = DateTime.Now - ftime ftime <- DateTime.Now fps <- Math.Round ((fps + 1000.0 / delta.TotalMilliseconds) / 2.0, 1) }
    OnRenderFrame
    OpenGL, :
    override o.OnRenderFrame(e) = base.OnRenderFrame e match (pause, isInProc) with | (false, false) -> isInProc <- true; Async.Start(o.doNextStep) | _ -> () GL.Clear(ClearBufferMask.ColorBufferBit ||| ClearBufferMask.DepthBufferBit) GL.MatrixMode(MatrixMode.Modelview) GL.LoadMatrix(&modelview) field |> Seq.iter (fun c -> o.DrawCell c) if not pause then base.Title <- String.Format("F# Life cell count: {0} Generation: {1} FPS: {2}", (field |> Seq.length), generation, fps) else base.Title <- String.Format("F# Life cell count: {0} Generation: {1} Paused", (field |> Seq.length), generation) base.SwapBuffers()

    , , LifeLength:
    member this.doNextStep = .... field <- res |> Array.filter(fun c -> c.Age < LifeLength ...

    . , :
    member this.DrawCell (cell:Cell) = let cellWidth = float32(this.ClientSize.Width) / float32 Size let alpha = match (1.f - float32 cell.Age / float32 LifeLength) with |c when c < 0.f -> 0.f | c -> c let color = match cell.Sex with |Male -> [|0.5f; 0.f; 0.f; alpha|] |Female -> [|0.7f; 0.f; 0.f; alpha|] let pos = (float32 (fst cell.Position) * cellWidth, float32 (snd cell.Position) * cellWidth) GL.Begin(BeginMode.Triangles) GL.Color4 (color) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.End()

    :
    рдЫрд╡рд┐
    - :



    .
    :)
    "" , /

    bitbucket
    !.

    Upd: . :)

  3. let rec lst (l:list) , .

    :
    member this.allNeighbourCells (position:int*int) = let nCells (point:int*int) = let x,y = point [| (x-1, y-1); (x-1, y); (x-1, y+1); (x, y-1); (x, y+1); (x+1, y-1); (x+1, y); (x+1, y+1); |] let (!) pos = let tx = match fst pos with |x when x < 0 -> Size - 1 |x when x >= Size -> 0 |_ -> fst pos let ty = match snd pos with |y when y < 0 -> Size - 1 |y when y >= Size -> 0 |_ -> snd pos (tx, ty) nCells position |> Array.map ((!))

    2 :
    nCells point
    ! , , , ┬л┬╗ .

    :
    member this.existCell field c = field |> Array.exists (fun af -> c = af.Position)
    .

    member this.partitionfield field = this.allNeighbourCells >> Array.partition(fun c -> this.existCell field c) member this.pFree field = this.partitionfield field >> snd member this.pExist field = this.partitionfield field >> fst
    Partitionfield tuple .
    pFree, pExist

    , :
    member this.Iterate (field:Cell[]) = // let freeNeighb = field |> PSeq.collect (fun c -> this.pFree field c.Position) |> Seq.distinct let born = freeNeighb |> Seq.filter (fun c -> this.pExist field c |> Array.length = 3) |> Seq.map(fun c -> let rnd = new System.Random() {this.genCell(rnd) with Position = c}) let alive = field |> PSeq.filter(fun c -> let neighb = this.pExist field c.Position |> Array.length neighb <= 3 && neighb >= 2) |> PSeq.map (fun c -> {c with Age = (c.Age + 1)}) let res = alive |> Seq.append born |> Seq.toArray res
    :
    , (freeNeighb) , (- = 3) (born) , 2

    , OpenGL , .. .
    2 :
    doNextStep
    , :
    member this.doNextStep = async{ let res = (this.life.Iterate field) field <- res |> Array.filter(fun c -> c.Age < LifeLength) isInProc <- false generation <- generation + 1 let delta = DateTime.Now - ftime ftime <- DateTime.Now fps <- Math.Round ((fps + 1000.0 / delta.TotalMilliseconds) / 2.0, 1) }
    OnRenderFrame
    OpenGL, :
    override o.OnRenderFrame(e) = base.OnRenderFrame e match (pause, isInProc) with | (false, false) -> isInProc <- true; Async.Start(o.doNextStep) | _ -> () GL.Clear(ClearBufferMask.ColorBufferBit ||| ClearBufferMask.DepthBufferBit) GL.MatrixMode(MatrixMode.Modelview) GL.LoadMatrix(&modelview) field |> Seq.iter (fun c -> o.DrawCell c) if not pause then base.Title <- String.Format("F# Life cell count: {0} Generation: {1} FPS: {2}", (field |> Seq.length), generation, fps) else base.Title <- String.Format("F# Life cell count: {0} Generation: {1} Paused", (field |> Seq.length), generation) base.SwapBuffers()

    , , LifeLength:
    member this.doNextStep = .... field <- res |> Array.filter(fun c -> c.Age < LifeLength ...

    . , :
    member this.DrawCell (cell:Cell) = let cellWidth = float32(this.ClientSize.Width) / float32 Size let alpha = match (1.f - float32 cell.Age / float32 LifeLength) with |c when c < 0.f -> 0.f | c -> c let color = match cell.Sex with |Male -> [|0.5f; 0.f; 0.f; alpha|] |Female -> [|0.7f; 0.f; 0.f; alpha|] let pos = (float32 (fst cell.Position) * cellWidth, float32 (snd cell.Position) * cellWidth) GL.Begin(BeginMode.Triangles) GL.Color4 (color) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.End()

    :
    рдЫрд╡рд┐
    - :



    .
    :)
    "" , /

    bitbucket
    !.

    Upd: . :)

  4. let rec lst (l:list) , .

    :
    member this.allNeighbourCells (position:int*int) = let nCells (point:int*int) = let x,y = point [| (x-1, y-1); (x-1, y); (x-1, y+1); (x, y-1); (x, y+1); (x+1, y-1); (x+1, y); (x+1, y+1); |] let (!) pos = let tx = match fst pos with |x when x < 0 -> Size - 1 |x when x >= Size -> 0 |_ -> fst pos let ty = match snd pos with |y when y < 0 -> Size - 1 |y when y >= Size -> 0 |_ -> snd pos (tx, ty) nCells position |> Array.map ((!))

    2 :
    nCells point
    ! , , , ┬л┬╗ .

    :
    member this.existCell field c = field |> Array.exists (fun af -> c = af.Position)
    .

    member this.partitionfield field = this.allNeighbourCells >> Array.partition(fun c -> this.existCell field c) member this.pFree field = this.partitionfield field >> snd member this.pExist field = this.partitionfield field >> fst
    Partitionfield tuple .
    pFree, pExist

    , :
    member this.Iterate (field:Cell[]) = // let freeNeighb = field |> PSeq.collect (fun c -> this.pFree field c.Position) |> Seq.distinct let born = freeNeighb |> Seq.filter (fun c -> this.pExist field c |> Array.length = 3) |> Seq.map(fun c -> let rnd = new System.Random() {this.genCell(rnd) with Position = c}) let alive = field |> PSeq.filter(fun c -> let neighb = this.pExist field c.Position |> Array.length neighb <= 3 && neighb >= 2) |> PSeq.map (fun c -> {c with Age = (c.Age + 1)}) let res = alive |> Seq.append born |> Seq.toArray res
    :
    , (freeNeighb) , (- = 3) (born) , 2

    , OpenGL , .. .
    2 :
    doNextStep
    , :
    member this.doNextStep = async{ let res = (this.life.Iterate field) field <- res |> Array.filter(fun c -> c.Age < LifeLength) isInProc <- false generation <- generation + 1 let delta = DateTime.Now - ftime ftime <- DateTime.Now fps <- Math.Round ((fps + 1000.0 / delta.TotalMilliseconds) / 2.0, 1) }
    OnRenderFrame
    OpenGL, :
    override o.OnRenderFrame(e) = base.OnRenderFrame e match (pause, isInProc) with | (false, false) -> isInProc <- true; Async.Start(o.doNextStep) | _ -> () GL.Clear(ClearBufferMask.ColorBufferBit ||| ClearBufferMask.DepthBufferBit) GL.MatrixMode(MatrixMode.Modelview) GL.LoadMatrix(&modelview) field |> Seq.iter (fun c -> o.DrawCell c) if not pause then base.Title <- String.Format("F# Life cell count: {0} Generation: {1} FPS: {2}", (field |> Seq.length), generation, fps) else base.Title <- String.Format("F# Life cell count: {0} Generation: {1} Paused", (field |> Seq.length), generation) base.SwapBuffers()

    , , LifeLength:
    member this.doNextStep = .... field <- res |> Array.filter(fun c -> c.Age < LifeLength ...

    . , :
    member this.DrawCell (cell:Cell) = let cellWidth = float32(this.ClientSize.Width) / float32 Size let alpha = match (1.f - float32 cell.Age / float32 LifeLength) with |c when c < 0.f -> 0.f | c -> c let color = match cell.Sex with |Male -> [|0.5f; 0.f; 0.f; alpha|] |Female -> [|0.7f; 0.f; 0.f; alpha|] let pos = (float32 (fst cell.Position) * cellWidth, float32 (snd cell.Position) * cellWidth) GL.Begin(BeginMode.Triangles) GL.Color4 (color) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.End()

    :
    рдЫрд╡рд┐
    - :



    .
    :)
    "" , /

    bitbucket
    !.

    Upd: . :)

let rec lst (l:list) , .

:
member this.allNeighbourCells (position:int*int) = let nCells (point:int*int) = let x,y = point [| (x-1, y-1); (x-1, y); (x-1, y+1); (x, y-1); (x, y+1); (x+1, y-1); (x+1, y); (x+1, y+1); |] let (!) pos = let tx = match fst pos with |x when x < 0 -> Size - 1 |x when x >= Size -> 0 |_ -> fst pos let ty = match snd pos with |y when y < 0 -> Size - 1 |y when y >= Size -> 0 |_ -> snd pos (tx, ty) nCells position |> Array.map ((!))

2 :
nCells point
! , , , ┬л┬╗ .

:
member this.existCell field c = field |> Array.exists (fun af -> c = af.Position)
.

member this.partitionfield field = this.allNeighbourCells >> Array.partition(fun c -> this.existCell field c) member this.pFree field = this.partitionfield field >> snd member this.pExist field = this.partitionfield field >> fst
Partitionfield tuple .
pFree, pExist

, :
member this.Iterate (field:Cell[]) = // let freeNeighb = field |> PSeq.collect (fun c -> this.pFree field c.Position) |> Seq.distinct let born = freeNeighb |> Seq.filter (fun c -> this.pExist field c |> Array.length = 3) |> Seq.map(fun c -> let rnd = new System.Random() {this.genCell(rnd) with Position = c}) let alive = field |> PSeq.filter(fun c -> let neighb = this.pExist field c.Position |> Array.length neighb <= 3 && neighb >= 2) |> PSeq.map (fun c -> {c with Age = (c.Age + 1)}) let res = alive |> Seq.append born |> Seq.toArray res
:
, (freeNeighb) , (- = 3) (born) , 2

, OpenGL , .. .
2 :
doNextStep
, :
member this.doNextStep = async{ let res = (this.life.Iterate field) field <- res |> Array.filter(fun c -> c.Age < LifeLength) isInProc <- false generation <- generation + 1 let delta = DateTime.Now - ftime ftime <- DateTime.Now fps <- Math.Round ((fps + 1000.0 / delta.TotalMilliseconds) / 2.0, 1) }
OnRenderFrame
OpenGL, :
override o.OnRenderFrame(e) = base.OnRenderFrame e match (pause, isInProc) with | (false, false) -> isInProc <- true; Async.Start(o.doNextStep) | _ -> () GL.Clear(ClearBufferMask.ColorBufferBit ||| ClearBufferMask.DepthBufferBit) GL.MatrixMode(MatrixMode.Modelview) GL.LoadMatrix(&modelview) field |> Seq.iter (fun c -> o.DrawCell c) if not pause then base.Title <- String.Format("F# Life cell count: {0} Generation: {1} FPS: {2}", (field |> Seq.length), generation, fps) else base.Title <- String.Format("F# Life cell count: {0} Generation: {1} Paused", (field |> Seq.length), generation) base.SwapBuffers()

, , LifeLength:
member this.doNextStep = .... field <- res |> Array.filter(fun c -> c.Age < LifeLength ...

. , :
member this.DrawCell (cell:Cell) = let cellWidth = float32(this.ClientSize.Width) / float32 Size let alpha = match (1.f - float32 cell.Age / float32 LifeLength) with |c when c < 0.f -> 0.f | c -> c let color = match cell.Sex with |Male -> [|0.5f; 0.f; 0.f; alpha|] |Female -> [|0.7f; 0.f; 0.f; alpha|] let pos = (float32 (fst cell.Position) * cellWidth, float32 (snd cell.Position) * cellWidth) GL.Begin(BeginMode.Triangles) GL.Color4 (color) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.End()

:
рдЫрд╡рд┐
- :



.
:)
"" , /

bitbucket
!.

Upd: . :)

let rec lst (l:list) , .

:
member this.allNeighbourCells (position:int*int) = let nCells (point:int*int) = let x,y = point [| (x-1, y-1); (x-1, y); (x-1, y+1); (x, y-1); (x, y+1); (x+1, y-1); (x+1, y); (x+1, y+1); |] let (!) pos = let tx = match fst pos with |x when x < 0 -> Size - 1 |x when x >= Size -> 0 |_ -> fst pos let ty = match snd pos with |y when y < 0 -> Size - 1 |y when y >= Size -> 0 |_ -> snd pos (tx, ty) nCells position |> Array.map ((!))

2 :
nCells point
! , , , ┬л┬╗ .

:
member this.existCell field c = field |> Array.exists (fun af -> c = af.Position)
.

member this.partitionfield field = this.allNeighbourCells >> Array.partition(fun c -> this.existCell field c) member this.pFree field = this.partitionfield field >> snd member this.pExist field = this.partitionfield field >> fst
Partitionfield tuple .
pFree, pExist

, :
member this.Iterate (field:Cell[]) = // let freeNeighb = field |> PSeq.collect (fun c -> this.pFree field c.Position) |> Seq.distinct let born = freeNeighb |> Seq.filter (fun c -> this.pExist field c |> Array.length = 3) |> Seq.map(fun c -> let rnd = new System.Random() {this.genCell(rnd) with Position = c}) let alive = field |> PSeq.filter(fun c -> let neighb = this.pExist field c.Position |> Array.length neighb <= 3 && neighb >= 2) |> PSeq.map (fun c -> {c with Age = (c.Age + 1)}) let res = alive |> Seq.append born |> Seq.toArray res
:
, (freeNeighb) , (- = 3) (born) , 2

, OpenGL , .. .
2 :
doNextStep
, :
member this.doNextStep = async{ let res = (this.life.Iterate field) field <- res |> Array.filter(fun c -> c.Age < LifeLength) isInProc <- false generation <- generation + 1 let delta = DateTime.Now - ftime ftime <- DateTime.Now fps <- Math.Round ((fps + 1000.0 / delta.TotalMilliseconds) / 2.0, 1) }
OnRenderFrame
OpenGL, :
override o.OnRenderFrame(e) = base.OnRenderFrame e match (pause, isInProc) with | (false, false) -> isInProc <- true; Async.Start(o.doNextStep) | _ -> () GL.Clear(ClearBufferMask.ColorBufferBit ||| ClearBufferMask.DepthBufferBit) GL.MatrixMode(MatrixMode.Modelview) GL.LoadMatrix(&modelview) field |> Seq.iter (fun c -> o.DrawCell c) if not pause then base.Title <- String.Format("F# Life cell count: {0} Generation: {1} FPS: {2}", (field |> Seq.length), generation, fps) else base.Title <- String.Format("F# Life cell count: {0} Generation: {1} Paused", (field |> Seq.length), generation) base.SwapBuffers()

, , LifeLength:
member this.doNextStep = .... field <- res |> Array.filter(fun c -> c.Age < LifeLength ...

. , :
member this.DrawCell (cell:Cell) = let cellWidth = float32(this.ClientSize.Width) / float32 Size let alpha = match (1.f - float32 cell.Age / float32 LifeLength) with |c when c < 0.f -> 0.f | c -> c let color = match cell.Sex with |Male -> [|0.5f; 0.f; 0.f; alpha|] |Female -> [|0.7f; 0.f; 0.f; alpha|] let pos = (float32 (fst cell.Position) * cellWidth, float32 (snd cell.Position) * cellWidth) GL.Begin(BeginMode.Triangles) GL.Color4 (color) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.End()

:
рдЫрд╡рд┐
- :



.
:)
"" , /

bitbucket
!.

Upd: . :)

let rec lst (l:list) , .

:
member this.allNeighbourCells (position:int*int) = let nCells (point:int*int) = let x,y = point [| (x-1, y-1); (x-1, y); (x-1, y+1); (x, y-1); (x, y+1); (x+1, y-1); (x+1, y); (x+1, y+1); |] let (!) pos = let tx = match fst pos with |x when x < 0 -> Size - 1 |x when x >= Size -> 0 |_ -> fst pos let ty = match snd pos with |y when y < 0 -> Size - 1 |y when y >= Size -> 0 |_ -> snd pos (tx, ty) nCells position |> Array.map ((!))

2 :
nCells point
! , , , ┬л┬╗ .

:
member this.existCell field c = field |> Array.exists (fun af -> c = af.Position)
.

member this.partitionfield field = this.allNeighbourCells >> Array.partition(fun c -> this.existCell field c) member this.pFree field = this.partitionfield field >> snd member this.pExist field = this.partitionfield field >> fst
Partitionfield tuple .
pFree, pExist

, :
member this.Iterate (field:Cell[]) = // let freeNeighb = field |> PSeq.collect (fun c -> this.pFree field c.Position) |> Seq.distinct let born = freeNeighb |> Seq.filter (fun c -> this.pExist field c |> Array.length = 3) |> Seq.map(fun c -> let rnd = new System.Random() {this.genCell(rnd) with Position = c}) let alive = field |> PSeq.filter(fun c -> let neighb = this.pExist field c.Position |> Array.length neighb <= 3 && neighb >= 2) |> PSeq.map (fun c -> {c with Age = (c.Age + 1)}) let res = alive |> Seq.append born |> Seq.toArray res
:
, (freeNeighb) , (- = 3) (born) , 2

, OpenGL , .. .
2 :
doNextStep
, :
member this.doNextStep = async{ let res = (this.life.Iterate field) field <- res |> Array.filter(fun c -> c.Age < LifeLength) isInProc <- false generation <- generation + 1 let delta = DateTime.Now - ftime ftime <- DateTime.Now fps <- Math.Round ((fps + 1000.0 / delta.TotalMilliseconds) / 2.0, 1) }
OnRenderFrame
OpenGL, :
override o.OnRenderFrame(e) = base.OnRenderFrame e match (pause, isInProc) with | (false, false) -> isInProc <- true; Async.Start(o.doNextStep) | _ -> () GL.Clear(ClearBufferMask.ColorBufferBit ||| ClearBufferMask.DepthBufferBit) GL.MatrixMode(MatrixMode.Modelview) GL.LoadMatrix(&modelview) field |> Seq.iter (fun c -> o.DrawCell c) if not pause then base.Title <- String.Format("F# Life cell count: {0} Generation: {1} FPS: {2}", (field |> Seq.length), generation, fps) else base.Title <- String.Format("F# Life cell count: {0} Generation: {1} Paused", (field |> Seq.length), generation) base.SwapBuffers()

, , LifeLength:
member this.doNextStep = .... field <- res |> Array.filter(fun c -> c.Age < LifeLength ...

. , :
member this.DrawCell (cell:Cell) = let cellWidth = float32(this.ClientSize.Width) / float32 Size let alpha = match (1.f - float32 cell.Age / float32 LifeLength) with |c when c < 0.f -> 0.f | c -> c let color = match cell.Sex with |Male -> [|0.5f; 0.f; 0.f; alpha|] |Female -> [|0.7f; 0.f; 0.f; alpha|] let pos = (float32 (fst cell.Position) * cellWidth, float32 (snd cell.Position) * cellWidth) GL.Begin(BeginMode.Triangles) GL.Color4 (color) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.End()

:
рдЫрд╡рд┐
- :



.
:)
"" , /

bitbucket
!.

Upd: . :)

 let rec lst (l:list)        ,   . 

:
member this.allNeighbourCells (position:int*int) = let nCells (point:int*int) = let x,y = point [| (x-1, y-1); (x-1, y); (x-1, y+1); (x, y-1); (x, y+1); (x+1, y-1); (x+1, y); (x+1, y+1); |] let (!) pos = let tx = match fst pos with |x when x < 0 -> Size - 1 |x when x >= Size -> 0 |_ -> fst pos let ty = match snd pos with |y when y < 0 -> Size - 1 |y when y >= Size -> 0 |_ -> snd pos (tx, ty) nCells position |> Array.map ((!))

2 :
nCells point
! , , , ┬л┬╗ .

:
member this.existCell field c = field |> Array.exists (fun af -> c = af.Position)
.

member this.partitionfield field = this.allNeighbourCells >> Array.partition(fun c -> this.existCell field c) member this.pFree field = this.partitionfield field >> snd member this.pExist field = this.partitionfield field >> fst
Partitionfield tuple .
pFree, pExist

, :
member this.Iterate (field:Cell[]) = // let freeNeighb = field |> PSeq.collect (fun c -> this.pFree field c.Position) |> Seq.distinct let born = freeNeighb |> Seq.filter (fun c -> this.pExist field c |> Array.length = 3) |> Seq.map(fun c -> let rnd = new System.Random() {this.genCell(rnd) with Position = c}) let alive = field |> PSeq.filter(fun c -> let neighb = this.pExist field c.Position |> Array.length neighb <= 3 && neighb >= 2) |> PSeq.map (fun c -> {c with Age = (c.Age + 1)}) let res = alive |> Seq.append born |> Seq.toArray res
:
, (freeNeighb) , (- = 3) (born) , 2

, OpenGL , .. .
2 :
doNextStep
, :
member this.doNextStep = async{ let res = (this.life.Iterate field) field <- res |> Array.filter(fun c -> c.Age < LifeLength) isInProc <- false generation <- generation + 1 let delta = DateTime.Now - ftime ftime <- DateTime.Now fps <- Math.Round ((fps + 1000.0 / delta.TotalMilliseconds) / 2.0, 1) }
OnRenderFrame
OpenGL, :
override o.OnRenderFrame(e) = base.OnRenderFrame e match (pause, isInProc) with | (false, false) -> isInProc <- true; Async.Start(o.doNextStep) | _ -> () GL.Clear(ClearBufferMask.ColorBufferBit ||| ClearBufferMask.DepthBufferBit) GL.MatrixMode(MatrixMode.Modelview) GL.LoadMatrix(&modelview) field |> Seq.iter (fun c -> o.DrawCell c) if not pause then base.Title <- String.Format("F# Life cell count: {0} Generation: {1} FPS: {2}", (field |> Seq.length), generation, fps) else base.Title <- String.Format("F# Life cell count: {0} Generation: {1} Paused", (field |> Seq.length), generation) base.SwapBuffers()

, , LifeLength:
member this.doNextStep = .... field <- res |> Array.filter(fun c -> c.Age < LifeLength ...

. , :
member this.DrawCell (cell:Cell) = let cellWidth = float32(this.ClientSize.Width) / float32 Size let alpha = match (1.f - float32 cell.Age / float32 LifeLength) with |c when c < 0.f -> 0.f | c -> c let color = match cell.Sex with |Male -> [|0.5f; 0.f; 0.f; alpha|] |Female -> [|0.7f; 0.f; 0.f; alpha|] let pos = (float32 (fst cell.Position) * cellWidth, float32 (snd cell.Position) * cellWidth) GL.Begin(BeginMode.Triangles) GL.Color4 (color) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.End()

:
рдЫрд╡рд┐
- :



.
:)
"" , /

bitbucket
!.

Upd: . :)

let rec lst (l:list) , .

:
member this.allNeighbourCells (position:int*int) = let nCells (point:int*int) = let x,y = point [| (x-1, y-1); (x-1, y); (x-1, y+1); (x, y-1); (x, y+1); (x+1, y-1); (x+1, y); (x+1, y+1); |] let (!) pos = let tx = match fst pos with |x when x < 0 -> Size - 1 |x when x >= Size -> 0 |_ -> fst pos let ty = match snd pos with |y when y < 0 -> Size - 1 |y when y >= Size -> 0 |_ -> snd pos (tx, ty) nCells position |> Array.map ((!))

2 :
nCells point
! , , , ┬л┬╗ .

:
member this.existCell field c = field |> Array.exists (fun af -> c = af.Position)
.

member this.partitionfield field = this.allNeighbourCells >> Array.partition(fun c -> this.existCell field c) member this.pFree field = this.partitionfield field >> snd member this.pExist field = this.partitionfield field >> fst
Partitionfield tuple .
pFree, pExist

, :
member this.Iterate (field:Cell[]) = // let freeNeighb = field |> PSeq.collect (fun c -> this.pFree field c.Position) |> Seq.distinct let born = freeNeighb |> Seq.filter (fun c -> this.pExist field c |> Array.length = 3) |> Seq.map(fun c -> let rnd = new System.Random() {this.genCell(rnd) with Position = c}) let alive = field |> PSeq.filter(fun c -> let neighb = this.pExist field c.Position |> Array.length neighb <= 3 && neighb >= 2) |> PSeq.map (fun c -> {c with Age = (c.Age + 1)}) let res = alive |> Seq.append born |> Seq.toArray res
:
, (freeNeighb) , (- = 3) (born) , 2

, OpenGL , .. .
2 :
doNextStep
, :
member this.doNextStep = async{ let res = (this.life.Iterate field) field <- res |> Array.filter(fun c -> c.Age < LifeLength) isInProc <- false generation <- generation + 1 let delta = DateTime.Now - ftime ftime <- DateTime.Now fps <- Math.Round ((fps + 1000.0 / delta.TotalMilliseconds) / 2.0, 1) }
OnRenderFrame
OpenGL, :
override o.OnRenderFrame(e) = base.OnRenderFrame e match (pause, isInProc) with | (false, false) -> isInProc <- true; Async.Start(o.doNextStep) | _ -> () GL.Clear(ClearBufferMask.ColorBufferBit ||| ClearBufferMask.DepthBufferBit) GL.MatrixMode(MatrixMode.Modelview) GL.LoadMatrix(&modelview) field |> Seq.iter (fun c -> o.DrawCell c) if not pause then base.Title <- String.Format("F# Life cell count: {0} Generation: {1} FPS: {2}", (field |> Seq.length), generation, fps) else base.Title <- String.Format("F# Life cell count: {0} Generation: {1} Paused", (field |> Seq.length), generation) base.SwapBuffers()

, , LifeLength:
member this.doNextStep = .... field <- res |> Array.filter(fun c -> c.Age < LifeLength ...

. , :
member this.DrawCell (cell:Cell) = let cellWidth = float32(this.ClientSize.Width) / float32 Size let alpha = match (1.f - float32 cell.Age / float32 LifeLength) with |c when c < 0.f -> 0.f | c -> c let color = match cell.Sex with |Male -> [|0.5f; 0.f; 0.f; alpha|] |Female -> [|0.7f; 0.f; 0.f; alpha|] let pos = (float32 (fst cell.Position) * cellWidth, float32 (snd cell.Position) * cellWidth) GL.Begin(BeginMode.Triangles) GL.Color4 (color) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.End()

:
рдЫрд╡рд┐
- :



.
:)
"" , /

bitbucket
!.

Upd: . :)

let rec lst (l:list) , .

:
member this.allNeighbourCells (position:int*int) = let nCells (point:int*int) = let x,y = point [| (x-1, y-1); (x-1, y); (x-1, y+1); (x, y-1); (x, y+1); (x+1, y-1); (x+1, y); (x+1, y+1); |] let (!) pos = let tx = match fst pos with |x when x < 0 -> Size - 1 |x when x >= Size -> 0 |_ -> fst pos let ty = match snd pos with |y when y < 0 -> Size - 1 |y when y >= Size -> 0 |_ -> snd pos (tx, ty) nCells position |> Array.map ((!))

2 :
nCells point
! , , , ┬л┬╗ .

:
member this.existCell field c = field |> Array.exists (fun af -> c = af.Position)
.

member this.partitionfield field = this.allNeighbourCells >> Array.partition(fun c -> this.existCell field c) member this.pFree field = this.partitionfield field >> snd member this.pExist field = this.partitionfield field >> fst
Partitionfield tuple .
pFree, pExist

, :
member this.Iterate (field:Cell[]) = // let freeNeighb = field |> PSeq.collect (fun c -> this.pFree field c.Position) |> Seq.distinct let born = freeNeighb |> Seq.filter (fun c -> this.pExist field c |> Array.length = 3) |> Seq.map(fun c -> let rnd = new System.Random() {this.genCell(rnd) with Position = c}) let alive = field |> PSeq.filter(fun c -> let neighb = this.pExist field c.Position |> Array.length neighb <= 3 && neighb >= 2) |> PSeq.map (fun c -> {c with Age = (c.Age + 1)}) let res = alive |> Seq.append born |> Seq.toArray res
:
, (freeNeighb) , (- = 3) (born) , 2

, OpenGL , .. .
2 :
doNextStep
, :
member this.doNextStep = async{ let res = (this.life.Iterate field) field <- res |> Array.filter(fun c -> c.Age < LifeLength) isInProc <- false generation <- generation + 1 let delta = DateTime.Now - ftime ftime <- DateTime.Now fps <- Math.Round ((fps + 1000.0 / delta.TotalMilliseconds) / 2.0, 1) }
OnRenderFrame
OpenGL, :
override o.OnRenderFrame(e) = base.OnRenderFrame e match (pause, isInProc) with | (false, false) -> isInProc <- true; Async.Start(o.doNextStep) | _ -> () GL.Clear(ClearBufferMask.ColorBufferBit ||| ClearBufferMask.DepthBufferBit) GL.MatrixMode(MatrixMode.Modelview) GL.LoadMatrix(&modelview) field |> Seq.iter (fun c -> o.DrawCell c) if not pause then base.Title <- String.Format("F# Life cell count: {0} Generation: {1} FPS: {2}", (field |> Seq.length), generation, fps) else base.Title <- String.Format("F# Life cell count: {0} Generation: {1} Paused", (field |> Seq.length), generation) base.SwapBuffers()

, , LifeLength:
member this.doNextStep = .... field <- res |> Array.filter(fun c -> c.Age < LifeLength ...

. , :
member this.DrawCell (cell:Cell) = let cellWidth = float32(this.ClientSize.Width) / float32 Size let alpha = match (1.f - float32 cell.Age / float32 LifeLength) with |c when c < 0.f -> 0.f | c -> c let color = match cell.Sex with |Male -> [|0.5f; 0.f; 0.f; alpha|] |Female -> [|0.7f; 0.f; 0.f; alpha|] let pos = (float32 (fst cell.Position) * cellWidth, float32 (snd cell.Position) * cellWidth) GL.Begin(BeginMode.Triangles) GL.Color4 (color) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.End()

:
рдЫрд╡рд┐
- :



.
:)
"" , /

bitbucket
!.

Upd: . :)

let rec lst (l:list) , .

:
member this.allNeighbourCells (position:int*int) = let nCells (point:int*int) = let x,y = point [| (x-1, y-1); (x-1, y); (x-1, y+1); (x, y-1); (x, y+1); (x+1, y-1); (x+1, y); (x+1, y+1); |] let (!) pos = let tx = match fst pos with |x when x < 0 -> Size - 1 |x when x >= Size -> 0 |_ -> fst pos let ty = match snd pos with |y when y < 0 -> Size - 1 |y when y >= Size -> 0 |_ -> snd pos (tx, ty) nCells position |> Array.map ((!))

2 :
nCells point
! , , , ┬л┬╗ .

:
member this.existCell field c = field |> Array.exists (fun af -> c = af.Position)
.

member this.partitionfield field = this.allNeighbourCells >> Array.partition(fun c -> this.existCell field c) member this.pFree field = this.partitionfield field >> snd member this.pExist field = this.partitionfield field >> fst
Partitionfield tuple .
pFree, pExist

, :
member this.Iterate (field:Cell[]) = // let freeNeighb = field |> PSeq.collect (fun c -> this.pFree field c.Position) |> Seq.distinct let born = freeNeighb |> Seq.filter (fun c -> this.pExist field c |> Array.length = 3) |> Seq.map(fun c -> let rnd = new System.Random() {this.genCell(rnd) with Position = c}) let alive = field |> PSeq.filter(fun c -> let neighb = this.pExist field c.Position |> Array.length neighb <= 3 && neighb >= 2) |> PSeq.map (fun c -> {c with Age = (c.Age + 1)}) let res = alive |> Seq.append born |> Seq.toArray res
:
, (freeNeighb) , (- = 3) (born) , 2

, OpenGL , .. .
2 :
doNextStep
, :
member this.doNextStep = async{ let res = (this.life.Iterate field) field <- res |> Array.filter(fun c -> c.Age < LifeLength) isInProc <- false generation <- generation + 1 let delta = DateTime.Now - ftime ftime <- DateTime.Now fps <- Math.Round ((fps + 1000.0 / delta.TotalMilliseconds) / 2.0, 1) }
OnRenderFrame
OpenGL, :
override o.OnRenderFrame(e) = base.OnRenderFrame e match (pause, isInProc) with | (false, false) -> isInProc <- true; Async.Start(o.doNextStep) | _ -> () GL.Clear(ClearBufferMask.ColorBufferBit ||| ClearBufferMask.DepthBufferBit) GL.MatrixMode(MatrixMode.Modelview) GL.LoadMatrix(&modelview) field |> Seq.iter (fun c -> o.DrawCell c) if not pause then base.Title <- String.Format("F# Life cell count: {0} Generation: {1} FPS: {2}", (field |> Seq.length), generation, fps) else base.Title <- String.Format("F# Life cell count: {0} Generation: {1} Paused", (field |> Seq.length), generation) base.SwapBuffers()

, , LifeLength:
member this.doNextStep = .... field <- res |> Array.filter(fun c -> c.Age < LifeLength ...

. , :
member this.DrawCell (cell:Cell) = let cellWidth = float32(this.ClientSize.Width) / float32 Size let alpha = match (1.f - float32 cell.Age / float32 LifeLength) with |c when c < 0.f -> 0.f | c -> c let color = match cell.Sex with |Male -> [|0.5f; 0.f; 0.f; alpha|] |Female -> [|0.7f; 0.f; 0.f; alpha|] let pos = (float32 (fst cell.Position) * cellWidth, float32 (snd cell.Position) * cellWidth) GL.Begin(BeginMode.Triangles) GL.Color4 (color) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.End()

:
рдЫрд╡рд┐
- :



.
:)
"" , /

bitbucket
!.

Upd: . :)

 let rec lst (l:list)        ,   . 

:
member this.allNeighbourCells (position:int*int) = let nCells (point:int*int) = let x,y = point [| (x-1, y-1); (x-1, y); (x-1, y+1); (x, y-1); (x, y+1); (x+1, y-1); (x+1, y); (x+1, y+1); |] let (!) pos = let tx = match fst pos with |x when x < 0 -> Size - 1 |x when x >= Size -> 0 |_ -> fst pos let ty = match snd pos with |y when y < 0 -> Size - 1 |y when y >= Size -> 0 |_ -> snd pos (tx, ty) nCells position |> Array.map ((!))

2 :
nCells point
! , , , ┬л┬╗ .

:
member this.existCell field c = field |> Array.exists (fun af -> c = af.Position)
.

member this.partitionfield field = this.allNeighbourCells >> Array.partition(fun c -> this.existCell field c) member this.pFree field = this.partitionfield field >> snd member this.pExist field = this.partitionfield field >> fst
Partitionfield tuple .
pFree, pExist

, :
member this.Iterate (field:Cell[]) = // let freeNeighb = field |> PSeq.collect (fun c -> this.pFree field c.Position) |> Seq.distinct let born = freeNeighb |> Seq.filter (fun c -> this.pExist field c |> Array.length = 3) |> Seq.map(fun c -> let rnd = new System.Random() {this.genCell(rnd) with Position = c}) let alive = field |> PSeq.filter(fun c -> let neighb = this.pExist field c.Position |> Array.length neighb <= 3 && neighb >= 2) |> PSeq.map (fun c -> {c with Age = (c.Age + 1)}) let res = alive |> Seq.append born |> Seq.toArray res
:
, (freeNeighb) , (- = 3) (born) , 2

, OpenGL , .. .
2 :
doNextStep
, :
member this.doNextStep = async{ let res = (this.life.Iterate field) field <- res |> Array.filter(fun c -> c.Age < LifeLength) isInProc <- false generation <- generation + 1 let delta = DateTime.Now - ftime ftime <- DateTime.Now fps <- Math.Round ((fps + 1000.0 / delta.TotalMilliseconds) / 2.0, 1) }
OnRenderFrame
OpenGL, :
override o.OnRenderFrame(e) = base.OnRenderFrame e match (pause, isInProc) with | (false, false) -> isInProc <- true; Async.Start(o.doNextStep) | _ -> () GL.Clear(ClearBufferMask.ColorBufferBit ||| ClearBufferMask.DepthBufferBit) GL.MatrixMode(MatrixMode.Modelview) GL.LoadMatrix(&modelview) field |> Seq.iter (fun c -> o.DrawCell c) if not pause then base.Title <- String.Format("F# Life cell count: {0} Generation: {1} FPS: {2}", (field |> Seq.length), generation, fps) else base.Title <- String.Format("F# Life cell count: {0} Generation: {1} Paused", (field |> Seq.length), generation) base.SwapBuffers()

, , LifeLength:
member this.doNextStep = .... field <- res |> Array.filter(fun c -> c.Age < LifeLength ...

. , :
member this.DrawCell (cell:Cell) = let cellWidth = float32(this.ClientSize.Width) / float32 Size let alpha = match (1.f - float32 cell.Age / float32 LifeLength) with |c when c < 0.f -> 0.f | c -> c let color = match cell.Sex with |Male -> [|0.5f; 0.f; 0.f; alpha|] |Female -> [|0.7f; 0.f; 0.f; alpha|] let pos = (float32 (fst cell.Position) * cellWidth, float32 (snd cell.Position) * cellWidth) GL.Begin(BeginMode.Triangles) GL.Color4 (color) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.End()

:
рдЫрд╡рд┐
- :



.
:)
"" , /

bitbucket
!.

Upd: . :)

let rec lst (l:list) , .

:
member this.allNeighbourCells (position:int*int) = let nCells (point:int*int) = let x,y = point [| (x-1, y-1); (x-1, y); (x-1, y+1); (x, y-1); (x, y+1); (x+1, y-1); (x+1, y); (x+1, y+1); |] let (!) pos = let tx = match fst pos with |x when x < 0 -> Size - 1 |x when x >= Size -> 0 |_ -> fst pos let ty = match snd pos with |y when y < 0 -> Size - 1 |y when y >= Size -> 0 |_ -> snd pos (tx, ty) nCells position |> Array.map ((!))

2 :
nCells point
! , , , ┬л┬╗ .

:
member this.existCell field c = field |> Array.exists (fun af -> c = af.Position)
.

member this.partitionfield field = this.allNeighbourCells >> Array.partition(fun c -> this.existCell field c) member this.pFree field = this.partitionfield field >> snd member this.pExist field = this.partitionfield field >> fst
Partitionfield tuple .
pFree, pExist

, :
member this.Iterate (field:Cell[]) = // let freeNeighb = field |> PSeq.collect (fun c -> this.pFree field c.Position) |> Seq.distinct let born = freeNeighb |> Seq.filter (fun c -> this.pExist field c |> Array.length = 3) |> Seq.map(fun c -> let rnd = new System.Random() {this.genCell(rnd) with Position = c}) let alive = field |> PSeq.filter(fun c -> let neighb = this.pExist field c.Position |> Array.length neighb <= 3 && neighb >= 2) |> PSeq.map (fun c -> {c with Age = (c.Age + 1)}) let res = alive |> Seq.append born |> Seq.toArray res
:
, (freeNeighb) , (- = 3) (born) , 2

, OpenGL , .. .
2 :
doNextStep
, :
member this.doNextStep = async{ let res = (this.life.Iterate field) field <- res |> Array.filter(fun c -> c.Age < LifeLength) isInProc <- false generation <- generation + 1 let delta = DateTime.Now - ftime ftime <- DateTime.Now fps <- Math.Round ((fps + 1000.0 / delta.TotalMilliseconds) / 2.0, 1) }
OnRenderFrame
OpenGL, :
override o.OnRenderFrame(e) = base.OnRenderFrame e match (pause, isInProc) with | (false, false) -> isInProc <- true; Async.Start(o.doNextStep) | _ -> () GL.Clear(ClearBufferMask.ColorBufferBit ||| ClearBufferMask.DepthBufferBit) GL.MatrixMode(MatrixMode.Modelview) GL.LoadMatrix(&modelview) field |> Seq.iter (fun c -> o.DrawCell c) if not pause then base.Title <- String.Format("F# Life cell count: {0} Generation: {1} FPS: {2}", (field |> Seq.length), generation, fps) else base.Title <- String.Format("F# Life cell count: {0} Generation: {1} Paused", (field |> Seq.length), generation) base.SwapBuffers()

, , LifeLength:
member this.doNextStep = .... field <- res |> Array.filter(fun c -> c.Age < LifeLength ...

. , :
member this.DrawCell (cell:Cell) = let cellWidth = float32(this.ClientSize.Width) / float32 Size let alpha = match (1.f - float32 cell.Age / float32 LifeLength) with |c when c < 0.f -> 0.f | c -> c let color = match cell.Sex with |Male -> [|0.5f; 0.f; 0.f; alpha|] |Female -> [|0.7f; 0.f; 0.f; alpha|] let pos = (float32 (fst cell.Position) * cellWidth, float32 (snd cell.Position) * cellWidth) GL.Begin(BeginMode.Triangles) GL.Color4 (color) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.End()

:
рдЫрд╡рд┐
- :



.
:)
"" , /

bitbucket
!.

Upd: . :)

 let rec lst (l:list)        ,   . 

:
member this.allNeighbourCells (position:int*int) = let nCells (point:int*int) = let x,y = point [| (x-1, y-1); (x-1, y); (x-1, y+1); (x, y-1); (x, y+1); (x+1, y-1); (x+1, y); (x+1, y+1); |] let (!) pos = let tx = match fst pos with |x when x < 0 -> Size - 1 |x when x >= Size -> 0 |_ -> fst pos let ty = match snd pos with |y when y < 0 -> Size - 1 |y when y >= Size -> 0 |_ -> snd pos (tx, ty) nCells position |> Array.map ((!))

2 :
nCells point
! , , , ┬л┬╗ .

:
member this.existCell field c = field |> Array.exists (fun af -> c = af.Position)
.

member this.partitionfield field = this.allNeighbourCells >> Array.partition(fun c -> this.existCell field c) member this.pFree field = this.partitionfield field >> snd member this.pExist field = this.partitionfield field >> fst
Partitionfield tuple .
pFree, pExist

, :
member this.Iterate (field:Cell[]) = // let freeNeighb = field |> PSeq.collect (fun c -> this.pFree field c.Position) |> Seq.distinct let born = freeNeighb |> Seq.filter (fun c -> this.pExist field c |> Array.length = 3) |> Seq.map(fun c -> let rnd = new System.Random() {this.genCell(rnd) with Position = c}) let alive = field |> PSeq.filter(fun c -> let neighb = this.pExist field c.Position |> Array.length neighb <= 3 && neighb >= 2) |> PSeq.map (fun c -> {c with Age = (c.Age + 1)}) let res = alive |> Seq.append born |> Seq.toArray res
:
, (freeNeighb) , (- = 3) (born) , 2

, OpenGL , .. .
2 :
doNextStep
, :
member this.doNextStep = async{ let res = (this.life.Iterate field) field <- res |> Array.filter(fun c -> c.Age < LifeLength) isInProc <- false generation <- generation + 1 let delta = DateTime.Now - ftime ftime <- DateTime.Now fps <- Math.Round ((fps + 1000.0 / delta.TotalMilliseconds) / 2.0, 1) }
OnRenderFrame
OpenGL, :
override o.OnRenderFrame(e) = base.OnRenderFrame e match (pause, isInProc) with | (false, false) -> isInProc <- true; Async.Start(o.doNextStep) | _ -> () GL.Clear(ClearBufferMask.ColorBufferBit ||| ClearBufferMask.DepthBufferBit) GL.MatrixMode(MatrixMode.Modelview) GL.LoadMatrix(&modelview) field |> Seq.iter (fun c -> o.DrawCell c) if not pause then base.Title <- String.Format("F# Life cell count: {0} Generation: {1} FPS: {2}", (field |> Seq.length), generation, fps) else base.Title <- String.Format("F# Life cell count: {0} Generation: {1} Paused", (field |> Seq.length), generation) base.SwapBuffers()

, , LifeLength:
member this.doNextStep = .... field <- res |> Array.filter(fun c -> c.Age < LifeLength ...

. , :
member this.DrawCell (cell:Cell) = let cellWidth = float32(this.ClientSize.Width) / float32 Size let alpha = match (1.f - float32 cell.Age / float32 LifeLength) with |c when c < 0.f -> 0.f | c -> c let color = match cell.Sex with |Male -> [|0.5f; 0.f; 0.f; alpha|] |Female -> [|0.7f; 0.f; 0.f; alpha|] let pos = (float32 (fst cell.Position) * cellWidth, float32 (snd cell.Position) * cellWidth) GL.Begin(BeginMode.Triangles) GL.Color4 (color) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.End()

:
рдЫрд╡рд┐
- :



.
:)
"" , /

bitbucket
!.

Upd: . :)

let rec lst (l:list) , .

:
member this.allNeighbourCells (position:int*int) = let nCells (point:int*int) = let x,y = point [| (x-1, y-1); (x-1, y); (x-1, y+1); (x, y-1); (x, y+1); (x+1, y-1); (x+1, y); (x+1, y+1); |] let (!) pos = let tx = match fst pos with |x when x < 0 -> Size - 1 |x when x >= Size -> 0 |_ -> fst pos let ty = match snd pos with |y when y < 0 -> Size - 1 |y when y >= Size -> 0 |_ -> snd pos (tx, ty) nCells position |> Array.map ((!))

2 :
nCells point
! , , , ┬л┬╗ .

:
member this.existCell field c = field |> Array.exists (fun af -> c = af.Position)
.

member this.partitionfield field = this.allNeighbourCells >> Array.partition(fun c -> this.existCell field c) member this.pFree field = this.partitionfield field >> snd member this.pExist field = this.partitionfield field >> fst
Partitionfield tuple .
pFree, pExist

, :
member this.Iterate (field:Cell[]) = // let freeNeighb = field |> PSeq.collect (fun c -> this.pFree field c.Position) |> Seq.distinct let born = freeNeighb |> Seq.filter (fun c -> this.pExist field c |> Array.length = 3) |> Seq.map(fun c -> let rnd = new System.Random() {this.genCell(rnd) with Position = c}) let alive = field |> PSeq.filter(fun c -> let neighb = this.pExist field c.Position |> Array.length neighb <= 3 && neighb >= 2) |> PSeq.map (fun c -> {c with Age = (c.Age + 1)}) let res = alive |> Seq.append born |> Seq.toArray res
:
, (freeNeighb) , (- = 3) (born) , 2

, OpenGL , .. .
2 :
doNextStep
, :
member this.doNextStep = async{ let res = (this.life.Iterate field) field <- res |> Array.filter(fun c -> c.Age < LifeLength) isInProc <- false generation <- generation + 1 let delta = DateTime.Now - ftime ftime <- DateTime.Now fps <- Math.Round ((fps + 1000.0 / delta.TotalMilliseconds) / 2.0, 1) }
OnRenderFrame
OpenGL, :
override o.OnRenderFrame(e) = base.OnRenderFrame e match (pause, isInProc) with | (false, false) -> isInProc <- true; Async.Start(o.doNextStep) | _ -> () GL.Clear(ClearBufferMask.ColorBufferBit ||| ClearBufferMask.DepthBufferBit) GL.MatrixMode(MatrixMode.Modelview) GL.LoadMatrix(&modelview) field |> Seq.iter (fun c -> o.DrawCell c) if not pause then base.Title <- String.Format("F# Life cell count: {0} Generation: {1} FPS: {2}", (field |> Seq.length), generation, fps) else base.Title <- String.Format("F# Life cell count: {0} Generation: {1} Paused", (field |> Seq.length), generation) base.SwapBuffers()

, , LifeLength:
member this.doNextStep = .... field <- res |> Array.filter(fun c -> c.Age < LifeLength ...

. , :
member this.DrawCell (cell:Cell) = let cellWidth = float32(this.ClientSize.Width) / float32 Size let alpha = match (1.f - float32 cell.Age / float32 LifeLength) with |c when c < 0.f -> 0.f | c -> c let color = match cell.Sex with |Male -> [|0.5f; 0.f; 0.f; alpha|] |Female -> [|0.7f; 0.f; 0.f; alpha|] let pos = (float32 (fst cell.Position) * cellWidth, float32 (snd cell.Position) * cellWidth) GL.Begin(BeginMode.Triangles) GL.Color4 (color) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.End()

:
рдЫрд╡рд┐
- :



.
:)
"" , /

bitbucket
!.

Upd: . :)

 let rec lst (l:list)        ,   . 

:
member this.allNeighbourCells (position:int*int) = let nCells (point:int*int) = let x,y = point [| (x-1, y-1); (x-1, y); (x-1, y+1); (x, y-1); (x, y+1); (x+1, y-1); (x+1, y); (x+1, y+1); |] let (!) pos = let tx = match fst pos with |x when x < 0 -> Size - 1 |x when x >= Size -> 0 |_ -> fst pos let ty = match snd pos with |y when y < 0 -> Size - 1 |y when y >= Size -> 0 |_ -> snd pos (tx, ty) nCells position |> Array.map ((!))

2 :
nCells point
! , , , ┬л┬╗ .

:
member this.existCell field c = field |> Array.exists (fun af -> c = af.Position)
.

member this.partitionfield field = this.allNeighbourCells >> Array.partition(fun c -> this.existCell field c) member this.pFree field = this.partitionfield field >> snd member this.pExist field = this.partitionfield field >> fst
Partitionfield tuple .
pFree, pExist

, :
member this.Iterate (field:Cell[]) = // let freeNeighb = field |> PSeq.collect (fun c -> this.pFree field c.Position) |> Seq.distinct let born = freeNeighb |> Seq.filter (fun c -> this.pExist field c |> Array.length = 3) |> Seq.map(fun c -> let rnd = new System.Random() {this.genCell(rnd) with Position = c}) let alive = field |> PSeq.filter(fun c -> let neighb = this.pExist field c.Position |> Array.length neighb <= 3 && neighb >= 2) |> PSeq.map (fun c -> {c with Age = (c.Age + 1)}) let res = alive |> Seq.append born |> Seq.toArray res
:
, (freeNeighb) , (- = 3) (born) , 2

, OpenGL , .. .
2 :
doNextStep
, :
member this.doNextStep = async{ let res = (this.life.Iterate field) field <- res |> Array.filter(fun c -> c.Age < LifeLength) isInProc <- false generation <- generation + 1 let delta = DateTime.Now - ftime ftime <- DateTime.Now fps <- Math.Round ((fps + 1000.0 / delta.TotalMilliseconds) / 2.0, 1) }
OnRenderFrame
OpenGL, :
override o.OnRenderFrame(e) = base.OnRenderFrame e match (pause, isInProc) with | (false, false) -> isInProc <- true; Async.Start(o.doNextStep) | _ -> () GL.Clear(ClearBufferMask.ColorBufferBit ||| ClearBufferMask.DepthBufferBit) GL.MatrixMode(MatrixMode.Modelview) GL.LoadMatrix(&modelview) field |> Seq.iter (fun c -> o.DrawCell c) if not pause then base.Title <- String.Format("F# Life cell count: {0} Generation: {1} FPS: {2}", (field |> Seq.length), generation, fps) else base.Title <- String.Format("F# Life cell count: {0} Generation: {1} Paused", (field |> Seq.length), generation) base.SwapBuffers()

, , LifeLength:
member this.doNextStep = .... field <- res |> Array.filter(fun c -> c.Age < LifeLength ...

. , :
member this.DrawCell (cell:Cell) = let cellWidth = float32(this.ClientSize.Width) / float32 Size let alpha = match (1.f - float32 cell.Age / float32 LifeLength) with |c when c < 0.f -> 0.f | c -> c let color = match cell.Sex with |Male -> [|0.5f; 0.f; 0.f; alpha|] |Female -> [|0.7f; 0.f; 0.f; alpha|] let pos = (float32 (fst cell.Position) * cellWidth, float32 (snd cell.Position) * cellWidth) GL.Begin(BeginMode.Triangles) GL.Color4 (color) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.End()

:
рдЫрд╡рд┐
- :



.
:)
"" , /

bitbucket
!.

Upd: . :)

let rec lst (l:list) , .

:
member this.allNeighbourCells (position:int*int) = let nCells (point:int*int) = let x,y = point [| (x-1, y-1); (x-1, y); (x-1, y+1); (x, y-1); (x, y+1); (x+1, y-1); (x+1, y); (x+1, y+1); |] let (!) pos = let tx = match fst pos with |x when x < 0 -> Size - 1 |x when x >= Size -> 0 |_ -> fst pos let ty = match snd pos with |y when y < 0 -> Size - 1 |y when y >= Size -> 0 |_ -> snd pos (tx, ty) nCells position |> Array.map ((!))

2 :
nCells point
! , , , ┬л┬╗ .

:
member this.existCell field c = field |> Array.exists (fun af -> c = af.Position)
.

member this.partitionfield field = this.allNeighbourCells >> Array.partition(fun c -> this.existCell field c) member this.pFree field = this.partitionfield field >> snd member this.pExist field = this.partitionfield field >> fst
Partitionfield tuple .
pFree, pExist

, :
member this.Iterate (field:Cell[]) = // let freeNeighb = field |> PSeq.collect (fun c -> this.pFree field c.Position) |> Seq.distinct let born = freeNeighb |> Seq.filter (fun c -> this.pExist field c |> Array.length = 3) |> Seq.map(fun c -> let rnd = new System.Random() {this.genCell(rnd) with Position = c}) let alive = field |> PSeq.filter(fun c -> let neighb = this.pExist field c.Position |> Array.length neighb <= 3 && neighb >= 2) |> PSeq.map (fun c -> {c with Age = (c.Age + 1)}) let res = alive |> Seq.append born |> Seq.toArray res
:
, (freeNeighb) , (- = 3) (born) , 2

, OpenGL , .. .
2 :
doNextStep
, :
member this.doNextStep = async{ let res = (this.life.Iterate field) field <- res |> Array.filter(fun c -> c.Age < LifeLength) isInProc <- false generation <- generation + 1 let delta = DateTime.Now - ftime ftime <- DateTime.Now fps <- Math.Round ((fps + 1000.0 / delta.TotalMilliseconds) / 2.0, 1) }
OnRenderFrame
OpenGL, :
override o.OnRenderFrame(e) = base.OnRenderFrame e match (pause, isInProc) with | (false, false) -> isInProc <- true; Async.Start(o.doNextStep) | _ -> () GL.Clear(ClearBufferMask.ColorBufferBit ||| ClearBufferMask.DepthBufferBit) GL.MatrixMode(MatrixMode.Modelview) GL.LoadMatrix(&modelview) field |> Seq.iter (fun c -> o.DrawCell c) if not pause then base.Title <- String.Format("F# Life cell count: {0} Generation: {1} FPS: {2}", (field |> Seq.length), generation, fps) else base.Title <- String.Format("F# Life cell count: {0} Generation: {1} Paused", (field |> Seq.length), generation) base.SwapBuffers()

, , LifeLength:
member this.doNextStep = .... field <- res |> Array.filter(fun c -> c.Age < LifeLength ...

. , :
member this.DrawCell (cell:Cell) = let cellWidth = float32(this.ClientSize.Width) / float32 Size let alpha = match (1.f - float32 cell.Age / float32 LifeLength) with |c when c < 0.f -> 0.f | c -> c let color = match cell.Sex with |Male -> [|0.5f; 0.f; 0.f; alpha|] |Female -> [|0.7f; 0.f; 0.f; alpha|] let pos = (float32 (fst cell.Position) * cellWidth, float32 (snd cell.Position) * cellWidth) GL.Begin(BeginMode.Triangles) GL.Color4 (color) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.End()

:
рдЫрд╡рд┐
- :



.
:)
"" , /

bitbucket
!.

Upd: . :)

let rec lst (l:list) , .

:
member this.allNeighbourCells (position:int*int) = let nCells (point:int*int) = let x,y = point [| (x-1, y-1); (x-1, y); (x-1, y+1); (x, y-1); (x, y+1); (x+1, y-1); (x+1, y); (x+1, y+1); |] let (!) pos = let tx = match fst pos with |x when x < 0 -> Size - 1 |x when x >= Size -> 0 |_ -> fst pos let ty = match snd pos with |y when y < 0 -> Size - 1 |y when y >= Size -> 0 |_ -> snd pos (tx, ty) nCells position |> Array.map ((!))

2 :
nCells point
! , , , ┬л┬╗ .

:
member this.existCell field c = field |> Array.exists (fun af -> c = af.Position)
.

member this.partitionfield field = this.allNeighbourCells >> Array.partition(fun c -> this.existCell field c) member this.pFree field = this.partitionfield field >> snd member this.pExist field = this.partitionfield field >> fst
Partitionfield tuple .
pFree, pExist

, :
member this.Iterate (field:Cell[]) = // let freeNeighb = field |> PSeq.collect (fun c -> this.pFree field c.Position) |> Seq.distinct let born = freeNeighb |> Seq.filter (fun c -> this.pExist field c |> Array.length = 3) |> Seq.map(fun c -> let rnd = new System.Random() {this.genCell(rnd) with Position = c}) let alive = field |> PSeq.filter(fun c -> let neighb = this.pExist field c.Position |> Array.length neighb <= 3 && neighb >= 2) |> PSeq.map (fun c -> {c with Age = (c.Age + 1)}) let res = alive |> Seq.append born |> Seq.toArray res
:
, (freeNeighb) , (- = 3) (born) , 2

, OpenGL , .. .
2 :
doNextStep
, :
member this.doNextStep = async{ let res = (this.life.Iterate field) field <- res |> Array.filter(fun c -> c.Age < LifeLength) isInProc <- false generation <- generation + 1 let delta = DateTime.Now - ftime ftime <- DateTime.Now fps <- Math.Round ((fps + 1000.0 / delta.TotalMilliseconds) / 2.0, 1) }
OnRenderFrame
OpenGL, :
override o.OnRenderFrame(e) = base.OnRenderFrame e match (pause, isInProc) with | (false, false) -> isInProc <- true; Async.Start(o.doNextStep) | _ -> () GL.Clear(ClearBufferMask.ColorBufferBit ||| ClearBufferMask.DepthBufferBit) GL.MatrixMode(MatrixMode.Modelview) GL.LoadMatrix(&modelview) field |> Seq.iter (fun c -> o.DrawCell c) if not pause then base.Title <- String.Format("F# Life cell count: {0} Generation: {1} FPS: {2}", (field |> Seq.length), generation, fps) else base.Title <- String.Format("F# Life cell count: {0} Generation: {1} Paused", (field |> Seq.length), generation) base.SwapBuffers()

, , LifeLength:
member this.doNextStep = .... field <- res |> Array.filter(fun c -> c.Age < LifeLength ...

. , :
member this.DrawCell (cell:Cell) = let cellWidth = float32(this.ClientSize.Width) / float32 Size let alpha = match (1.f - float32 cell.Age / float32 LifeLength) with |c when c < 0.f -> 0.f | c -> c let color = match cell.Sex with |Male -> [|0.5f; 0.f; 0.f; alpha|] |Female -> [|0.7f; 0.f; 0.f; alpha|] let pos = (float32 (fst cell.Position) * cellWidth, float32 (snd cell.Position) * cellWidth) GL.Begin(BeginMode.Triangles) GL.Color4 (color) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.End()

:
рдЫрд╡рд┐
- :



.
:)
"" , /

bitbucket
!.

Upd: . :)

let rec lst (l:list) , .

:
member this.allNeighbourCells (position:int*int) = let nCells (point:int*int) = let x,y = point [| (x-1, y-1); (x-1, y); (x-1, y+1); (x, y-1); (x, y+1); (x+1, y-1); (x+1, y); (x+1, y+1); |] let (!) pos = let tx = match fst pos with |x when x < 0 -> Size - 1 |x when x >= Size -> 0 |_ -> fst pos let ty = match snd pos with |y when y < 0 -> Size - 1 |y when y >= Size -> 0 |_ -> snd pos (tx, ty) nCells position |> Array.map ((!))

2 :
nCells point
! , , , ┬л┬╗ .

:
member this.existCell field c = field |> Array.exists (fun af -> c = af.Position)
.

member this.partitionfield field = this.allNeighbourCells >> Array.partition(fun c -> this.existCell field c) member this.pFree field = this.partitionfield field >> snd member this.pExist field = this.partitionfield field >> fst
Partitionfield tuple .
pFree, pExist

, :
member this.Iterate (field:Cell[]) = // let freeNeighb = field |> PSeq.collect (fun c -> this.pFree field c.Position) |> Seq.distinct let born = freeNeighb |> Seq.filter (fun c -> this.pExist field c |> Array.length = 3) |> Seq.map(fun c -> let rnd = new System.Random() {this.genCell(rnd) with Position = c}) let alive = field |> PSeq.filter(fun c -> let neighb = this.pExist field c.Position |> Array.length neighb <= 3 && neighb >= 2) |> PSeq.map (fun c -> {c with Age = (c.Age + 1)}) let res = alive |> Seq.append born |> Seq.toArray res
:
, (freeNeighb) , (- = 3) (born) , 2

, OpenGL , .. .
2 :
doNextStep
, :
member this.doNextStep = async{ let res = (this.life.Iterate field) field <- res |> Array.filter(fun c -> c.Age < LifeLength) isInProc <- false generation <- generation + 1 let delta = DateTime.Now - ftime ftime <- DateTime.Now fps <- Math.Round ((fps + 1000.0 / delta.TotalMilliseconds) / 2.0, 1) }
OnRenderFrame
OpenGL, :
override o.OnRenderFrame(e) = base.OnRenderFrame e match (pause, isInProc) with | (false, false) -> isInProc <- true; Async.Start(o.doNextStep) | _ -> () GL.Clear(ClearBufferMask.ColorBufferBit ||| ClearBufferMask.DepthBufferBit) GL.MatrixMode(MatrixMode.Modelview) GL.LoadMatrix(&modelview) field |> Seq.iter (fun c -> o.DrawCell c) if not pause then base.Title <- String.Format("F# Life cell count: {0} Generation: {1} FPS: {2}", (field |> Seq.length), generation, fps) else base.Title <- String.Format("F# Life cell count: {0} Generation: {1} Paused", (field |> Seq.length), generation) base.SwapBuffers()

, , LifeLength:
member this.doNextStep = .... field <- res |> Array.filter(fun c -> c.Age < LifeLength ...

. , :
member this.DrawCell (cell:Cell) = let cellWidth = float32(this.ClientSize.Width) / float32 Size let alpha = match (1.f - float32 cell.Age / float32 LifeLength) with |c when c < 0.f -> 0.f | c -> c let color = match cell.Sex with |Male -> [|0.5f; 0.f; 0.f; alpha|] |Female -> [|0.7f; 0.f; 0.f; alpha|] let pos = (float32 (fst cell.Position) * cellWidth, float32 (snd cell.Position) * cellWidth) GL.Begin(BeginMode.Triangles) GL.Color4 (color) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(fst pos + 0.5f, snd pos + 0.5f, 1.f) GL.Vertex3(cellWidth + fst pos - 0.5f, cellWidth + snd pos - 0.5f, 1.f) GL.End()

:
рдЫрд╡рд┐
- :



.
:)
"" , /

bitbucket
!.

Upd: . :)

Source: https://habr.com/ru/post/In173419/


All Articles