SlideShare ist ein Scribd-Unternehmen logo
1 von 38
Downloaden Sie, um offline zu lesen
Drawing Circles Three Ways:
Generating Graphics for the
Web
Amy Cheng

Web Developer, New York Magazine
Hello! My name is Amy Cheng.
• Web Developer for New York Magazine
2
What do we mean by
“creating graphics for the web?”
• Using code to create visual elements on a web page
3
The History of Creating Graphics on the Web
• Proprietary software like Macromedia Flash/Director
• Third-party plugins
4
The Present!
• native browser apis
• CSS, SVG, <canvas>/JS
5
CSS Circles
• DOM element (most likely a <div>)
• border-radius
6
7
8
<style>
.css-circle {
background-color: red;
border-radius: 50%;
height: 100px;
width: 100px;
}
</style>
9
<div class="css-circle"></div>
10
<div class="css-circle animate"></div>
11
12
<style>
@keyframes position {
0%, 100% {
margin-left: 0;
}
50% {
margin-left: calc(100% - 100px);
}
}
.animate {
animation: position 5s infinite;
}
…
CSS Pros
• scales and responsive (when using relative units)
• in-between frames
13
14
<style>
.css-circle {
background-color: red;
border-radius: 50%;
height: 100px;
width: 100px;
}
</style>
CSS Cons
• hacky
• not a good mental model "does a circle have a border?"
• content less DOM element
15
SVG Circles
• DOM element (<svg>)
• can be an embedded file or inlined XML!
• <circle>
16
17
18
<svg height="100" width="100">
<circle cx="50" cy="50" r="50" stroke-width="3" fill="red" />
</svg>
19
<svg class="animate" height="100" width="100">
<circle cx="50" cy="50" r="50" stroke-width="3" fill="red" />
</svg>
20
SVG Pros
• scales and responsive (when using relative units)
• accessible API
• XML can be exported from third-party software (Adobe
Illustrator)
21
SVG Cons
• animation is not a native SVG api
• bloated mark-up
22
<canvas> Circles
• <canvas></canvas> + JavaScript
23
24
25
<script type="text/javascript">
function staticCircle(){
var c=document.getElementById('static-canvas-circle'),
ctx = c.getContext("2d");
ctx.beginPath();
ctx.arc(50,50,50,0,2*Math.PI);
ctx.strokeStyle="red";
ctx.stroke();
ctx.fillStyle = "red";
ctx.fill();
}
26
var posX = 50, direction = 1;
…
ctx.clearRect(0, 0, 800, 105); // clear canvas
ctx.fillStyle = 'white';
ctx.strokeStyle = 'whte';
…
ctx.arc(posX,50,50,0,2*Math.PI);
…
if(posX > 800) {
direction = -1;
}
if(posX < 0) {
direction = 1;
}
posX = posX + direction;
window.requestAnimationFrame(animatedCircle);
}
27
<canvas> Cons
• code is verbose
• when we think of circles, do we usually see them as arcs?
• bitmap graphics
• there is no tween default
28
<canvas> Pros
• use JavaScript for complex behaviors
29
30
Wrapping it all together
• Are you creating user interfaces?
• Are you creating data visualizations?
• Are you creating animations?
• Is performance a concern?
31
32
33
34
35
36
An opportunity for collaboration!
• Data scientists
• Visual Designer
• Motion Graphics
37
Thanks!
38
amy (at) amycheng.info

Weitere ähnliche Inhalte

Ähnlich wie Drawing a Circle Three Ways: Generating Graphics for the Web

Илья Пухальский (EPAM Systems)
Илья Пухальский (EPAM Systems)Илья Пухальский (EPAM Systems)
Илья Пухальский (EPAM Systems)
Ontico
 
How to build a html5 websites.v1
How to build a html5 websites.v1How to build a html5 websites.v1
How to build a html5 websites.v1
Bitla Software
 

Ähnlich wie Drawing a Circle Three Ways: Generating Graphics for the Web (20)

Thats Not Flash?
Thats Not Flash?Thats Not Flash?
Thats Not Flash?
 
CSS3 Takes on the World
CSS3 Takes on the WorldCSS3 Takes on the World
CSS3 Takes on the World
 
SVG overview
SVG overviewSVG overview
SVG overview
 
Flash Camp - Degrafa & FXG
Flash Camp - Degrafa & FXGFlash Camp - Degrafa & FXG
Flash Camp - Degrafa & FXG
 
Svcc 2013-d3
Svcc 2013-d3Svcc 2013-d3
Svcc 2013-d3
 
SVCC 2013 D3.js Presentation (10/05/2013)
SVCC 2013 D3.js Presentation (10/05/2013)SVCC 2013 D3.js Presentation (10/05/2013)
SVCC 2013 D3.js Presentation (10/05/2013)
 
Creating dynamic SVG elements in JavaScript
Creating dynamic SVG elements in JavaScriptCreating dynamic SVG elements in JavaScript
Creating dynamic SVG elements in JavaScript
 
I Can't Believe It's Not Flash
I Can't Believe It's Not FlashI Can't Believe It's Not Flash
I Can't Believe It's Not Flash
 
GOTO Berlin - You can use CSS for that
GOTO Berlin - You can use CSS for thatGOTO Berlin - You can use CSS for that
GOTO Berlin - You can use CSS for that
 
Илья Пухальский (EPAM Systems)
Илья Пухальский (EPAM Systems)Илья Пухальский (EPAM Systems)
Илья Пухальский (EPAM Systems)
 
Images meet Web
Images meet WebImages meet Web
Images meet Web
 
IE9에서 HTML5 개발하기
IE9에서 HTML5 개발하기IE9에서 HTML5 개발하기
IE9에서 HTML5 개발하기
 
STC Summit 2015 Hypergraphics for visual-first help
STC Summit 2015 Hypergraphics for visual-first helpSTC Summit 2015 Hypergraphics for visual-first help
STC Summit 2015 Hypergraphics for visual-first help
 
Biological Modeling, Powered by AngularJS
Biological Modeling, Powered by AngularJSBiological Modeling, Powered by AngularJS
Biological Modeling, Powered by AngularJS
 
CSS and CSS3
CSS and CSS3CSS and CSS3
CSS and CSS3
 
SVG (Devoxx 2011, 2011-NOV-14)
SVG (Devoxx 2011, 2011-NOV-14)SVG (Devoxx 2011, 2011-NOV-14)
SVG (Devoxx 2011, 2011-NOV-14)
 
SVG, CSS3, and D3 for Beginners
SVG, CSS3, and D3 for BeginnersSVG, CSS3, and D3 for Beginners
SVG, CSS3, and D3 for Beginners
 
How to build a html5 websites.v1
How to build a html5 websites.v1How to build a html5 websites.v1
How to build a html5 websites.v1
 
Setting the Stage for SVG Animation
Setting the Stage for SVG AnimationSetting the Stage for SVG Animation
Setting the Stage for SVG Animation
 
JavaONE 2012 Using Java with HTML5 and CSS3
JavaONE 2012 Using Java with HTML5 and CSS3JavaONE 2012 Using Java with HTML5 and CSS3
JavaONE 2012 Using Java with HTML5 and CSS3
 

Mehr von Cloudinary

Mehr von Cloudinary (15)

Imagecon 2019 - Jon Sneyers
Imagecon 2019 - Jon Sneyers Imagecon 2019 - Jon Sneyers
Imagecon 2019 - Jon Sneyers
 
Imagecon 2019 - Jen Looper
Imagecon 2019 - Jen LooperImagecon 2019 - Jen Looper
Imagecon 2019 - Jen Looper
 
Imagecon 2019 - Aaron Gustafson
Imagecon 2019 - Aaron GustafsonImagecon 2019 - Aaron Gustafson
Imagecon 2019 - Aaron Gustafson
 
Imagecon 2019 - Amy Balliett
Imagecon 2019 - Amy BalliettImagecon 2019 - Amy Balliett
Imagecon 2019 - Amy Balliett
 
Imagecon Itai
Imagecon ItaiImagecon Itai
Imagecon Itai
 
ImageCon CTO keynote
ImageCon CTO keynoteImageCon CTO keynote
ImageCon CTO keynote
 
ImageCon keynote product
ImageCon keynote productImageCon keynote product
ImageCon keynote product
 
Images For Everyone
Images For EveryoneImages For Everyone
Images For Everyone
 
Beyond Resizing: The Image Performance Checklist
Beyond Resizing: The Image Performance ChecklistBeyond Resizing: The Image Performance Checklist
Beyond Resizing: The Image Performance Checklist
 
Moving Metrics with Better Mobile Images
Moving Metrics with Better Mobile ImagesMoving Metrics with Better Mobile Images
Moving Metrics with Better Mobile Images
 
Images in the Era of the Algorithm
Images in the Era of the AlgorithmImages in the Era of the Algorithm
Images in the Era of the Algorithm
 
Media Processing Workflows using AWS Step Functions and Machine Learning on A...
Media Processing Workflows using AWS Step Functions and Machine Learning on A...Media Processing Workflows using AWS Step Functions and Machine Learning on A...
Media Processing Workflows using AWS Step Functions and Machine Learning on A...
 
The Physics of Fast Image Compression
The Physics of Fast Image CompressionThe Physics of Fast Image Compression
The Physics of Fast Image Compression
 
Delivering Responsive Images
Delivering Responsive Images Delivering Responsive Images
Delivering Responsive Images
 
Measuring Image Performance
Measuring Image PerformanceMeasuring Image Performance
Measuring Image Performance
 

Kürzlich hochgeladen

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Kürzlich hochgeladen (20)

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
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
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
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
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...
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
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
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
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
 

Drawing a Circle Three Ways: Generating Graphics for the Web