-
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.
feat (renderer:point) add color support to point
- Loading branch information
1 parent
096d137
commit 0b83b8b
Showing
12 changed files
with
236 additions
and
14 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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<!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"> | ||
Click to put a random color | ||
<br /> | ||
<label for="max">Max Points: </label> | ||
<input type="number" name="max" id="max" value="100" /> | ||
</div> | ||
<canvas id="canvas"></canvas> | ||
<br /> | ||
Source Code: | ||
<pre><code class="language-javascript"> | ||
export type CanvasOptions = { | ||
/** | ||
* The element to append the canvas on @default body | ||
*/ | ||
parentElement: HTMLElement; | ||
/** | ||
* Width of the canvas on @default 800px | ||
*/ | ||
width: number; | ||
/** | ||
* Height of the canvas on @default 600px | ||
*/ | ||
height: number; | ||
}; | ||
|
||
export type EngineOptions = { | ||
contextOptions?: CanvasRenderingContext2DSettings; | ||
// TODO: not yet decided | ||
engineOptions: { | ||
clearEachFrame: boolean; | ||
border: string; | ||
bg: string; | ||
width: number; | ||
height: number; | ||
}; | ||
}; | ||
|
||
|
||
</code></pre> | ||
<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,28 @@ | ||
import { Engine, Point } from '../../lib'; | ||
|
||
const engine = new Engine( | ||
document.getElementById('canvas') as HTMLCanvasElement, | ||
); | ||
const renderer = engine.renderer; | ||
|
||
const canvasX = engine.canvas.getBoundingClientRect().x; | ||
const canvasY = engine.canvas.getBoundingClientRect().y; | ||
let maxAmount = 100; | ||
|
||
document.getElementById('max')?.addEventListener('change', (e) => { | ||
maxAmount = +(e.target as HTMLInputElement).value; | ||
}); | ||
|
||
window.addEventListener('click', (e: MouseEvent) => { | ||
const p1 = new Point(); | ||
p1.options.x = e.clientX - canvasX; | ||
p1.options.y = e.clientY - canvasY; | ||
p1.options.radius = 6; | ||
p1.options.color = `rgb(${Math.random() * 255}, ${Math.random() * 255}, ${ | ||
Math.random() * 255 | ||
})`; | ||
|
||
renderer.addObject(p1); | ||
}); | ||
|
||
console.log(renderer.objects); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
body { | ||
background: #000; | ||
color: white; | ||
margin: 20px; | ||
} | ||
|
||
input { | ||
margin: 10px; | ||
} | ||
|
||
/* | ||
Atom One Dark by Daniel Gamage | ||
Original One Dark Syntax theme from https://github.com/atom/one-dark-syntax | ||
base: #282c34 | ||
mono-1: #abb2bf | ||
mono-2: #818896 | ||
mono-3: #5c6370 | ||
hue-1: #56b6c2 | ||
hue-2: #61aeee | ||
hue-3: #c678dd | ||
hue-4: #98c379 | ||
hue-5: #e06c75 | ||
hue-5-2: #be5046 | ||
hue-6: #d19a66 | ||
hue-6-2: #e6c07b | ||
*/ | ||
|
||
.hljs { | ||
color: #abb2bf; | ||
background: #282c34; | ||
} | ||
|
||
.hljs-comment, | ||
.hljs-quote { | ||
color: #5c6370; | ||
font-style: italic; | ||
} | ||
|
||
.hljs-doctag, | ||
.hljs-keyword, | ||
.hljs-formula { | ||
color: #c678dd; | ||
} | ||
|
||
.hljs-section, | ||
.hljs-name, | ||
.hljs-selector-tag, | ||
.hljs-deletion, | ||
.hljs-subst { | ||
color: #e06c75; | ||
} | ||
|
||
.hljs-literal { | ||
color: #56b6c2; | ||
} | ||
|
||
.hljs-string, | ||
.hljs-regexp, | ||
.hljs-addition, | ||
.hljs-attribute, | ||
.hljs-meta .hljs-string { | ||
color: #98c379; | ||
} | ||
|
||
.hljs-attr, | ||
.hljs-variable, | ||
.hljs-template-variable, | ||
.hljs-type, | ||
.hljs-selector-class, | ||
.hljs-selector-attr, | ||
.hljs-selector-pseudo, | ||
.hljs-number { | ||
color: #d19a66; | ||
} | ||
|
||
.hljs-symbol, | ||
.hljs-bullet, | ||
.hljs-link, | ||
.hljs-meta, | ||
.hljs-selector-id, | ||
.hljs-title { | ||
color: #61aeee; | ||
} | ||
|
||
.hljs-built_in, | ||
.hljs-title.class_, | ||
.hljs-class .hljs-title { | ||
color: #e6c07b; | ||
} | ||
|
||
.hljs-emphasis { | ||
font-style: italic; | ||
} | ||
|
||
.hljs-strong { | ||
font-weight: bold; | ||
} | ||
|
||
.hljs-link { | ||
text-decoration: underline; | ||
} |
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
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