Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %====CODE====%
- local
- MaxTime = 10 % nombre de frame l'animation
- MyFunction
- Map
- CheckMap
- Extensions = opt(withExtendedFormula:true
- withIfThenElse:true
- withComparison:true
- withTimeWindow:false
- withCheckMapEasy:true
- withCheckMapComplete:false
- )
- in
- Map = map(ru:scale(rx:20.0 ry:20.0 1:primitive(kind:water)|nil)|nil pu:translate(dx:200.0 dy:200.0 1:primitive(kind:pokestop)|nil)|nil) %% TODO change the map here
- fun{MyFunction Map}
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %%REALUNIVERSE%%
- local ListeReal ListePoke Append in
- local Runiverse in
- fun {Runiverse P}
- local Traduction Liste FlattenList Translate Scale Rotate Affiche Take Inverse L CheckValue in
- fun {CheckValue Value}
- if {Float.is Value} then Value
- else
- case Value
- of plus(X Y) then {CheckValue X}+{CheckValue Y}
- []minus(X Y) then {CheckValue X}-{CheckValue Y}
- []mult(X Y) then {CheckValue X}*{CheckValue Y}
- []'div'(X Y) then {CheckValue X}/{CheckValue Y}
- []sin(X) then {Float.sin {CheckValue X}}
- []cos(X) then {Float.cos {CheckValue X}}
- []tan(X) then {Float.tan {CheckValue X}}
- []exp(X) then {Float.exp {CheckValue X}}
- []log(X) then {Float.log {CheckValue X}}
- []neg(X) then ~{CheckValue X}
- end
- end
- end
- fun {Liste L Acc Acc2}
- case L of nil then Acc2
- []H|T then case H
- of translate(dx:DX dy:DY 1:N) then {Liste N H|Acc Acc2}|{Liste T Acc Acc2}
- [] rotate(angle:A 1:N) then {Liste N H|Acc Acc2}|{Liste T Acc Acc2}
- [] scale(rx:RX ry:RY 1:N) then{Liste N H|Acc Acc2}|{Liste T Acc Acc2}
- [] primitive(kind:A) then [H|Acc]|Acc2|{Liste T Acc Acc2}
- end
- end
- end
- fun {FlattenList L}
- case L
- of nil then nil
- [] nil|T then {FlattenList T}
- [](H1|T1)|T then {FlattenList H1|T1|T}
- [] X|T then X|{FlattenList T}
- else L
- end
- end
- fun {Take L Acc Acc2}%%Sors la premiere liste contenant une primitive et ses deformations associees.
- case L of nil then Acc2
- []primitive(kind:K)|T then {Take T nil {Traduction primitive(kind:K)|Acc nil}|Acc2}
- []H|T then {Take T H|Acc Acc2}
- end
- end
- fun{Inverse L Acc}%%retourne une liste inversee.
- case L of nil then Acc
- []H|T then {Inverse T H|Acc}
- end
- end
- fun {Scale A Rx Ry} %%Ok
- case A
- of realitem(kind:H p1:pt(x:B y:C) p2:pt(x:D y:E))
- then realitem(kind:H
- p1:pt(x:B*{CheckValue Rx} y:C*{CheckValue Ry})
- p2:pt(x:D*{CheckValue Rx} y:E*{CheckValue Ry}))%pour translater la road
- []realitem(kind:H p1:B p2:C p3:D p4:E)
- then
- realitem(kind:H
- p1:pt(x:B.x*{CheckValue Rx} y:B.y*{CheckValue Ry})
- p2:pt(x:C.x*{CheckValue Rx} y:C.y*{CheckValue Ry})
- p3:pt(x:D.x*{CheckValue Rx} y:D.y*{CheckValue Ry})
- p4:pt(x:E.x*{CheckValue Rx} y:E.y*{CheckValue Ry}))%pour translater water et building
- else nil
- end
- end
- fun{Rotate A B}
- case A
- of r(kind:Q position:pt(x:D y:E))
- then r(kind:Q position:pt(x:D*{CheckValue cos(B)}+E*{CheckValue sin(B)} y:~D*{CheckValue sin(B)}+E*{CheckValue cos(B)}))
- []r(kind:Q p1:pt(x:M y:N) p2:pt(x:D y:E))
- then r(kind:Q
- p1:pt(x:M*{CheckValue cos(B)}+N*{CheckValue sin(B)} y:~M*{CheckValue sin(B)}+N*{CheckValue cos(B)})
- p2:pt(x:D*{CheckValue cos(B)}+E*{CheckValue sin(B)} y:~D*{CheckValue sin(B)}+E*{CheckValue cos(B)}))%pour faire une rotation de la road
- []r(kind:Q p1:pt(x:M y:N) p2:pt(x:D y:E) p3:pt(x:F y:G) p4:pt(x:H y:I))
- then r(kind:Q
- p1:pt(x:M*{CheckValue cos(B)}+N*{CheckValue sin(B)} y:~M*{CheckValue sin(B)}+N*{CheckValue cos(B)})
- p2:pt(x:D*{CheckValue cos(B)}+E*{CheckValue sin(B)} y:~D*{CheckValue sin(B)}+E*{CheckValue cos(B)})
- p3:pt(x:F*{CheckValue cos(B)}+G*{CheckValue sin(B)} y:~F*{CheckValue sin(B)}+G*{CheckValue cos(B)})
- p4:pt(x:H*{CheckValue cos(B)}+I*{CheckValue sin(B)} y:~H*{CheckValue sin(B)}+I*{CheckValue cos(B)}))%pour faire une rotation de water et buildin
- end
- end
- fun{Translate Z DX DY}%ok
- case Z
- of realitem(kind:A p1:pt(x:B y:C) p2:pt(x:D y:E))
- then realitem(kind:A
- p1:pt(x:B+{CheckValue DX} y:C+{CheckValue DY})
- p2:pt(x:D+{CheckValue DX} y:E+{CheckValue DY}))%pour translater la road
- []realitem(kind:A p1:pt(x:B y:C) p2:pt(x:D y:E) p3:pt(x:F y:G) p4:pt(x:H y:I))
- then realitem(kind:A
- p1:pt(x:B+{CheckValue DX} y:C+{CheckValue DY})
- p2:pt(x:D+{CheckValue DX} y:E+{CheckValue DY})
- p3:pt(x:F+{CheckValue DX} y:G+{CheckValue DY})
- p4:pt(x:H+{CheckValue DX} y:I+{CheckValue DY}))%pour translater water et building
- else nil
- end
- end
- fun {Traduction L F}%fonction prend en arg une liste contenant une prim et sort une fct prenant le temps en arg qui affiche un mapitem
- case L of nil then fun{$ Time} F end
- []translate(dx:DX dy:DY 1:New)|T then {Traduction T {Translate F DX DY}}
- []rotate(angle:A 1:New)|T then {Traduction T {Rotate F A}}
- []scale(rx:A ry:B 1:New)|T then {Traduction T {Scale F A B}}
- []primitive(kind:A)|T then {Traduction T {Affiche L.1}}
- end
- end
- fun{Affiche A}
- local P1 P2 P3 P4 in
- P1=pt(x:0.0 y:0.0)
- P2=pt(x:0.0 y:1.0)
- P3=pt(x:1.0 y:1.0)
- P4=pt(x:1.0 y:0.0)
- case A of nil then nil
- [] primitive(kind:K) then
- case K of building then realitem(kind:building p1:P1 p2:P2 p3:P3 p4:P4)
- [] water then realitem(kind:water p1:P1 p2:P2 p3:P3 p4:P4)
- else realitem(kind:road p1:P1 p2:P4)
- end
- end
- end
- end
- L= {Inverse {FlattenList {Liste Map.ru nil nil}} nil}
- {Take L nil nil}
- end
- end
- ListeReal={Runiverse Map}
- end
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %%POKEUNIVERSE%%
- local Puniverse in
- fun {Puniverse L}
- local Liste FlattenList Affiche Traduction Inverse Take Formula L in
- fun {Traduction L F}%fonction prend en arg une liste contenant une prim et sort une fct prenant le temps en arg qui affiche un mapitem
- case L of nil then nil
- []translate(dx:DX dy:DY 1:New)|T then
- local Translate in
- fun{Translate Z Time DX DY}
- fun{$ Time}
- case {Z Time}
- of pokeitem(kind:A position:B) then pokeitem(kind:A position: pt(x:{Formula plus(B DX) Time} y:{Formula plus(B DY) Time}))%pour deplacer le pokeitem
- end
- end|{Translate T Time DX DY}
- end
- {Traduction T Translate}
- end
- []primitive(kind:A)|T then fun{$ Time} {Affiche L.1} end|nil
- end
- end
- fun{Affiche A}
- case A
- of nil then nil
- [] primitive(kind:K) then
- case K
- of pokemon then pokeitem(kind:pokemon position:pt(x:0.0 y:0.0))
- [] arena then pokeitem(kind:arena position:pt(x:0.0 y:0.0))
- else pokeitem(kind:pokestop position:pt(x:0.0 y:0.0))
- end
- end
- end
- fun {Take L Acc Acc2}%%Sors la premiere liste contenant une primitive et ses deformations associees.
- case L of nil then Acc2
- []primitive(kind:K)|T then {Take T nil {Traduction primitive(kind:K)|Acc nil}|Acc2}
- []H|T then {Take T H|Acc Acc2}
- end
- end
- fun {Formula Value Time}
- if {Float.is Value} then Value
- else
- case Value
- of time then Time
- []plus(X Y) then {Formula X Time}+{Formula Y Time}
- []minus(X Y) then{Formula X Time}-{Formula Y Time}
- []mult(X Y) then{Formula X Time}*{Formula Y Time}
- []'div'(X Y) then {Formula X Time}/{Formula Y Time}
- []sin(X) then {Float.sin {Formula X Time}}
- []cos(X) then {Float.cos {Formula X Time}}
- []tan(X) then {Float.tan {Formula X Time}}
- []exp(X) then {Float.exp {Formula X Time}}
- []log(X) then {Float.log {Formula X Time}}
- []neg(X) then {Float.neg {Formula X Time}}
- else 0.0
- end
- end
- end
- fun {FlattenList L}
- case L
- of nil then nil
- [] nil|T then {FlattenList T}
- [](H1|T1)|T then {FlattenList H1|T1|T}
- [] X|T then X|{FlattenList T}
- else L
- end
- end
- fun{Inverse L Acc}%%retourne une liste inversee.
- case L of nil then Acc
- []H|T then {Inverse T H|Acc}
- end
- end
- fun {Liste L Acc Acc2}
- case L
- of nil then Acc2
- []H|T then case H
- of translate(dx:DX dy:DY 1:N) then {Liste N H|Acc Acc2}|{Liste T Acc Acc2}
- [] primitive(kind:A) then [H|Acc]|Acc2|{Liste T Acc Acc2}
- end
- end
- end
- L={Inverse {FlattenList {Liste Map.pu nil nil}} nil}
- {FlattenList {Take L nil nil}}
- end
- end
- ListePoke={Puniverse Map}
- end
- fun{Append L1 L2}
- case L1
- of nil then L2
- [] H|T then H|{Append T L2}
- end
- end
- local VI in
- proc{VI L}
- case L
- of nil then {Browse nil}
- [] H|T then {Browse {H 0.0}} {VI T}
- end
- end
- {VI ListePoke}
- end
- {Append ListeReal ListePoke}
- end
- end
- fun{CheckMap Map}
- local IsRU IsPU IsRPOI CheckValue IsPPOI Formula in
- fun{IsRU A}
- case A of nil then true
- []translate(dx:X dy:Y 1:Z)|T then if {IsRU Z} andthen {IsRU T} andthen {CheckValue X} andthen {CheckValue Y} then true
- else false
- end
- []rotate(angle:A 1:B)|T then if {IsRU B} andthen {IsRU T} andthen {CheckValue A} then true
- else false
- end
- []scale(rx:A ry:B 1:C)|T then if {IsRU C} andthen {IsRU T} then true
- else false
- end
- []primitive(kind:A)|T then if {IsRU T} andthen {IsRPOI A} then true
- else false
- end
- []nil|T then {IsRU T}
- else false
- end
- end
- fun {IsRPOI A}
- case A of road then true
- []building then true
- []water then true
- else false
- end
- end
- fun {CheckValue Value}
- if {Float.is Value}==true then Value
- else
- case Value
- of plus(X Y) then {CheckValue X}+{CheckValue Y}
- []minus(X Y) then {CheckValue X}-{CheckValue Y}
- []mult(X Y) then {CheckValue X}*{CheckValue Y}
- []'div'(X Y) then {CheckValue X}/{CheckValue Y}
- []sin(X) then {Float.sin {CheckValue X}}
- []cos(X) then {Float.cos {CheckValue X}}
- []tan(X) then {Float.tan {CheckValue X}}
- []exp(X) then {Float.exp {CheckValue X}}
- []log(X) then {Float.log {CheckValue X}}
- []neg(X) then ~{CheckValue X}
- end
- end
- end
- fun {IsPU X}
- case X of nil then true
- []primitive(kind:A)|T then if {IsPPOI A} andthen {IsPU T} then true
- else false
- end
- []translate(dx:X dy:Y 1:Z)|T then if {IsPU T} andthen {IsPU Z} andthen {Formula X} andthen {Formula Y} then true
- else false
- end
- []nil|T then {IsPU T}
- end
- end
- fun {Formula Value}
- if {Float.is Value}==true then true
- else
- case Value
- of time then true
- []plus(X Y) then {Formula X}+{Formula Y}
- []minus(X Y) then{Formula X}-{Formula Y}
- []mult(X Y) then{Formula X}*{Formula Y}
- []'div'(X Y) then {Formula X}/{Formula Y}
- []sin(X) then {Float.sin {Formula X }}
- []cos(X) then {Float.cos {Formula X }}
- []tan(X) then {Float.tan {Formula X }}
- []exp(X) then {Float.exp {Formula X }}
- []log(X) then {Float.log {Formula X }}
- []neg(X) then {Float.neg {Formula X }}
- else false
- end
- end
- end
- fun {IsPPOI X}
- case X of pokemon then true
- []pokestop then true
- []arena then true
- else false
- end
- end
- case Map of nil then false
- []map(ru:A pu:B) then if {IsRU A} andthen {IsPU B} then true
- else false
- end
- else false
- end
- end
- end
- {Projet.run MyFunction Map MaxTime Extensions CheckMap}
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement