-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGollyPatternSettings.java
654 lines (547 loc) · 13.6 KB
/
GollyPatternSettings.java
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
public class GollyPatternSettings implements java.io.Serializable
{
/* Members */
private int fillRActive = 0;
private int fillGActive = 0;
private int fillBActive = 0;
private int fillAActive = 255;
private int fillRInactive = 255; //100
private int fillGInactive = 199; //100
private int fillBInactive = 22; //100
private int fillAInactive = 255;
private int strokeRActive = 100;
private int strokeGActive = 100;
private int strokeBActive = 100;
private int strokeAActive = 255;
private int strokeRInactive = 255;
private int strokeGInactive = 255;
private int strokeBInactive = 255;
private int strokeAInactive = 255;
private int strokeWeightActive = 1;
private int strokeWeightInactive = 0;
private int scaleFactor = 1;
private float shapeWidthActive = 8;
private float shapeWidthInactive = 8;
private float shapeHeightActive = 8;
private float shapeHeightInactive = 8;
// private float scaleFactor = 1.0f;
private boolean showGrid = true;
private boolean showInactives = false;
private boolean keepCellRatio = true;
private boolean keepShapeRatioActive = true;
private boolean keepShapeRatioInactive = true;
private boolean shapesLikeCellsActive = false;
private boolean shapesLikeCellsInactive = false;
private boolean isStrokeOnActive = false;
private boolean isStrokeOnInactive = false;
private boolean isFillOnActive = true;
private boolean isFillOnInactive = true;
private boolean workingOnActiveStates = true;
private CellShape cellShape = CellShape.SQUARE;
private String SVGPath = null;
// private SketchTransformer transformer;
private String rleFilePath = null;
private CategoricalDistribution distribution;
private ColorPalette colorPalette;
private ColorMode colorMode = ColorMode.NORMAL;
private ColorAssignment currentColorAssignment = null;
private ColorAssignment normalColorAssignment = null;
private ColorAssignment randomColorAssignment = null;
private ColorAssignment randomLocalColorAssignment = null;
private ColorAssignment randomLocalStarColorAssignment = null;
private int windowRadius = 1;
private static final int defaultNeighbourExpansionMode = 1;
/* Utilities */
// public void initTransformer(float xOffset, float yOffset,
// float scaleFactor) {
// transformer = new SketchTransformer(xOffset, yOffset, scaleFactor);
// }
/* Getters: */
public int getFillRActive()
{
return fillRActive;
}
public int getFillGActive()
{
return fillGActive;
}
public int getFillBActive()
{
return fillBActive;
}
public int getFillAActive()
{
return fillAActive;
}
public int getFillRInactive()
{
return fillRInactive;
}
public int getFillGInactive()
{
return fillGInactive;
}
public int getFillBInactive()
{
return fillBInactive;
}
public int getFillAInactive()
{
return fillAInactive;
}
public int getStrokeRActive()
{
return strokeRActive;
}
public int getStrokeGActive()
{
return strokeGActive;
}
public int getStrokeBActive()
{
return strokeBActive;
}
public int getStrokeAActive()
{
return strokeAActive;
}
public int getStrokeRInactive()
{
return strokeRInactive;
}
public int getStrokeGInactive()
{
return strokeGInactive;
}
public int getStrokeBInactive()
{
return strokeBInactive;
}
public int getStrokeAInactive()
{
return strokeAInactive;
}
public int getStrokeWeightActive()
{
return strokeWeightActive;
}
public int getStrokeWeightInactive()
{
return strokeWeightInactive;
}
public int getScaleFactor()
{
return scaleFactor;
}
public float getShapeWidthActive()
{
return shapeWidthActive;
}
public float getShapeWidthInactive()
{
return shapeWidthInactive;
}
public float getShapeHeightActive()
{
return shapeHeightActive;
}
public float getShapeHeightInactive()
{
return shapeHeightInactive;
}
// public SketchTransformer getTransformer()
// {
// return transformer;
// }
// public float getScaleFactor()
// {
// return scaleFactor;
// }
public boolean getShowGrid()
{
return showGrid;
}
public boolean getShowInactives()
{
return showInactives;
}
public boolean getKeepCellRatio()
{
return keepCellRatio;
}
public boolean getKeepShapeRatioActive()
{
return keepShapeRatioActive;
}
public boolean getKeepShapeRatioInactive()
{
return keepShapeRatioInactive;
}
public boolean getShapesLikeCellsActive()
{
return shapesLikeCellsActive;
}
public boolean getShapesLikeCellsInactive()
{
return shapesLikeCellsInactive;
}
public boolean isStrokeOnActive()
{
return isStrokeOnActive;
}
public boolean isStrokeOnInactive()
{
return isStrokeOnInactive;
}
public boolean isFillOnActive()
{
return isFillOnActive;
}
public boolean isFillOnInactive()
{
return isFillOnInactive;
}
public boolean workingOnActiveStates()
{
return workingOnActiveStates;
}
public CellShape getCellShape()
{
return cellShape;
}
public ColorMode getColorMode()
{
return colorMode;
}
public ColorAssignment getCurrentColorAssingment()
{
return currentColorAssignment;
}
public String getSVGPath()
{
return SVGPath;
}
public String getRleFilePath()
{
return rleFilePath;
}
public int getWindowRadius()
{
return windowRadius;
}
public double getColorProbability(int index)
{
return distribution.getOutcomeProbability(index);
}
// public void setColorProbability(int index, double value)
// {
// distribution.setOutcomeProbability(index, value);
// }
/* Setters */
public void setFillRActive(int val)
{
fillRActive = val;
}
public void setFillGActive(int val)
{
fillGActive = val;
}
public void setFillBActive(int val)
{
fillBActive = val;
}
public void setFillAActive(int val)
{
fillAActive = val;
}
public void setFillRInactive(int val)
{
fillRInactive = val;
}
public void setFillGInactive(int val)
{
fillGInactive = val;
}
public void setFillBInactive(int val)
{
fillBInactive = val;
}
public void setFillAInactive(int val)
{
fillAInactive = val;
}
public void setStrokeRActive(int val)
{
strokeRActive = val;
}
public void setStrokeGActive(int val)
{
strokeGActive = val;
}
public void setStrokeBActive(int val)
{
strokeBActive = val;
}
public void setStrokeAActive(int val)
{
strokeAActive = val;
}
public void setStrokeRInactive(int val)
{
strokeRInactive = val;
}
public void setStrokeGInactive(int val)
{
strokeGInactive = val;
}
public void setStrokeBInactive(int val)
{
strokeBInactive = val;
}
public void setStrokeAInactive(int val)
{
strokeAInactive = val;
}
public void setStrokeWeightActive(int val)
{
strokeWeightActive = val;
}
public void setStrokeWeightInactive(int val)
{
strokeWeightInactive = val;
}
public void setScaleFactor(int val)
{
scaleFactor = val;
}
public void setShapeWidthActive(float val)
{
shapeWidthActive = val;
}
public void setShapeWidthInactive(float val)
{
shapeWidthInactive = val;
}
public void setShapeHeightActive(float val)
{
shapeHeightActive = val;
}
public void setShapeHeightInactive(float val)
{
shapeHeightInactive = val;
}
// public void setScaleFactor(float val)
// {
// scaleFactor = val;
// }
public void setShowGrid(boolean flag)
{
showGrid = flag;
}
public void setShowInactives(boolean flag)
{
showInactives = flag;
}
public void setKeepCellRatio(boolean flag)
{
keepCellRatio = flag;
}
public void setKeepShapeRatioActive(boolean flag)
{
keepShapeRatioActive = flag;
}
public void setKeepShapeRatioInactive(boolean flag)
{
keepShapeRatioInactive = flag;
}
public void setShapesLikeCellsActive(boolean flag)
{
shapesLikeCellsActive = flag;
}
public void setShapesLikeCellsInactive(boolean flag)
{
shapesLikeCellsInactive = flag;
}
public void setIsStrokeOnActive(boolean flag)
{
isStrokeOnActive = flag;
}
public void setIsStrokeOnInactive(boolean flag)
{
isStrokeOnInactive = flag;
}
public void setIsFillOnActive(boolean flag)
{
isFillOnActive = flag;
}
public void setIsFillOnInactive(boolean flag)
{
isFillOnInactive = flag;
}
public void setWorkingOnActiveStates(boolean flag)
{
workingOnActiveStates = flag;
}
public void setCellShape(CellShape cellShape)
{
this.cellShape = cellShape;
}
/* TODO: propagate this through the UI */
public void setColorMode(ColorMode mode)
{
colorMode = mode;
/* updating the color assignment */
switch(mode)
{
case NORMAL:
currentColorAssignment = normalColorAssignment;
break;
case RANDOM:
if(randomColorAssignment == null)
{
randomColorAssignment =
currentColorAssignment.newRandomColorAssignment(distribution);
}
currentColorAssignment = randomColorAssignment;
break;
case RANDOM_LOCAL:
if(randomLocalColorAssignment == null)
{
randomLocalColorAssignment =
currentColorAssignment.newRandomLocalColorAssignment(distribution,
windowRadius,
0);
}
currentColorAssignment = randomLocalColorAssignment;
break;
case RANDOM_LOCAL_STAR:
if (randomLocalStarColorAssignment == null)
{
randomLocalStarColorAssignment =
currentColorAssignment.newRandomLocalColorAssignment(distribution,
windowRadius,
1);
}
currentColorAssignment = randomLocalStarColorAssignment;
break;
default:
currentColorAssignment = normalColorAssignment;
break;
}
}
// public void setColorPalette(ColorPalette palette)
// {
// colorPalette = palette;
// }
/* color management, hiding the palette and the assignment */
public void initColors(int numColors, GollyRleConfiguration config)
{
/* assuming a uniform distribution at start
creating a palette */
distribution = new CategoricalDistribution(numColors);
colorPalette = new ColorPalette(numColors, distribution);
/* creating a new color assignment */
normalColorAssignment = new ColorAssignment(config);
/* setting it as the current one */
currentColorAssignment = normalColorAssignment;
}
public boolean isActiveState(int i, int j)
{
return currentColorAssignment.getColorCode(i, j) >= 0;
}
public void setColorProbability(int index, double prob)
{
colorPalette.setColorProbability(index, prob);
}
public void setColorProbability(double[] distribution)
{
colorPalette.setColorProbability(distribution);
}
public void setColor(int index, int code)
{
colorPalette.setColor(index, code);
}
public int getColor(int index)
{
return colorPalette.getColor(index);
}
public int getColor(int i, int j)
{
int code = currentColorAssignment.getColorCode(i, j);
int cellColor = -1; /* TODO: set the inactive color */
if(code >= 0)
{
cellColor = colorPalette.getColor(code);
}
return cellColor;
}
public void nextColorAssignment(int i, int j)
{
// println("curr ass", currentColorAssignment.getColorCode(i, j));
if(currentColorAssignment.getColorCode(i, j) + 1 < colorPalette.getPaletteLength())
{
currentColorAssignment.nextColor(i, j);
}
}
public void previousColorAssignment(int i, int j)
{
currentColorAssignment.previousColor(i, j);
}
public void shuffleColorAssignment()
{
randomColorAssignment.shuffle(distribution);
}
public void shuffleRLColorAssignment()
{
// randomLocalColorAssignment =
// currentColorAssignment.newRandomLocalColorAssignment(distribution,
// windowRadius);
// currentColorAssignment = randomLocalColorAssignment;
if(colorMode == ColorMode.RANDOM_LOCAL)
{
randomLocalColorAssignment.shuffleLocal(normalColorAssignment,
distribution,
windowRadius,
0);
}
else if(colorMode == ColorMode.RANDOM_LOCAL_STAR)
{
randomLocalStarColorAssignment.shuffleLocal(normalColorAssignment,
distribution,
windowRadius,
1);
}
}
/* file utils */
public void setSVGPath(String path)
{
SVGPath = path;
}
public void setRleFilePath(String path)
{
rleFilePath = path;
}
public void setWindowRadius(int radius)
{
if (windowRadius != radius)
{
windowRadius = radius;
if (colorMode == ColorMode.RANDOM_LOCAL)
{
randomLocalColorAssignment =
currentColorAssignment.newRandomLocalColorAssignment(distribution,
windowRadius,
0);
currentColorAssignment = randomLocalColorAssignment;
}
else if(colorMode == ColorMode.RANDOM_LOCAL_STAR)
{
randomLocalStarColorAssignment =
currentColorAssignment.newRandomLocalColorAssignment(distribution,
windowRadius,
1);
currentColorAssignment = randomLocalStarColorAssignment;
}
}
}
}