However I will try and incorporate some of the more useful expressions (cos, sin, sqrt, exp etc) in my future rules, note that you may need to completely parenthesize these expressions, owing the terse syntax of cfdg (no separators, the parser will get confused).

If you've got some complicated expression you would like to incorporate in several places in your cfdg checkout this from Florian Brucker you can use the C preprocessor to do the dirty work for you. This is my previous mondrian example where the phi(A) is substituted (on the fly if you use Florians cfdgpp script). Note the very necessary extra parenthesis with the negative phi.

` 1:startshape mondrian`

2:

3:# define phi(A) (A * (sqrt(5) +1)/2)

4:

5:rule mondrian {

6: white_box{}

7: yellow_box{y 1.005}

8: red_box{x 1.005}

9: blue_box{y 1.005 x 1.005}

10:}

11:

12:path red_box {

13: FILL{brightness 1 hue 360 sat 1}

14: MOVETO{x 0.5 y phi(0.5)}

15: LINETO{x -0.5 y phi(0.5)}

16: LINETO{x -0.5 y (-phi(0.5))}

17: LINETO{x 0.5 y (-phi(0.5))}

18: CLOSEPOLY{}

19: STROKE{}

20:}

21: path white_box{

22: MOVETO{x 0.5 y phi(0.5)}

23: LINETO{x -0.5 y phi(0.5)}

24: LINETO{x -0.5 y (-phi(0.5))}

25: LINETO{x 0.5 y (-phi(0.5))}

26: CLOSEPOLY{}

27: STROKE{}

28:}

29:path yellow_box {

30: FILL{brightness 1 hue 60 sat 1}

31: MOVETO{x 0.5 y 0.5}

32: LINETO{x -0.5 y 0.5}

33: LINETO{x -0.5 y 0.25}

34: LINETO{x -0.5 y -0.25}

35: LINETO{x 0.5 y -0.25}

36: CLOSEPOLY{}

37: STROKE{}

38:}

39:path blue_box {

40: FILL{brightness 1 hue 220 sat 1}

41: MOVETO{x 0.5 y 0.5}

42: LINETO{x -0.5 y 0.5}

43: LINETO{x -0.5 y -0.5}

44: LINETO{x 0.5 y -0.5}

45: CLOSEPOLY{}

46: STROKE{}

47:}

## No comments:

## Post a Comment