Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mouth size & facial line opacity #4

Merged
merged 1 commit into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 43 additions & 5 deletions public/editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,13 @@
<div class="d-md-flex">
<div class="flex-grow-1">
<div class="mb-4 mt-2 d-xl-flex">
<h1>
faces.js editor
</h1>
<h1>faces.js editor</h1>
<div class="d-sm-flex align-items-center ml-xl-3">
<div class="d-flex">
<select
id="option-race"
class="form-control mr-3"
style="width: 100px;"
style="width: 100px"
>
<option value="random">Random</option>
<option value="asian">Asian</option>
Expand All @@ -109,7 +107,7 @@ <h1>
<select
id="option-gender"
class="form-control mr-3"
style="width: 80px;"
style="width: 80px"
>
<option value="male">Male</option>
<option value="female">Female</option>
Expand Down Expand Up @@ -327,6 +325,26 @@ <h4>Head</h4>
step="0.01"
/>
</div>
<div class="group-item-multiline">
<div class="group-item-header">
<label for="lineOpacity">Line Visibility</label>
<input
class="random-attribute randomize-head"
type="checkbox"
value=""
checked
id="randomize-lineOpacity"
/>
</div>
<input
type="number"
class="form-control"
id="lineOpacity"
min="0"
max="1"
step="0.01"
/>
</div>
</div>
<div class="group-wrapper">
<div class="group-header">
Expand Down Expand Up @@ -651,6 +669,26 @@ <h4>Mouth</h4>
/>
</div>
</div>
<div class="group-item-multiline">
<div class="group-item-header">
<label for="mouth-size">Size</label>
<input
class="random-attribute randomize-mouth"
type="checkbox"
value=""
checked
id="randomize-mouth-size"
/>
</div>
<input
type="number"
class="form-control"
id="mouth-size"
min="0.7"
max="1.3"
step="0.01"
/>
</div>
</div>
</div>
<div class="col-6 col-sm-4 col-md-6 col-lg-4 col-xl-3">
Expand Down
11 changes: 10 additions & 1 deletion src/display.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,10 @@ const translate = (
const fatScale = (fatness: number) => 0.8 + 0.2 * fatness;

type FeatureInfo = {
name: Exclude<keyof Face, "fatness" | "teamColors">;
name: Exclude<keyof Face, "fatness" | "teamColors" | "lineOpacity">;
positions: [null] | [number, number][];
scaleFatness?: true;
opaqueLines?: true;
};

const drawFeature = (svg: SVGSVGElement, face: Face, info: FeatureInfo) => {
Expand Down Expand Up @@ -232,6 +233,11 @@ const drawFeature = (svg: SVGSVGElement, face: Face, info: FeatureInfo) => {
scaleCentered(svg.lastChild, scale, scale);
}

if (info.opaqueLines) {
// @ts-ignore
svg.lastChild.setAttribute("stroke-opacity", String(face.lineOpacity));
}

if (info.scaleFatness && info.positions[0] !== null) {
// Scale individual feature relative to the edge of the head. If fatness is 1, then there are 47 pixels on each side. If fatness is 0, then there are 78 pixels on each side.
const distance = (78 - 47) * (1 - face.fatness);
Expand Down Expand Up @@ -307,17 +313,20 @@ export const display = (
{
name: "eyeLine",
positions: [null],
opaqueLines: true,
},
{
name: "smileLine",
positions: [
[150, 435],
[250, 435],
],
opaqueLines: true,
},
{
name: "miscLine",
positions: [null],
opaqueLines: true,
},
{
name: "facialHair",
Expand Down
2 changes: 2 additions & 0 deletions src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export const generate = (

const face = {
fatness: roundTwoDecimals((gender === "female" ? 0.4 : 1) * Math.random()),
lineOpacity: roundTwoDecimals((0.25 + 0.5 * Math.random()) ** 2),
teamColors: defaultTeamColors,
hairBg: {
id:
Expand Down Expand Up @@ -165,6 +166,7 @@ export const generate = (
mouth: {
id: getID("mouth", gender),
flip: isFlipped,
size: roundTwoDecimals(0.6 + Math.random() * 0.6),
},
nose: {
id: getID("nose", gender),
Expand Down