expo-processing 0.0.0-canary-20231123-1b19f96

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,86 @@
1
+ https://user-images.githubusercontent.com/379606/119428009-fb40c200-bcc0-11eb-8328-fb19e5d3557c.mp4
2
+
3
+ *NOTE: The recording above looks weird some times because of artifacts, the real thing is nice, I promise...*
4
+
5
+ # expo-processing
6
+
7
+ Use [Processing.js](http://processingjs.org) on [Expo](https://expo.dev)! Just
8
+ `npm i -S processing-js expo-processing` in your Expo project and import it with
9
+ `import { ProcessingView } from 'expo-processing;`.
10
+
11
+ ## Components
12
+
13
+ ### `ExpoProcessing.ProcessingView`
14
+
15
+ Display a `Processing.js` sketch.
16
+
17
+ #### Props
18
+
19
+ The component accepts all `View` layout props for specifying its layout.
20
+
21
+ - `sketch`: A Processing.js sketch function that takes a `processing` instance
22
+ and calls Processing.js functions on it, such as the [`sketchProc` function](http://processingjs.org/articles/jsQuickStart.html#javascriptonlyprocessingcode) in
23
+ the Processing.js documentation for writing JavaScript-only Processing.js
24
+ code.
25
+
26
+ ## Example
27
+
28
+ This is based on
29
+ the ["In and out"](https://www.openprocessing.org/sketch/434617) sketch on
30
+ OpenProcessing.org.
31
+
32
+ In
33
+ a
34
+ [new blank Expo project](https://docs.expo.dev/versions/v18.0.0/guides/up-and-running.html),
35
+ run `npm i -S processing-js expo-processing` to install Processing.js and ExpoProcessing. Then replace
36
+ `App.js` with the following:
37
+
38
+ ```js
39
+ import React from 'react';
40
+ import { ProcessingView } from 'expo-processing';
41
+
42
+ export default class App extends React.Component {
43
+ render() {
44
+ return (
45
+ <ProcessingView style={{ flex: 1 }} sketch={this._sketch} />
46
+ );
47
+ }
48
+
49
+ _sketch = (p) => {
50
+ p.setup = () => {
51
+ p.strokeWeight(7);
52
+ }
53
+
54
+ const harom = (ax, ay, bx, by, level, ratio) => {
55
+ if (level <= 0) {
56
+ return;
57
+ }
58
+
59
+ const vx = bx - ax;
60
+ const vy = by - ay;
61
+ const nx = p.cos(p.PI / 3) * vx - p.sin(p.PI / 3) * vy;
62
+ const ny = p.sin(p.PI / 3) * vx + p.cos(p.PI / 3) * vy;
63
+ const cx = ax + nx;
64
+ const cy = ay + ny;
65
+ p.line(ax, ay, bx, by);
66
+ p.line(ax, ay, cx, cy);
67
+ p.line(cx, cy, bx, by);
68
+
69
+ harom(
70
+ ax * ratio + cx * (1 - ratio),
71
+ ay * ratio + cy * (1 - ratio),
72
+ ax * (1 - ratio) + bx * ratio,
73
+ ay * (1 - ratio) + by * ratio,
74
+ level - 1,
75
+ ratio);
76
+ }
77
+
78
+ p.draw = () => {
79
+ p.background(240);
80
+ harom(
81
+ p.width - 142, p.height - 142, 142, p.height - 142, 6,
82
+ (p.sin(0.0005 * Date.now() % (2 * p.PI)) + 1) / 2);
83
+ }
84
+ }
85
+ }
86
+ ````
package/index.js ADDED
@@ -0,0 +1,84 @@
1
+ import React from 'react';
2
+ import { GLView } from 'expo-gl';
3
+
4
+ const Browser = require('processing-js/lib/Browser');
5
+ Browser.window = window;
6
+ const Processing = require('processing-js/src')(Browser);
7
+
8
+ export class ProcessingView extends React.Component {
9
+ componentWillUnmount() {
10
+ if (this._p) {
11
+ this._p.exit();
12
+ this._p = null;
13
+ }
14
+ cancelAnimationFrame(this._rafID);
15
+ }
16
+
17
+ render() {
18
+ const { sketch, ...props } = this.props;
19
+ return <GLView {...props} onContextCreate={this._onGLContextCreate} />;
20
+ }
21
+
22
+ _onGLContextCreate = gl => {
23
+ // Canvas polyfilling
24
+
25
+ let canvas = Browser.document.createElement('canvas');
26
+
27
+ canvas.getContext = () => gl;
28
+
29
+ // Cache uniform and attrib locations
30
+
31
+ const origGetUniformLocation = gl.getUniformLocation;
32
+ gl.getUniformLocation = (program, name) => {
33
+ if (!program.uniformLocationCache) {
34
+ program.uniformLocationCache = {};
35
+ }
36
+ let loc = program.uniformLocationCache[name];
37
+ if (loc !== undefined) {
38
+ return loc;
39
+ }
40
+ loc = origGetUniformLocation.call(gl, program, name);
41
+ program.uniformLocationCache[name] = loc;
42
+ return loc;
43
+ };
44
+
45
+ const origGetAttribLocation = gl.getAttribLocation;
46
+ gl.getAttribLocation = (program, name) => {
47
+ if (!program.attribLocationCache) {
48
+ program.attribLocationCache = {};
49
+ }
50
+ let loc = program.attribLocationCache[name];
51
+ if (loc !== undefined) {
52
+ return loc;
53
+ }
54
+ loc = origGetAttribLocation.call(gl, program, name);
55
+ program.attribLocationCache[name] = loc;
56
+ return loc;
57
+ };
58
+
59
+ // Call `gl.endFrameEXP()` every frame
60
+
61
+ const keepFlushing = () => {
62
+ gl.endFrameEXP();
63
+ this._rafID = requestAnimationFrame(keepFlushing);
64
+ };
65
+ keepFlushing();
66
+
67
+ // The Processing sketch
68
+
69
+ new Processing(canvas, p => {
70
+ this._p = p;
71
+
72
+ // Force render viewport size / mode
73
+ p.size(gl.drawingBufferWidth, gl.drawingBufferHeight, p.WEBGL);
74
+ p.size = () => {};
75
+
76
+ // Run user's sketch
77
+ if (this.props.sketch) {
78
+ this.props.sketch(p);
79
+ } else {
80
+ p.draw = () => {};
81
+ }
82
+ });
83
+ };
84
+ }
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "expo-processing",
3
+ "version": "0.0.0-canary-20231123-1b19f96",
4
+ "description": "Utilities for using Processing.js on Expo",
5
+ "main": "index.js",
6
+ "keywords": [
7
+ "expo",
8
+ "processing.js",
9
+ "graphics",
10
+ "opengl",
11
+ "gl"
12
+ ],
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/expo/expo.git",
16
+ "directory": "packages/expo-processing"
17
+ },
18
+ "bugs": {
19
+ "url": "https://github.com/expo/expo/issues"
20
+ },
21
+ "author": "650 Industries, Inc.",
22
+ "license": "MIT",
23
+ "homepage": "https://github.com/expo/expo/tree/main/packages/expo-processing",
24
+ "dependencies": {
25
+ "expo-gl": "0.0.0-canary-20231123-1b19f96"
26
+ },
27
+ "peerDependencies": {
28
+ "expo": "*",
29
+ "processing-js": "^1.6.6"
30
+ },
31
+ "gitHead": "1b19f96bd0e50f43e4329e388347423e7cce20b6"
32
+ }