Compare commits

..

No commits in common. "f397af24cdf38aa0809d3c28ee20606989b69bed" and "007da37674093454283e1d8da871f696b68152b0" have entirely different histories.

3 changed files with 41 additions and 63 deletions

View File

@ -18,7 +18,7 @@ import {ColourNamer} from './src/components/colour_namer.js';
const CELL = 10;
const MAG = 2;
const WIDTH = 200;
const WIDTH = 20;
const HEIGHT = WIDTH;
// number of pixels which have to be visible for a colour to be
// mentioned in the alt text
@ -36,12 +36,10 @@ function randomise_params() {
f: random.choice(RADIUS_OPTS),
r: random.float(0, 0.4),
}});
const cell = 5 + random.float() * random.float() * 55;
return {
background: palette[0],
palette: palette_name,
patterns: patterns,
cell: cell,
patterns: patterns
}
}
@ -136,21 +134,18 @@ function poptimal_svg(params) {
const document = window.document;
const container = d3.select(document.body).append("div");
const width = WIDTH / params.cell;
const height = WIDTH / params.cell;
const dm = new DotMaker(width, height);
const dm = new DotMaker(WIDTH);
const svg = container.append("svg")
.attr("width", WIDTH * MAG)
.attr("height", HEIGHT * MAG)
.attr("viewBox", [ 0, 0, width, height ]);
.attr("width", WIDTH * CELL * MAG)
.attr("height", HEIGHT * CELL * MAG)
.attr("viewBox", [ 0, 0, WIDTH, HEIGHT ]);
const background = svg.append("rect")
.attr("x", 0)
.attr("y", 0)
.attr("width", width)
.attr("height", height)
.attr("width", WIDTH)
.attr("height", WIDTH)
.attr("fill", params.background);
@ -232,6 +227,7 @@ async function main() {
const colourf = params.palette === 'grayscale' ? cf['grayscale'] : cf['colour'];
const namer = new ColourNamer();
console.log(`Loading colours ${colourf}`);
await namer.load_colours(colourf);
@ -254,7 +250,7 @@ async function main() {
// so we don't include obscured colours
const hist = await get_histogram(imgfile);
const alt_text = image_description(namer, params, hist);
params.alt_text = alt_text;
await save_params(paramsfile, params);
console.log(alt_text);
console.log(imgfile);

View File

@ -1,6 +1,5 @@
// calculate tiles
const SIN_PERIOD = 100 / Math.PI;
const RADIUS_OPTS = [
"const",
@ -12,14 +11,9 @@ const RADIUS_OPTS = [
"right-down",
"left-up",
"left-down",
"circle-in",
"circle-out",
"hyper-in",
"hyper-out",
"in",
"out",
"noise",
"diamonds",
"horizontal-bands",
"vertical-bands",
];
const RADIUS_DESC = {
@ -32,21 +26,15 @@ const RADIUS_DESC = {
"right-down": "getting larger towards the lower right",
"left-up": "getting larger towards the upper left",
"left-down": "getting larger towards the lower left",
"circle-in": "forming a circle at the centre",
"circle-out": "leaving a circular gap at the centre",
"hyper-in": "forming a starlike pattern at the centre",
"hyper-out": "leaving a starlike pattern gap in the centre",
"in": "getting larger in the centre",
"out": "getting larger at the edges",
"noise": "of random sizes",
"diamonds": "in a grid tilted at 45 degrees",
"horizontal-bands": "in horizontal bands",
"vertical-bands": "in a vertical bands",
}
function distance(dx, dy) {
return Math.sqrt(dx ** 2 + dy ** 2);
}
function int_range(v1, v2) {
const vs = [v1, v2];
vs.sort((a, b) => a - b);
@ -57,6 +45,7 @@ function int_range(v1, v2) {
class DotMaker {
constructor(width, height) {
console.log(width, height);
this.width = width;
this.height = height;
this.wh = 0.5 * (width + height);
@ -83,44 +72,40 @@ class DotMaker {
return ps;
}
radius(func) {
radius(d, func, maxr) {
switch (func) {
case "const":
return (d, r) => r;
return maxr;
case "right":
return (d, r) => r * d.x / this.width;
return maxr * d.x / this.width;
case "left":
return (d, r) => r * (this.width - d.x) / this.width;
return maxr * (this.width - d.x) / this.width;
case "down":
return (d, r) => r * d.y / this.height;
return maxr * d.y / this.height;
case "up":
return (d, r) => r * (this.height - d.y) / this.height;
return maxr * (this.height - d.y) / this.height;
case "right-up":
return (d, r) => 0.5 * r * (d.x + this.height - d.y) / this.wh;
return 0.5 * maxr * (d.x + this.height - d.y) / this.wh;
case "left-up":
return (d, r) => 0.5 * r * (this.width - d.x + this.height - d.y) / this.wh;
return 0.5 * maxr * (this.width - d.x + this.height - d.y) / this.wh;
case "right-down":
return (d, r) => 0.5 * r * (d.x + d.y) / this.wh;
return 0.5 * maxr * (d.x + d.y) / this.wh;
case "left-down":
return (d, r) => 0.5 * r * (this.width - d.x + d.y) / this.wh;
case "circle-out":
return (d, r) => 2 * r * distance((d.x - this.cx), (d.y - this.cy)) / this.wh;
case "circle-in":
return (d, r) => 2 * r * (0.5 * this.wh - distance((d.x - this.cx), (d.y - this.cy))) / this.wh;
case "hyper-in":
return (d, r) => r * Math.abs((d.x - this.cx) * (d.y - this.cy)) / this.wh;
case "hyper-out":
return (d, r) => r * (1 - Math.abs((d.x - this.cx) * (d.y - this.cy)) / this.wh);
return 0.5 * maxr * (this.width - d.x + d.y) / this.wh;
case "out":
return 2 * maxr * distance((d.x - this.cx), (d.y - this.cy)) / this.wh;
case "in":
return 2 * maxr * (0.5 * this.wh - distance((d.x - this.cx), (d.y - this.cy))) / this.wh;
// case "hyper-out":
// return 2 * maxr * Math.abs(d.x - this.cx) (d.y - this.cy)) / this.width;
// case "hyper-in":
// return 2 * maxr * (0.5 * this.width - distance((d.x - this.cx), (d.y - this.cy))) / this.width;
case "noise":
return (d, r) => r * Math.random();
case "horizontal-bands":
return (d, r) => r * (1 + Math.cos(SIN_PERIOD *(d.y - this.cy)/ this.wh));
case "vertical-bands":
return (d, r) => r * (1 + Math.cos(SIN_PERIOD *(d.x - this.cx)/ this.wh));
case "grid":
return (d, r) => r * (0.5 + 0.5 * (Math.cos(SIN_PERIOD *(d.x - this.cx)/ this.wh) + Math.cos(SIN_PERIOD * (d.y - this.cy)/ this.wh)));
return maxr * Math.random();
default:
return (d, r) => r;
return maxr;
}
}
}

View File

@ -144,8 +144,8 @@ const dots2 = dm.dots(1 / m2, n2, false);
const svg = d3.create("svg")
.attr("width", WIDTH * MAG)
.attr("height", HEIGHT * MAG)
.attr("width", width * cell * MAG)
.attr("height", height * cell * MAG)
.attr("viewBox", [ 0, 0, width, height ]);
@ -209,12 +209,9 @@ display(svg.node());
```js
// separate code block for when I understand transitions better
const rfunc1 = dm.radius(f1);
const rfunc2 = dm.radius(f2);
dots_g1.selectAll("circle").attr("r", (d) => rfunc1(d, r1));
dots_g2.selectAll("circle").attr("r", (d) => rfunc2(d, r2));
dots_g1.selectAll("circle").attr("r", (d) => dm.radius(d, f1, r1));
dots_g2.selectAll("circle").attr("r", (d) => dm.radius(d, f2, r2));
```