summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dimension/common.nonterminals8
-rw-r--r--dimension/common.rules48
-rw-r--r--dimension/common.terminals4
-rw-r--r--dimension/directives.declarations2
-rw-r--r--dimension/grammar.declarations2
-rw-r--r--dimension/grammar.epilogue7
-rw-r--r--dimension/lexer.l3
-rw-r--r--dimension/parse.h3
-rw-r--r--dimension/realize.c36
-rw-r--r--tests/dimension/demo.pov13
-rwxr-xr-xtests/dimension/demo.sh41
11 files changed, 157 insertions, 10 deletions
diff --git a/dimension/common.nonterminals b/dimension/common.nonterminals
index ddd0efb..c7140b5 100644
--- a/dimension/common.nonterminals
+++ b/dimension/common.nonterminals
@@ -60,6 +60,11 @@
%type <astnode> OBJECT_MODIFIERS
%type <astnode> OBJECT_MODIFIER
+/* Patterns */
+%type <astnode> BLOCK_PATTERN_TYPE
+%type <astnode> CONTINUOUS_PATTERN_TYPE
+%type <astnode> PATTERN_TYPE
+
/* Textures */
%type <astnode> TEXTURE
%type <astnode> TEXTURE_ITEMS
@@ -69,6 +74,9 @@
%type <astnode> PIGMENT_TYPE
%type <astnode> PIGMENT_MODIFIERS
%type <astnode> COLOR_LIST2
+%type <astnode> COLOR_MAP
+%type <astnode> COLOR_MAP_ENTRIES
+%type <astnode> COLOR_MAP_ENTRY
%type <astnode> BITMAP_TYPE
/* Finishes */
diff --git a/dimension/common.rules b/dimension/common.rules
index 7abae80..754e063 100644
--- a/dimension/common.rules
+++ b/dimension/common.rules
@@ -472,6 +472,26 @@ OBJECT_MODIFIER: TRANSFORMATION
| INTERIOR
;
+/* Patterns */
+
+BLOCK_PATTERN_TYPE: "checker" {
+ dmnsn_astnode p
+ = dmnsn_new_astnode(DMNSN_AST_CHECKER, @$);
+ $$ = dmnsn_new_astnode1(DMNSN_AST_PATTERN, @$, p);
+ }
+;
+
+CONTINUOUS_PATTERN_TYPE: "gradient" VECTOR {
+ dmnsn_astnode p
+ = dmnsn_new_astnode1(DMNSN_AST_GRADIENT, @$, $2);
+ $$ = dmnsn_new_astnode1(DMNSN_AST_PATTERN, @$, p);
+ }
+;
+
+PATTERN_TYPE: BLOCK_PATTERN_TYPE
+ | CONTINUOUS_PATTERN_TYPE
+;
+
/* Textures */
TEXTURE: "texture" "{"
@@ -520,6 +540,7 @@ PIGMENT: "pigment" "{"
;
PIGMENT_TYPE: COLOR
+ | CONTINUOUS_PATTERN_TYPE
| "image_map" "{"
BITMAP_TYPE STRING
"}"
@@ -547,6 +568,10 @@ PIGMENT_MODIFIERS: /* empty */ {
$$ = $1;
dmnsn_array_push($$.children, &$2);
}
+ | PIGMENT_MODIFIERS COLOR_MAP {
+ $$ = $1;
+ dmnsn_array_push($$.children, &$2);
+ }
;
COLOR_LIST2: /* empty */ {
@@ -562,6 +587,29 @@ COLOR_LIST2: /* empty */ {
$1, $3);
$$ = dmnsn_new_astnode1(DMNSN_AST_COLOR_LIST, @$, list);
}
+;
+
+COLOR_MAP: "color_map" "{"
+ COLOR_MAP_ENTRIES
+ "}"
+ {
+ $$ = $3;
+ }
+;
+
+COLOR_MAP_ENTRIES: COLOR_MAP_ENTRY {
+ $$ = dmnsn_new_astnode1(DMNSN_AST_COLOR_MAP, @$, $1);
+ }
+ | COLOR_MAP_ENTRIES COLOR_MAP_ENTRY {
+ $$ = $1;
+ dmnsn_array_push($$.children, &$2);
+ }
+;
+
+COLOR_MAP_ENTRY: "[" FLOAT "color" COLOR_BODY "]" {
+ $$ = dmnsn_new_astnode2(DMNSN_AST_COLOR_MAP_ENTRY, @$, $2, $4);
+ }
+;
/* Finishes */
FINISH: "finish" "{"
diff --git a/dimension/common.terminals b/dimension/common.terminals
index 84f05eb..7b19a33 100644
--- a/dimension/common.terminals
+++ b/dimension/common.terminals
@@ -130,7 +130,7 @@
%token DMNSN_T_CLOCK_ON
%token DMNSN_T_COLLECT
%token DMNSN_T_COLOR "color"
-%token DMNSN_T_COLOR_MAP
+%token DMNSN_T_COLOR_MAP "color_map"
%token DMNSN_T_COMPONENT
%token DMNSN_T_COMPOSITE
%token DMNSN_T_CONCAT
@@ -213,7 +213,7 @@
%token DMNSN_T_GIF
%token DMNSN_T_GLOBAL_LIGHTS
%token DMNSN_T_GLOBAL_SETTINGS "global_settings"
-%token DMNSN_T_GRADIENT
+%token DMNSN_T_GRADIENT "gradient"
%token DMNSN_T_GRANITE
%token DMNSN_T_GRAY "gray"
%token DMNSN_T_GRAY_THRESHOLD
diff --git a/dimension/directives.declarations b/dimension/directives.declarations
index 9562ec3..b1a984d 100644
--- a/dimension/directives.declarations
+++ b/dimension/directives.declarations
@@ -21,7 +21,7 @@
%name-prefix "dmnsn_ld_yy"
-%expect 14
+%expect 15
%expect-rr 6
%parse-param {const char *filename}
diff --git a/dimension/grammar.declarations b/dimension/grammar.declarations
index b31ac26..987d9c9 100644
--- a/dimension/grammar.declarations
+++ b/dimension/grammar.declarations
@@ -23,7 +23,7 @@
%name-prefix "dmnsn_yy"
-%expect 10
+%expect 11
%parse-param {const char *filename}
%parse-param {void *yyscanner}
diff --git a/dimension/grammar.epilogue b/dimension/grammar.epilogue
index 6a8e164..731d017 100644
--- a/dimension/grammar.epilogue
+++ b/dimension/grammar.epilogue
@@ -147,14 +147,17 @@ dmnsn_astnode_string(dmnsn_astnode_type astnode_type)
dmnsn_astnode_map(DMNSN_AST_OBJECT_MODIFIERS, "object-modifiers");
- dmnsn_astnode_map(DMNSN_AST_PATTERN, "pattern");
- dmnsn_astnode_map(DMNSN_AST_CHECKER, "checker");
+ dmnsn_astnode_map(DMNSN_AST_PATTERN, "pattern");
+ dmnsn_astnode_map(DMNSN_AST_CHECKER, "checker");
+ dmnsn_astnode_map(DMNSN_AST_GRADIENT, "gradient");
dmnsn_astnode_map(DMNSN_AST_TEXTURE, "texture");
dmnsn_astnode_map(DMNSN_AST_PIGMENT, "pigment");
dmnsn_astnode_map(DMNSN_AST_PIGMENT_MODIFIERS, "pigment-modifiers");
dmnsn_astnode_map(DMNSN_AST_COLOR_LIST, "color-list");
+ dmnsn_astnode_map(DMNSN_AST_COLOR_MAP, "color_map");
+ dmnsn_astnode_map(DMNSN_AST_COLOR_MAP_ENTRY, "color_map-entry");
dmnsn_astnode_map(DMNSN_AST_IMAGE_MAP, "image_map");
dmnsn_astnode_map(DMNSN_AST_PNG, "png");
diff --git a/dimension/lexer.l b/dimension/lexer.l
index 511e3df..2f84620 100644
--- a/dimension/lexer.l
+++ b/dimension/lexer.l
@@ -184,7 +184,9 @@ unsigned long wchar;
"camera" RETURN_TOKEN(DMNSN_T_CAMERA);
"checker" RETURN_TOKEN(DMNSN_T_CHECKER);
"color" RETURN_TOKEN(DMNSN_T_COLOR);
+"color_map" RETURN_TOKEN(DMNSN_T_COLOR_MAP);
"colour" RETURN_TOKEN(DMNSN_T_COLOR);
+"colour_map" RETURN_TOKEN(DMNSN_T_COLOR_MAP);
"cone" RETURN_TOKEN(DMNSN_T_CONE);
"cos" RETURN_TOKEN(DMNSN_T_COS);
"cosh" RETURN_TOKEN(DMNSN_T_COSH);
@@ -201,6 +203,7 @@ unsigned long wchar;
"finish" RETURN_TOKEN(DMNSN_T_FINISH);
"floor" RETURN_TOKEN(DMNSN_T_FLOOR);
"global_settings" RETURN_TOKEN(DMNSN_T_GLOBAL_SETTINGS);
+"gradient" RETURN_TOKEN(DMNSN_T_GRADIENT);
"gray" RETURN_TOKEN(DMNSN_T_GRAY);
"grey" RETURN_TOKEN(DMNSN_T_GRAY);
"green" RETURN_TOKEN(DMNSN_T_GREEN);
diff --git a/dimension/parse.h b/dimension/parse.h
index 6e09302..09ca685 100644
--- a/dimension/parse.h
+++ b/dimension/parse.h
@@ -63,12 +63,15 @@ typedef enum {
DMNSN_AST_PATTERN,
DMNSN_AST_CHECKER,
+ DMNSN_AST_GRADIENT,
DMNSN_AST_TEXTURE,
DMNSN_AST_PIGMENT,
DMNSN_AST_PIGMENT_MODIFIERS,
DMNSN_AST_COLOR_LIST,
+ DMNSN_AST_COLOR_MAP,
+ DMNSN_AST_COLOR_MAP_ENTRY,
DMNSN_AST_IMAGE_MAP,
DMNSN_AST_PNG,
diff --git a/dimension/realize.c b/dimension/realize.c
index bac3d7e..859919f 100644
--- a/dimension/realize.c
+++ b/dimension/realize.c
@@ -460,6 +460,14 @@ dmnsn_realize_pattern(dmnsn_astnode astnode)
case DMNSN_AST_CHECKER:
pattern = dmnsn_new_checker_pattern();
break;
+ case DMNSN_AST_GRADIENT:
+ {
+ dmnsn_astnode orientation;
+ dmnsn_array_get(type.children, 0, &orientation);
+ dmnsn_vector v = dmnsn_realize_vector(orientation);
+ pattern = dmnsn_new_gradient_pattern(v);
+ break;
+ }
default:
dmnsn_assert(false, "Unexpected pattern type.");
@@ -488,6 +496,30 @@ dmnsn_realize_color_list(dmnsn_astnode astnode)
return color_map;
}
+static dmnsn_color_map *
+dmnsn_realize_color_map(dmnsn_astnode astnode)
+{
+ dmnsn_assert(astnode.type == DMNSN_AST_COLOR_MAP, "Expected a color_map.");
+
+ dmnsn_color_map *color_map = dmnsn_new_color_map();
+
+ DMNSN_ARRAY_FOREACH (dmnsn_astnode *, entry, astnode.children) {
+ dmnsn_assert(entry->type == DMNSN_AST_COLOR_MAP_ENTRY,
+ "Expected a color_map entry.");
+
+ dmnsn_astnode n_node, color_node;
+ dmnsn_array_get(entry->children, 0, &n_node);
+ dmnsn_array_get(entry->children, 1, &color_node);
+
+ double n = dmnsn_realize_float(n_node);
+ dmnsn_color color = dmnsn_realize_color(color_node);
+
+ dmnsn_add_color_map_entry(color_map, n, color);
+ }
+
+ return color_map;
+}
+
static dmnsn_pigment *
dmnsn_realize_pattern_pigment(dmnsn_astnode type, dmnsn_astnode modifiers)
{
@@ -504,6 +536,9 @@ dmnsn_realize_pattern_pigment(dmnsn_astnode type, dmnsn_astnode modifiers)
case DMNSN_AST_COLOR_LIST:
color_map = dmnsn_realize_color_list(*modifier);
break;
+ case DMNSN_AST_COLOR_MAP:
+ color_map = dmnsn_realize_color_map(*modifier);
+ break;
default:
break;
@@ -555,6 +590,7 @@ dmnsn_realize_pigment_modifiers(dmnsn_astnode astnode, dmnsn_pigment *pigment)
break;
case DMNSN_AST_COLOR_LIST:
+ case DMNSN_AST_COLOR_MAP:
/* Already handled by dmnsn_realize_pattern_pigment() */
break;
diff --git a/tests/dimension/demo.pov b/tests/dimension/demo.pov
index 544cd10..197fe23 100644
--- a/tests/dimension/demo.pov
+++ b/tests/dimension/demo.pov
@@ -81,7 +81,18 @@ union {
}
pigment {
- color rgb <1, 0, 0>
+ gradient y
+ color_map {
+ [0 color rgb <1, 0, 0>]
+ [1/6 color rgb <1, 0.5, 0>]
+ [2/6 color rgb <1, 1, 0>]
+ [3/6 color rgb <0, 1, 0>]
+ [4/6 color rgb <0, 0, 1>]
+ [5/6 color rgb <1, 0, 1>]
+ [1 color rgb <1, 0, 0>]
+ }
+ scale <1, 2.75, 1>
+ translate -1.25*y
}
rotate -45*x
}
diff --git a/tests/dimension/demo.sh b/tests/dimension/demo.sh
index 05b01aa..c3d9750 100755
--- a/tests/dimension/demo.sh
+++ b/tests/dimension/demo.sh
@@ -95,9 +95,44 @@ demo_exp=$(echo -n \
object-modifiers))
(object-modifiers
(pigment
- (vector (integer 1) (integer 0) (integer 0)
- (integer 0) (integer 0))
- pigment-modifiers)
+ (pattern (gradient (vector (integer 0) (integer 1) (integer 0)
+ (integer 0) (integer 0))))
+ (pigment-modifiers
+ (color_map
+ (color_map-entry
+ (integer 0)
+ (vector (integer 1) (integer 0) (integer 0)
+ (integer 0) (integer 0)))
+ (color_map-entry
+ (float 0.166667)
+ (vector (integer 1) (float 0.5) (integer 0)
+ (integer 0) (integer 0)))
+ (color_map-entry
+ (float 0.333333)
+ (vector (integer 1) (integer 1) (integer 0)
+ (integer 0) (integer 0)))
+ (color_map-entry
+ (float 0.5)
+ (vector (integer 0) (integer 1) (integer 0)
+ (integer 0) (integer 0)))
+ (color_map-entry
+ (float 0.666667)
+ (vector (integer 0) (integer 0) (integer 1)
+ (integer 0) (integer 0)))
+ (color_map-entry
+ (float 0.833333)
+ (vector (integer 1) (integer 0) (integer 1)
+ (integer 0) (integer 0)))
+ (color_map-entry
+ (integer 1)
+ (vector (integer 1) (integer 0) (integer 0)
+ (integer 0) (integer 0))))
+ (transformation
+ (scale (vector (integer 1) (float 2.75) (integer 1)
+ (integer 0) (integer 0))))
+ (transformation
+ (translation (vector (float 0) (float -1.25) (float 0)
+ (float 0) (float 0))))))
(transformation
(rotation (vector (integer -45) (integer 0) (integer 0)
(integer 0) (integer 0))))))