mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-13 06:49:31 -06:00
Graftals in GF. examples/graftals
This commit is contained in:
11
examples/graftals/Cantor.gf
Normal file
11
examples/graftals/Cantor.gf
Normal file
@@ -0,0 +1,11 @@
|
||||
concrete Cantor of Graftal = {
|
||||
lincat N = {f : Str; g : Str} ;
|
||||
lincat S = {s : Str} ;
|
||||
|
||||
lin z = {f = F; g = G} ;
|
||||
lin s x = {f = x.f ++ x.g ++ x.f; g = x.g ++ x.g ++ x.g} ;
|
||||
lin c x = {s = "newpath 10 550 moveto" ++ x.f ++ "stroke showpage"} ;
|
||||
|
||||
oper F : Str = "1 0 rlineto" ;
|
||||
oper G : Str = "1 0 rmoveto" ;
|
||||
}
|
||||
13
examples/graftals/Dragon.gf
Normal file
13
examples/graftals/Dragon.gf
Normal file
@@ -0,0 +1,13 @@
|
||||
concrete Dragon of Graftal = {
|
||||
lincat N = {x : Str; y : Str} ;
|
||||
lincat S = {s : Str} ;
|
||||
|
||||
lin z = {x = ""; y = ""} ;
|
||||
lin s x = {x = x.x ++ R ++ x.y ++ F ++ R; y = L ++ F ++ x.x ++ L ++ x.y} ;
|
||||
lin c x = {s = "newpath 300 550 moveto" ++ F ++ x.x ++ "stroke showpage"} ;
|
||||
|
||||
oper F : Str = "0 5 rlineto" ;
|
||||
oper L : Str = "+90 rotate" ;
|
||||
oper R : Str = "-90 rotate" ;
|
||||
|
||||
}
|
||||
15
examples/graftals/Graftal.gf
Normal file
15
examples/graftals/Graftal.gf
Normal file
@@ -0,0 +1,15 @@
|
||||
-- (c) Krasimir Angelov
|
||||
--
|
||||
-- The L-System is a grammar formalism which is used to describe
|
||||
-- graftals (recursive graphical objects). It is interesting
|
||||
-- coincidence that every L-System grammar could be redefined
|
||||
-- as PMCFG grammar. This demo shows how to generate graftals
|
||||
-- using GF. The output from every concrete syntax is in postscript
|
||||
-- format.
|
||||
|
||||
abstract Graftal = {
|
||||
cat N; S;
|
||||
fun z : N ;
|
||||
s : N -> N ;
|
||||
c : N -> S ;
|
||||
}
|
||||
12
examples/graftals/Koch.gf
Normal file
12
examples/graftals/Koch.gf
Normal file
@@ -0,0 +1,12 @@
|
||||
concrete Koch of Graftal = {
|
||||
lincat N = {f : Str} ;
|
||||
lincat S = {s : Str} ;
|
||||
|
||||
lin z = {f = F} ;
|
||||
lin s x = {f = x.f ++ L ++ x.f ++ R ++ x.f ++ R ++ x.f ++ L ++ x.f} ;
|
||||
lin c x = {s = "newpath 10 550 moveto" ++ x.f ++ "stroke showpage"} ;
|
||||
|
||||
oper F : Str = "2 0 rlineto" ;
|
||||
oper L : Str = "+90 rotate" ;
|
||||
oper R : Str = "-90 rotate" ;
|
||||
}
|
||||
14
examples/graftals/Sierpinski.gf
Normal file
14
examples/graftals/Sierpinski.gf
Normal file
@@ -0,0 +1,14 @@
|
||||
concrete Sierpinski of Graftal = {
|
||||
lincat N = {a : Str; b : Str} ;
|
||||
lincat S = {s : Str} ;
|
||||
|
||||
lin z = {a = A; b = B} ;
|
||||
lin s x = {a = x.b ++ R ++ x.a ++ R ++ x.b; b =x.a ++ L ++ x.b ++ L ++ x.a} ;
|
||||
lin c x = {s = "newpath 300 550 moveto" ++ x.a ++ "stroke showpage"} ;
|
||||
|
||||
oper A : Str = "0 2 rlineto" ;
|
||||
oper B : Str = "0 2 rlineto" ;
|
||||
oper L : Str = "+60 rotate" ;
|
||||
oper R : Str = "-60 rotate" ;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user