-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
65b192a
commit e5a5235
Showing
40 changed files
with
2,519 additions
and
399 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,5 +1,6 @@ | ||
node_modules | ||
temp | ||
tmp | ||
.now | ||
.vscode | ||
docs | ||
|
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,5 +1,6 @@ | ||
node_modules | ||
temp | ||
tmp | ||
test | ||
benchmark | ||
docs | ||
|
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,21 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width,initial-scale=1" /> | ||
<title>Webgl line plotting framework - Lines</title> | ||
<link rel="stylesheet" href="style.css" type="text/css" /> | ||
</head> | ||
|
||
<body> | ||
<div> | ||
<canvas class="canvas" id="my_canvas"></canvas> | ||
<p>Entre the number of lines to be created and push Click button</p> | ||
<button id="btClick" class="button">Click!</button> | ||
<input type="number" id="inNum" name="tentacles" min="1" max="100000" value="1" /> | ||
<p>Open the console (F12) for logs</p> | ||
</div> | ||
</body> | ||
|
||
<script type="module" src="./bench-thick.js"></script> | ||
</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,75 @@ | ||
import { WebglPlot, ColorRGBA, WebglThickLine } from "../dist/webglplot.esm.js"; | ||
|
||
const canvas = document.getElementById("my_canvas"); | ||
|
||
const devicePixelRatio = window.devicePixelRatio || 1; | ||
canvas.width = canvas.clientWidth * devicePixelRatio; | ||
canvas.height = canvas.clientHeight * devicePixelRatio; | ||
|
||
const numX = canvas.width; | ||
|
||
const wglp = new WebglPlot(canvas, { powerPerformance: "high-performance" }); | ||
|
||
const createLines = (num) => { | ||
wglp.removeAllLines(); | ||
for (let i = 0; i < num; i++) { | ||
const color = new ColorRGBA(Math.random(), Math.random(), Math.random(), 1); | ||
const thickLine = new WebglThickLine(color, numX, 0.01); | ||
thickLine.lineSpaceX(-1, 2 / numX); | ||
thickLine.offsetY = (i - Math.floor(num / 2)) / num; | ||
wglp.addThickLine(thickLine); | ||
} | ||
}; | ||
|
||
createLines(1); | ||
|
||
let frame = 0; | ||
let prevTime = new Date(); | ||
|
||
const newFrame = () => { | ||
//const timeStrat = +new Date(); | ||
update(); | ||
wglp.update(); | ||
const timeNow = new Date(); | ||
if (timeNow - prevTime > 1000) { | ||
console.log(frame); | ||
frame = 0; | ||
prevTime = timeNow; | ||
} else { | ||
frame++; | ||
} | ||
|
||
requestAnimationFrame(newFrame); | ||
}; | ||
requestAnimationFrame(newFrame); | ||
|
||
const update = () => { | ||
const freq = 0.001; | ||
const amp = 0.5; | ||
const noise = 0.01; | ||
|
||
let yFinal = new Float32Array(numX); | ||
|
||
for (let i = 0; i < yFinal.length; i++) { | ||
const ySin = Math.sin(Math.PI * i * freq * Math.PI * 2); | ||
const yNoise = Math.random() - 0.5; | ||
yFinal[i] = ySin * amp + yNoise * noise; | ||
} | ||
//console.log(yFinal); | ||
|
||
wglp.thickLines.forEach((line) => { | ||
for (let i = 0; i < yFinal.length; i++) { | ||
line.setY(i, yFinal[i]); | ||
} | ||
}); | ||
}; | ||
|
||
const btClick = document.getElementById("btClick"); | ||
const inNum = document.getElementById("inNum"); | ||
btClick.addEventListener("click", () => { | ||
const numLine = inNum.value; | ||
const timeStart = new Date(); | ||
createLines(numLine); | ||
const timeEnd = new Date(); | ||
console.log(`Created ${numLine} in ${timeEnd - timeStart} milliseconds`); | ||
}); |
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,51 @@ | ||
import type { ColorRGBA } from "./ColorRGBA"; | ||
import { WebglBase } from "./WebglBase"; | ||
/** | ||
* The standard Line class | ||
*/ | ||
export declare class WebglThickLine extends WebglBase { | ||
private currentIndex; | ||
private _linePoints; | ||
private _thickness; | ||
/** | ||
* Create a new line | ||
* @param c - the color of the line | ||
* @param numPoints - number of data pints | ||
* @example | ||
* ```typescript | ||
* x= [0,1] | ||
* y= [1,2] | ||
* line = new WebglLine( new ColorRGBA(0.1,0.1,0.1,1), 2); | ||
* ``` | ||
*/ | ||
constructor(c: ColorRGBA, numPoints: number, thickness: number); | ||
convertToTriPoints(): void; | ||
/** | ||
* Set the X value at a specific index | ||
* @param index - the index of the data point | ||
* @param x - the horizontal value of the data point | ||
*/ | ||
setX(index: number, x: number): void; | ||
/** | ||
* Set the Y value at a specific index | ||
* @param index : the index of the data point | ||
* @param y : the vertical value of the data point | ||
*/ | ||
setY(index: number, y: number): void; | ||
/** | ||
* Make an equally spaced array of X points | ||
* @param start - the start of the series | ||
* @param stepSize - step size between each data point | ||
* | ||
* @example | ||
* ```typescript | ||
* //x = [-1, -0.8, -0.6, -0.4, -0.2, 0, 0.2, 0.4, 0.6, 0.8] | ||
* const numX = 10; | ||
* line.lineSpaceX(-1, 2 / numX); | ||
* ``` | ||
*/ | ||
lineSpaceX(start: number, stepSize: number): void; | ||
setThickness(thickness: number): void; | ||
getThickness(): number; | ||
} | ||
//# sourceMappingURL=WbglThickLine.d.ts.map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.