-
-
Notifications
You must be signed in to change notification settings - Fork 153
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 poisson-circles & stratified-grid examples
- Loading branch information
1 parent
104bb58
commit fcc23ac
Showing
16 changed files
with
284 additions
and
0 deletions.
There are no files selected for viewing
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 @@ | ||
# poisson-circles | ||
|
||
[Live demo](http://demo.thi.ng/umbrella/poisson-circles/) | ||
|
||
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,17 @@ | ||
<!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>poisson-circles</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/poisson-circles">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,39 @@ | ||
{ | ||
"name": "poisson-circles", | ||
"version": "0.0.1", | ||
"description": "2D Poisson-disc sampler with procedural gradient map", | ||
"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.3", | ||
"typescript": "^3.7.5" | ||
}, | ||
"dependencies": { | ||
"@thi.ng/geom": "latest", | ||
"@thi.ng/geom-accel": "latest", | ||
"@thi.ng/math": "latest", | ||
"@thi.ng/poisson": "latest", | ||
"@thi.ng/vectors": "latest" | ||
}, | ||
"browserslist": [ | ||
"last 3 Chrome versions" | ||
], | ||
"browser": { | ||
"process": false | ||
}, | ||
"thi.ng": { | ||
"readme": [ | ||
"geom-accel", | ||
"poisson" | ||
], | ||
"screenshot": "poisson/poisson.jpg" | ||
} | ||
} |
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,26 @@ | ||
import { asSvg, circle, svgDoc } from "@thi.ng/geom"; | ||
import { KdTreeSet } from "@thi.ng/geom-accel"; | ||
import { fit01 } from "@thi.ng/math"; | ||
import { samplePoisson } from "@thi.ng/poisson"; | ||
import { dist, randMinMax2 } from "@thi.ng/vectors"; | ||
|
||
const index = new KdTreeSet(2); | ||
|
||
const pts = samplePoisson({ | ||
index, | ||
points: () => randMinMax2(null, [0, 0], [500, 500]), | ||
density: (p) => fit01(Math.pow(dist(p, [250, 250]) / 250, 2), 2, 10), | ||
iter: 5, | ||
max: 8000, | ||
quality: 500, | ||
}); | ||
|
||
// use thi.ng/geom to visualize results | ||
// each circle's radius is set to distance to its nearest neighbor | ||
const circles = pts.map((p) => | ||
circle(p, dist(p, index.queryKeys(p, 40, 2)[1]) / 2) | ||
); | ||
|
||
document.body.innerHTML = asSvg( | ||
svgDoc({ fill: "none", stroke: "blue" }, ...circles) | ||
); |
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
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 @@ | ||
# stratified-grid | ||
|
||
[Live demo](http://demo.thi.ng/umbrella/stratified-grid/) | ||
|
||
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,17 @@ | ||
<!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>stratified-grid</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/stratified-grid">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,39 @@ | ||
{ | ||
"name": "stratified-grid", | ||
"version": "0.0.1", | ||
"description": "2D Stratified grid sampling example", | ||
"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.3", | ||
"typescript": "^3.7.5" | ||
}, | ||
"dependencies": { | ||
"@thi.ng/geom": "latest", | ||
"@thi.ng/geom-accel": "latest", | ||
"@thi.ng/poisson": "latest", | ||
"@thi.ng/transducers": "latest", | ||
"@thi.ng/vectors": "latest" | ||
}, | ||
"browserslist": [ | ||
"last 3 Chrome versions" | ||
], | ||
"browser": { | ||
"process": false | ||
}, | ||
"thi.ng": { | ||
"readme": [ | ||
"geom-accel", | ||
"poisson" | ||
], | ||
"screenshot": "poisson/stratified-grid.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,28 @@ | ||
import { asSvg, circle, svgDoc } from "@thi.ng/geom"; | ||
import { KdTreeSet } from "@thi.ng/geom-accel"; | ||
import { stratifiedGrid } from "@thi.ng/poisson"; | ||
import { map } from "@thi.ng/transducers"; | ||
import { dist } from "@thi.ng/vectors"; | ||
|
||
const index = new KdTreeSet(2); | ||
index.into(stratifiedGrid({ dim: [50, 50], samples: 1 })); | ||
|
||
document.body.innerHTML = asSvg( | ||
svgDoc( | ||
{ | ||
width: 600, | ||
height: 600, | ||
fill: "none", | ||
stroke: "blue", | ||
"stroke-width": 0.1, | ||
}, | ||
...map( | ||
(p) => | ||
circle( | ||
p, | ||
dist(p, index.queryKeys(p, 2 * Math.SQRT2, 2)[1]) / 2 | ||
), | ||
index.keys() | ||
) | ||
) | ||
); |
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 | ||
} | ||
}; |