SlideShare une entreprise Scribd logo
1  sur  77
Télécharger pour lire hors ligne
Graphics for Web Devs
Jarrod Overson - Shape Security
@jsoverson
Yes, we're not game developers.
But what are you looking for in your applications?
• 60 FPS
• Beautiful graphics
• Responsive Interaction
• Smooth animations
When I say "video games"
think: "performance critical graphic applications"
The web is one of the only computer
platforms that hasn't grown with video
games pushing the edge.
Why?
1996
The web may not need games.
But losing that discipline has handicapped us.
So where do we start?
<canvas>
document.createElement('canvas');
<canvas>
or
canvas.width = 1280;
canvas.height = 720;
var context = canvas.getContext('2d');
or "webgl"
context.fillStyle = 'MediumAquaMarine';
context.fillRect(10, 10, 100, 100);
for (var i = 0; i < 500; i++) {
context.fillRect(10 + i, 10 + i, 100, 100);
}
for (var i = 0; i < 500; i++) {
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillRect(10 + i, 10 + i, 100, 100);
}
setTimeout(draw, 1000/60)
requestAnimationFrame(draw)
var i = 0;
function draw() {
if (i < 500) i++;
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillRect(i + 10, i + 10, 100, 100);
requestAnimationFrame(draw);
}
draw();
var i = 0;
function draw() {
if (i < 500) i++;
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillRect(i + 10, i + 10, 100, 100);
requestAnimationFrame(draw);
}
draw();
First we update our state.
var i = 0;
function draw() {
if (i < 500) i++;
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillRect(i + 10, i + 10, 100, 100);
requestAnimationFrame(draw);
}
draw();
Then we render our current state.
var i = 0;
function draw() {
if (i < 500) i++;
context.clearRect(0, 0, canvas.width, canvas.height);
context.fillRect(i + 10, i + 10, 100, 100);
requestAnimationFrame(draw);
}
draw();
And we do it all over again.
Update Render
Our loop
function loop() {
update();
render();
requestAnimationFrame(loop);
}
loop();
Particle System
Particles Emitters
class ParticleSystem {
constructor() {
this.particles = [];
this.emitters = [];
}
}
class Particle {
constructor(position, velocity, acceleration) {
this.position = position;
this.velocity = velocity;
this.acceleration = acceleration;
}
}
class Particle {
constructor(position, velocity, acceleration) {
this.position = position || {x: 0, y: 0};
this.velocity = velocity || {x: 0, y: 0};
this.acceleration = acceleration || {x: 0, y: 0};
}
}
class Vector {
constructor(x, y) {
this.x = x || 0;
this.y = y || 0;
}
}
class Particle {
constructor(position, velocity, acceleration) {
this.position = position || new Vector(0, 0);
this.velocity = velocity || new Vector(0, 0);
this.acceleration = acceleration || new Vector(0, 0);
}
}
class Emitter {
constructor(point, velocity) {
this.position = point || new Vector(0, 0);
this.velocity = velocity || new Vector(0, 0);
}
}
class ParticleSystem {
constructor(width, height) { /* …snipped… */ }
render(context) {
context.clearRect(0, 0, this.width, this.height);
this.emitters.forEach(emitter => emitter.render(context));
this.particles.forEach(particle => particle.render(context));
}
}
class Particle {
constructor(position, velocity, acceleration) { /* … */ }
render(context) {
context.fillStyle = 'red';
context.fillRect(this.position.x, this.position.y, 2, 2);
}
}
var system = new ParticleSystem(width, height);
system.emitters.push(new Emitter(new Vector(10, 10)));
system.particles.push(new Particle(new Vector(20, 20)));
system.particles.push(new Particle(new Vector(10, 20)));
system.particles.push(new Particle(new Vector(20, 10)));
function loop() {
system.render(context);
window.requestAnimationFrame(loop);
}
loop();
var system = new ParticleSystem(width, height);
system.addEmitter(320, 180);
function loop() {
system.update();
system.render(context);
window.requestAnimationFrame(loop);
}
loop();
class Emitter {
constructor(position, velocity) { /* … */ }
render(context) { /* … */ }
emitParticle() {
return new Particle(this.position.clone(), this.velocity.clone());
}
}
class Particle {
constructor(position, velocity, acceleration) { /* … */ }
render(context) { /* … */ }
update() {
this.velocity.add(this.acceleration);
this.position.add(this.velocity);
}
}
class ParticleSystem {
constructor(width, height) { /* … */ }
addEmitter(x, y, velX, velY) { /* … */ }
update() {
this.emitters.forEach(
emitter => this.particles.push(emitter.emitParticle())
);
this.particles = this.particles.filter(particle => {
particle.update();
let pos = particle.position;
let outOfBounds = pos.x > this.width || pos.y > this.height ||
pos.x < 0 || pos.y < 0
return !outOfBounds;
})
}
}
emitParticle() {
// Define a maximum angle range in radians.
let spread = Math.PI / 32;
// Use an angle randomized over a spread so we have more of a "spray"
var angle = this.velocity.rad() + spread - (Math.random() * spread * 2);
// The magnitude of the emitter's velocity
var magnitude = this.velocity.length();
// New velocity based off of the calculated angle and magnitude
var velocity = Vector.fromAngle(angle, magnitude);
// return our new Particle
return new Particle(this.position.clone(), velocity);
}
emitParticle() {
// Define a maximum angle range in radians.
let spread = Math.PI / 32;
// Use an angle randomized over a spread so we have more of a "spray"
var angle = this.velocity.rad() + spread - (Math.random() * spread * 2);
// The magnitude of the emitter's velocity
var magnitude = this.velocity.length();
// New velocity based off of the calculated angle and magnitude
var velocity = Vector.fromAngle(angle, magnitude);
// return our new Particle
return new Particle(this.position.clone(), velocity);
}
emitParticle() {
// Define a maximum angle range in radians.
let spread = Math.PI / 32;
// Use an angle randomized over a spread so we have more of a "spray"
var angle = this.velocity.rad() + spread - (Math.random() * spread * 2);
// The magnitude of the emitter's velocity
var magnitude = this.velocity.length();
// New velocity based off of the calculated angle and magnitude
var velocity = Vector.fromAngle(angle, magnitude);
// return our new Particle
return new Particle(this.position.clone(), velocity);
}
Velocity
+ Spread
- (2 * spread)
- (2 * spread) * rand
emitParticle() {
// Define a maximum angle range in radians.
let spread = Math.PI / 32;
// Use an angle randomized over a spread so we have more of a "spray"
var angle = this.velocity.rad() + spread - (Math.random() * spread * 2);
// The magnitude of the emitter's velocity
var magnitude = this.velocity.length();
// New velocity based off of the calculated angle and magnitude
var velocity = Vector.fromAngle(angle, magnitude);
// return our new Particle
return new Particle(this.position.clone(), velocity);
}
emitParticle() {
// Define a maximum angle range in radians.
let spread = Math.PI / 32;
// Use an angle randomized over a spread so we have more of a "spray"
var angle = this.velocity.rad() + spread - (Math.random() * spread * 2);
// The magnitude of the emitter's velocity
var magnitude = this.velocity.length();
// New velocity based off of the calculated angle and magnitude
var velocity = Vector.fromAngle(angle, magnitude);
// return our new Particle
return new Particle(this.position.clone(), velocity);
}
emitParticle() {
// Define a maximum angle range in radians.
let spread = Math.PI / 32;
// Use an angle randomized over a spread so we have more of a "spray"
var angle = this.velocity.rad() + spread - (Math.random() * spread * 2);
// The magnitude of the emitter's velocity
var magnitude = this.velocity.length();
// New velocity based off of the calculated angle and magnitude
var velocity = Vector.fromAngle(angle, magnitude);
// return our new Particle
return new Particle(this.position.clone(), velocity);
}
1. Application state modified and rendered independently.
2. Expensive mutations performed as little as possible.
3. Physics based animations.
We're getting there. You can do this now, sort of.
var Greets = React.createClass({
getInitialState: function() {
return { name: "Portland" };
},
render: function() {
return <div>Hello {this.state.name}</div>;
}
});
The virtual DOM is an abstraction that saves you the cost of
expensive render-based mutation in a familiar package.
It's better, but a virtual DOM is not our application state.
While you're exploring JavaScript, explore graphics & games.
Go, do neat things with canvas!
Maybe you'll find a use for normal mapped backgrounds.
http://jsoverson.github.io/texture.js/demo/bricks.html
Or maybe you'll use it to understand the bounds of an optical illusion.
http://jsoverson.github.io/concentric-circle-illusion/
Or maybe you'll make some really awesome games.
https://ga.me/games/polycraft (turbulenz.com)
Or maybe you'll try…
phaser.io
Graphics for Web Devs
Jarrod Overson - Shape Security
@jsoverson

Contenu connexe

En vedette

HTML5 Canvas - The Future of Graphics on the Web
HTML5 Canvas - The Future of Graphics on the WebHTML5 Canvas - The Future of Graphics on the Web
HTML5 Canvas - The Future of Graphics on the WebRobin Hawkes
 
Molecular Cloning - Vectors: Types & Characteristics
Molecular Cloning -  Vectors: Types & CharacteristicsMolecular Cloning -  Vectors: Types & Characteristics
Molecular Cloning - Vectors: Types & CharacteristicsSruthy Chandran
 
Strategies to Drive Web Traffic in the Real Estate World
Strategies to Drive Web Traffic in the Real Estate WorldStrategies to Drive Web Traffic in the Real Estate World
Strategies to Drive Web Traffic in the Real Estate WorldRand Fishkin
 
How to Make Awesome SlideShares: Tips & Tricks
How to Make Awesome SlideShares: Tips & TricksHow to Make Awesome SlideShares: Tips & Tricks
How to Make Awesome SlideShares: Tips & TricksSlideShare
 
Getting Started With SlideShare
Getting Started With SlideShareGetting Started With SlideShare
Getting Started With SlideShareSlideShare
 

En vedette (7)

HTML5 Canvas - The Future of Graphics on the Web
HTML5 Canvas - The Future of Graphics on the WebHTML5 Canvas - The Future of Graphics on the Web
HTML5 Canvas - The Future of Graphics on the Web
 
Molecular Cloning - Vectors: Types & Characteristics
Molecular Cloning -  Vectors: Types & CharacteristicsMolecular Cloning -  Vectors: Types & Characteristics
Molecular Cloning - Vectors: Types & Characteristics
 
Strategies to Drive Web Traffic in the Real Estate World
Strategies to Drive Web Traffic in the Real Estate WorldStrategies to Drive Web Traffic in the Real Estate World
Strategies to Drive Web Traffic in the Real Estate World
 
ZIKA - What You Need to Know!
ZIKA - What You Need to Know! ZIKA - What You Need to Know!
ZIKA - What You Need to Know!
 
Inaugural Addresses
Inaugural AddressesInaugural Addresses
Inaugural Addresses
 
How to Make Awesome SlideShares: Tips & Tricks
How to Make Awesome SlideShares: Tips & TricksHow to Make Awesome SlideShares: Tips & Tricks
How to Make Awesome SlideShares: Tips & Tricks
 
Getting Started With SlideShare
Getting Started With SlideShareGetting Started With SlideShare
Getting Started With SlideShare
 

Similaire à Graphics Programming for Web Developers

1- Create a class called Point that has two instance variables, defi.pdf
1- Create a class called Point that has two instance variables, defi.pdf1- Create a class called Point that has two instance variables, defi.pdf
1- Create a class called Point that has two instance variables, defi.pdfjeeteshmalani1
 
視覚化とSwiftのタイプについて
視覚化とSwiftのタイプについて視覚化とSwiftのタイプについて
視覚化とSwiftのタイプについてRay Fix
 
05 Geographic scripting in uDig - halfway between user and developer
05 Geographic scripting in uDig - halfway between user and developer05 Geographic scripting in uDig - halfway between user and developer
05 Geographic scripting in uDig - halfway between user and developerAndrea Antonello
 
Hi,I have updated your code. It is working fine now. Highllighted .pdf
Hi,I have updated your code. It is working fine now. Highllighted .pdfHi,I have updated your code. It is working fine now. Highllighted .pdf
Hi,I have updated your code. It is working fine now. Highllighted .pdfaniyathikitchen
 
Create a java project that - Draw a circle with three random init.pdf
Create a java project that - Draw a circle with three random init.pdfCreate a java project that - Draw a circle with three random init.pdf
Create a java project that - Draw a circle with three random init.pdfarihantmobileselepun
 
Object Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsObject Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsMuhammadTalha436
 
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdfCreat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdfaromanets
 
Bindings: the zen of montage
Bindings: the zen of montageBindings: the zen of montage
Bindings: the zen of montageKris Kowal
 
1.what is the difference between a instance variable and an local va.pdf
1.what is the difference between a instance variable and an local va.pdf1.what is the difference between a instance variable and an local va.pdf
1.what is the difference between a instance variable and an local va.pdfarchgeetsenterprises
 
HTML5 Canvas (Wall Clock).pptx
HTML5 Canvas (Wall Clock).pptxHTML5 Canvas (Wall Clock).pptx
HTML5 Canvas (Wall Clock).pptxAhmadAbba6
 
The Canvas API for Rubyists
The Canvas API for RubyistsThe Canvas API for Rubyists
The Canvas API for Rubyistsdeanhudson
 
Exploring Canvas
Exploring CanvasExploring Canvas
Exploring CanvasKevin Hoyt
 
package chapter15;import javafx.application.Application;import j.pdf
package chapter15;import javafx.application.Application;import j.pdfpackage chapter15;import javafx.application.Application;import j.pdf
package chapter15;import javafx.application.Application;import j.pdfKARTIKINDIA
 
Writing SOLID C++ [gbgcpp meetup @ Zenseact]
Writing SOLID C++ [gbgcpp meetup @ Zenseact]Writing SOLID C++ [gbgcpp meetup @ Zenseact]
Writing SOLID C++ [gbgcpp meetup @ Zenseact]Dimitrios Platis
 

Similaire à Graphics Programming for Web Developers (20)

1- Create a class called Point that has two instance variables, defi.pdf
1- Create a class called Point that has two instance variables, defi.pdf1- Create a class called Point that has two instance variables, defi.pdf
1- Create a class called Point that has two instance variables, defi.pdf
 
視覚化とSwiftのタイプについて
視覚化とSwiftのタイプについて視覚化とSwiftのタイプについて
視覚化とSwiftのタイプについて
 
05 Geographic scripting in uDig - halfway between user and developer
05 Geographic scripting in uDig - halfway between user and developer05 Geographic scripting in uDig - halfway between user and developer
05 Geographic scripting in uDig - halfway between user and developer
 
Player x 0 y ga.docx
Player x 0 y ga.docxPlayer x 0 y ga.docx
Player x 0 y ga.docx
 
Hi,I have updated your code. It is working fine now. Highllighted .pdf
Hi,I have updated your code. It is working fine now. Highllighted .pdfHi,I have updated your code. It is working fine now. Highllighted .pdf
Hi,I have updated your code. It is working fine now. Highllighted .pdf
 
Chapter10.pptx
Chapter10.pptxChapter10.pptx
Chapter10.pptx
 
Create a java project that - Draw a circle with three random init.pdf
Create a java project that - Draw a circle with three random init.pdfCreate a java project that - Draw a circle with three random init.pdf
Create a java project that - Draw a circle with three random init.pdf
 
Object Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsObject Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ Exams
 
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdfCreat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
 
Bindings: the zen of montage
Bindings: the zen of montageBindings: the zen of montage
Bindings: the zen of montage
 
Css5 canvas
Css5 canvasCss5 canvas
Css5 canvas
 
1.what is the difference between a instance variable and an local va.pdf
1.what is the difference between a instance variable and an local va.pdf1.what is the difference between a instance variable and an local va.pdf
1.what is the difference between a instance variable and an local va.pdf
 
Ch3
Ch3Ch3
Ch3
 
HTML5 Canvas (Wall Clock).pptx
HTML5 Canvas (Wall Clock).pptxHTML5 Canvas (Wall Clock).pptx
HTML5 Canvas (Wall Clock).pptx
 
ES6 Overview
ES6 OverviewES6 Overview
ES6 Overview
 
The Canvas API for Rubyists
The Canvas API for RubyistsThe Canvas API for Rubyists
The Canvas API for Rubyists
 
130717666736980000
130717666736980000130717666736980000
130717666736980000
 
Exploring Canvas
Exploring CanvasExploring Canvas
Exploring Canvas
 
package chapter15;import javafx.application.Application;import j.pdf
package chapter15;import javafx.application.Application;import j.pdfpackage chapter15;import javafx.application.Application;import j.pdf
package chapter15;import javafx.application.Application;import j.pdf
 
Writing SOLID C++ [gbgcpp meetup @ Zenseact]
Writing SOLID C++ [gbgcpp meetup @ Zenseact]Writing SOLID C++ [gbgcpp meetup @ Zenseact]
Writing SOLID C++ [gbgcpp meetup @ Zenseact]
 

Plus de Jarrod Overson

Practical WebAssembly with Apex, wasmRS, and nanobus
Practical WebAssembly with Apex, wasmRS, and nanobusPractical WebAssembly with Apex, wasmRS, and nanobus
Practical WebAssembly with Apex, wasmRS, and nanobusJarrod Overson
 
AppSecCali - How Credential Stuffing is Evolving
AppSecCali - How Credential Stuffing is EvolvingAppSecCali - How Credential Stuffing is Evolving
AppSecCali - How Credential Stuffing is EvolvingJarrod Overson
 
How Credential Stuffing is Evolving - PasswordsCon 2019
How Credential Stuffing is Evolving - PasswordsCon 2019How Credential Stuffing is Evolving - PasswordsCon 2019
How Credential Stuffing is Evolving - PasswordsCon 2019Jarrod Overson
 
JSconf JP - Analysis of an exploited npm package. Event-stream's role in a su...
JSconf JP - Analysis of an exploited npm package. Event-stream's role in a su...JSconf JP - Analysis of an exploited npm package. Event-stream's role in a su...
JSconf JP - Analysis of an exploited npm package. Event-stream's role in a su...Jarrod Overson
 
Analysis of an OSS supply chain attack - How did 8 millions developers downlo...
Analysis of an OSS supply chain attack - How did 8 millions developers downlo...Analysis of an OSS supply chain attack - How did 8 millions developers downlo...
Analysis of an OSS supply chain attack - How did 8 millions developers downlo...Jarrod Overson
 
Deepfakes - How they work and what it means for the future
Deepfakes - How they work and what it means for the futureDeepfakes - How they work and what it means for the future
Deepfakes - How they work and what it means for the futureJarrod Overson
 
The State of Credential Stuffing and the Future of Account Takeovers.
The State of Credential Stuffing and the Future of Account Takeovers.The State of Credential Stuffing and the Future of Account Takeovers.
The State of Credential Stuffing and the Future of Account Takeovers.Jarrod Overson
 
How to Reverse Engineer Web Applications
How to Reverse Engineer Web ApplicationsHow to Reverse Engineer Web Applications
How to Reverse Engineer Web ApplicationsJarrod Overson
 
The life of breached data and the attack lifecycle
The life of breached data and the attack lifecycleThe life of breached data and the attack lifecycle
The life of breached data and the attack lifecycleJarrod Overson
 
The Life of Breached Data & The Dark Side of Security
The Life of Breached Data & The Dark Side of SecurityThe Life of Breached Data & The Dark Side of Security
The Life of Breached Data & The Dark Side of SecurityJarrod Overson
 
Shape Security @ WaffleJS October 16
Shape Security @ WaffleJS October 16Shape Security @ WaffleJS October 16
Shape Security @ WaffleJS October 16Jarrod Overson
 
The Dark Side of Security
The Dark Side of SecurityThe Dark Side of Security
The Dark Side of SecurityJarrod Overson
 
JavaScript and the AST
JavaScript and the ASTJavaScript and the AST
JavaScript and the ASTJarrod Overson
 
Maintainability SFJS Sept 4 2014
Maintainability SFJS Sept 4 2014 Maintainability SFJS Sept 4 2014
Maintainability SFJS Sept 4 2014 Jarrod Overson
 
Idiot proofing your code
Idiot proofing your codeIdiot proofing your code
Idiot proofing your codeJarrod Overson
 
Riot on the web - Kenote @ QCon Sao Paulo 2014
Riot on the web - Kenote @ QCon Sao Paulo 2014Riot on the web - Kenote @ QCon Sao Paulo 2014
Riot on the web - Kenote @ QCon Sao Paulo 2014Jarrod Overson
 
Managing JavaScript Complexity in Teams - Fluent
Managing JavaScript Complexity in Teams - FluentManaging JavaScript Complexity in Teams - Fluent
Managing JavaScript Complexity in Teams - FluentJarrod Overson
 
Real World Web components
Real World Web componentsReal World Web components
Real World Web componentsJarrod Overson
 
Managing JavaScript Complexity
Managing JavaScript ComplexityManaging JavaScript Complexity
Managing JavaScript ComplexityJarrod Overson
 

Plus de Jarrod Overson (20)

Practical WebAssembly with Apex, wasmRS, and nanobus
Practical WebAssembly with Apex, wasmRS, and nanobusPractical WebAssembly with Apex, wasmRS, and nanobus
Practical WebAssembly with Apex, wasmRS, and nanobus
 
AppSecCali - How Credential Stuffing is Evolving
AppSecCali - How Credential Stuffing is EvolvingAppSecCali - How Credential Stuffing is Evolving
AppSecCali - How Credential Stuffing is Evolving
 
How Credential Stuffing is Evolving - PasswordsCon 2019
How Credential Stuffing is Evolving - PasswordsCon 2019How Credential Stuffing is Evolving - PasswordsCon 2019
How Credential Stuffing is Evolving - PasswordsCon 2019
 
JSconf JP - Analysis of an exploited npm package. Event-stream's role in a su...
JSconf JP - Analysis of an exploited npm package. Event-stream's role in a su...JSconf JP - Analysis of an exploited npm package. Event-stream's role in a su...
JSconf JP - Analysis of an exploited npm package. Event-stream's role in a su...
 
Analysis of an OSS supply chain attack - How did 8 millions developers downlo...
Analysis of an OSS supply chain attack - How did 8 millions developers downlo...Analysis of an OSS supply chain attack - How did 8 millions developers downlo...
Analysis of an OSS supply chain attack - How did 8 millions developers downlo...
 
Deepfakes - How they work and what it means for the future
Deepfakes - How they work and what it means for the futureDeepfakes - How they work and what it means for the future
Deepfakes - How they work and what it means for the future
 
The State of Credential Stuffing and the Future of Account Takeovers.
The State of Credential Stuffing and the Future of Account Takeovers.The State of Credential Stuffing and the Future of Account Takeovers.
The State of Credential Stuffing and the Future of Account Takeovers.
 
How to Reverse Engineer Web Applications
How to Reverse Engineer Web ApplicationsHow to Reverse Engineer Web Applications
How to Reverse Engineer Web Applications
 
The life of breached data and the attack lifecycle
The life of breached data and the attack lifecycleThe life of breached data and the attack lifecycle
The life of breached data and the attack lifecycle
 
The Life of Breached Data & The Dark Side of Security
The Life of Breached Data & The Dark Side of SecurityThe Life of Breached Data & The Dark Side of Security
The Life of Breached Data & The Dark Side of Security
 
Shape Security @ WaffleJS October 16
Shape Security @ WaffleJS October 16Shape Security @ WaffleJS October 16
Shape Security @ WaffleJS October 16
 
The Dark Side of Security
The Dark Side of SecurityThe Dark Side of Security
The Dark Side of Security
 
JavaScript and the AST
JavaScript and the ASTJavaScript and the AST
JavaScript and the AST
 
ES2015 workflows
ES2015 workflowsES2015 workflows
ES2015 workflows
 
Maintainability SFJS Sept 4 2014
Maintainability SFJS Sept 4 2014 Maintainability SFJS Sept 4 2014
Maintainability SFJS Sept 4 2014
 
Idiot proofing your code
Idiot proofing your codeIdiot proofing your code
Idiot proofing your code
 
Riot on the web - Kenote @ QCon Sao Paulo 2014
Riot on the web - Kenote @ QCon Sao Paulo 2014Riot on the web - Kenote @ QCon Sao Paulo 2014
Riot on the web - Kenote @ QCon Sao Paulo 2014
 
Managing JavaScript Complexity in Teams - Fluent
Managing JavaScript Complexity in Teams - FluentManaging JavaScript Complexity in Teams - Fluent
Managing JavaScript Complexity in Teams - Fluent
 
Real World Web components
Real World Web componentsReal World Web components
Real World Web components
 
Managing JavaScript Complexity
Managing JavaScript ComplexityManaging JavaScript Complexity
Managing JavaScript Complexity
 

Dernier

Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 

Dernier (20)

Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 

Graphics Programming for Web Developers

  • 1. Graphics for Web Devs Jarrod Overson - Shape Security @jsoverson
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10. Yes, we're not game developers. But what are you looking for in your applications?
  • 11. • 60 FPS • Beautiful graphics • Responsive Interaction • Smooth animations
  • 12. When I say "video games" think: "performance critical graphic applications"
  • 13. The web is one of the only computer platforms that hasn't grown with video games pushing the edge. Why?
  • 14. 1996
  • 15.
  • 16.
  • 17.
  • 18. The web may not need games. But losing that discipline has handicapped us.
  • 19.
  • 20.
  • 21. So where do we start? <canvas>
  • 24. var context = canvas.getContext('2d'); or "webgl"
  • 26.
  • 27. for (var i = 0; i < 500; i++) { context.fillRect(10 + i, 10 + i, 100, 100); }
  • 28.
  • 29. for (var i = 0; i < 500; i++) { context.clearRect(0, 0, canvas.width, canvas.height); context.fillRect(10 + i, 10 + i, 100, 100); }
  • 30.
  • 32. var i = 0; function draw() { if (i < 500) i++; context.clearRect(0, 0, canvas.width, canvas.height); context.fillRect(i + 10, i + 10, 100, 100); requestAnimationFrame(draw); } draw();
  • 33.
  • 34. var i = 0; function draw() { if (i < 500) i++; context.clearRect(0, 0, canvas.width, canvas.height); context.fillRect(i + 10, i + 10, 100, 100); requestAnimationFrame(draw); } draw(); First we update our state.
  • 35. var i = 0; function draw() { if (i < 500) i++; context.clearRect(0, 0, canvas.width, canvas.height); context.fillRect(i + 10, i + 10, 100, 100); requestAnimationFrame(draw); } draw(); Then we render our current state.
  • 36. var i = 0; function draw() { if (i < 500) i++; context.clearRect(0, 0, canvas.width, canvas.height); context.fillRect(i + 10, i + 10, 100, 100); requestAnimationFrame(draw); } draw(); And we do it all over again.
  • 40. class ParticleSystem { constructor() { this.particles = []; this.emitters = []; } }
  • 41. class Particle { constructor(position, velocity, acceleration) { this.position = position; this.velocity = velocity; this.acceleration = acceleration; } }
  • 42. class Particle { constructor(position, velocity, acceleration) { this.position = position || {x: 0, y: 0}; this.velocity = velocity || {x: 0, y: 0}; this.acceleration = acceleration || {x: 0, y: 0}; } }
  • 43. class Vector { constructor(x, y) { this.x = x || 0; this.y = y || 0; } }
  • 44. class Particle { constructor(position, velocity, acceleration) { this.position = position || new Vector(0, 0); this.velocity = velocity || new Vector(0, 0); this.acceleration = acceleration || new Vector(0, 0); } }
  • 45. class Emitter { constructor(point, velocity) { this.position = point || new Vector(0, 0); this.velocity = velocity || new Vector(0, 0); } }
  • 46. class ParticleSystem { constructor(width, height) { /* …snipped… */ } render(context) { context.clearRect(0, 0, this.width, this.height); this.emitters.forEach(emitter => emitter.render(context)); this.particles.forEach(particle => particle.render(context)); } }
  • 47. class Particle { constructor(position, velocity, acceleration) { /* … */ } render(context) { context.fillStyle = 'red'; context.fillRect(this.position.x, this.position.y, 2, 2); } }
  • 48. var system = new ParticleSystem(width, height); system.emitters.push(new Emitter(new Vector(10, 10))); system.particles.push(new Particle(new Vector(20, 20))); system.particles.push(new Particle(new Vector(10, 20))); system.particles.push(new Particle(new Vector(20, 10))); function loop() { system.render(context); window.requestAnimationFrame(loop); } loop();
  • 49.
  • 50. var system = new ParticleSystem(width, height); system.addEmitter(320, 180); function loop() { system.update(); system.render(context); window.requestAnimationFrame(loop); } loop();
  • 51. class Emitter { constructor(position, velocity) { /* … */ } render(context) { /* … */ } emitParticle() { return new Particle(this.position.clone(), this.velocity.clone()); } }
  • 52. class Particle { constructor(position, velocity, acceleration) { /* … */ } render(context) { /* … */ } update() { this.velocity.add(this.acceleration); this.position.add(this.velocity); } }
  • 53. class ParticleSystem { constructor(width, height) { /* … */ } addEmitter(x, y, velX, velY) { /* … */ } update() { this.emitters.forEach( emitter => this.particles.push(emitter.emitParticle()) ); this.particles = this.particles.filter(particle => { particle.update(); let pos = particle.position; let outOfBounds = pos.x > this.width || pos.y > this.height || pos.x < 0 || pos.y < 0 return !outOfBounds; }) } }
  • 54.
  • 55. emitParticle() { // Define a maximum angle range in radians. let spread = Math.PI / 32; // Use an angle randomized over a spread so we have more of a "spray" var angle = this.velocity.rad() + spread - (Math.random() * spread * 2); // The magnitude of the emitter's velocity var magnitude = this.velocity.length(); // New velocity based off of the calculated angle and magnitude var velocity = Vector.fromAngle(angle, magnitude); // return our new Particle return new Particle(this.position.clone(), velocity); }
  • 56. emitParticle() { // Define a maximum angle range in radians. let spread = Math.PI / 32; // Use an angle randomized over a spread so we have more of a "spray" var angle = this.velocity.rad() + spread - (Math.random() * spread * 2); // The magnitude of the emitter's velocity var magnitude = this.velocity.length(); // New velocity based off of the calculated angle and magnitude var velocity = Vector.fromAngle(angle, magnitude); // return our new Particle return new Particle(this.position.clone(), velocity); }
  • 57. emitParticle() { // Define a maximum angle range in radians. let spread = Math.PI / 32; // Use an angle randomized over a spread so we have more of a "spray" var angle = this.velocity.rad() + spread - (Math.random() * spread * 2); // The magnitude of the emitter's velocity var magnitude = this.velocity.length(); // New velocity based off of the calculated angle and magnitude var velocity = Vector.fromAngle(angle, magnitude); // return our new Particle return new Particle(this.position.clone(), velocity); }
  • 60. - (2 * spread)
  • 61. - (2 * spread) * rand
  • 62. emitParticle() { // Define a maximum angle range in radians. let spread = Math.PI / 32; // Use an angle randomized over a spread so we have more of a "spray" var angle = this.velocity.rad() + spread - (Math.random() * spread * 2); // The magnitude of the emitter's velocity var magnitude = this.velocity.length(); // New velocity based off of the calculated angle and magnitude var velocity = Vector.fromAngle(angle, magnitude); // return our new Particle return new Particle(this.position.clone(), velocity); }
  • 63. emitParticle() { // Define a maximum angle range in radians. let spread = Math.PI / 32; // Use an angle randomized over a spread so we have more of a "spray" var angle = this.velocity.rad() + spread - (Math.random() * spread * 2); // The magnitude of the emitter's velocity var magnitude = this.velocity.length(); // New velocity based off of the calculated angle and magnitude var velocity = Vector.fromAngle(angle, magnitude); // return our new Particle return new Particle(this.position.clone(), velocity); }
  • 64. emitParticle() { // Define a maximum angle range in radians. let spread = Math.PI / 32; // Use an angle randomized over a spread so we have more of a "spray" var angle = this.velocity.rad() + spread - (Math.random() * spread * 2); // The magnitude of the emitter's velocity var magnitude = this.velocity.length(); // New velocity based off of the calculated angle and magnitude var velocity = Vector.fromAngle(angle, magnitude); // return our new Particle return new Particle(this.position.clone(), velocity); }
  • 65.
  • 66.
  • 67.
  • 68. 1. Application state modified and rendered independently. 2. Expensive mutations performed as little as possible. 3. Physics based animations.
  • 69. We're getting there. You can do this now, sort of.
  • 70. var Greets = React.createClass({ getInitialState: function() { return { name: "Portland" }; }, render: function() { return <div>Hello {this.state.name}</div>; } });
  • 71. The virtual DOM is an abstraction that saves you the cost of expensive render-based mutation in a familiar package. It's better, but a virtual DOM is not our application state.
  • 72. While you're exploring JavaScript, explore graphics & games. Go, do neat things with canvas!
  • 73. Maybe you'll find a use for normal mapped backgrounds. http://jsoverson.github.io/texture.js/demo/bricks.html
  • 74. Or maybe you'll use it to understand the bounds of an optical illusion. http://jsoverson.github.io/concentric-circle-illusion/
  • 75. Or maybe you'll make some really awesome games. https://ga.me/games/polycraft (turbulenz.com)
  • 76. Or maybe you'll try… phaser.io
  • 77. Graphics for Web Devs Jarrod Overson - Shape Security @jsoverson