rodzic
c448a858da
commit
db7d186234
|
@ -23,5 +23,6 @@ jobs:
|
||||||
node-version: ${{ matrix.node-version }}
|
node-version: ${{ matrix.node-version }}
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
- run: npm run build -- --no-minify
|
- run: npm run build -- --no-minify
|
||||||
|
- run: npm run prettier:check
|
||||||
- run: npm run typecheck
|
- run: npm run typecheck
|
||||||
- run: npm test
|
- run: npm test
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
lib/_svg-vocabulary.ts
|
14
README.md
14
README.md
|
@ -29,6 +29,20 @@ To run tests interactively, run:
|
||||||
npm run test:watch
|
npm run test:watch
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Code style
|
||||||
|
|
||||||
|
All code styling is managed by [Prettier][].
|
||||||
|
|
||||||
|
To format the code automatically, run:
|
||||||
|
|
||||||
|
```
|
||||||
|
npm run prettier:fix
|
||||||
|
```
|
||||||
|
|
||||||
|
You can alternatively install a Prettier extension for your editor; see its website for more details.
|
||||||
|
|
||||||
|
[Prettier]: https://prettier.io/
|
||||||
|
|
||||||
## Deployment
|
## Deployment
|
||||||
|
|
||||||
To deploy the project to GitHub Pages, run:
|
To deploy the project to GitHub Pages, run:
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { Random } from "./random";
|
import { Random } from "./random";
|
||||||
import { range } from "./util";
|
import { range } from "./util";
|
||||||
import * as colorspaces from 'colorspaces';
|
import * as colorspaces from "colorspaces";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clamp the given number to be between 0 and 255, then
|
* Clamp the given number to be between 0 and 255, then
|
||||||
|
@ -20,38 +20,40 @@ export function clampedByteToHex(value: number): string {
|
||||||
}
|
}
|
||||||
|
|
||||||
function createRandomColor(rng: Random): string {
|
function createRandomColor(rng: Random): string {
|
||||||
const max_luv_samples = 100;
|
const max_luv_samples = 100;
|
||||||
let luv_sample_failed = true;
|
let luv_sample_failed = true;
|
||||||
let rand_color_hex:string = "#000000";
|
let rand_color_hex: string = "#000000";
|
||||||
|
|
||||||
//See if we can pull out a sample inside the LUV solid
|
//See if we can pull out a sample inside the LUV solid
|
||||||
for (let i=0; i<max_luv_samples; i++) {
|
for (let i = 0; i < max_luv_samples; i++) {
|
||||||
let L = rng.inRange({ min: 0, max: 100, step: 1 });
|
let L = rng.inRange({ min: 0, max: 100, step: 1 });
|
||||||
let u = rng.inRange({ min: -128, max: 128, step: 1 });
|
let u = rng.inRange({ min: -128, max: 128, step: 1 });
|
||||||
let v = rng.inRange({ min: -128, max: 128, step: 1 });
|
let v = rng.inRange({ min: -128, max: 128, step: 1 });
|
||||||
let rand_color = colorspaces.make_color('CIELUV', [L, u, v]);
|
let rand_color = colorspaces.make_color("CIELUV", [L, u, v]);
|
||||||
|
|
||||||
if(rand_color.is_displayable()) {
|
if (rand_color.is_displayable()) {
|
||||||
rand_color_hex = rand_color.as('hex');
|
rand_color_hex = rand_color.as("hex");
|
||||||
luv_sample_failed = false;
|
luv_sample_failed = false;
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//just sample sRGB if I couldn't sample a random LUV color
|
//just sample sRGB if I couldn't sample a random LUV color
|
||||||
if(luv_sample_failed) {
|
if (luv_sample_failed) {
|
||||||
console.log("Sampling sRGB")
|
console.log("Sampling sRGB");
|
||||||
let rgb = (new Array<number>(3)).map(() => rng.inRange({ min: 0, max: 255, step: 1 }));
|
let rgb = new Array<number>(3).map(() =>
|
||||||
console.log(rgb)
|
rng.inRange({ min: 0, max: 255, step: 1 })
|
||||||
for(let i=0; i<rgb.length; i++) {
|
);
|
||||||
rgb[i] = rgb[i]/255.0;
|
console.log(rgb);
|
||||||
}
|
for (let i = 0; i < rgb.length; i++) {
|
||||||
console.log(rgb)
|
rgb[i] = rgb[i] / 255.0;
|
||||||
let rand_color = colorspaces.make_color('sRGB',rgb);
|
|
||||||
rand_color_hex = rand_color.as('hex');
|
|
||||||
}
|
}
|
||||||
|
console.log(rgb);
|
||||||
|
let rand_color = colorspaces.make_color("sRGB", rgb);
|
||||||
|
rand_color_hex = rand_color.as("hex");
|
||||||
|
}
|
||||||
|
|
||||||
return rand_color_hex;
|
return rand_color_hex;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"deploy": "npm run build && gh-pages -d dist",
|
"deploy": "npm run build && gh-pages -d dist",
|
||||||
|
"prettier:check": "prettier --check lib/**/*.ts lib/**/*.ts",
|
||||||
|
"prettier:fix": "prettier --write lib/**/*.ts lib/**/*.ts",
|
||||||
"typecheck": "tsc --noemit",
|
"typecheck": "tsc --noemit",
|
||||||
"test:watch": "jest --watch",
|
"test:watch": "jest --watch",
|
||||||
"test": "jest",
|
"test": "jest",
|
||||||
|
|
Ładowanie…
Reference in New Issue