-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRothkoFrame.pde
93 lines (70 loc) · 2.39 KB
/
RothkoFrame.pde
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
import java.util.TreeSet;
class RothkoFrame {
int frameHeight;
int frameWidth;
int margin = 30;
float heightOffset = margin;
String title;
ArrayList<RothkoRect> rects = new ArrayList<RothkoRect>();
color backgroundColor;
RothkoFrame(int frameWidth, int frameHeight, color backgroundColor) {
this(frameWidth, frameHeight, (color) backgroundColor, (String) null, 30);
}
RothkoFrame(int frameWidth, int frameHeight, color backgroundColor, String title, int margin) {
this.frameWidth = frameWidth;
this.frameHeight = frameHeight;
this.backgroundColor = backgroundColor;
this.title = title;
this.margin = margin;
this.heightOffset = margin;
}
/** Add a color rectangle to the frame.
* @param rectHeight Height of this rectangle in percent of the whole painting.
* @param color Color of the rectangle.
* @param i Intensity of the color. This is the number of time this rectangle will be drawn.
*/
void addRect(float rectHeight, color c, int i) {
float bottomY = (frameHeight*rectHeight) + heightOffset;
PVector topLeft = new PVector(margin, heightOffset);
PVector botRight = new PVector(frameWidth - margin, bottomY);
RothkoRect rect = new RothkoRect(topLeft, botRight, c, i);
rects.add(rect);
heightOffset = bottomY;
}
/** Draw the complete painting. */
void draw() {
noStroke();
//background(backgroundColor);
//clear();
fill(backgroundColor);
rect(0, 0, width, height);
noFill();
// randomize rect drawing order
Collections.shuffle(rects);
for (RothkoRect rect : rects) {
rect.draw();
}
}
/** Get the title of the painting. Generate a random title if none was provided. */
String getTitle() {
if (title != null) {
return title;
}
ColorNames colorNames = new ColorNames();
Set<String> names = new TreeSet<String>();
names.add(colorNames.getColorName(backgroundColor).match.name);
for (RothkoRect rect : rects) {
names.add(colorNames.getColorName(rect.rectColor).match.name);
}
String[] titleColors = names.toArray(new String[names.size()]);
String prefix = "";
if (random(1) > 0.8) {
return "Untitled";
}
if (random(1) > 0.7) {
prefix = "No. " + ((int)random(50, 120)) + " (";
}
title = prefix + String.join(", ", titleColors) + (prefix.isEmpty() ? "" : ")");
return title;
}
}