Skip to content

Commit

Permalink
Major redesign of the gallery.
Browse files Browse the repository at this point in the history
To every example, a description string is now provided.
Also, an image or video is provided.
  • Loading branch information
Erkaman committed Jul 31, 2016
1 parent 59fb505 commit a6656c8
Show file tree
Hide file tree
Showing 73 changed files with 321 additions and 49 deletions.
169 changes: 157 additions & 12 deletions bin/build-gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,168 @@ function jsName (file) {
return file.replace('example', 'www/gallery') + '.js'
}

function imgName (file) {
return file.replace('example', 'gallery/img').replace('.js', '.png')
}

var stylesheet = `
body {
margin: 0 auto;
max-width: 860px;
}
li a {
text-decoration: none;
color: #000;
}
li a:hover {
color: #666;
}
p a {
text-decoration: none;
color: #00C;
}
p a:visited {
color: #009;
}
p a:hover {
color: #00F;
}
* {margin: 0; padding: 0;}
div {
margin: 20px;
}
ul {
list-style-type: none;
}
h3 {
font: 700 1.27em verdana;
margin-top: 50px;
margin-bottom: 20px;
}
h1 {
font: 700 3.27em verdana;
max-width: 600px;
margin: 0 auto;
}
li img {
float: right;
margin: 40px 15px 0 0;
}
li iframe {
float: right;
margin: 40px 15px 0 0;
}
li p {
font: 95%/1.3 verdana;
max-width: 390px;
padding-bottom: 16px;
}
li {
padding: 50px;
overflow: auto;
list-style-type: none;
}
`

function generateGallery (files) {
fs.writeFile('www/gallery.html',
`<!DOCTYPE html>
var html = `<!DOCTYPE html>
<html>
<head>
<title>regl gallery</title>
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
<meta charset=utf-8>
<style>` +
stylesheet +
` </style>
</head>
<body>
<ul>
${files.map(function (file) {
return `
<li><a href="${file.replace('example', 'gallery')}.html"'>
${file}
</a></li>`
}).join('\n')}
</ul>
<body>`

html += '<h1>Example Gallery</h1>'

html += '<ul>'

html += files.map(function (file) {
var li = '<li>' // begin list item

var link = file.replace('example', 'gallery') + '.html'

function getEmbedTag (id) {
return '<iframe width="332" height="187" src="https://www.youtube.com/embed/' +
id +
'?rel=0" frameborder="0" allowfullscreen" frameborder="0" allowfullscreen></iframe>'
}

li += '<a href="' + link + '">'
var img = imgName(file)

var s = file.replace('example/', '').replace('.js', '')

if (fs.existsSync('example/img/' + s + '.txt')) {
li += getEmbedTag(
fs.readFileSync('example/img/' + s + '.txt') + '')
} else if (fs.existsSync('example/img/' + s + '.png')) {
li += '<img src="' + img + '" width="332" height="208" alt="' + file + '" >'
} else {
throw new Error(
'You need to provide either a youtube link or an image for the example ' +
file)
}
li += '</a>'

li += '<a href="' + link + '"><h3>' + file.replace('example/', '') + '</h3></a>'

var fileSrc = fs.readFileSync(file) + ''
var beg = fileSrc.search('/\\*')
var end = fileSrc.search('\\*/')

if (beg !== 0 || end === 0) {
throw new Error(
'The example ' + file +
' must begin with a description commment')
}
var desc = fileSrc.substring(beg + 2, end - 1)
li += desc

li += '<p>' +
'<a href="' +
link +
'">Run Example</a>' +
'</p>'

li += '<p>' +
'<a href="' +
'https://github.com/mikolalysenko/regl/blob/gh-pages/' + file +
'">Source Code</a>' +
'</p>'

li += '</li>'

return li
}).join('\n')

html += '</ul>'

html += `
</body>
</html>`)
</html>`

fs.writeFile('www/gallery.html', html)
}

mkdirp('www/gallery', function (err) {
Expand All @@ -43,6 +185,9 @@ mkdirp('www/gallery', function (err) {
ncp('example/assets', 'www/gallery/assets', function (err) {
console.log(err)
})
ncp('example/img', 'www/gallery/img', function (err) {
console.log(err)
})
glob('example/*.js', {}, function (err, files) {
if (err) {
throw err
Expand Down
4 changes: 4 additions & 0 deletions example/audio.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/*
<p>No description</p>
*/
/* global AudioContext */
const regl = require('../regl')({pixelRatio: 1})
const perspective = require('gl-mat4/perspective')
Expand Down
5 changes: 4 additions & 1 deletion example/basic.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// This example is a simple demonstration of how to use regl.
/*
<p> This example is a simple demonstration of how to use regl to draw a triangle. </p>
*/

// The default method exposed by the module wraps a canvas element
const regl = require('../regl')()

Expand Down
9 changes: 5 additions & 4 deletions example/batch.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// This example demonstrates how to use batch mode commands
//
// To use a command in batch mode, we pass in an array of objects. Then
// the command is executed once for each object in the array.
/* <p>This example demonstrates how to use batch mode commands</p>
<p> To use a command in batch mode, we pass in an array of objects. Then
the command is executed once for each object in the array. </p>
*/

// As usual, we start by creating a full screen regl object
const regl = require('../regl')()
Expand Down
7 changes: 4 additions & 3 deletions example/blur.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/*
<p>This examples demonstrates how we can render a height map, how to place out several models(using the batching feature), and how to
implement a simple fullscreen post-process effect(using the framebuffer feature) in regl. </p>
This examples demonstrates how we can render a height map, how to place out several models(using the batching feature), and how to
implement a simple fullscreen post-process effect(using the framebuffer feature) in REGL. The post-process effect is a simple box filter blur.
*/
<p> The post-process effect is a simple box filter blur. </p>
*/

const canvas = document.body.appendChild(document.createElement('canvas'))
const fit = require('canvas-fit')
Expand Down
5 changes: 3 additions & 2 deletions example/bunny.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// This example shows how to draw a mesh with regl

/*
<p> This example shows how to draw a mesh with regl </p>
*/
const regl = require('../regl')()
const mat4 = require('gl-mat4')
const bunny = require('bunny')
Expand Down
4 changes: 4 additions & 0 deletions example/camera.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/*
<p>This example shows how to implement a movable camera with regl.</p>
*/

const mat4 = require('gl-mat4')
const bunny = require('bunny')
const fit = require('canvas-fit')
Expand Down
11 changes: 6 additions & 5 deletions example/cloth.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/*
In this example, we use the mass-spring model described by Thomas Jakobsen to implement
a simple cloth simulation.
<p>In this example, we use the mass-spring model described by Thomas Jakobsen to implement
a simple cloth simulation. It is also demonstrated how we can manage a dynamic mesh in regl. <p>
More info here:
http://graphics.cs.cmu.edu/nsp/course/15-869/2006/papers/jakobsen.htm
http://gamedevelopment.tutsplus.com/tutorials/simulate-fabric-and-ragdolls-with-simple-verlet-integration--gamedev-519
<p> You can read more about cloth simulation <a href="http://graphics.cs.cmu.edu/nsp/course/15-869/2006/papers/jakobsen.htm">here</a> and
<a href="http://gamedevelopment.tutsplus.com/tutorials/simulate-fabric-and-ragdolls-with-simple-verlet-integration--gamedev-519">here</a>
</p>
*/

const canvas = document.body.appendChild(document.createElement('canvas'))
Expand Down
5 changes: 5 additions & 0 deletions example/cube-fbo.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
<p>This example shows how you can render reflections using cubic framebuffers.</p>
*/

const regl = require('../regl')()
const mat4 = require('gl-mat4')
const bunny = require('bunny')
Expand Down
5 changes: 5 additions & 0 deletions example/cube.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
<p>This examples renders a spinning textured cube.</p>
*/

const regl = require('../regl')()
const mat4 = require('gl-mat4')

Expand Down
4 changes: 4 additions & 0 deletions example/dds.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/*
<p>This example shows how you can parse dds files with resl.</p>
*/

const regl = require('../regl')({
extensions: 'WEBGL_compressed_texture_s3tc'
})
Expand Down
8 changes: 4 additions & 4 deletions example/deferred_shading.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
This example is a simple implementation of deferred shading.
<p> This example is a simple implementation of deferred shading. </p>
The focus of this implementation was readability, so it is not an
<p> The focus of this implementation was readability, so it is not an
optimized implementation, and can certainly be made more efficient.
(by for instance getting rid of the "position" render target.
It can be computed from the depth buffer. )
It can be computed from the depth buffer. ) </p>
This example demonstrates the usage of Multiple-render targets in regl.
<p> This example demonstrates the usage of Multiple-render targets in regl. </p>
*/
const webglCanvas = document.body.appendChild(document.createElement('canvas'))
const fit = require('canvas-fit')
Expand Down
4 changes: 3 additions & 1 deletion example/dynamic.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// This example shows how to pass props to draw commands
/*
<p> This example shows how to pass props to draw commands </p>
*/

const regl = require('../regl')()

Expand Down
4 changes: 4 additions & 0 deletions example/elements.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/*
<p> This example demonstrates how you can use `elements` to draw lines. </p>
*/

const regl = require('../regl')()

regl.clear({
Expand Down
5 changes: 5 additions & 0 deletions example/envmap.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
<p>This example shows how you can render reflections with an environment map.</p>
*/

const regl = require('../regl')()
const mat4 = require('gl-mat4')
const bunny = require('bunny')
Expand Down
4 changes: 3 additions & 1 deletion example/feedback.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// This example shows how to use copyTexImage2D to implement feedback effects
/*
<p> This example shows how to use copyTexImage2D to implement feedback effects </p>
*/

const regl = require('../regl')()
const mouse = require('mouse-change')()
Expand Down
3 changes: 3 additions & 0 deletions example/geomorph.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/*
<p>No description</p>
*/
const regl = require('../regl')()
const mat4 = require('gl-mat4')
const bunny = require('bunny')
Expand Down
5 changes: 5 additions & 0 deletions example/graph.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
<p>No description.</p>
*/

const regl = require('../regl')({
extensions: ['webgl_draw_buffers', 'oes_texture_float']
})
Expand Down
Binary file added example/img/audio.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/img/basic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/img/batch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions example/img/blur.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
OJkT24MxydA
Binary file added example/img/bunny.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/img/camera.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions example/img/cloth.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
scg33DHDnHc
Binary file added example/img/cube-fbo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/img/cube.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/img/dds.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/img/deferred_shading.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/img/dynamic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/img/elements.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/img/envmap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/img/feedback.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/img/geomorph.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/img/graph.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/img/instance-mesh.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/img/instance-triangle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/img/life.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/img/lighting.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/img/microphone.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/img/minecraft.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/img/mipmap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/img/particles.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/img/point-light-shadow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/img/pong.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/img/scope.png
Binary file added example/img/shadow_map.png
Binary file added example/img/sprites.png
Binary file added example/img/stats.png
Binary file added example/img/text.png
Binary file added example/img/texture.png
Binary file added example/img/theta360.png
Binary file added example/img/tile.png
Binary file added example/img/video.png
4 changes: 2 additions & 2 deletions example/instance-mesh.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
In this example, it is shown how you can draw a bunch of bunny meshes using the
instancing feature of regl.
<p> In this example, it is shown how you can draw a bunch of bunny meshes using the
instancing feature of regl. </p>
*/

const mat4 = require('gl-mat4')
Expand Down
4 changes: 2 additions & 2 deletions example/instance-triangle.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
In this example, it is shown how you can draw a bunch of triangles using the
instancing feature of regl.
<p> In this example, it is shown how you can draw a bunch of triangles using the
instancing feature of regl. </p>
*/
const regl = require('../regl')({extensions: ['angle_instanced_arrays']})

Expand Down
5 changes: 5 additions & 0 deletions example/life.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
<p>This example implements the game of life in regl.</p>
*/

const regl = require('../regl')()

const RADIUS = 512
Expand Down
4 changes: 4 additions & 0 deletions example/lighting.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/*
<p>This example shows how you can apply multiple light sources to a model</p>
*/
const regl = require('../regl')()
const normals = require('angle-normals')
const mat4 = require('gl-mat4')
Expand Down
Loading

0 comments on commit a6656c8

Please sign in to comment.