SlideShare ist ein Scribd-Unternehmen logo
1 von 77
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Andere mochten auch

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
 

Andere mochten auch (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
 

Ähnlich wie 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
 

Ähnlich wie 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]
 

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

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
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
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
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 

Kürzlich hochgeladen (20)

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
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 

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