1
0
Fork 0

Added sampling style that iterates of hue range

This commit is contained in:
Joost De Cock 2018-09-22 10:41:51 +02:00
parent 408fdd09fe
commit c60e66b979
2 changed files with 33 additions and 17 deletions

View file

@ -1,4 +1,4 @@
import { macroName, debugStyle, round } from "./utils"; import { macroName, debugStyle, round, sampleStyle } from "./utils";
import Part from "./part"; import Part from "./part";
import Point from "./point"; import Point from "./point";
import Path from "./path"; import Path from "./path";
@ -43,6 +43,8 @@ export default function Pattern(config = false) {
if (typeof option.pct !== "undefined") this.options[i] = option.pct / 100; if (typeof option.pct !== "undefined") this.options[i] = option.pct / 100;
else if (typeof option.mm !== "undefined") this.options[i] = option.mm; else if (typeof option.mm !== "undefined") this.options[i] = option.mm;
else if (typeof option.deg !== "undefined") this.options[i] = option.deg; else if (typeof option.deg !== "undefined") this.options[i] = option.deg;
else if (typeof option.count !== "undefined")
this.options[i] = option.count;
else if (typeof option.dflt !== "undefined") else if (typeof option.dflt !== "undefined")
this.options[i] = option.dflt; this.options[i] = option.dflt;
else throw "Unknown option type"; else throw "Unknown option type";
@ -97,7 +99,7 @@ Pattern.prototype.sample = function() {
Pattern.prototype.sampleParts = function() { Pattern.prototype.sampleParts = function() {
let parts = {}; let parts = {};
this.settings.quick = true; this.settings.complete = false;
this.settings.paperless = false; this.settings.paperless = false;
this.draft(); this.draft();
for (let i in this.parts) { for (let i in this.parts) {
@ -107,7 +109,13 @@ Pattern.prototype.sampleParts = function() {
return parts; return parts;
}; };
Pattern.prototype.sampleRun = function(parts, anchors, l, extraClass = false) { Pattern.prototype.sampleRun = function(
parts,
anchors,
run,
runs,
extraClass = false
) {
this.draft(); this.draft();
for (let i in this.parts) { for (let i in this.parts) {
let anchor = false; let anchor = false;
@ -124,16 +132,16 @@ Pattern.prototype.sampleRun = function(parts, anchors, l, extraClass = false) {
} }
} }
for (let j in this.parts[i].paths) { for (let j in this.parts[i].paths) {
parts[i].paths[j + "_" + l] = this.parts[i].paths[j] parts[i].paths[j + "_" + run] = this.parts[i].paths[j]
.clone() .clone()
.attr("class", "sample sample-" + l, true); .attr("style", sampleStyle(run, runs));
if (this.parts[i].points.anchor) if (this.parts[i].points.anchor)
parts[i].paths[j + "_" + l] = parts[i].paths[j + "_" + l].translate( parts[i].paths[j + "_" + run] = parts[i].paths[j + "_" + run].translate(
dx, dx,
dy dy
); );
if (extraClass !== false) if (extraClass !== false)
parts[i].paths[j + "_" + l].attributes.add("class", extraClass); parts[i].paths[j + "_" + run].attributes.add("class", extraClass);
} }
} }
}; };
@ -159,13 +167,13 @@ Pattern.prototype.sampleOption = function(optionName) {
if (typeof option.pct !== "undefined") factor = 100; if (typeof option.pct !== "undefined") factor = 100;
val = option.min / factor; val = option.min / factor;
step = (option.max / factor - val) / 9; step = (option.max / factor - val) / 9;
for (let l = 1; l < 11; l++) { for (let run = 1; run < 11; run++) {
this.options[optionName] = val; this.options[optionName] = val;
this.debug( this.debug(
debugStyle("info", "🔬 Sample run"), debugStyle("info", "🔬 Sample run"),
`Sampling option ${optionName} with value ${round(val)}` `Sampling option ${optionName} with value ${round(val)}`
); );
this.sampleRun(parts, anchors, l); this.sampleRun(parts, anchors, run, 10);
val += step; val += step;
} }
this.parts = parts; this.parts = parts;
@ -177,15 +185,16 @@ Pattern.prototype.sampleListOption = function(optionName) {
let parts = this.sampleParts(); let parts = this.sampleParts();
let option = this.config.options[optionName]; let option = this.config.options[optionName];
let anchors = {}; let anchors = {};
let count = 1; let run = 1;
let runs = options.list.length;
for (let val of option.list) { for (let val of option.list) {
this.options[optionName] = val; this.options[optionName] = val;
this.debug( this.debug(
debugStyle("info", "🔬 Sample run"), debugStyle("info", "🔬 Sample run"),
`Sampling option ${optionName} with value ${round(val)}` `Sampling option ${optionName} with value ${round(val)}`
); );
this.sampleRun(parts, anchors, count); this.sampleRun(parts, anchors, run, runs);
count++; run++;
} }
this.parts = parts; this.parts = parts;
@ -202,13 +211,13 @@ Pattern.prototype.sampleMeasurement = function(measurementName) {
if (val === undefined) throw "Cannot sample a measurement that is undefined"; if (val === undefined) throw "Cannot sample a measurement that is undefined";
let step = val / 50; let step = val / 50;
val = val * 0.9; val = val * 0.9;
for (let l = 1; l < 11; l++) { for (let run = 1; run < 11; run++) {
this.settings.measurements[measurementName] = val; this.settings.measurements[measurementName] = val;
this.debug( this.debug(
debugStyle("info", "🔬 Sample run"), debugStyle("info", "🔬 Sample run"),
`Sampling measurement ${measurementName} with value ${round(val)}` `Sampling measurement ${measurementName} with value ${round(val)}`
); );
this.sampleRun(parts, anchors, l); this.sampleRun(parts, anchors, run, 10);
val += step; val += step;
} }
this.parts = parts; this.parts = parts;
@ -222,13 +231,14 @@ Pattern.prototype.sampleMeasurement = function(measurementName) {
Pattern.prototype.sampleModels = function(models, focus = false) { Pattern.prototype.sampleModels = function(models, focus = false) {
let anchors = {}; let anchors = {};
let parts = this.sampleParts(); let parts = this.sampleParts();
let count = 0; let run = 0;
let runs = models.length;
for (let l in models) { for (let l in models) {
count++; run++;
this.settings.measurements = models[l]; this.settings.measurements = models[l];
this.debug(debugStyle("info", "🔬 Sample run"), `Sampling model ${l}`); this.debug(debugStyle("info", "🔬 Sample run"), `Sampling model ${l}`);
let className = l === focus ? "sample-focus" : ""; let className = l === focus ? "sample-focus" : "";
this.sampleRun(parts, anchors, count, className); this.sampleRun(parts, anchors, run, runs, className);
} }
this.parts = parts; this.parts = parts;

View file

@ -328,3 +328,9 @@ export function stretchToScale(stretch) {
export function round(value) { export function round(value) {
return Math.round(value * 1e2) / 1e2; return Math.round(value * 1e2) / 1e2;
} }
export function sampleStyle(run, runs) {
let hue = (run - 1) * (330 / runs);
return `stroke: hsl(${hue}, 100%, 35%);`;
}