http://www.contextfreeart.org/mediawiki/index.php/Reference_Card that explains context free syntax in a 'nutshell'.

Anyway finally I managed to combine the two files, see what you think. If you run the rules yourself and don't like what you get run them again, the trees are random (by the way in terse syntax r == rotate not random as I first thought).

` 1:startshape forest // modified martinstannard grass.cfdg && forest == demo1.cfdg`

2:

3:background {hue 200 sat 0.5}

4:rule forest {

5: seed {s 400 800}

6: seed {x -20}

7: seed {x -40}

8: world{h 120 sat 1 b 0 r 90 }

9: world{h 100 sat 1 b 0 r 90 }

10: world{h 80 sat 1 b 0 r 90 }

11:}

12:

13:rule seed {branch {}}

14:rule seed {branch {r 1}}

15:rule seed {branch {r -1}}

16:rule seed {branch {r 2}}

17:rule seed {branch {r -2}}

18:rule seed {fork {}}

19:

20:rule branch {leftbranch {flip 90}}

21:rule branch {leftbranch {}}

22:

23:rule leftbranch 4 {block {} leftbranch {y 0.885 r 0.1 s 0.99}}

24:rule leftbranch 4 {block {} leftbranch {y 0.885 r 0.2 s 0.99}}

25:rule leftbranch {block {} leftbranch {y 0.885 r 4 s 0.99}}

26:rule leftbranch {block {} fork {}}

27:

28:

29:rule block {

30: SQUARE {r 1}

31: SQUARE {r -1}

32: SQUARE {}

33:}

34:

35:rule fork {

36: branch { }

37: branch {s 0.5 r 40}

38:}

39:rule fork {

40: branch { }

41: branch {s 0.5 r -40}

42:}

43:rule fork {

44: branch {s 0.5 r -20}

45: branch { }

46:}

47:rule fork {

48: branch {s 0.7 y 0.1 r 20}

49: branch {s 0.7 y 0.1 r -20}

50:}

51:

52:rule world

53:{

54: 800*{y 1 } blade{ sat 0.2 b 0.5}

55:}

56:

57:rule blade 25

58:{

59: SQUARE{}

60: blade{x 0.95 r -2 s 0.98 }

61:}

62:

63:rule blade 18

64:{

65: SQUARE{}

66: blade{x 0.90 r 1 s 0.97 b 0.1 }

67:}

68:

69:rule blade 16

70:{

71: SQUARE{}

72: blade{x 0.90 r 2 s 0.93 b 0.1 }

73:}

74:

75:rule blade

76:{

77: SQUARE{}

78:}

One thing I read about context free is that the program is unlikely to fail on error, if there are ambiguous commands, the program will just follow one. SQUARE and CIRCLE are the big built in features, infinite recursion is allowed so long as results tend to zero....

I don't know that there are any strict conventions on case so I've used lowercase for non built in rules.

Click on image to see the picture properly.

## No comments:

## Post a Comment