SlideShare a Scribd company logo
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

More Related Content

Viewers also liked

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
Robin Hawkes
 
Molecular Cloning - Vectors: Types & Characteristics
Molecular Cloning -  Vectors: Types & CharacteristicsMolecular Cloning -  Vectors: Types & Characteristics
Molecular Cloning - Vectors: Types & Characteristics
Sruthy 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 World
Rand Fishkin
 
ZIKA - What You Need to Know!
ZIKA - What You Need to Know! ZIKA - What You Need to Know!
ZIKA - What You Need to Know!
Empowered Presentations
 
Inaugural Addresses
Inaugural AddressesInaugural Addresses
Inaugural Addresses
Booz Allen Hamilton
 
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
SlideShare
 
Getting Started With SlideShare
Getting Started With SlideShareGetting Started With SlideShare
Getting Started With SlideShare
SlideShare
 

Viewers also liked (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
 

Similar to 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.pdf
jeeteshmalani1
 
視覚化と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 developer
Andrea Antonello
 
Player x 0 y ga.docx
Player x 0 y ga.docxPlayer x 0 y ga.docx
Player x 0 y ga.docx
mattjtoni51554
 
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
aniyathikitchen
 
Chapter10.pptx
Chapter10.pptxChapter10.pptx
Chapter10.pptx
RahulChaudhary51756
 
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
arihantmobileselepun
 
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
MuhammadTalha436
 
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
aromanets
 
Bindings: the zen of montage
Bindings: the zen of montageBindings: the zen of montage
Bindings: the zen of montage
Kris Kowal
 
Css5 canvas
Css5 canvasCss5 canvas
Css5 canvas
Vadim Spiridenko
 
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
archgeetsenterprises
 
Ch3
Ch3Ch3
HTML5 Canvas (Wall Clock).pptx
HTML5 Canvas (Wall Clock).pptxHTML5 Canvas (Wall Clock).pptx
HTML5 Canvas (Wall Clock).pptx
AhmadAbba6
 
ES6 Overview
ES6 OverviewES6 Overview
ES6 Overview
Bruno Scopelliti
 
The Canvas API for Rubyists
The Canvas API for RubyistsThe Canvas API for Rubyists
The Canvas API for Rubyists
deanhudson
 
130717666736980000
130717666736980000130717666736980000
130717666736980000
Tanzeel Ahmad
 
Exploring Canvas
Exploring CanvasExploring Canvas
Exploring Canvas
Kevin 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.pdf
KARTIKINDIA
 
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
 

Similar to 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]
 

More from 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 nanobus
Jarrod Overson
 
AppSecCali - How Credential Stuffing is Evolving
AppSecCali - How Credential Stuffing is EvolvingAppSecCali - How Credential Stuffing is Evolving
AppSecCali - How Credential Stuffing is Evolving
Jarrod 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 2019
Jarrod 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 future
Jarrod 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 Applications
Jarrod 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 lifecycle
Jarrod 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 Security
Jarrod Overson
 
Shape Security @ WaffleJS October 16
Shape Security @ WaffleJS October 16Shape Security @ WaffleJS October 16
Shape Security @ WaffleJS October 16
Jarrod Overson
 
The Dark Side of Security
The Dark Side of SecurityThe Dark Side of Security
The Dark Side of Security
Jarrod Overson
 
JavaScript and the AST
JavaScript and the ASTJavaScript and the AST
JavaScript and the AST
Jarrod Overson
 
ES2015 workflows
ES2015 workflowsES2015 workflows
ES2015 workflows
Jarrod 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 code
Jarrod 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 2014
Jarrod Overson
 
Managing JavaScript Complexity in Teams - Fluent
Managing JavaScript Complexity in Teams - FluentManaging JavaScript Complexity in Teams - Fluent
Managing JavaScript Complexity in Teams - Fluent
Jarrod Overson
 
Real World Web components
Real World Web componentsReal World Web components
Real World Web components
Jarrod Overson
 
Managing JavaScript Complexity
Managing JavaScript ComplexityManaging JavaScript Complexity
Managing JavaScript Complexity
Jarrod Overson
 

More from 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
 

Recently uploaded

Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
Apps Break Data
Apps Break DataApps Break Data
Apps Break Data
Ivo Velitchkov
 
High performance Serverless Java on AWS- GoTo Amsterdam 2024
High performance Serverless Java on AWS- GoTo Amsterdam 2024High performance Serverless Java on AWS- GoTo Amsterdam 2024
High performance Serverless Java on AWS- GoTo Amsterdam 2024
Vadym Kazulkin
 
AppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSFAppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSF
Ajin Abraham
 
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptxPRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
christinelarrosa
 
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
Fwdays
 
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge GraphGraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
Neo4j
 
Mutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented ChatbotsMutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented Chatbots
Pablo Gómez Abajo
 
Essentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation ParametersEssentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation Parameters
Safe Software
 
Harnessing the Power of NLP and Knowledge Graphs for Opioid Research
Harnessing the Power of NLP and Knowledge Graphs for Opioid ResearchHarnessing the Power of NLP and Knowledge Graphs for Opioid Research
Harnessing the Power of NLP and Knowledge Graphs for Opioid Research
Neo4j
 
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
Edge AI and Vision Alliance
 
Poznań ACE event - 19.06.2024 Team 24 Wrapup slidedeck
Poznań ACE event - 19.06.2024 Team 24 Wrapup slidedeckPoznań ACE event - 19.06.2024 Team 24 Wrapup slidedeck
Poznań ACE event - 19.06.2024 Team 24 Wrapup slidedeck
FilipTomaszewski5
 
What is an RPA CoE? Session 2 – CoE Roles
What is an RPA CoE?  Session 2 – CoE RolesWhat is an RPA CoE?  Session 2 – CoE Roles
What is an RPA CoE? Session 2 – CoE Roles
DianaGray10
 
Y-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PPY-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PP
c5vrf27qcz
 
"What does it really mean for your system to be available, or how to define w...
"What does it really mean for your system to be available, or how to define w..."What does it really mean for your system to be available, or how to define w...
"What does it really mean for your system to be available, or how to define w...
Fwdays
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
Neo4j
 
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Neo4j
 
"Scaling RAG Applications to serve millions of users", Kevin Goedecke
"Scaling RAG Applications to serve millions of users",  Kevin Goedecke"Scaling RAG Applications to serve millions of users",  Kevin Goedecke
"Scaling RAG Applications to serve millions of users", Kevin Goedecke
Fwdays
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
AstuteBusiness
 
Demystifying Knowledge Management through Storytelling
Demystifying Knowledge Management through StorytellingDemystifying Knowledge Management through Storytelling
Demystifying Knowledge Management through Storytelling
Enterprise Knowledge
 

Recently uploaded (20)

Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
Apps Break Data
Apps Break DataApps Break Data
Apps Break Data
 
High performance Serverless Java on AWS- GoTo Amsterdam 2024
High performance Serverless Java on AWS- GoTo Amsterdam 2024High performance Serverless Java on AWS- GoTo Amsterdam 2024
High performance Serverless Java on AWS- GoTo Amsterdam 2024
 
AppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSFAppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSF
 
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptxPRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
PRODUCT LISTING OPTIMIZATION PRESENTATION.pptx
 
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
 
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge GraphGraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
 
Mutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented ChatbotsMutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented Chatbots
 
Essentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation ParametersEssentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation Parameters
 
Harnessing the Power of NLP and Knowledge Graphs for Opioid Research
Harnessing the Power of NLP and Knowledge Graphs for Opioid ResearchHarnessing the Power of NLP and Knowledge Graphs for Opioid Research
Harnessing the Power of NLP and Knowledge Graphs for Opioid Research
 
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
 
Poznań ACE event - 19.06.2024 Team 24 Wrapup slidedeck
Poznań ACE event - 19.06.2024 Team 24 Wrapup slidedeckPoznań ACE event - 19.06.2024 Team 24 Wrapup slidedeck
Poznań ACE event - 19.06.2024 Team 24 Wrapup slidedeck
 
What is an RPA CoE? Session 2 – CoE Roles
What is an RPA CoE?  Session 2 – CoE RolesWhat is an RPA CoE?  Session 2 – CoE Roles
What is an RPA CoE? Session 2 – CoE Roles
 
Y-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PPY-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PP
 
"What does it really mean for your system to be available, or how to define w...
"What does it really mean for your system to be available, or how to define w..."What does it really mean for your system to be available, or how to define w...
"What does it really mean for your system to be available, or how to define w...
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
 
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
 
"Scaling RAG Applications to serve millions of users", Kevin Goedecke
"Scaling RAG Applications to serve millions of users",  Kevin Goedecke"Scaling RAG Applications to serve millions of users",  Kevin Goedecke
"Scaling RAG Applications to serve millions of users", Kevin Goedecke
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
 
Demystifying Knowledge Management through Storytelling
Demystifying Knowledge Management through StorytellingDemystifying Knowledge Management through Storytelling
Demystifying Knowledge Management through Storytelling
 

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