-
-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(examples): add geom-fuzz-basics example
- Loading branch information
1 parent
3ff1484
commit 8b82723
Showing
10 changed files
with
221 additions
and
3 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.cache | ||
out | ||
node_modules | ||
yarn.lock | ||
*.js | ||
*.map | ||
!src/*.d.ts | ||
!*.config.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# geom-fuzz-basics | ||
|
||
[Live demo](http://demo.thi.ng/umbrella/geom-fuzz-basics/) | ||
|
||
Please refer to the [example build instructions](https://github.com/thi-ng/umbrella/wiki/Example-build-instructions) on the wiki. | ||
|
||
## Authors | ||
|
||
- Karsten Schmidt | ||
|
||
## License | ||
|
||
© 2020 Karsten Schmidt // Apache Software License 2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge" /> | ||
<title>geom-fuzz-basics</title> | ||
<link | ||
href="https://unpkg.com/tachyons@4/css/tachyons.min.css" | ||
rel="stylesheet" | ||
/> | ||
<style></style> | ||
</head> | ||
<body class="sans-serif"> | ||
<div id="app"></div> | ||
<div> | ||
<a | ||
class="link" | ||
href="https://github.com/thi-ng/umbrella/tree/develop/examples/geom-fuzz-basics" | ||
>Source code</a | ||
> | ||
</div> | ||
<script type="text/javascript" src="./src/index.ts"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"name": "geom-fuzz-basics", | ||
"version": "0.0.1", | ||
"description": "geom-fuzz basic shape & fill examples", | ||
"repository": "https://github.com/thi-ng/umbrella", | ||
"author": "Karsten Schmidt <k+npm@thi.ng>", | ||
"license": "Apache-2.0", | ||
"scripts": { | ||
"clean": "rm -rf .cache build out", | ||
"build": "yarn clean && parcel build index.html -d out --public-url ./ --no-source-maps --no-cache --detailed-report --experimental-scope-hoisting", | ||
"build:webpack": "../../node_modules/.bin/webpack --mode production", | ||
"start": "parcel index.html -p 8080 --open" | ||
}, | ||
"devDependencies": { | ||
"parcel-bundler": "^1.12.4", | ||
"terser": "^4.6.13", | ||
"typescript": "^3.9.2" | ||
}, | ||
"dependencies": { | ||
"@thi.ng/adapt-dpi": "latest", | ||
"@thi.ng/geom": "latest", | ||
"@thi.ng/geom-fuzz": "latest", | ||
"@thi.ng/hiccup-canvas": "latest", | ||
"@thi.ng/rstream": "latest" | ||
}, | ||
"browserslist": [ | ||
"last 3 Chrome versions" | ||
], | ||
"browser": { | ||
"process": false | ||
}, | ||
"thi.ng": { | ||
"readme": [ | ||
"geom", | ||
"geom-fuzz", | ||
"hiccup-canvas" | ||
], | ||
"screenshot": "geom/geom-fuzz.png" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { adaptDPI } from "@thi.ng/adapt-dpi"; | ||
import { circle, group, star, vertices } from "@thi.ng/geom"; | ||
import { | ||
compFill, | ||
defDots, | ||
defHatchPen, | ||
fuzzyPoly, | ||
jitterPoints, | ||
} from "@thi.ng/geom-fuzz"; | ||
import { draw } from "@thi.ng/hiccup-canvas"; | ||
import { fromInterval } from "@thi.ng/rstream"; | ||
|
||
const W = 300; | ||
|
||
const SHAPES = { | ||
tri: vertices(circle(100), 3), | ||
hex: vertices(circle(50), 6), | ||
star: vertices(star(50, 6, [0.5, 1])), | ||
spike: jitterPoints(vertices(circle(40), 12), 15), | ||
}; | ||
|
||
const PEN1 = defHatchPen([0, 0.8, 1, 0.5]); | ||
const PEN2 = compFill( | ||
defHatchPen("#f3f", "d", 1, 3), | ||
defHatchPen("#f3f", "v", 1, 3) | ||
); | ||
const PEN3 = defHatchPen([1, 1, 0, 0.5], "h", 4, 1.2); | ||
const PEN4 = defDots({ | ||
jitter: 1, | ||
attribs: { size: 1.5, fill: [0, 1, 0], stroke: "none" }, | ||
}); | ||
|
||
const curvePos = ( | ||
t: number, | ||
fx: number, | ||
fy: number, | ||
ax: number, | ||
ay: number | ||
) => [Math.sin(t * fx) * ax + W / 2, Math.cos(t * fy) * ay + W / 2]; | ||
|
||
const canvas: HTMLCanvasElement = document.createElement("canvas"); | ||
document.body.appendChild(canvas); | ||
adaptDPI(canvas, W, W); | ||
|
||
const ctx = canvas.getContext("2d")!; | ||
|
||
fromInterval(1000 / 15).subscribe({ | ||
next(t: number) { | ||
ctx.clearRect(0, 0, canvas.width, canvas.height); | ||
draw( | ||
ctx, | ||
group({ stroke: "black", scale: window.devicePixelRatio || 1 }, [ | ||
fuzzyPoly( | ||
SHAPES.tri, | ||
{ translate: [150, 150], rotate: t * 0.04 }, | ||
{ | ||
fill: PEN1, | ||
curveScale: 0.05, | ||
jitter: 3, | ||
} | ||
), | ||
fuzzyPoly( | ||
SHAPES.star, | ||
{ | ||
translate: curvePos(t, 0.02, 0.03, 100, 50), | ||
}, | ||
{ | ||
fill: PEN2, | ||
curveScale: 0.3, | ||
} | ||
), | ||
fuzzyPoly( | ||
SHAPES.hex, | ||
{ | ||
translate: curvePos(t + 100, 0.03, 0.02, 100, 50), | ||
}, | ||
{ | ||
fill: PEN3, | ||
curveScale: 0.1, | ||
} | ||
), | ||
fuzzyPoly( | ||
SHAPES.spike, | ||
{ | ||
translate: curvePos(t, 0.04, 0.03, 50, 100), | ||
}, | ||
{ | ||
fill: PEN4, | ||
} | ||
), | ||
]) | ||
); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
declare module "*.jpg"; | ||
declare module "*.png"; | ||
declare module "*.svg"; | ||
declare module "*.json"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": ".", | ||
"target": "es6", | ||
"sourceMap": true | ||
}, | ||
"include": [ | ||
"./src/**/*.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module.exports = { | ||
entry: "./src/index.ts", | ||
output: { | ||
filename: "bundle.[hash].js", | ||
path: __dirname + "/out" | ||
}, | ||
resolve: { | ||
extensions: [".ts", ".js"] | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.(png|jpg|gif)$/, | ||
loader: "file-loader", | ||
options: { name: "[path][hash].[ext]" } | ||
}, | ||
{ test: /\.ts$/, use: "ts-loader" } | ||
] | ||
}, | ||
node: { | ||
process: false | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters