[demos] Add directory from which to serve demos.skia.org

To run the demos locally, cd in to the directory and run
  make local

Then navigate to, for example, http://localhost:8123/demos/hello_world/

Change-Id: I5954989053d4602cd558c646e19106998dc00604
Bug: skia:10170
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/298397
Reviewed-by: Weston Tracey <westont@google.com>
This commit is contained in:
Kevin Lubick 2020-06-23 11:51:39 -04:00
parent ebea6d0133
commit 2639a144ff
2 changed files with 46 additions and 0 deletions

4
demos.skia.org/Makefile Normal file
View File

@ -0,0 +1,4 @@
.PHONY: local
local:
echo "Go check out http://localhost:8123/hello_world/index.html"
python2 -m SimpleHTTPServer 8123

View File

@ -0,0 +1,42 @@
<!DOCTYPE html>
<title>Hello World Demo</title>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="text/javascript" src="https://particles.skia.org/static/canvaskit.js"></script>
<style>
canvas {
border: 1px dashed grey;
}
</style>
<body>
<h1>Hello world</h1>
<canvas id=draw width=500 height=500></canvas>
</body>
<script type="text/javascript" charset="utf-8">
const ckLoaded = CanvasKitInit({locateFile: (file) => 'https://particles.skia.org/static/'+file});
ckLoaded.then((CanvasKit) => {
const surface = CanvasKit.MakeCanvasSurface('draw');
if (!surface) {
throw 'Could not make surface';
}
const paint = new CanvasKit.SkPaint();
paint.setColor(CanvasKit.RED);
const textPaint = new CanvasKit.SkPaint();
const textFont = new CanvasKit.SkFont(null, 20);
function drawFrame(canvas) {
canvas.drawRect(CanvasKit.LTRBRect(10, 10, 50, 50), paint);
canvas.drawText('If you see this, CanvasKit loaded!!', 5, 100, textPaint, textFont);
}
surface.requestAnimationFrame(drawFrame);
});
</script>