This repository has been archived by the owner on Dec 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d2a4e46
Showing
35 changed files
with
1,706 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
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,29 @@ | ||
name: Check | ||
|
||
on: | ||
# Post-submit. | ||
push: | ||
branches: [ main ] | ||
|
||
# Pre-submit. | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/[email protected] | ||
- uses: dart-lang/[email protected] | ||
- uses: actions/setup-node@v4 | ||
- uses: browser-actions/setup-chrome@v1 | ||
- run: dart pub get | ||
- run: dart format --output none --set-exit-if-changed . | ||
- run: dart analyze | ||
- run: dart test | ||
- run: ./chore coverage -- -P coverage | ||
- name: Upload coverage | ||
uses: coverallsapp/[email protected] | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
path-to-lcov: coverage/lcov.info |
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,21 @@ | ||
name: Deploy | ||
|
||
on: | ||
# Post-submit. | ||
push: | ||
branches: [ main ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/[email protected] | ||
- uses: dart-lang/[email protected] | ||
- run: dart pub get | ||
- name: Build API Docs | ||
run: ./chore dartdoc | ||
- name: Deploy to GitHub Pages | ||
uses: peaceiris/actions-gh-pages@v4 | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
publish_dir: ./doc/api |
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 @@ | ||
.dart_tool/ | ||
coverage/ | ||
doc/api/ | ||
pubspec.lock |
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,5 @@ | ||
{ | ||
"recommendations": [ | ||
"dart-code.dart-code" | ||
] | ||
} |
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,5 @@ | ||
# Changelog | ||
|
||
## 0.1.0 | ||
|
||
- Initial release. |
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,19 @@ | ||
Copyright (c) 2024 Matan Lurey | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,69 @@ | ||
# Mirage | ||
|
||
Generates noise and patterns algorithmically for use in software, textures, and graphics. | ||
|
||
![Mirage on pub.dev][pub_img]][pub_url] | ||
[![Code coverage][cov_img]][cov_url] | ||
[![Github action status][gha_img]][gha_url] | ||
[![Dartdocs][doc_img]][doc_url] | ||
[![Style guide][sty_img]][sty_url] | ||
|
||
[pub_url]: https://pub.dartlang.org/packages/chaos | ||
[pub_img]: https://img.shields.io/pub/v/mirage.svg | ||
[gha_url]: https://github.com/matanlurey/mirage.dart/actions | ||
[gha_img]: https://github.com/matanlurey/mirage.dart/actions/workflows/check.yaml/badge.svg | ||
[cov_url]: https://coveralls.io/github/matanlurey/mirage.dart?branch=main | ||
[cov_img]: https://coveralls.io/repos/github/matanlurey/mirage.dart/badge.svg?branch=main | ||
[doc_url]: https://www.dartdocs.org/documentation/chaos/latest | ||
[doc_img]: https://img.shields.io/badge/Documentation-mirage-blue.svg | ||
[sty_url]: https://pub.dev/packages/oath | ||
[sty_img]: https://img.shields.io/badge/style-oath-9cf.svg | ||
|
||
## Usage | ||
|
||
An example of generating a Simplex noise pattern: | ||
|
||
![Simlex](./example/out/simplex_noise.png) | ||
|
||
```dart | ||
import 'package:mirage/mirage.dart'; | ||
void main() { | ||
final noise = Simplex(); | ||
for (var y = 0; y < 256; y++) { | ||
for (var x = 0; x < 256; x++) { | ||
final value = noise.get2d(x / 256, y / 256); | ||
// Do something with the value... | ||
} | ||
} | ||
} | ||
``` | ||
|
||
For a full example, see the [example](./example) directory. | ||
|
||
## Features | ||
|
||
- Full implementations of popular 2D noise functions. | ||
- Simple and predictable API for generating noise patterns. | ||
- Build your own generator functions with the `Pattern2d` interface. | ||
- Thoughtfully tested and documented for ease of use. | ||
|
||
## Contributing | ||
|
||
To run the tests, run: | ||
|
||
```shell | ||
dart test | ||
``` | ||
|
||
To check code coverage locally, run: | ||
|
||
```shell | ||
./chore coverage | ||
``` | ||
|
||
To preview `dartdoc` output locally, run: | ||
|
||
```shell | ||
./chore dartodc | ||
``` |
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,3 @@ | ||
# Format: https://dart.dev/tools/analysis#the-analysis-options-file. | ||
|
||
include: package:oath/strict.yaml |
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,15 @@ | ||
#!/usr/bin/env sh | ||
|
||
# Chore is a tiny task runner with some pre-defined commands. | ||
|
||
set -e | ||
|
||
GIT_URL="https://github.com/matanlurey/chore.dart.git" | ||
GIT_REF="8b252e7" | ||
|
||
# Silently activate the pinned version of `chore.dart` from GitHub. | ||
# Only print if there is an error. | ||
dart pub global activate -sgit $GIT_URL --git-ref=$GIT_REF 2>&1 > /dev/null | ||
|
||
# Now run and forward arguments and the output. | ||
dart pub global run chore "$@" |
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,22 @@ | ||
# https://github.com/dart-lang/test/blob/master/pkgs/test/doc/configuration.md | ||
|
||
presets: | ||
# Runs VM-specific tests and captures coverage. | ||
coverage: | ||
reporter: github | ||
|
||
# Runs tests on the VM and NodeJS. | ||
all: | ||
platforms: | ||
- vm | ||
- node | ||
|
||
platforms: | ||
- vm | ||
|
||
fold_stack_frames: | ||
except: | ||
- checks | ||
- test | ||
- test_api | ||
- stream_channel |
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,33 @@ | ||
# Examples | ||
|
||
The provided script, [`generate_pngs.dart`](./generate_pngs.dart) uses this | ||
library combined with `package:image` to generate the following images for each | ||
pattern function: | ||
|
||
## `Checkerboard` | ||
|
||
![Checkerboard](./out/checkerboard.png) | ||
|
||
## `White` | ||
|
||
![White](./out/white_noise.png) | ||
|
||
## `Value` | ||
|
||
![Value](./out/value_noise.png) | ||
|
||
## `Perlin` | ||
|
||
![Perlin](./out/perlin_noise.png) | ||
|
||
## `Simplex` | ||
|
||
![Simplex](./out/simplex_noise.png) | ||
|
||
## `Worley.distance` | ||
|
||
![Worley.distance](./out/worley_distance.png) | ||
|
||
## `Worley.value` | ||
|
||
![Worley.value](./out/worley_value.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,73 @@ | ||
#!/usr/bin/env dart | ||
|
||
import 'dart:math'; | ||
|
||
import 'package:image/image.dart' as i; | ||
import 'package:mirage/mirage.dart'; | ||
import 'package:path/path.dart' as p; | ||
|
||
/// This script generates PNG previews for all patterns in the library. | ||
/// | ||
/// ## Usage | ||
/// | ||
/// ```sh | ||
/// dart example/generate_pngs.dart [seed] | ||
/// ``` | ||
void main(List<String> args) async { | ||
final Random random; | ||
if (args.isNotEmpty) { | ||
random = Random(int.parse(args.first)); | ||
} else { | ||
random = Random(0xDEADBEEF); | ||
} | ||
|
||
final output = p.join('example', 'out'); | ||
|
||
const width = 256; | ||
const height = 256; | ||
Future<void> generate( | ||
String name, | ||
Pattern2d Function(Random) generate, | ||
) async { | ||
final pattern = generate(random).normalized; | ||
final image = i.Image(width: width, height: height); | ||
for (var y = 0; y < height; y++) { | ||
for (var x = 0; x < width; x++) { | ||
// 0.0 = black, 1.0 = white | ||
final value = pattern.get2d(x, y); | ||
final color = (value * 255).toInt(); | ||
image.setPixel(x, y, i.ColorRgb8(color, color, color)); | ||
} | ||
} | ||
await i.writeFile(p.join(output, '$name.png'), i.encodePng(image)); | ||
} | ||
|
||
await generate( | ||
'checkerboard', | ||
(_) => Checkerboard.odd, | ||
); | ||
await generate( | ||
'white_noise', | ||
White.new, | ||
); | ||
await generate( | ||
'value_noise', | ||
(r) => Value(NoiseTable(r)), | ||
); | ||
await generate( | ||
'perlin_noise', | ||
(r) => Perlin(NoiseTable(r)), | ||
); | ||
await generate( | ||
'simplex_noise', | ||
(r) => Simplex(NoiseTable(r)), | ||
); | ||
await generate( | ||
'worley_value', | ||
(r) => Worley.value(hasher: NoiseTable(r)), | ||
); | ||
await generate( | ||
'worley_distance', | ||
(r) => Worley.distance(hasher: NoiseTable(r)), | ||
); | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,13 @@ | ||
/// Generates noise and patterns algorithmically for use in software, textures, | ||
/// and graphics. | ||
library; | ||
|
||
export 'src/generator.dart'; | ||
export 'src/math.dart'; | ||
export 'src/noise/hasher.dart'; | ||
export 'src/noise/perlin.dart'; | ||
export 'src/noise/simplex.dart'; | ||
export 'src/noise/value.dart'; | ||
export 'src/noise/white.dart'; | ||
export 'src/noise/worley.dart'; | ||
export 'src/patterns.dart'; |
Oops, something went wrong.