├── .eslintrc
├── .gitignore
├── LICENSE
├── README.md
├── package-lock.json
├── package.json
├── public
├── favicon.ico
├── img
│ ├── github-logo.png
│ └── screeshot.png
├── index.html
└── manifest.json
└── src
├── components
├── App
│ ├── __test__
│ │ └── index.test.js
│ └── index.jsx
├── ControlPanel
│ └── index.js
├── Header
│ └── index.jsx
└── P5Wrapper
│ ├── index.jsx
│ └── sketch.js
├── index.css
├── index.js
├── lib
├── config
│ └── index.js
└── sliders
│ └── index.js
└── registerServiceWorker.js
/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "react-app"
3 | }
4 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/ignore-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 |
6 | # testing
7 | /coverage
8 |
9 | # production
10 | /build
11 |
12 | # misc
13 | .DS_Store
14 | .env.local
15 | .env.development.local
16 | .env.test.local
17 | .env.production.local
18 |
19 | npm-debug.log*
20 | yarn-debug.log*
21 | yarn-error.log*
22 |
23 | __storage__
24 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 atorov
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | ### UPDATE 2019-04-21
3 |
4 | An example, build on the same concept but using the latest React features such as **hooks and context**), can be found [here](https://github.com/atorov/react-hooks-p5js)
5 |
6 | ---
7 |
8 | # Using React with p5.js
9 |
10 | 
11 |
12 | This project demonstrates the possibility of combining React, Bootstrap, p5.js and other advanced technologies for real-time visualization, animation and simulation.
13 |
14 | [React](https://reactjs.org/) is one of the most popular JavaScript libraries for creating single page applications.
15 | [p5.js](https://p5js.org/) is a JavaScript library with a full set of drawing functionality.
16 | [Bootstrap](https://getbootstrap.com/) is an open source toolkit for developing with HTML, CSS, and JS.
17 |
18 | Check the online version [here](http://fractal-tree-simulator.surge.sh/).
19 |
20 | The basic idea is that the p5.js sketch is wrapped in a React component. The data that comes into the sketch is passed on to this component as props. Callbacks are used to return information back from the sketch to the application.
21 |
22 | A much more simpler example, built on the same concept, can be found [here](https://github.com/atorov/react-p5js).
23 |
24 | ## p5.js sketch
25 | - p5.Graphics for creating a graphics buffer;
26 | - p5.Vector for describing a two dimensional vectors;
27 | - p5.noise() - Perlin noise random sequence generator that produces a more natural ordered, harmonic succession of numbers compared to the standard random() function;
28 | - p5.colorMode() - both RGB and HSB color spaces;
29 | - p5.translate() and p5.rotate() matrix transformations, etc.
30 |
31 | ## Project Structure
32 | The project is build on [Create React App](https://github.com/facebookincubator/create-react-app).
33 |
34 | For the project to build, **these files must exist with exact filenames**:
35 |
36 | * `public/index.html` is the page template;
37 | * `src/index.js` is the JavaScript entry point.
38 |
39 | You can delete or rename the other files. You may create subdirectories inside `src`. For faster rebuilds, only files inside `src` are processed by Webpack. You need to **put any JS and CSS files inside `src`**, otherwise Webpack won’t see them.
40 |
41 | Only files inside `public` can be used from `public/index.html`.
42 |
43 | You can, however, create more top-level directories. They will not be included in the production build so you can use them for things like documentation.
44 |
45 | ## Available Scripts
46 |
47 | In the project directory, you can run:
48 |
49 | ### `npm start`
50 |
51 | Runs the app in the development mode. Open [http://localhost:3000](http://localhost:3000) to view it in the browser. The page will reload if you make edits. You will also see any lint errors in the console.
52 |
53 | ### `npm test`
54 |
55 | Launches the test runner in the interactive watch mode.
56 |
57 | ### `npm run build`
58 |
59 | Builds the app for production to the `build` folder. It correctly bundles React in production mode and optimizes the build for the best performance. The build is minified and the filenames include the hashes. Your app is ready to be deployed.
60 |
61 | ### `npm run eject`
62 |
63 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!**
64 |
65 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
66 |
67 | Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
68 |
69 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
70 |
71 | ## Supported Language Features and Polyfills
72 |
73 | This project supports a superset of the latest JavaScript standard. In addition to [ES6](https://github.com/lukehoban/es6features) syntax features, it also supports:
74 |
75 | * [Exponentiation Operator](https://github.com/rwaldron/exponentiation-operator) (ES2016).
76 | * [Async/await](https://github.com/tc39/ecmascript-asyncawait) (ES2017).
77 | * [Object Rest/Spread Properties](https://github.com/sebmarkbage/ecmascript-rest-spread) (stage 3 proposal).
78 | * [Dynamic import()](https://github.com/tc39/proposal-dynamic-import) (stage 3 proposal)
79 | * [Class Fields and Static Properties](https://github.com/tc39/proposal-class-public-fields) (part of stage 3 proposal).
80 | * [JSX](https://facebook.github.io/react/docs/introducing-jsx.html) and [Flow](https://flowtype.org/) syntax.
81 |
82 | ## Syntax Highlighting and Displaying Lint Output in the Editor
83 |
84 | Тhe most popular editors should be covered and your editor should report the linting warnings..
85 |
86 | ## Code Splitting
87 |
88 | Code splitting allows you to split your code into small chunks which you can then load on demand.
89 | This project setup supports code splitting via [dynamic `import()`](http://2ality.com/2017/01/import-operator.html#loading-code-on-demand).
90 |
91 | ## Adding a Router and Redux
92 |
93 | [React Router](https://reacttraining.com/react-router/) is the most popular option.
94 | [Redux](https://redux.js.org/) is a predictable state container for JavaScript apps.
95 |
96 | React Router and Redux can easily be added to the project.
97 |
98 | ## Running Tests
99 |
100 | [Jest](https://facebook.github.io/jest/) is a Node-based runner. While Jest provides browser globals such as `window` thanks to [jsdom](https://github.com/tmpvar/jsdom), they are only approximations of the real browser behavior. Jest is intended to be used for unit tests of your logic and your components rather than the DOM quirks.
101 |
102 | ### Filename Conventions
103 |
104 | Jest will look for test files with any of the following popular naming conventions:
105 |
106 | * Files with `.js` suffix in `__tests__` folders.
107 | * Files with `.test.js` suffix.
108 | * Files with `.spec.js` suffix.
109 |
110 | The `.test.js` / `.spec.js` files (or the `__tests__` folders) can be located at any depth under the `src` top level folder. It is recommended to put the test files (or `__tests__` folders) next to the code they are testing so that relative imports appear shorter. For example, if `App.test.js` and `App.js` are in the same folder, the test just needs to `import App from './App'` instead of a long relative path. Colocation also helps find tests more quickly in larger projects.
111 |
112 | ### Command Line Interface
113 |
114 | When you run `npm test`, Jest will launch in the watch mode. Every time you save a file, it will re-run the tests, just like `npm start` recompiles the code.
115 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "fractal-tree-simulator",
3 | "version": "2.1.1",
4 | "private": true,
5 | "description": "An advanced example of using React with p5.js",
6 | "keywords": [
7 | "react",
8 | "reactjs",
9 | "p5",
10 | "p5js",
11 | "p5.js",
12 | "processing",
13 | "fractals",
14 | "tree",
15 | "simulator",
16 | "physics"
17 | ],
18 | "homepage": ".",
19 | "repository": {
20 | "type": "git",
21 | "url": "https://github.com/atorov/fractal-tree-simulator.git"
22 | },
23 | "bugs": {
24 | "url": "https://github.com/atorov/fractal-tree-simulator/issues"
25 | },
26 | "author": "atorov",
27 | "license": "MIT",
28 | "main": "src/index.js",
29 | "dependencies": {
30 | "react": "^16.2.0",
31 | "react-bootstrap": "^0.32.1",
32 | "react-dom": "^16.2.0",
33 | "react-scripts": "1.1.0"
34 | },
35 | "scripts": {
36 | "start": "react-scripts start",
37 | "build": "react-scripts build",
38 | "test": "react-scripts test --env=jsdom",
39 | "eject": "react-scripts eject"
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/atorov/fractal-tree-simulator/cdd38f19c87bb06defc9e275fef4171f2da4b26f/public/favicon.ico
--------------------------------------------------------------------------------
/public/img/github-logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/atorov/fractal-tree-simulator/cdd38f19c87bb06defc9e275fef4171f2da4b26f/public/img/github-logo.png
--------------------------------------------------------------------------------
/public/img/screeshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/atorov/fractal-tree-simulator/cdd38f19c87bb06defc9e275fef4171f2da4b26f/public/img/screeshot.png
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |