/
symmetry_tile.py
executable file
·804 lines (655 loc) · 28.3 KB
/
symmetry_tile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
#!/usr/bin/env python
# Copyright (C) 2014 Eleanor Howick github.com/elfnor>
#
#This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.
#To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/4.0/.
from gimpfu import *
import math
import random
#setting debug to True leaves the original cell and tile as non visible
#construction layers on the image.
#otherewise these two layers are deleted.
debug = False
sym_types_list = ['p1','p2','pm','pg','pgg','pmm', 'pmg','cm','cmm', 'p4', 'p3m1', 'p3', 'p4g', 'p4m', 'p6', 'p31m', 'p6m',
'17 groups','all square cells', 'Escher\'s Potato Game']
rect_strs =[('p1', 'b', False),
('p2', 'bq', False),
('p2', 'b|q', False),
('p2', 'bq|qb', False),
('pm', 'bd', False),
('pm', 'b|p', False),
('cm', 'bp|pb', False),
('cm', 'bd|db', False),
('cmm', 'bdpq|pqbd', False),
('cmm', 'bd|qp|db|pq', False),
('cmm', 'bqpd|pdbq', False),
('cmm', 'bd|pq|db|qp', False),
('pg', 'bp', False),
('pg', 'b|d', False),
('pgg', 'bp|dq', False),
('pgg', 'bq|dp', False),
('pgg', 'bp|qd', False),
('pmg', 'bd|qp', False),
('pmg', 'b|p|d|q', False),
('pmg', 'b|q|d|p', False),
('pmg', 'bdpq', False),
('pmg', 'bqpd', False),
('pmg', 'bq|pd', False),
('pmm', 'bd|pq', False),
('pg', 'bd+|d+b', True),
('pg', 'bp+|p+b', True),
('p4', 'bb+|q+q', True),
('p4', 'bq+|b+q', True),
('p4g', 'bdp+b+|pqq+d+|p+b+bd|q+d+pq', True),
('p4g', 'bdd+q+|b+p+pq|d+q+bd|pqb+p+', True),
('p4g', 'bb+p+d|q+qpd+|p+dbb+|pd+q+q', True),
('p4g', 'bq+d+d|pp+b+q|d+dbq+|b+qpp+', True)]
rect_single_index = [0,1,4,6,8,12,16,19,23,26,28]
rect_strs_single = [rect_strs[i] for i in rect_single_index]
rect_cells = [rect_strs[i][0] for i in rect_single_index]
def symmetry_tile(old, drawable, width, height, sym_type, multiple, bdpq_str):
"""
plugin entry function
"""
old_is_sel, old_x1, old_y1, old_x2, old_y2 = pdb.gimp_selection_bounds(old)
if not old_is_sel:
pdb.gimp_message("FATAL: Missing selection in old image!")
coords = (old_x1, old_y1, old_x2, old_y2 )
if sym_types_list[sym_type] in rect_cells:
if multiple:
sym_list = [row for row in rect_strs if row[0] == sym_types_list[sym_type]]
for sym_name, sym_str, square in sym_list:
img_sym_str(sym_name, sym_str, square, old, drawable, width, height, coords)
else:
sym_name, sym_str, square = rect_strs_single[rect_cells.index(sym_types_list[sym_type])]
img_sym_str(sym_name, sym_str, square, old, drawable, width, height, coords)
if sym_types_list[sym_type] == 'p3': p3(old, drawable, width, height, coords)
if sym_types_list[sym_type] == 'p3m1': p3m1(old, drawable, width, height, coords)
if sym_types_list[sym_type] == 'p4m': p4m(old, drawable, width, height,coords)
if sym_types_list[sym_type] == 'p31m': p31m(old, drawable, width, height,coords)
if sym_types_list[sym_type] == 'p6m': p6m(old, drawable, width, height, coords)
if sym_types_list[sym_type] == 'p6':
if multiple:
p6(old, drawable, width, height, coords, rot60=0)
p6(old, drawable, width, height, coords, rot60=1)
p6(old, drawable, width, height, coords, rot60=2)
else:
p6(old, drawable, width, height, coords, rot60=0)
if sym_types_list[sym_type] == '17 groups': all_groups(old, drawable, width, height, multiple, coords)
if sym_types_list[sym_type] == 'all square cells': all_square(old, drawable, width, height, multiple, coords)
if sym_types_list[sym_type] == 'Escher\'s Potato Game':
if bdpq_str == "":
bdpq_str = random_potato_game_string()
if '+' in bdpq_str:
square = True
else:
square = False
img_sym_str('epg', bdpq_str, square, old, drawable, width, height, coords)
return
def clean_up(img):
#delete any invisible layers used in construction
if not debug:
for layer in img.layers:
if not layer.visible:
pdb.gimp_image_remove_layer(img, layer)
def all_groups(old, drawable, width, height, multiple, coords):
"""
Makes 17 (or 40 if multple set) new images using the same left edge of the rectangular selection
"""
if multiple:
sym_list = rect_strs
else:
sym_list = rect_strs_single
for sym_type, sym_str, square in sym_list:
img_sym_str(sym_type, sym_str, square, old, drawable, width, height, coords)
p4m(old, drawable, width, height, coords)
if multiple:
p6(old, drawable, width, height, coords, rot60=0)
p6(old, drawable, width, height, coords, rot60=1)
p6(old, drawable, width, height, coords, rot60=2)
else:
p6(old, drawable, width, height, coords, rot60=0)
p31m(old, drawable, width, height, coords)
p3m1(old, drawable, width, height, coords)
p6m(old, drawable, width, height, coords)
p3(old, drawable, width, height, coords)
return
def all_square(old, drawable, width, height, multiple, coords):
"""
Makes 11 (or 32 if multiple set) images all with the same square cell
"""
if multiple:
sym_list = rect_strs
else:
sym_list = rect_strs_single
for sym_type, sym_str, square in sym_list:
img_sym_str(sym_type, sym_str, True, old, drawable, width, height, coords)
"""-----------------------------------------------------------------------------"""
def copy_primary_cell(old, drawable, width, height, cell_width, cell_height):
"""
copies the new selected area to a new image
"""
# Copy the selected area
pdb.gimp_edit_copy(drawable)
# Create a new image
img = gimp.Image(width, height, RGB)
# Create a new layer and set the size of the layer = the size of the initial selection
layer = gimp.Layer(img, "first", int(cell_width), int(cell_height), 0, 100, 0)
img.add_layer(layer, 0)
layer.add_alpha()
# Clear the layer of any initial garbage
pdb.gimp_edit_clear(layer)
# Add the copied selection to the layer, and the layer to the image
layer.fill(3)
pdb.gimp_edit_paste(layer, 1)
#pdb.gimp_floating_sel_anchor(pdb.gimp_image_get_floating_sel(img))
cell = img.merge_visible_layers(1)
cell.visible = False
cell.name = 'cell'
return cell, img
def get_rect_primary_cell(old_img, coords, square=False):
"""
The primary cell is derived from the user selection
"""
old_x1, old_y1, old_x2, old_y2 = coords
cell_width = old_x2 - old_x1
cell_height = old_y2 - old_y1
if square:
cell_width = cell_height
pdb.gimp_image_select_rectangle(old_img, CHANNEL_OP_REPLACE, old_x1, old_y1, cell_width, cell_height)
return cell_width, cell_height
"""----------------------------------------------------------------------------"""
def copy_tile(tile, img, x0, x1):
"""
tile: the merged layer of primary cells
img: the new image type gimp.Image
x0: (x,y) vector along one edge of paralleogram defining tile
x1: (x,y) vector along other edge of paralleogram defining tile
"""
# first cell is placed so top left corner of a rectangle is at (0,0)
# do a loop from -1*x0 to +nx*x0
# do a loop from -1*x1 to ny*x1
# for hexagonal tiles need to add an extra half tile per row, do it for all.
tile.visible = False
tile.name = 'tile'
nx = int(img.width/x0[0]) + 2
ny = int(img.height/x1[1]) + 2
for j in range(-1, ny):
for i in range(-abs(j), nx):
this_layer = tile.copy(0)
this_layer.visible = True
img.add_layer(this_layer, 0)
xshft = i*x0[0] + j*x1[0]
yshft = i*x0[1] + j*x1[1]
pdb.gimp_layer_translate(this_layer, round(xshft), round(yshft))
pattern = img.merge_visible_layers(1)
pattern.name = 'pattern'
clean_up(img)
gimp.Display(img)
def cell_b(cell, cell_width, cell_height, img, pos, rotate90=False):
"""
this takes cell returned from get_rect_primary_cell() call
and places it at pos
eg.
pos = (1,0) one cell_width to the right
pos = (0,1) one cell_height down
"""
cell_2 = cell.copy(0)
cell_2.visible = True
img.add_layer(cell_2,0)
if rotate90:
pdb.gimp_item_transform_rotate_simple(cell_2,ROTATE_90,TRUE,0,0)
pdb.gimp_layer_translate(cell_2, cell_width*pos[0], cell_height*pos[1])
return
def cell_q(cell, cell_width, cell_height, img, pos, rotate90=False):
"""
this takes cell returned from get_rect_primary_cell() call
rotates it 180 degrees and places it at pos
eg.
pos = (1,0) one cell_width to the right
pos = (0,1) one cell_height down
"""
cell_2 = cell.copy(0)
cell_2.visible = True
img.add_layer(cell_2,0)
pdb.gimp_item_transform_rotate_simple(cell_2,ROTATE_180,TRUE,0,0)
if rotate90:
pdb.gimp_item_transform_rotate_simple(cell_2,ROTATE_90,TRUE,0,0)
pdb.gimp_layer_translate(cell_2, cell_width*pos[0], cell_height*pos[1])
return
def cell_d(cell, cell_width, cell_height, img, pos, rotate90=False):
"""
this takes cell returned from get_rect_primary_cell() call
flips it horizontally and places it at pos
eg.
pos = (1,0) one cell_width to the right
pos = (0,1) one cell_height down
"""
cell_2 = cell.copy(0)
cell_2.visible = True
img.add_layer(cell_2,0)
pdb.gimp_item_transform_flip_simple(cell_2, ORIENTATION_HORIZONTAL, True, 0)
if rotate90:
pdb.gimp_item_transform_rotate_simple(cell_2,ROTATE_90,TRUE,0,0)
pdb.gimp_layer_translate(cell_2, cell_width*pos[0], cell_height*pos[1])
return
def cell_p(cell, cell_width, cell_height, img, pos, rotate90=False):
"""
this takes cell returned from get_rect_primary_cell() call
flips it vertically and places it at pos
eg.
pos = (1,0) one cell_width to the right
pos = (0,1) one cell_height down
"""
cell_2 = cell.copy(0)
cell_2.visible = True
img.add_layer(cell_2,0)
pdb.gimp_item_transform_flip_simple(cell_2, ORIENTATION_VERTICAL, True, 0)
if rotate90:
pdb.gimp_item_transform_rotate_simple(cell_2,ROTATE_90,TRUE,0,0)
pdb.gimp_layer_translate(cell_2, cell_width*pos[0], cell_height*pos[1])
return
"""----------------------------------------------------------------------------"""
def img_sym_str(sym_type, sym_str, square, old_img, drawable, width, height, coords):
"""
Makes an image from the specified sym_str
"""
cell_width, cell_height= get_rect_primary_cell(old_img, coords, square)
cell, img = copy_primary_cell(old_img, drawable, width, height, cell_width, cell_height)
tile, x, y = tile_sym_str(sym_str, cell, cell_width, cell_height, img)
file_name = sym_type + '_' + filesafe_bdpq_str(sym_str) + '.xcf'
pdb.gimp_image_set_filename(img,file_name)
copy_tile(tile, img, (cell_width*x, 0), (0, cell_height*y))
def tile_sym_str(sym_str, cell_1, cell_width, cell_height, img):
"""
This takes a string simailar to 'bq|qb'and builds the pattern tile for
patterns based on a rectanglular primary cell .
The syntax for the string:
string must start with 'b' (for symmetry groups)
q is the cell rotated 180 deg
d is the cell fliped horizontally
p is the cell flipped vertically
| denotes a new line
That is 'bq|qb' will build this tile
bq
qb
and hence this pattern (symmetry group p2
bqbqbq
qbqbqb
bqbqbq
qbqbqb
b+, d+, p+, q+ represent each cell rotated 90 deg (clockwise), these are
only required for p4 and p4g
"""
i = 0
rot90 = False
x = 0
y = 0
if len(sym_str) != 1:
while i < len(sym_str):
ch_index = i
try:
if sym_str[ch_index+1] == '+':
rot90 = True
i = i + 1
except:
#ran out of string
pass
if sym_str[ch_index] == 'b' :
cell_b(cell_1, cell_width, cell_height, img, (x,y), rot90)
if sym_str[ch_index] == 'd' :
cell_d(cell_1, cell_width, cell_height, img, (x,y), rot90)
if sym_str[ch_index] == 'p' :
cell_p(cell_1, cell_width, cell_height, img, (x,y), rot90)
if sym_str[ch_index] == 'q' :
cell_q(cell_1, cell_width, cell_height, img, (x,y), rot90)
if sym_str[i] == '|':
y = y + 1
x = 0
else :
x = x + 1
rot90 = False
i = i + 1
x_repeats = x
y_repeats = y + 1
else:
x_repeats = 1
y_repeats = 1
tile = img.merge_visible_layers(1)
return tile, x_repeats, y_repeats
bdpq_strs = ['b','b+','d','d+','p','p+','q','q+']
def random_potato_game_string():
"""
produces a random 'bdpq' style string for a 2 x 2 tile
"""
pg_str = random.choice(bdpq_strs) + random.choice(bdpq_strs) + '|' + \
random.choice(bdpq_strs) + random.choice(bdpq_strs)
return pg_str
def filesafe_bdpq_str(bdpq_str):
"""
takes a bdpq type string and returns one for use in filenames
"""
sym_name = bdpq_str
sym_name = sym_name.replace('+','t')
sym_name = sym_name.replace('|','l')
return sym_name
"""-----------------------------------------------------------------------------
Groups with non-rectangular primary cells
--------------------------------------------------------------------------------"""
def get_tri_90_45_45_primary_cell(old_img, coords):
"""
A half square triangle primary cell is derived from the user's rectangular selection.
The left most side of the rectangle is used as the left edge of the triangle, with the rectangle
and triangle sharing the top left corner.
This copies a selected triangle to new layer on a new image
"""
old_x1, old_y1, old_x2, old_y2 = coords
cell_height = old_y2 - old_y1
# Turn the initial selection into a triangle with 90, 45, 45 degree angles, original rectangle and triangle
# share top left corner
points = (old_x1, old_y1, old_x1 + cell_height, old_y1 , old_x1, old_y2)
pdb.gimp_image_select_polygon(old_img, CHANNEL_OP_REPLACE, 6, points)
new_cell_width = cell_height
new_cell_height = cell_height
return new_cell_width, new_cell_height
def get_tri_90_60_30_primary_cell(old_img, coords):
"""
A 90, 60, 30 triangle primary cell is derived from the user's rectangular selection.
The left most side of the rectangle is used as the left edge of the triangle, with the rectangle
and triangle sharing the top left corner. The longer edge is the left most edge.
This copies a selected triangle to new layer on a new image.
"""
old_x1, old_y1, old_x2, old_y2 = coords
cell_height = old_y2 - old_y1
# Turn the initial selection into a triangle with 90, 60, 30 degree angles, original rectangle and triangle
# share top left corner
points = (old_x1, old_y1, old_x1 + int(cell_height/(3**0.5)), old_y1, old_x1, old_y2)
pdb.gimp_image_select_polygon(old_img, CHANNEL_OP_REPLACE, 6, points)
new_cell_width = int(cell_height/(3**0.5))
new_cell_height = cell_height
return new_cell_width, new_cell_height
def get_tri_60_60_60_primary_cell(old_img, coords):
"""
An equalateral triangle is derived from the user's rectangular selection
The triangle shares the rectangle's left side and the triangle points to the right.
The triangle is selected in the original image and copied to a new layer on a new image
"""
old_x1, old_y1, old_x2, old_y2 = coords
cell_height = old_y2 - old_y1
# Turn the initial selection into a equilateral triangle with equal sides, pointing to the right
xm = int(round((old_y1 + (cell_height / 2.0))))
inner_width = int(round(math.sqrt((cell_height**2)-((cell_height/2.0)**2))))
ym = int(round((old_x1 + inner_width)))
inner_width = int(inner_width)
points = (old_x1, old_y1, ym, xm, old_x1, old_y2)
pdb.gimp_image_select_polygon(old_img, CHANNEL_OP_REPLACE, 6, points)
new_cell_width = inner_width
new_cell_height = cell_height
return new_cell_width, new_cell_height
def get_diamond_primary_cell(old_img, coords):
"""
A 30/60 diamond is derived from the user's rectangular selection
The diamond shares the rectangle's left side and the diamond points down and to the right.
The diamond is selected in the original image and copied to a new layer on a new image
"""
old_x1, old_y1, old_x2, old_y2 = coords
cell_height = round(old_y2 - old_y1)
# Turn the initial selection into a diamond with equal sides and 30 deg 60 deg angles,
# diamond points down and to the right
cell_width = round(math.sqrt((cell_height**2)-((cell_height/2.0)**2)))
x2 = old_x1 + cell_width
y2 = round((old_y1 + (cell_height / 2.0)))
x3 = x2
y3 = round(old_y1 + 1.5*cell_height)
x4 = old_x1
y4 = old_y1 + cell_height
points = (old_x1, old_y1, x2, y2, x3, y3, x4, y4)
pdb.gimp_image_select_polygon(old_img, CHANNEL_OP_REPLACE, 8, points)
new_cell_width = cell_width
new_cell_height = round(1.5*cell_height)
return new_cell_width, new_cell_height
def get_kite_primary_cell(old_img, coords):
"""
A kite with 90 120 90 60 degree angles is derived from the user's rectangular selection.
the kite is 1/3 of an equilateral triangle.
The kite shares the rectangle's left side and the top left corner
The diamond is selected in the original image and copied to a new layer on a new image
"""
old_x1, old_y1, old_x2, old_y2 = coords
cell_height = int(old_y2 - old_y1)
# Turn the initial selection into a diamond with equal sides and 30 deg 60 deg angles,
# diamond points down and to the right
cell_width = int(math.sqrt((cell_height**2)-((cell_height/2.0)**2)))
x3 = old_x1 + cell_width
y3 = old_y1 + int(cell_height/2.0)
x4 = old_x1 + int(cell_height/(3**0.5))
y4 = old_y1
points = (old_x1, old_y1, old_x1, old_y2, x3, y3, x4, y4)
pdb.gimp_image_select_polygon(old_img, CHANNEL_OP_REPLACE, 8, points)
new_cell_width = cell_width
new_cell_height = cell_height
return new_cell_width, new_cell_height
def p3m1(old_img, drawable, width, height, coords):
"""
The primary cell of p3m1 is an equilateral triangle.
"""
cell_width, cell_height = get_tri_60_60_60_primary_cell(old_img, coords)
cell, img = copy_primary_cell(old_img, drawable, width, height, cell_width, cell_height)
cell_1 = cell.copy(0)
cell_1.visible = True
img.add_layer(cell_1,0)
pdb.gimp_layer_translate(cell_1, 0, cell_height/2)
cell_2 = cell_1.copy(0)
img.add_layer(cell_2,0)
pdb.gimp_item_transform_flip_simple(cell_2, ORIENTATION_VERTICAL, 1, 0)
pdb.gimp_item_transform_rotate(cell_2, math.pi/3.0, False,cell_width, cell_height)
#pdb.gimp_selection_none(img)
pair_1 = img.merge_visible_layers(1)
pair_2 = pair_1.copy(0)
img.add_layer(pair_2,0)
pdb.gimp_item_transform_rotate(pair_2, 2.0*math.pi/3.0, False,cell_width, cell_height)
#pdb.gimp_selection_none(img)
pair_3 = pair_1.copy(0)
img.add_layer(pair_3,0)
pdb.gimp_item_transform_rotate(pair_3, 4.0*math.pi/3.0, False,cell_width, cell_height)
#pdb.gimp_selection_none(img)
tile = img.merge_visible_layers(1)
pdb.gimp_image_set_filename(img,'p3m1.xcf')
copy_tile(tile, img, (2*cell_width, 0), (cell_width, int(1.5*cell_height)))
def p3(old_img, drawable, width, height, coords):
"""
The primary cell of p3 is a 30 60 diamond.
"""
cell_width, cell_height = get_diamond_primary_cell(old_img, coords)
cell, img = copy_primary_cell(old_img, drawable, width, height, cell_width, cell_height)
cell_1 = cell.copy(0)
cell_1.visible = True
img.add_layer(cell_1,0)
pdb.gimp_layer_translate(cell_1, 0, round(cell_height/3))
cell_2 = cell_1.copy(0)
img.add_layer(cell_2,0)
pdb.gimp_item_transform_rotate(cell_2, 2.0*math.pi/3.0, 1,0, 0)
pdb.gimp_layer_translate(cell_2, round(cell_width/2), round(-0.5*cell_height))
pdb.gimp_selection_none(img)
cell_3 = cell_1.copy(0)
img.add_layer(cell_3,0)
pdb.gimp_item_transform_rotate(cell_3, 4.0*math.pi/3.0, 1,0, 0)
pdb.gimp_layer_translate(cell_3, cell_width, 0)
pdb.gimp_selection_none(img)
tile = img.merge_visible_layers(1)
pdb.gimp_image_set_filename(img,'p3.xcf')
copy_tile(tile, img, (2*cell_width, 0), (cell_width, cell_height))
def p4m(old_img, drawable, width, height, coords):
"""
The primary cell of p4m is a 90 45 45 triangle.
"""
cell_width, cell_height = get_tri_90_45_45_primary_cell(old_img, coords)
cell, img = copy_primary_cell(old_img, drawable, width, height, cell_width, cell_height)
cell_1 = cell.copy(0)
cell_1.visible = True
img.add_layer(cell_1,0)
#make a copy and mirror it along long side of cell
cell_2 = cell_1.copy(0)
img.add_layer(cell_2,0)
pdb.gimp_item_transform_flip(cell_2, cell_width, 0, 0, cell_height)
tile_1 = img.merge_visible_layers(1)
# Make a copy of the 1st cell and mirror it
tile_2 = tile_1.copy(0)
img.add_layer(tile_2,0)
pdb.gimp_item_transform_flip_simple(tile_2, ORIENTATION_HORIZONTAL, True, 0)
pdb.gimp_layer_translate(tile_2, cell_width, 0)
# Merge the two layers
pair_1 = img.merge_visible_layers(1)
# Make copies of the fist pair and mirror them
pair_2 = pair_1.copy(0)
img.add_layer(pair_2, 0)
pdb.gimp_item_transform_flip_simple(pair_2, ORIENTATION_VERTICAL, True, 0)
pdb.gimp_layer_translate(pair_2, 0, cell_height)
tile = img.merge_visible_layers(1)
pdb.gimp_image_set_filename(img,'p4m.xcf')
copy_tile(tile, img, (2*cell_width, 0), (0, 2*cell_height))
def p6(old_img, drawable, width, height, coords, rot60=0):
"""
The primary cell of p6 is either an equilateral triangle or a kite
we'll do the equilateral triangle
3 alternatives
rotate the block 60 deg and regenerate tile
rot60 = 0, 1, 2 number of 60 degree rotations to apply
"""
cell_width, cell_height = get_tri_60_60_60_primary_cell(old_img, coords)
cell, img = copy_primary_cell(old_img, drawable, width, height, cell_width, cell_height)
cell_1 = cell.copy(0)
cell_1.visible = True
img.add_layer(cell_1,0)
pdb.gimp_item_transform_rotate(cell_1, rot60*2.0*math.pi/3.0, 0, int(cell_height/(2.0*(3.0**0.5))) , int(cell_height/2.0) )
pdb.gimp_layer_translate(cell_1, 0, round(cell_height/2.0))
pdb.gimp_selection_none(img)
#rotate 60 deg
cell_2 = cell_1.copy(0)
img.add_layer(cell_2,0)
pdb.gimp_item_transform_rotate(cell_2, math.pi/3.0, 0 ,cell_width, cell_height)
pdb.gimp_selection_none(img)
#rotate 120 deg
cell_3 = cell_1.copy(0)
img.add_layer(cell_3,0)
pdb.gimp_item_transform_rotate(cell_3, 2.0*math.pi/3.0, 0 ,cell_width, cell_height)
pdb.gimp_selection_none(img)
#rotate 180 deg
cell_4 = cell_1.copy(0)
img.add_layer(cell_4,0)
pdb.gimp_item_transform_rotate(cell_4, 3.0*math.pi/3.0, 0 ,cell_width, cell_height)
pdb.gimp_selection_none(img)
#rotate 240 deg
cell_5 = cell_1.copy(0)
img.add_layer(cell_5,0)
pdb.gimp_item_transform_rotate(cell_5, 4.0*math.pi/3.0, 0 ,cell_width, cell_height)
pdb.gimp_selection_none(img)
#rotate 300 deg
cell_6 = cell_1.copy(0)
img.add_layer(cell_6,0)
pdb.gimp_item_transform_rotate(cell_6, 5.0*math.pi/3.0, 0 ,cell_width, cell_height)
pdb.gimp_selection_none(img)
tile = img.merge_visible_layers(1)
pdb.gimp_image_set_filename(img,'p6_' + str(rot60) + '.xcf')
copy_tile(tile, img, (2*cell_width, 0), (cell_width, round(1.5*cell_height)))
def p31m(old_img, drawable, width, height, coords):
"""
The primary cell of p31m is a 1/3 equilateral triangle, this can be a 30,30,120 triangle, half a hexagon or a kite.
we'll do the kite
"""
cell_width, cell_height = get_kite_primary_cell(old_img, coords)
cell, img = copy_primary_cell(old_img, drawable, width, height, cell_width, cell_height)
cell_1 = cell.copy(0)
cell_1.visible = True
img.add_layer(cell_1,0)
pdb.gimp_item_transform_rotate(cell_1, -math.pi/2.0, 0 ,0, 0)
cell_length = int(2.0*cell_height/(3**0.5))
pdb.gimp_layer_translate(cell_1, 0, cell_length)
#mirror along one side
cell_2 = cell_1.copy(0)
img.add_layer(cell_2,0)
pdb.gimp_item_transform_flip(cell_2, 0, cell_length, cell_height, cell_length)
pdb.gimp_selection_none(img)
tile_1 = img.merge_visible_layers(1)
#rotate 120 deg
tile_2 = tile_1.copy(0)
img.add_layer(tile_2,0)
pdb.gimp_item_transform_rotate(tile_2, 2.0*math.pi/3.0, 0 ,cell_height, cell_length)
pdb.gimp_selection_none(img)
#rotate 240 deg
tile_3 = tile_1.copy(0)
img.add_layer(tile_3,0)
pdb.gimp_item_transform_rotate(tile_3, 4.0*math.pi/3.0, 0 ,cell_height, cell_length)
pdb.gimp_selection_none(img)
#merge into one tile
tile = img.merge_visible_layers(1)
pdb.gimp_image_set_filename(img,'p31m.xcf')
copy_tile(tile, img, (2*cell_height, 0), (cell_height, (3.0**0.5)*cell_height))
def p6m(old_img, drawable, width, height, coords):
"""
The primary cell of p6 is a triangle with 90, 60, 30 degree angles.
"""
cell_width, cell_height = get_tri_90_60_30_primary_cell(old_img, coords)
cell, img = copy_primary_cell(old_img, drawable, width, height, cell_width, cell_height)
cell_1 = cell.copy(0)
cell_1.visible = True
img.add_layer(cell_1,0)
r = 2 * cell_width
# rotate and move cell_1
pdb.gimp_item_transform_rotate(cell_1, -math.pi/2.0, 0 ,0, 0)
pdb.gimp_layer_translate(cell_1, 0, r)
#mirror cell_1 to give equilateral triangle
cell_2 = cell_1.copy(0)
img.add_layer(cell_2,0)
pdb.gimp_item_transform_flip(cell_2, 0, r, cell_height, r)
pdb.gimp_selection_none(img)
cell_1 = img.merge_visible_layers(1)
#make six rotational copies
#rotate 60 deg
cell_2 = cell_1.copy(0)
img.add_layer(cell_2,0)
pdb.gimp_item_transform_rotate(cell_2, math.pi/3.0, 0 ,cell_height, r)
pdb.gimp_selection_none(img)
#rotate 120 deg
cell_3 = cell_1.copy(0)
img.add_layer(cell_3,0)
pdb.gimp_item_transform_rotate(cell_3, 2.0*math.pi/3.0, 0 ,cell_height, r)
pdb.gimp_selection_none(img)
#rotate 180 deg
cell_4 = cell_1.copy(0)
img.add_layer(cell_4,0)
pdb.gimp_item_transform_rotate(cell_4, 3.0*math.pi/3.0, 0 ,cell_height, r)
pdb.gimp_selection_none(img)
#rotate 240 deg
cell_5 = cell_1.copy(0)
img.add_layer(cell_5,0)
pdb.gimp_item_transform_rotate(cell_5, 4.0*math.pi/3.0, 0 ,cell_height, r)
pdb.gimp_selection_none(img)
#rotate 300 deg
cell_6 = cell_1.copy(0)
img.add_layer(cell_6,0)
pdb.gimp_item_transform_rotate(cell_6, 5.0*math.pi/3.0, 0 ,cell_height, r)
pdb.gimp_selection_none(img)
tile = img.merge_visible_layers(1)
pdb.gimp_image_set_filename(img,'p6m.xcf')
copy_tile(tile, img, (2*cell_height, 0), (cell_height, (3.0**0.5)*cell_height))
# Register with The Gimp
register(
"symmetry_tile",
"Turn selection into tiled symmetric image",
"Turn selection into tiled symmetric image",
"Eleanor Howick",
"(c) 2014, Eleanor Howick",
"2014-07-16",
"<Image>/Filters/Render/Symmetry Tile",
"*",
[
(PF_INT32, "width", "Width", 500),
(PF_INT32, "height", "Height", 500),
(PF_OPTION,"sym_type", "Symmetry group:", 0, sym_types_list),
(PF_BOOL, "muliple","Multiple images:" , 0),
(PF_STRING, "bdpq_str", "bdpq string:", "")
],
[],
symmetry_tile);
main()