Skip to content

Commit

Permalink
Added fourth image
Browse files Browse the repository at this point in the history
  • Loading branch information
umbertoloria committed Nov 8, 2023
1 parent 69cd129 commit 6783665
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 11 deletions.
Binary file added input/20231002_103537.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
add,
addList,
color,
colorHex,
filterColor,
filterScalar,
filterScalarAndStretch,
Expand Down Expand Up @@ -117,6 +118,48 @@ const filesConfs: {
},
},

'20231002_103537.jpg': {
'20231002_103537.jpg'(c) {
return addList(
// Base
mult(colorHex('#cc1a4d'), scalar(.02)),

// Mattoni base
mult(
scalar((
filterScalarAndStretch(getR(c), .11, .81)
- filterScalarAndStretch(getB(c), .11, .81)
) * .6),
colorHex('#00222f'),
),

// Mattoni luce
mult(
scalar((
filterScalarAndStretch(getR(c), .11, .81)
- filterScalarAndStretch(getG(c), .11, .81)
) * .7),
colorHex('#001749'),
),

// Effetti su mattoni
mult(
scalar((
filterScalarAndStretch(getG(c), .5, .6)
- filterScalarAndStretch(getB(c), .5, .6)
) * .7),
colorHex('#cc1a4d'),
),

// Mensole
mult(
scalar(filterScalarAndStretch(getG(c), .85, .95) * .23),
colorHex('#880c31'),
),
);
},
},

};

(async () => {
Expand Down
37 changes: 26 additions & 11 deletions src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,30 @@ export const color = (r: number, g: number, b: number): RGB => ({
g,
b,
});
export const colorHex = (hex: string): RGB => {
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
if (!result) {
throw new Error('Invalid HEX color');
}
const rHex = result[1];
const gHex = result[2];
const bHex = result[3];
return {
r: parseInt(rHex, 16) / 255,
g: parseInt(gHex, 16) / 255,
b: parseInt(bHex, 16) / 255,
};
};
export const add = (a: RGB, b: RGB): RGB => ({
r: a.r + b.r,
g: a.g + b.g,
b: a.b + b.b,
});
export const negate = (c: RGB): RGB => ({
r: -c.r,
g: -c.g,
b: -c.b,
export const sub = (a: RGB, b: RGB) => add(a, {
r: -b.r,
g: -b.g,
b: -b.b,
});
export const sub = (a: RGB, b: RGB) => add(a, negate(b));
export const mult = (a: RGB, b: RGB): RGB => ({
r: a.r * b.r,
g: a.g * b.g,
Expand Down Expand Up @@ -81,14 +94,16 @@ export const onlyB = (b: number): RGB => ({
export const getR = (c: RGB) => c.r;
export const getG = (c: RGB) => c.g;
export const getB = (c: RGB) => c.b;
export const addList = (...cList: RGB[]): RGB => {
export const addList = (...cList: (RGB | boolean)[]): RGB => {
let r = 0;
let g = 0;
let b = 0;
for (const c of cList) {
r += c.r;
g += c.g;
b += c.b;
if (typeof c === 'object') {
r += c.r;
g += c.g;
b += c.b;
}
}
return {
r,
Expand All @@ -101,7 +116,7 @@ export const xorColor = (a: RGB, b: RGB) => color(
Math.abs(a.r - b.r),
Math.abs(a.g - b.g),
Math.abs(a.b - b.b),
)
);

export const mean = (c: RGB): number => (c.r + c.g + c.b) / 3.0;

Expand All @@ -111,4 +126,4 @@ export const blend = (a: RGB, b: RGB, percentage: number) => add(
);

// type Filter = (c: RGB) => RGB
// export const wrap = (filter: Filter, c: RGB) => copy(filter(copy(c)));
// export const wrap = (filter: Filter, c: RGB) => copy(filter(copy(c)));

0 comments on commit 6783665

Please sign in to comment.