# P3m1 Reference Implementation

Wechseln zu: Navigation, Suche

Let \$image be an image from which a triangle part should be cut out and used as prototile for the p3m1 tile. There is only one free parameter needed for the generation of a p3m1 tile from a equilateral triangle mask and that is the width of the triangle: \$t_w. The height is computed with: \$t_h = int(1/2 * sqrt(3) * \$t_w)+1;

In the following relative translation parameters are used that are referencing to the one prototile that is used viz. to \$t_w and \$t_h. If patterns are generated with more than one prototile relative parameters should referencing to the width and height of the pattern image that itself is constructed as a function of the widths and heights of the prototile set and a general multiplicator or two multiplicators for width and height. Such a function (\$w_P, \$h_P) = f(\$mult, \$w_S_i, \$h_S_i | i = 1, …, n) or f(\$mult_w, \$mult_h, \$w_S_i, \$h_S_i | i = 1, …, n) is specified in the design space definition.

```# GENERATE MASK/S
\$t_h = int(1/2 * sqrt(3) * \$t_w)+1;
\$mask->Set(size=>"\$t_w x \$t_h"); print "generate triangle mask with t_w x t_h = \$t_w x \$t_h \n";
\$mask->Read('xc:none');
\$t_w_1_2 = int(1/2 * \$t_w)+1; #print "triangle_half_wide t_w_1_2 = \$t_w_1_2 \n";
\$mask->Draw(primitive=>'polyline', points => "0,0 \$t_w,0 \$t_w_1_2,\$t_h", fill=>'red');   #\$mask->Write(filename=>"\$output_meta_folder/mask_AfterGeneration.png");
```

Fehler beim Erstellen des Vorschaubildes: Datei fehlt

The prototile is generated with the triangle mask and the image and the rusult is pushed in a image list for all the prototiles to reflect the general case that a pattern is made of more than one prototile type:

```# GENERATE PROTOTILE/S
\$mask->Composite(image=>\$image, compose=>'in', color=>'transparent', matte=>'true');     print "generate prototile \n";
\$mask->Set(page=>'0x0+0+0');	 \$mask->Write(filename=>"\$output_meta_folder/mask_AfterCompose.png");
```
```# PUSH PROTOTILE INTO \$Shape_list
push(@\$Shape_list, \$mask);#\$Shape_list->Write(filename=>"\$output_meta_folder/Shape_list.png");
\$nr_Shape_list = @\$Shape_list;
```

Fehler beim Erstellen des Vorschaubildes: Datei fehlt

In the next step an empty p3m1 tile is generated for example with transparent background. It has 3 times the width and 2 times the hight of the prototile triangle:

```# GENERATE EMPTY p3m1-TILE \$tile AS A FUNCTION OF \$mask or \$prototile
\$tile_w = 3 * \$t_w;
\$tile_h = 2 * \$t_h;
\$tile->Set(size=>"\$tile_w x \$tile_h");  print "generate empty tile with tile_w x tile_h = \$tile_w x \$tile_h \n";
\$tile->Read('xc:none');  #\$tile->Write(filename=>"\$output_meta_folder/tile_AfterGeneration.png");
```

What follows is a sequence of 14 image processing operations, the CRMT commands that takes a clone of the prototile, rotates it, Flop and/or Flip it and makes a composite operation with compose=>over that includes a translation of the prototile over the tile image. The images are shown in jpg which means that the transparent background is transformed to black.

```# CRMT-COMMAND-LIST_01:  f(G1) = (C0, x0, y0)
@\$prototile_crm = ();
\$prototile_crm = \$Shape_list->[0]->Clone();
\$tile->Composite(image=>\$prototile_crm, compose=>'over', x=>'0', y=>'0', color=>'transparent', matte=>'true');
#\$tile->Write(filename=>"\$output_meta_folder/tile_after_crmt_01.png");
\$tile->Write(filename=>"\$output_meta_folder/tile_after_crmt_01.jpg");
```
Fehler beim Erstellen des Vorschaubildes: Datei fehlt
```# CRMT-COMMAND-LIST_02: f(G6) => (C0, Fo, R-60, x-t_w/2, y0)
@\$prototile_crm = ();
\$prototile_crm = \$Shape_list->[0]->Clone();
\$prototile_crm->Flop();
\$prototile_crm->Rotate(degrees=>-60, color=>'transparent');
\$prototile_crm->Set(page=>'0x0+0+0');#\$prototile_crm->Write(filename=>"\$output_meta_folder/prototile_crm_AfterRot_minus60.png");
\$prototile_crm->Trim();
\$tile->Composite(image=>\$prototile_crm, compose=>'over', x=>-\$t_w/2, y=>'0', color=>'transparent', matte=>'true');
#\$tile->Set(page=>'0x0+0+0');\$tile->Write(filename=>"\$output_meta_folder/tile_after_crmt_02.png");
\$tile->Write(filename=>"\$output_meta_folder/tile_after_crmt_02.jpg");
```
Fehler beim Erstellen des Vorschaubildes: Datei fehlt
```# CRMT-COMMAND-LIST_03: f(G2) => (C0, Fo, R60, x1/2*t_w, y0)
@\$prototile_crm = ();
\$prototile_crm = \$Shape_list->[0]->Clone();
\$prototile_crm->Flop();
\$prototile_crm->Rotate(degrees=>60, color=>'transparent');
\$prototile_crm->Set(page=>'0x0+0+0');
\$prototile_crm->Trim();
\$tile->Composite(image=>\$prototile_crm, compose=>'over', x=>\$t_w/2, y=>'0', color=>'transparent', matte=>'true');
\$tile->Set(page=>'0x0+0+0');
#\$tile->Write(filename=>"\$output_meta_folder/tile_after_crmt_03.png");
\$tile->Write(filename=>"\$output_meta_folder/tile_after_crmt_03.jpg");
```
Fehler beim Erstellen des Vorschaubildes: Datei fehlt
```# CRMT-COMMAND-LIST_04: f(G5) => (C0, Fo, R-60, Fi, xt_w, y0)  G5=Flip(G6)
@\$prototile_crm = ();
\$prototile_crm = \$Shape_list->[0]->Clone();
\$prototile_crm->Flop();
\$prototile_crm->Rotate(degrees=>-60, color=>'transparent');
\$prototile_crm->Set(page=>'0x0+0+0');
\$prototile_crm->Trim();
\$prototile_crm->Flip();
\$tile->Composite(image=>\$prototile_crm, compose=>'over', x=>\$t_w, y=>'0', color=>'transparent', matte=>'true');
\$tile->Set(page=>'0x0+0+0');
#\$tile->Write(filename=>"\$output_meta_folder/tile_after_crmt_04.png");
\$tile->Write(filename=>"\$output_meta_folder/tile_after_crmt_04.jpg");
```
Fehler beim Erstellen des Vorschaubildes: Datei fehlt
```# CRMT-COMMAND-LIST_05: f(G1) => (C0, Fi, x3/2*t_w, y0)
@\$prototile_crm = ();
\$prototile_crm = \$Shape_list->[0]->Clone();
\$prototile_crm->Flip();
\$tile->Composite(image=>\$prototile_crm, compose=>'over', x=>3/2*\$t_w, y=>'0', color=>'transparent', matte=>'true');
#\$tile->Set(page=>'0x0+0+0'); \$tile->Write(filename=>"\$output_meta_folder/tile_after_crmt_05.png");
\$tile->Write(filename=>"\$output_meta_folder/tile_after_crmt_05.jpg");
```
Fehler beim Erstellen des Vorschaubildes: Datei fehlt
```# CRMT-COMMAND-LIST_06: f(G2) => (C0, Fo, R60, Fi, x2*t_w, y0)
@\$prototile_crm = ();
\$prototile_crm = \$Shape_list->[0]->Clone();
\$prototile_crm->Flop();
\$prototile_crm->Rotate(degrees=>60, color=>'transparent');
\$prototile_crm->Set(page=>'0x0+0+0');
\$prototile_crm->Trim();
\$prototile_crm->Flip();
\$tile->Composite(image=>\$prototile_crm, compose=>'over', x=>2*\$t_w, y=>'0', color=>'transparent', matte=>'true');
\$tile->Set(page=>'0x0+0+0');
# \$tile->Write(filename=>"\$output_meta_folder/tile_after_crmt_06.png");
\$tile->Write(filename=>"\$output_meta_folder/tile_after_crmt_06.jpg");
```
Fehler beim Erstellen des Vorschaubildes: Datei fehlt
```# CRMT-COMMAND-LIST_07: f(G6) => (C0, Fo, R-60, x5/2*t_w, y0)
@\$prototile_crm = ();
\$prototile_crm = \$Shape_list->[0]->Clone();
\$prototile_crm->Flop();                                                                    #\$prototile_crm->Write(filename=>"\$output_meta_folder/prototile_crm_AfterFlop.png");
\$prototile_crm->Rotate(degrees=>-60, color=>'transparent');
\$prototile_crm->Set(page=>'0x0+0+0');                                                      #\$prototile_crm->Write(filename=>"\$output_meta_folder/prototile_crm_AfterRot_minus60.png");
\$prototile_crm->Trim();                                                                    #\$prototile_crm->Write(filename=>"\$output_meta_folder/prototile_crm_AfterTrim.png");
\$tile->Composite(image=>\$prototile_crm, compose=>'over', x=>5/2*\$t_w, y=>'0', color=>'transparent', matte=>'true');
\$tile->Set(page=>'0x0+0+0');                                                               \$tile->Write(filename=>"\$output_meta_folder/tile_after_crmt_07.png");
\$tile->Write(filename=>"\$output_meta_folder/tile_after_crmt_07.jpg");
```
Fehler beim Erstellen des Vorschaubildes: Datei fehlt
```# CRMT-COMMAND-LIST_08:  f(G1) = (C0, Fi, x0, yt_h)
@\$prototile_crm = ();
\$prototile_crm = \$Shape_list->[0]->Clone();                                                #\$prototile_crm->Write(filename=>"\$output_meta_folder/prototile_crm_AfterGeneration.png");
\$prototile_crm->Flip();                                                                    #\$prototile_crm->Write(filename=>"\$output_meta_folder/prototile_crm_AfterFlip.png");
\$tile->Composite(image=>\$prototile_crm, compose=>'over', x=>0, y=>\$t_h, color=>'transparent', matte=>'true');
\$tile->Set(page=>'0x0+0+0');                                                               \$tile->Write(filename=>"\$output_meta_folder/tile_after_crmt_08.png");
\$tile->Write(filename=>"\$output_meta_folder/tile_after_crmt_08.jpg");
```
Fehler beim Erstellen des Vorschaubildes: Datei fehlt
```# CRMT-COMMAND-LIST_09: f(G5) => (C0, Fo, R-60, Fi, x-t_w/2, yt_h)
@\$prototile_crm = ();
\$prototile_crm = \$Shape_list->[0]->Clone();
\$prototile_crm->Flop();                                                                    #\$prototile_crm->Write(filename=>"\$output_meta_folder/prototile_crm_AfterFlop.png");
\$prototile_crm->Rotate(degrees=>-60, color=>'transparent');
\$prototile_crm->Set(page=>'0x0+0+0');                                                      #\$prototile_crm->Write(filename=>"\$output_meta_folder/prototile_crm_AfterRot_minus60.png");
\$prototile_crm->Trim();                                                                    #\$prototile_crm->Write(filename=>"\$output_meta_folder/prototile_crm_AfterTrim.png");
\$prototile_crm->Flip();                                                                    #\$prototile_crm->Write(filename=>"\$output_meta_folder/prototile_crm_AfterFlip.png");
\$tile->Composite(image=>\$prototile_crm, compose=>'over', x=>-\$t_w/2, y=>\$t_h, color=>'transparent', matte=>'true');
\$tile->Set(page=>'0x0+0+0');\$tile->Write(filename=>"\$output_meta_folder/tile_after_crmt_09.png");
\$tile->Write(filename=>"\$output_meta_folder/tile_after_crmt_09.jpg");
```
Fehler beim Erstellen des Vorschaubildes: Datei fehlt
```# CRMT-COMMAND-LIST_10: f(G2) => (C0, Fo, R60, Fi, x1/2*t_w, yt_h)
@\$prototile_crm = ();
\$prototile_crm = \$Shape_list->[0]->Clone();
\$prototile_crm->Flop();                                                                     #\$prototile_crm->Write(filename=>"\$output_meta_folder/prototile_crm_AfterFlop.png");
\$prototile_crm->Rotate(degrees=>60, color=>'transparent');
\$prototile_crm->Set(page=>'0x0+0+0');                                                       #\$prototile_crm->Write(filename=>"\$output_meta_folder/prototile_crm_AfterRot_60.png");
\$prototile_crm->Trim();                                                                     #\$prototile_crm->Write(filename=>"\$output_meta_folder/prototile_crm_AfterTrim.png");
\$prototile_crm->Flip();                                                                     #\$prototile_crm->Write(filename=>"\$output_meta_folder/prototile_crm_AfterFlip.png");
\$tile->Composite(image=>\$prototile_crm, compose=>'over', x=>1/2*\$t_w, y=>\$t_h, color=>'transparent', matte=>'true');
\$tile->Set(page=>'0x0+0+0');                                                                \$tile->Write(filename=>"\$output_meta_folder/tile_after_crmt_10.png");
\$tile->Write(filename=>"\$output_meta_folder/tile_after_crmt_10.jpg");
```
Fehler beim Erstellen des Vorschaubildes: Datei fehlt
```# CRMT-COMMAND-LIST_11: f(G6) => (C0, Fo, R-60, x1/2*t_w, yt_h)  G5=Flip(G6)
@\$prototile_crm = ();
\$prototile_crm = \$Shape_list->[0]->Clone();
\$prototile_crm->Flop();                                                                      #\$prototile_crm->Write(filename=>"\$output_meta_folder/prototile_crm_AfterFlop.png");
\$prototile_crm->Rotate(degrees=>-60, color=>'transparent');
\$prototile_crm->Set(page=>'0x0+0+0');                                                        #\$prototile_crm->Write(filename=>"\$output_meta_folder/prototile_crm_AfterRot_minus60.png");
\$prototile_crm->Trim();                                                                      #\$prototile_crm->Write(filename=>"\$output_meta_folder/prototile_crm_AfterTrim.png");
\$tile->Composite(image=>\$prototile_crm, compose=>'over', x=>\$t_w, y=>\$t_h, color=>'transparent', matte=>'true');
\$tile->Set(page=>'0x0+0+0');                                                                 \$tile->Write(filename=>"\$output_meta_folder/tile_after_crmt_11.png");
\$tile->Write(filename=>"\$output_meta_folder/tile_after_crmt_11.jpg");
```
Fehler beim Erstellen des Vorschaubildes: Datei fehlt
```# CRMT-COMMAND-LIST_12: f(G1) => (C0, x3*t_w/2, yt_h)
@\$prototile_crm = ();
\$prototile_crm = \$Shape_list->[0]->Clone();
\$tile->Composite(image=>\$prototile_crm, compose=>'over', x=>3/2*\$t_w, y=>\$t_h, color=>'transparent', matte=>'true');
\$tile->Set(page=>'0x0+0+0');                                                                 \$tile->Write(filename=>"\$output_meta_folder/tile_after_crmt_12.png");
\$tile->Write(filename=>"\$output_meta_folder/tile_after_crmt_12.jpg");
```
Fehler beim Erstellen des Vorschaubildes: Datei fehlt
```# CRMT-COMMAND-LIST_13: f(G2) => (C0, Fo, R60, x2*t_w, yt_h)
@\$prototile_crm = ();
\$prototile_crm = \$Shape_list->[0]->Clone();
\$prototile_crm->Flop();                                                                      #\$prototile_crm->Write(filename=>"\$output_meta_folder/prototile_crm_AfterFlop.png");
\$prototile_crm->Rotate(degrees=>60, color=>'transparent');
\$prototile_crm->Set(page=>'0x0+0+0');                                                        #\$prototile_crm->Write(filename=>"\$output_meta_folder/prototile_crm_AfterRot_60.png");
\$prototile_crm->Trim();                                                                      #\$prototile_crm->Write(filename=>"\$output_meta_folder/prototile_crm_AfterTrim.png");
\$tile->Composite(image=>\$prototile_crm, compose=>'over', x=>2*\$t_w, y=>\$t_h, color=>'transparent', matte=>'true');
\$tile->Set(page=>'0x0+0+0');                                                                 \$tile->Write(filename=>"\$output_meta_folder/tile_after_crmt_13.png");
\$tile->Write(filename=>"\$output_meta_folder/tile_after_crmt_13.jpg");
```
Fehler beim Erstellen des Vorschaubildes: Datei fehlt
```# CRMT-COMMAND-LIST_14: f(G6) => (C0, Fo, R-60, Fi, x5/2*t_w, yt_h)
@\$prototile_crm = ();
\$prototile_crm = \$Shape_list->[0]->Clone();
\$prototile_crm->Flop();                                                                      #\$prototile_crm->Write(filename=>"\$output_meta_folder/prototile_crm_AfterFlop.png");
\$prototile_crm->Rotate(degrees=>-60, color=>'transparent');
\$prototile_crm->Set(page=>'0x0+0+0');                                                        #\$prototile_crm->Write(filename=>"\$output_meta_folder/prototile_crm_AfterRot_minus60.png");
\$prototile_crm->Trim();                                                                      #\$prototile_crm->Write(filename=>"\$output_meta_folder/prototile_crm_AfterTrim.png");
\$prototile_crm->Flip();                                                                      #\$prototile_crm->Write(filename=>"\$output_meta_folder/prototile_crm_AfterFlip.png");
\$tile->Composite(image=>\$prototile_crm, compose=>'over', x=>5/2*\$t_w, y=>\$t_h, color=>'transparent', matte=>'true');
\$tile->Set(page=>'0x0+0+0');                                                                 \$tile->Write(filename=>"\$output_meta_folder/tile_after_crmt_14.png");
\$tile->Write(filename=>"\$output_meta_folder/tile_after_crmt_14.jpg");
```
Fehler beim Erstellen des Vorschaubildes: Datei fehlt

In general there are gap artefacts along the diagonals, in the middle and in the top and bottom, which are shown as transparent pixel lines in png images or black pixel lines in jpg images. Diagonal artefacts are caused by rotation and the non-sub-pixel resolution of the image processing. Horizontal artefacts are caused by the trim command that could leave a one or two pixel border around the image object viz. the triangle. The larger the image the less are those artefacts viewable in the png files and saving as jpg smoothes the artefacts. Nevertheless there were postprocessing workarounds developed to fill the gap artefacts with local pixels by using a slightly upscaled image clone that is composed under the result image. This is a huge computational effort to correct very few pixels but such an correction is necessary because the back pixel artefacts could be aesthetically very disturbing. Compare the last shown image tile_after_crmt_14.jpg with the following image (Tile_after_diagonal_workaround.jpg) in an appropriate enlargement. Inpainting methods or experimentation with antialias are possible alternatives that could also be explored for postprocessing.

Fehler beim Erstellen des Vorschaubildes: Datei fehlt

If the image processing commands were combined and integrated one get a string that codes the building of a p3m1 tile from a given prototile triangle:

\$CRMT_string = 'C0, x0, y0, C0, Fo, R-60, x-1/2*t_w, y0, C0, Fo, R60, x1/2*t_w, y0, C0, Fo, R-60, Fi, xt_w, y0, C0, Fi, x3/2*t_w, y0, C0, Fo, R60, Fi, x2*t_w, y0, C0, Fo, R-60, x5/2*t_w, y0, C0, Fi, x0, yt_h, C0, Fo, R-60, Fi, x-1/2*t_w, yt_h, C0, Fo, R60, Fi, x1/2*t_w, yt_h, C0, Fo, R-60, xt_w, yt_h, C0, x3/2*t_w, yt_h, C0, Fo, R60, x2*t_w, yt_h, C0, Fo, R-60, Fi, x5/2*t_w, yt_h';

Such a string is written in a txt file and an CRMT-image interpreter, that has be be programmed, should be able to reconstruct the building of a p3m1 tile from any given equilateral triangle prototile. The gole here is an image interpreter that should be able to build tiles from the command strings that were generated from Evolutionary Algorithms environments in the Patterns and Tilings Competition.