|
1 |
| -**Requirements:** |
2 |
| -VS Code, Git, Node, Bash type Terminal |
3 |
| - |
4 |
| -**Steps, create directory structures:** |
5 |
| -1. Install Node |
6 |
| -2. Open your terminal program and navigate to where you want to develop your Node based creative coding projects, |
7 |
| -3. Type: `mkdir CreativeCoding_NodeDev` (or name you want to use for your Node based dev work) |
8 |
| -4. Type: `cd nodeDev` |
9 |
| -5. Type: `npm init -y` |
10 |
| -6. `mkdir src dist` |
11 |
| -7. `cd src` |
12 |
| -8. `mkdir p5 three` |
13 |
| -9. `cd p5` |
14 |
| -10. `mkdir Proj01` |
15 |
| -11. `cd ../three` |
16 |
| -12. `mkdir Proj01` |
17 |
| - |
18 |
| -**install js modules and TypeScript type definitions** |
19 |
| -1. `npm i typescript p5 three` |
20 |
| -2. `npm i @types/p5` |
21 |
| -3. `npm i @types/three` |
22 |
| - |
23 |
| -**install webpack and utilities** |
24 |
| -`npm i webpack webpack-cli ts-loader webpack-dev-server` |
25 |
| - |
26 |
| -**create config files** |
27 |
| -1. create new file in nodeDev named tsconfig.json |
28 |
| -2. create new file in nodeDev named webpack.config.js |
29 |
| - |
30 |
| -**Add this to the tsconfig.json file:** |
31 |
| - |
32 |
| -{ |
33 |
| -"compilerOptions": { |
34 |
| -"allowJs": true, |
35 |
| -"module": "commonjs", |
36 |
| -"noImplicitAny": true, |
37 |
| -"esModuleInterop": true, |
38 |
| -"pretty": true, |
39 |
| -"outDir": "dist", |
40 |
| -"sourceMap": true, |
41 |
| -"strict": true, |
42 |
| -"target": "es6" |
43 |
| - } |
44 |
| -} |
45 |
| - |
46 |
| - |
47 |
| -**Add this to the webpack.config.js file: |
48 |
| -** |
49 |
| - |
50 |
| -const path = require("path");\ |
51 |
| -module.exports = {\ |
52 |
| - entry: "./src/p5/Proj01/sketch.ts", |
53 |
| - |
54 |
| - module: { |
55 |
| - rules: [ |
56 |
| - { |
57 |
| - test: /\.ts$/, |
58 |
| - use: "ts-loader", |
59 |
| - exclude: /node_modules/ |
60 |
| - } |
61 |
| - ] |
62 |
| - }, |
63 |
| - resolve: { |
64 |
| - extensions: [".ts", ".js"] |
65 |
| - }, |
66 |
| - output: { |
67 |
| - filename: "bundle.js", |
68 |
| - path: path.resolve(__dirname, "dist") |
69 |
| - }, |
70 |
| - devServer: { |
71 |
| - static: path.join(__dirname, "dist"), |
72 |
| - compress: true, |
73 |
| - port: 8080 |
74 |
| - } |
75 |
| - }; |
76 |
| - |
77 |
| -**cd into the dist directory** |
78 |
| -create index.html file. |
79 |
| - |
80 |
| -**Add the following to index.html:** |
81 |
| -<!DOCTYPE html> |
82 |
| -<html lang="en"> |
83 |
| -<head> |
84 |
| - <meta charset="UTF-8"> |
85 |
| - <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
86 |
| - <meta http-equiv="X-UA-Compatible" content="ie=edge">/ |
87 |
| - |
88 |
| - <!-- Css --> |
89 |
| - <link rel="stylesheet" type="text/css" href="./css/style.css"> |
90 |
| - <!-- js Libraries --> |
91 |
| - |
92 |
| -</head> |
93 |
| -<body> |
94 |
| - <script type="module" src="./bundle.js"></script> |
95 |
| - |
96 |
| -</body> |
97 |
| -</html> |
98 |
| - |
99 |
| -**cd to src/p5/Prog01 directory** |
100 |
| -create sketch.ts file |
101 |
| -**Add the following to sketch.ts** |
102 |
| - |
103 |
| -import p5 from "p5" |
104 |
| -/* |
105 |
| - * P5 Sketch |
106 |
| - */ |
107 |
| -const sketch = (p: p5) => { |
108 |
| - /* |
109 |
| - * P5 Setup |
110 |
| - */ |
111 |
| - p.setup = () => { |
112 |
| - document.title = "Proj01 | CreativeCoding_NodeDev.2024"; |
113 |
| - p.createCanvas(p.windowWidth, p.windowHeight); |
114 |
| - p.background(p.color('#080808')); |
115 |
| - }; |
116 |
| - |
117 |
| - /* |
118 |
| - * P5 Draw |
119 |
| - */ |
120 |
| - p.draw = () => { |
121 |
| - |
122 |
| - }; |
123 |
| -}; |
124 |
| - |
125 |
| -export default new p5(sketch); |
126 |
| - |
127 |
| -cd to src/three/Prog01 directory |
128 |
| -create sketch.ts file |
129 |
| - |
130 |
| -**Add the following to sketch.ts** |
131 |
| -// three example code from: https://github.com/Sean-Bradley/Three.js-TypeScript-Boilerplate |
132 |
| -import * as THREE from 'three' |
133 |
| -import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls' |
134 |
| - |
135 |
| -const scene = new THREE.Scene() |
136 |
| - |
137 |
| -const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000) |
138 |
| -camera.position.z = 2 |
139 |
| - |
140 |
| -const renderer = new THREE.WebGLRenderer() |
141 |
| -renderer.setSize(window.innerWidth, window.innerHeight) |
142 |
| -document.body.appendChild(renderer.domElement) |
143 |
| - |
144 |
| -const controls = new OrbitControls(camera, renderer.domElement) |
145 |
| - |
146 |
| -const geometry = new THREE.BoxGeometry() |
147 |
| -const material = new THREE.MeshBasicMaterial({ |
148 |
| - color: 0x00ff00, |
149 |
| - wireframe: true, |
150 |
| -}) |
151 |
| - |
152 |
| -const cube = new THREE.Mesh(geometry, material) |
153 |
| -scene.add(cube) |
154 |
| - |
155 |
| -window.addEventListener('resize', onWindowResize, false) |
156 |
| -function onWindowResize() { |
157 |
| - camera.aspect = window.innerWidth / window.innerHeight |
158 |
| - camera.updateProjectionMatrix() |
159 |
| - renderer.setSize(window.innerWidth, window.innerHeight) |
160 |
| - render() |
161 |
| -} |
162 |
| - |
163 |
| -function animate() { |
164 |
| - requestAnimationFrame(animate) |
165 |
| - |
166 |
| - cube.rotation.x += 0.01 |
167 |
| - cube.rotation.y += 0.01 |
168 |
| - |
169 |
| - controls.update() |
170 |
| - |
171 |
| - render() |
172 |
| -} |
173 |
| - |
174 |
| -function render() { |
175 |
| - renderer.render(scene, camera) |
176 |
| -} |
177 |
| -animate() |
178 |
| - |
179 |
| -Add these lines to the "scripts" in the package.json file: |
180 |
| - "test": "echo \"Error: no test specified\" && exit 1", |
181 |
| - "dev": "webpack-dev-server --mode development", |
182 |
| - "build": "webpack --mode production" |
183 |
| - |
184 |
| -Finally to run, type in the terminal: `npm run dev` |
185 |
| - |
186 |
| - |
187 |
| - |
188 |
| - |
| 1 | +Please see build steps for this environment: https://gist.github.com/irajgreenberg/8869d97d600be140bf572061e5ff1f7d |
0 commit comments