-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- move default options from static property to assign in constructor - add default options value BREAKING CHANGE: switch to type module
- Loading branch information
Showing
15 changed files
with
3,327 additions
and
3,931 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,9 @@ | ||
root = true | ||
|
||
[*] | ||
end_of_line = lf | ||
charset = utf-8 | ||
indent_style = space | ||
indent_size = 2 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true |
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,2 +1,4 @@ | ||
node_modules | ||
.DS_Store | ||
types | ||
lib |
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,2 +1,10 @@ | ||
demo.js | ||
screenshot.gif | ||
web_modules | ||
examples | ||
docs | ||
coverage | ||
test | ||
.github | ||
screenshot.* | ||
index.html | ||
tsconfig.json | ||
.editorconfig |
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,96 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge" /> | ||
<title>raf-perf by Damien Seguin (https://github.com/dmnsgn)</title> | ||
<style> | ||
:root { | ||
--color-dark: #404040; | ||
--color-light: #f2f2f2; | ||
--color-accent: #fd5e62; | ||
} | ||
|
||
body { | ||
margin: 0; | ||
overflow: hidden; | ||
overscroll-behavior: none; | ||
font-family: sans-serif; | ||
color: var(--color-dark); | ||
background-color: var(--color-light); | ||
} | ||
|
||
main { | ||
padding: 0 20px; | ||
max-width: 600px; | ||
margin: auto; | ||
} | ||
|
||
.RectCount { | ||
color: var(--color-accent); | ||
font-size: 30px; | ||
font-weight: bold; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<main> | ||
<h1>raf-perf</h1> | ||
<p class="RectCount"></p> | ||
</main> | ||
<script async src="web_modules/es-module-shims.js"></script> | ||
<script src="web_modules/import-map.json" type="importmap"></script> | ||
|
||
<script type="module"> | ||
import RafPerf from "./index.js"; | ||
import createCanvasContext from "canvas-context"; | ||
|
||
const { context, canvas } = createCanvasContext("2d", { | ||
width: 600, | ||
height: 600, | ||
alpha: false, | ||
}); | ||
document.querySelector("main").appendChild(canvas); | ||
|
||
const maxRectCount = 580; | ||
let rectCount = maxRectCount; | ||
const RectCountElement = document.querySelector(".RectCount"); | ||
|
||
const engine = new RafPerf(); | ||
|
||
const color = window | ||
.getComputedStyle(document.documentElement) | ||
.getPropertyValue("--color-accent"); | ||
|
||
engine.on("tick", (dt) => { | ||
context.clearRect(0, 0, canvas.width, canvas.height); | ||
|
||
for (let i = 0; i < rectCount; i++) { | ||
context.shadowColor = color; | ||
context.shadowBlur = 30; | ||
|
||
context.fillStyle = color; | ||
context.fillRect(40 + i * 0.5, 40 + i * 0.5, 200, 100); | ||
} | ||
RectCountElement.innerText = `${rectCount} rect with shadowBlur`; | ||
}); | ||
|
||
engine.on("perf", (ratio) => { | ||
if (!ratio) return; | ||
|
||
console.log(`Performance ratio: ${ratio}`); | ||
|
||
if (ratio < 0.9) { | ||
console.log("Too many draws"); | ||
rectCount -= 10; | ||
} else if (ratio >= 0.9 && rectCount < maxRectCount) { | ||
console.log("Draw more"); | ||
rectCount += 5; | ||
} | ||
}); | ||
|
||
engine.start(); | ||
</script> | ||
</body> | ||
</html> |
Oops, something went wrong.