-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add object specific update method example
This will help modularize the framework and write object specific code in different files.
- Loading branch information
1 parent
6cd14db
commit afe55c6
Showing
10 changed files
with
159 additions
and
25 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,29 +1,32 @@ | ||
Examples: | ||
- 'examples/**' | ||
- 'examples/**' | ||
|
||
Library: | ||
- 'lib/**' | ||
- 'lib/**' | ||
|
||
ReadMe: | ||
- 'readme.md' | ||
- 'readme.md' | ||
|
||
CodeEditor: | ||
- '.vscode/**' | ||
- '.vscode/**' | ||
|
||
Tests: | ||
- any: ['test/**', '**/*.test.ts', '**/*.test.js'] | ||
- any: ['test/**', '**/*.test.ts', '**/*.test.js'] | ||
|
||
Core: | ||
- 'lib/core/**' | ||
- 'lib/core/**' | ||
|
||
CoreWithTests: | ||
- all: ['lib/core/**', 'test/**'] | ||
- all: ['lib/core/**', 'test/**'] | ||
|
||
Actions: | ||
- '.github/**' | ||
- '.github/**' | ||
|
||
Docs: | ||
- 'Docs/**' | ||
- 'Docs/**' | ||
|
||
Types: | ||
- 'lib/types/**' | ||
- 'lib/types/**' | ||
|
||
Packages: | ||
- '**/**/package*.json' |
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,12 @@ | ||
# First load nvm and provide access to the nvm command. | ||
export NVM_DIR="$HOME/.nvm" | ||
[ -s "/usr/local/opt/nvm/nvm.sh" ] && . "/usr/local/opt/nvm/nvm.sh" | ||
|
||
# Use the nvm ls command to detect the version being used. | ||
export NVM_DIR="$HOME/.nvm" | ||
a=$(nvm ls | grep 'node') | ||
b=${a#*(-> } | ||
v=${b%%[)| ]*} | ||
|
||
# Export the current version in your path for husky to find. | ||
export PATH="$NVM_DIR/versions/node/$v/bin:$PATH" |
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
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
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 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/vite.svg" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<link | ||
rel="stylesheet" | ||
href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/styles/default.min.css" | ||
/> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/highlight.min.js"></script> | ||
|
||
<!-- and it's easy to individually load additional languages --> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/languages/go.min.js"></script> | ||
<script src="https://unpkg.com/highlightjs-copy/dist/highlightjs-copy.min.js"></script> | ||
<link | ||
rel="stylesheet" | ||
href="https://unpkg.com/highlightjs-copy/dist/highlightjs-copy.min.css" | ||
/> | ||
<link rel="stylesheet" href="/styles.css" /> | ||
|
||
<script> | ||
hljs.addPlugin(new CopyButtonPlugin()); | ||
hljs.highlightAll(); | ||
</script> | ||
<title>MiniPoint Colors</title> | ||
</head> | ||
<body> | ||
<div id="app">Single Objects also have their own update method</div> | ||
<div class="main-area"> | ||
<canvas id="canvas"></canvas> | ||
<pre><code class="language-javascript"> | ||
import { Engine, Point } from '../../lib'; | ||
|
||
const engine = new Engine( | ||
document.getElementById('canvas') as HTMLCanvasElement, | ||
{ | ||
engineOptions: { | ||
width: 600, | ||
height: 400, | ||
}, | ||
}, | ||
); | ||
|
||
const { renderer, input } = engine; | ||
|
||
// we will always get the engine as parameter for any use. | ||
engine.update = (_engine) => { | ||
if (input.mouse.click) { | ||
const p1 = new Point({ | ||
x: input.mouse.position.x, | ||
y: input.mouse.position.y, | ||
radius: 6, | ||
color: `rgb(${Math.random() * 255}, ${Math.random() * 255}, ${ | ||
Math.random() * 255 | ||
})`, | ||
}); | ||
|
||
// this is object specific update method, it could be conditional as well. | ||
p1.update = () => { | ||
p1.options.radius = (p1.options.radius ?? 0) + 0.1; | ||
}; | ||
|
||
renderer.addObject(p1); | ||
} | ||
}; | ||
|
||
|
||
</code></pre> | ||
</div> | ||
<script type="module" src="./script.ts"></script> | ||
</body> | ||
</html> |
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,34 @@ | ||
import { Engine, Point } from '../../lib'; | ||
|
||
const engine = new Engine( | ||
document.getElementById('canvas') as HTMLCanvasElement, | ||
{ | ||
engineOptions: { | ||
width: 600, | ||
height: 400, | ||
}, | ||
}, | ||
); | ||
|
||
const { renderer, input } = engine; | ||
|
||
// we will always get the engine as parameter for any use. | ||
engine.update = (_engine) => { | ||
if (input.mouse.click) { | ||
const p1 = new Point({ | ||
x: input.mouse.position.x, | ||
y: input.mouse.position.y, | ||
radius: 6, | ||
color: `rgb(${Math.random() * 255}, ${Math.random() * 255}, ${ | ||
Math.random() * 255 | ||
})`, | ||
}); | ||
|
||
// this is object specific update method, it could be conditional as well. | ||
p1.update = () => { | ||
p1.options.radius = (p1.options.radius ?? 0) + 0.1; | ||
}; | ||
|
||
renderer.addObject(p1); | ||
} | ||
}; |
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
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
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
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