Skip to content

Commit b11d6de

Browse files
committed
smaller fixes
1 parent b51b430 commit b11d6de

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

drawingSettings.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -126,25 +126,29 @@ const PREDEFINED_COLOR_PALETTES = [
126126
]
127127
];
128128

129+
function round(num) {
130+
return Math.round(num * 100) / 100;
131+
}
132+
129133
function randomSettings(bbox=false) {
130134
let svgSettings = {};
131135
if (bbox) {
132136
if (Math.random() < 0.4) {
133137
svgSettings['fill'] = 'color'
134138
};
135139
if (Math.random() < 0.1) {
136-
svgSettings['fill-opacity'] = Math.random() * 0.6 + 0.4;
140+
svgSettings['fill-opacity'] = round(Math.random() * 0.6 + 0.4);
137141
};
138142
if (Math.random() < 0.3) {
139143
if (Math.random() < 0.1) {
140-
svgSettings['scale'] = Math.random() * 3 + 1;
144+
svgSettings['scale'] = round(Math.random() * 3 + 1);
141145
} else {
142-
svgSettings['scale'] = Math.random();
146+
svgSettings['scale'] = round(Math.random());
143147
}
144148
}
145149
if (Math.random() < 0.2) {
146-
svgSettings['rx'] = Math.random();
147-
svgSettings['ry'] = Math.random();
150+
svgSettings['rx'] = Math.round(Math.random() * 100) / 100;
151+
svgSettings['ry'] = Math.round(Math.random() * 100) / 100;
148152
if (Math.random() < 0.8) {
149153
svgSettings['ry'] = svgSettings['rx'];
150154
}
@@ -161,10 +165,10 @@ function randomSettings(bbox=false) {
161165
}
162166
}
163167
if (Math.random() < 0.4) {
164-
svgSettings['stroke-width'] = Math.random();
168+
svgSettings['stroke-width'] = round(Math.random());
165169
}
166170
if (Math.random() < 0.4) {
167-
svgSettings['stroke-opacity'] = Math.random() * 0.6 + 0.4;
171+
svgSettings['stroke-opacity'] = round(Math.random() * 0.6 + 0.4);
168172
}
169173
return svgSettings;
170174
}
@@ -181,14 +185,15 @@ function getRandomSettings() {
181185

182186
const SETTING_NAMES = ["belts", "underground-belts", "pipes", "underground-pipes", "heat-pipes", "inserters", "rails", "power-lines", "green-wire-lines", "red-wire-lines"];
183187
let temp_settings = [];
184-
const sampleSettings = shuffleArray([...SETTING_NAMES]).slice(0, 3);
185-
for (const settingName of sampleSettings) {
188+
189+
const numSettings = Math.floor(Math.random() * 6);
190+
for (let i = 0; i < numSettings; i++) {
191+
const settingName = SETTING_NAMES[Math.floor(Math.random() * SETTING_NAMES.length)];
186192
const settings = randomSettings(false);
187193
temp_settings.push([settingName, settings]);
188194
}
189195

190-
// Add 0-4 random bbox settings
191-
const bboxCount = Math.floor(Math.random() * 5); // Random number 0-4
196+
const bboxCount = Math.floor(Math.random() * 5);
192197
const genericBuildingTerms = Object.keys(buildingGenericTerms);
193198
const buildingTerms = Object.keys(entityNameToProperties);
194199
const allTerms = [...genericBuildingTerms, ...genericBuildingTerms, ...buildingTerms];

0 commit comments

Comments
 (0)