parent
b41ad18871
commit
4a4824e268
@ -1,3 +1,21 @@
|
|||||||
# chaos-toy
|
# chaos-toy
|
||||||
|
|
||||||
A small web app to play around with your own rules for chaos game
|
A small web app to play around with your own rules for chaos game
|
||||||
|
|
||||||
|
## Building
|
||||||
|
|
||||||
|
To build this project, you will need the [rust toolchain](https://rustup.rs/) and `wasm-pack`, [which you can download here](https://rustwasm.github.io/wasm-pack/installer/) (or just run `cargo install wasm-pack`).
|
||||||
|
|
||||||
|
Then, run `wasm-pack build simulator` to build the rust simulator.
|
||||||
|
|
||||||
|
If you wish to build the simulator with the debug profile, then run `wasm-pack build simulator --dev` or `npm run prepare-dev`.
|
||||||
|
Re-running these commands should work with Vite's auto-reload.
|
||||||
|
|
||||||
|
If `wasm-pack` fails to download `wasm-opt`, then you can try installing it manually (`brew install binaryen`, `pacman -S binaryen`).
|
||||||
|
Alternatively, you can disable `wasm-opt` by uncommenting the relevant lines in `simulator/Cargo.toml`.
|
||||||
|
|
||||||
|
At this point, you can now run `npm install`, which will symlink `simulator/pkg/` to `node_modules/chaos-toy-rs`.
|
||||||
|
|
||||||
|
## Running
|
||||||
|
|
||||||
|
To run in development mode, simply run `npm run dev` or `yarn dev`.
|
||||||
|
@ -0,0 +1,20 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Chaos toy</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||||
|
<div id="root"></div>
|
||||||
|
|
||||||
|
<script src="/src/index.tsx" type="module"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,31 @@
|
|||||||
|
{
|
||||||
|
"name": "chaos-toy",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"description": "A small web app to play around with your own rules for chaos game",
|
||||||
|
"main": "src/index.ts",
|
||||||
|
"scripts": {
|
||||||
|
"dev": "vite",
|
||||||
|
"build": "wasm-pack build simulator && vite build",
|
||||||
|
"prepare-dev": "wasm-pack build --dev simulator",
|
||||||
|
"serve": "vite preview"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://git.shadamethyst.xyz/adri326/chaos-toy"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"chaos-game"
|
||||||
|
],
|
||||||
|
"author": "Shad Amethyst",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"solid-js": "^1.6.2"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"chaos-toy-rs": "file:./simulator/pkg/",
|
||||||
|
"typescript": "^4.9.0",
|
||||||
|
"vite": "^3.0.9",
|
||||||
|
"vite-plugin-solid": "^2.3.0",
|
||||||
|
"vite-plugin-wasm": "^3.1.0"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
/target
|
||||||
|
**/*.rs.bk
|
||||||
|
Cargo.lock
|
||||||
|
bin/
|
||||||
|
pkg/
|
||||||
|
wasm-pack.log
|
@ -0,0 +1,36 @@
|
|||||||
|
[package]
|
||||||
|
name = "chaos-toy-rs"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Adrien Burgun <adrien.burgun@orange.fr>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
# Uncomment the following lines if you are having trouble building with wasm-pack
|
||||||
|
# [package.metadata.wasm-pack.profile.release]
|
||||||
|
# wasm-opt = false
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
crate-type = ["cdylib", "rlib"]
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["console_error_panic_hook"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
wasm-bindgen = "0.2.63"
|
||||||
|
|
||||||
|
# The `console_error_panic_hook` crate provides better debugging of panics by
|
||||||
|
# logging them with `console.error`. This is great for development, but requires
|
||||||
|
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
|
||||||
|
# code size when deploying.
|
||||||
|
console_error_panic_hook = { version = "0.1.6", optional = true }
|
||||||
|
|
||||||
|
# `wee_alloc` is a tiny allocator for wasm that is only ~1K in code size
|
||||||
|
# compared to the default allocator's ~10K. It is slower than the default
|
||||||
|
# allocator, however.
|
||||||
|
wee_alloc = { version = "0.4.5", optional = true }
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
wasm-bindgen-test = "0.3.13"
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
# Tell `rustc` to optimize for small code size.
|
||||||
|
opt-level = "s"
|
@ -0,0 +1,18 @@
|
|||||||
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
|
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
|
||||||
|
// allocator.
|
||||||
|
#[cfg(feature = "wee_alloc")]
|
||||||
|
#[global_allocator]
|
||||||
|
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn init() {
|
||||||
|
#[cfg(feature = "console_error_panic_hook")]
|
||||||
|
console_error_panic_hook::set_once();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn hello_world() -> String {
|
||||||
|
return String::from("Hello, world!");
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
//! Test suite for the Web and headless browsers.
|
||||||
|
|
||||||
|
#![cfg(target_arch = "wasm32")]
|
||||||
|
|
||||||
|
extern crate wasm_bindgen_test;
|
||||||
|
use wasm_bindgen_test::*;
|
||||||
|
|
||||||
|
wasm_bindgen_test_configure!(run_in_browser);
|
||||||
|
|
||||||
|
#[wasm_bindgen_test]
|
||||||
|
fn pass() {
|
||||||
|
assert_eq!(1 + 1, 2);
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
import type { Component } from "solid-js";
|
||||||
|
import Simulator from "./Simulator";
|
||||||
|
|
||||||
|
const App: Component = () => {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Simulator />
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default App;
|
@ -0,0 +1,11 @@
|
|||||||
|
import { hello_world } from "chaos-toy-rs";
|
||||||
|
import type { Component } from "solid-js";
|
||||||
|
|
||||||
|
const Simulator: Component = () => {
|
||||||
|
return (<>
|
||||||
|
<div>{hello_world()}</div>
|
||||||
|
<canvas>Sorry, your browser needs to support canvases</canvas>
|
||||||
|
</>);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Simulator;
|
@ -0,0 +1,9 @@
|
|||||||
|
/* @refresh reload */
|
||||||
|
import { render } from "solid-js/web";
|
||||||
|
import * as chaos_toy_rs from "chaos-toy-rs";
|
||||||
|
|
||||||
|
import App from "./App";
|
||||||
|
|
||||||
|
chaos_toy_rs.init();
|
||||||
|
|
||||||
|
render(() => <App />, document.getElementById("root") as HTMLElement);
|
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "ESNext",
|
||||||
|
"module": "ESNext",
|
||||||
|
"moduleResolution": "node",
|
||||||
|
"allowSyntheticDefaultImports": true,
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"jsx": "preserve",
|
||||||
|
"jsxImportSource": "solid-js",
|
||||||
|
"types": ["vite/client"],
|
||||||
|
"noEmit": true,
|
||||||
|
"isolatedModules": true
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
import { defineConfig } from "vite";
|
||||||
|
import solidPlugin from "vite-plugin-solid";
|
||||||
|
import wasm from "vite-plugin-wasm";
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
clearScreen: false,
|
||||||
|
plugins: [
|
||||||
|
wasm(),
|
||||||
|
solidPlugin(),
|
||||||
|
],
|
||||||
|
server: {
|
||||||
|
port: 3000,
|
||||||
|
},
|
||||||
|
build: {
|
||||||
|
target: "esnext",
|
||||||
|
},
|
||||||
|
});
|
Loading…
Reference in new issue