SlideShare ist ein Scribd-Unternehmen logo
1 von 25
By : Samuel Santos | email : thiagsamuel@gmail.com
Blog : http://samueltcsantos.blogspot.com
The canvas drawing API
Canvas
• In the real world things exist in space. In the
HTML5 world the equivalent is that objects
exist on the canvas element.
The canvas coordinate system
• To know how to position objects on canvas,
it is necessary to understand the canvas
coordinate system.
The canvas coordinate system
• The canvas coordinate system is
somewhat different from the usual
Cartesian system of coordinates in math.
The canvas coordinate system
The canvas coordinate system
• Another oddity in the canvas coordinate
system is that angles are measured in a
clockwise sense from the direction of
the positive x-axis
The canvas coordinate system
The canvas drawing API
• The canvas drawing application
programming interface (API) allows you to
draw things such as shapes and fills using
JavaScript.
The canvas context
• The object that allows access to the
canvas drawing API is the canvas
rendering context.
The canvas context
• The API is nothing but a collection of
properties and methods of that
object.
The canvas context
• how to access the canvas context:
var canvas = document.getElementById('canvas');
var context = canvas.getContext('2d');
Drawing lines and curves
• The following are a few essential
properties and methods of the canvas
context for drawing basic shapes using
lines and curves.
Drawing lines and curves
• The strokeStyle property specifies the line
color in CSS-style format.
• The default value is '#000000' (black).
context.strokeStyle = '#0000ff';
Drawing lines and curves
• The lineWidth property specifies the line
thickness in pixels. The default value is 1.
context.lineWidth = 2;
Drawing lines and curves
• The beginPath() method resets the current
path. A path is a collection of subpaths.
• Each subpath is a set of points connected
by straight or curved lines.
context.beginPath() ;
Drawing lines and curves
• The closePath() method closes the current
subpath and starts a new one from the
end of the closed subpath.
context.closePath() ;
Drawing lines and curves
• The moveTo(x, y) method moves the cursor
to the specified location (x, y) without
drawing anything, that is, it creates a new
subpath from the specified point.
context.moveTo(x,y) ;
Drawing lines and curves
• The lineTo(x, y) method draws a straight
line from the current location to the new
location (x, y) , that is, it adds a new point to
a subpath and connects that point to the
previous point in the subpath with a straight
line.
context.lineTo(x,y) ;
Drawing lines and curves
• The arc (x, y, radius, startAngle, endAngle,
anticlockwise) method adds an arc to the
path with center (x, y), and of the specified
radius. The starting and ending angles are in
radians. The anticlockwise parameter is a
boolean: if true, the arc is drawn in a
counterclockwise direction; if false, it is drawn
in a clockwise direction.
context.arc(x, y, radius, startAngle, endAngle, anticlockwise);
Drawing lines and curves
• The rect(x, y, w, h) method creates a new
closed rectangular subpath with the upper-
left corner at (x, y) and width w and height h.
context.rect(x, y, w, h);
Drawing lines and curves
• The strokeRect(x, y, w, h) method
combines the last two methods to
render an outline of the specified
rectangle.
context.stroke Rect(x,y,w,h);
Drawing lines and curves
• The stroke() method renders the current
subpath using the current stroke styles.
context.stroke ();
Creating fills
• The fillStyle property gets or sets the style
for filling shapes. It can be a color or a
gradient.
context.fillStyle = ‘#333’;
Creating fills
• The fill() method fills subpaths using the
current fill style.
context.fill();
Creating fills
• The fillRect(x, y, w, h) method creates a filled
rectangle with the upper-left corner at (x, y)
and width w and height h, using the
current fill style.
context. fillRect(x, y, w, h) ;

Weitere ähnliche Inhalte

Was ist angesagt?

Lesson 11 Isometric Projection - Part I
Lesson 11 Isometric Projection - Part ILesson 11 Isometric Projection - Part I
Lesson 11 Isometric Projection - Part IJeyapoovan Thangasamy
 
Various types of surfaces 131044119001
Various types of surfaces 131044119001Various types of surfaces 131044119001
Various types of surfaces 131044119001rockrakos
 
Html5 Canvas Drawing and Animation
Html5 Canvas Drawing and AnimationHtml5 Canvas Drawing and Animation
Html5 Canvas Drawing and AnimationMindfire Solutions
 
Writeup advanced lane_lines_project
Writeup advanced lane_lines_projectWriteup advanced lane_lines_project
Writeup advanced lane_lines_projectManish Jauhari
 
CAD/CAM & Automation Unit I computer graphics
CAD/CAM & Automation Unit I computer graphicsCAD/CAM & Automation Unit I computer graphics
CAD/CAM & Automation Unit I computer graphicsAniket Joshi
 
Engineering graphics model paper
Engineering graphics model paperEngineering graphics model paper
Engineering graphics model papervipul m goti
 
Chapter11 1
Chapter11 1Chapter11 1
Chapter11 1pandysp
 
Steps in constructing an isometric drawing
Steps in constructing an isometric drawingSteps in constructing an isometric drawing
Steps in constructing an isometric drawingRodolfo Aquino
 
Invariant Generalised Hough Transform
Invariant Generalised Hough TransformInvariant Generalised Hough Transform
Invariant Generalised Hough TransformShashank Dhariwal
 
3D Transformation in Computer Graphics
3D Transformation in Computer Graphics3D Transformation in Computer Graphics
3D Transformation in Computer Graphicssabbirantor
 
Isometric projections
Isometric projectionsIsometric projections
Isometric projectionssushma chinta
 
Bezier Curve and Spline Curve
Bezier Curve and Spline CurveBezier Curve and Spline Curve
Bezier Curve and Spline CurveAsifShahariar1
 
isometric drawing (Chapter )
isometric drawing (Chapter )isometric drawing (Chapter )
isometric drawing (Chapter )Junea June
 
Computer Vision - Single View
Computer Vision - Single ViewComputer Vision - Single View
Computer Vision - Single ViewWael Badawy
 
PGL (Persamaan Garis Dari Gambar Garis Lurus & Dari Dua Titik) - Pertemuan 1
PGL (Persamaan Garis Dari Gambar Garis Lurus & Dari Dua Titik) - Pertemuan 1PGL (Persamaan Garis Dari Gambar Garis Lurus & Dari Dua Titik) - Pertemuan 1
PGL (Persamaan Garis Dari Gambar Garis Lurus & Dari Dua Titik) - Pertemuan 1Shinta Novianti
 

Was ist angesagt? (19)

Lesson 11 Isometric Projection - Part I
Lesson 11 Isometric Projection - Part ILesson 11 Isometric Projection - Part I
Lesson 11 Isometric Projection - Part I
 
Various types of surfaces 131044119001
Various types of surfaces 131044119001Various types of surfaces 131044119001
Various types of surfaces 131044119001
 
Html5 Canvas Drawing and Animation
Html5 Canvas Drawing and AnimationHtml5 Canvas Drawing and Animation
Html5 Canvas Drawing and Animation
 
Writeup advanced lane_lines_project
Writeup advanced lane_lines_projectWriteup advanced lane_lines_project
Writeup advanced lane_lines_project
 
Ge2111 ENGINEERING GRAPHICS
Ge2111 ENGINEERING GRAPHICSGe2111 ENGINEERING GRAPHICS
Ge2111 ENGINEERING GRAPHICS
 
Cap.7
Cap.7Cap.7
Cap.7
 
CAD/CAM & Automation Unit I computer graphics
CAD/CAM & Automation Unit I computer graphicsCAD/CAM & Automation Unit I computer graphics
CAD/CAM & Automation Unit I computer graphics
 
Engineering graphics model paper
Engineering graphics model paperEngineering graphics model paper
Engineering graphics model paper
 
Oblique parallel projection
Oblique parallel projectionOblique parallel projection
Oblique parallel projection
 
Chapter11 1
Chapter11 1Chapter11 1
Chapter11 1
 
Steps in constructing an isometric drawing
Steps in constructing an isometric drawingSteps in constructing an isometric drawing
Steps in constructing an isometric drawing
 
Invariant Generalised Hough Transform
Invariant Generalised Hough TransformInvariant Generalised Hough Transform
Invariant Generalised Hough Transform
 
3D Transformation in Computer Graphics
3D Transformation in Computer Graphics3D Transformation in Computer Graphics
3D Transformation in Computer Graphics
 
Isometric projections
Isometric projectionsIsometric projections
Isometric projections
 
Bezier Curve and Spline Curve
Bezier Curve and Spline CurveBezier Curve and Spline Curve
Bezier Curve and Spline Curve
 
isometric drawing (Chapter )
isometric drawing (Chapter )isometric drawing (Chapter )
isometric drawing (Chapter )
 
Computer Vision - Single View
Computer Vision - Single ViewComputer Vision - Single View
Computer Vision - Single View
 
viewing3d pipeline
viewing3d pipelineviewing3d pipeline
viewing3d pipeline
 
PGL (Persamaan Garis Dari Gambar Garis Lurus & Dari Dua Titik) - Pertemuan 1
PGL (Persamaan Garis Dari Gambar Garis Lurus & Dari Dua Titik) - Pertemuan 1PGL (Persamaan Garis Dari Gambar Garis Lurus & Dari Dua Titik) - Pertemuan 1
PGL (Persamaan Garis Dari Gambar Garis Lurus & Dari Dua Titik) - Pertemuan 1
 

Ähnlich wie Javascript Canvas API

HTML5 Canvas - Basics.pptx
HTML5 Canvas - Basics.pptxHTML5 Canvas - Basics.pptx
HTML5 Canvas - Basics.pptxAhmadAbba6
 
Html5 canvas
Html5 canvasHtml5 canvas
Html5 canvasGary Yeh
 
Digital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing AlgorithmDigital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing AlgorithmKasun Ranga Wijeweera
 
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
 
Lec02 03 rasterization
Lec02 03 rasterizationLec02 03 rasterization
Lec02 03 rasterizationMaaz Rizwan
 
Lec02 03 rasterization
Lec02 03 rasterizationLec02 03 rasterization
Lec02 03 rasterizationMaaz Rizwan
 
Fundamentals of Multimedia - Vector Graphics.pdf
Fundamentals of Multimedia - Vector Graphics.pdfFundamentals of Multimedia - Vector Graphics.pdf
Fundamentals of Multimedia - Vector Graphics.pdfFatihahIrra
 
Computer Graphics in Java and Scala - Part 1
Computer Graphics in Java and Scala - Part 1Computer Graphics in Java and Scala - Part 1
Computer Graphics in Java and Scala - Part 1Philip Schwarz
 
Basic Graphics in Java
Basic Graphics in JavaBasic Graphics in Java
Basic Graphics in JavaPrakash Kumar
 
Lectures r-graphics
Lectures r-graphicsLectures r-graphics
Lectures r-graphicsetyca
 
Kulum alin-11 jan2014
Kulum alin-11 jan2014Kulum alin-11 jan2014
Kulum alin-11 jan2014rolly purnomo
 
Line Detection using Hough transform .pptx
Line Detection using Hough transform .pptxLine Detection using Hough transform .pptx
Line Detection using Hough transform .pptxshubham loni
 
Introduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User GroupIntroduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User Groupdreambreeze
 
Introduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User GroupIntroduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User Groupbernice-chan
 

Ähnlich wie Javascript Canvas API (20)

canvas_1.pptx
canvas_1.pptxcanvas_1.pptx
canvas_1.pptx
 
canvas.pptx
canvas.pptxcanvas.pptx
canvas.pptx
 
HTML5 Canvas - Basics.pptx
HTML5 Canvas - Basics.pptxHTML5 Canvas - Basics.pptx
HTML5 Canvas - Basics.pptx
 
Html5 canvas
Html5 canvasHtml5 canvas
Html5 canvas
 
HTML5 Canvas
HTML5 CanvasHTML5 Canvas
HTML5 Canvas
 
Digital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing AlgorithmDigital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing Algorithm
 
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
 
Lec02 03 rasterization
Lec02 03 rasterizationLec02 03 rasterization
Lec02 03 rasterization
 
Lec02 03 rasterization
Lec02 03 rasterizationLec02 03 rasterization
Lec02 03 rasterization
 
Fundamentals of Multimedia - Vector Graphics.pdf
Fundamentals of Multimedia - Vector Graphics.pdfFundamentals of Multimedia - Vector Graphics.pdf
Fundamentals of Multimedia - Vector Graphics.pdf
 
Chapter 13
Chapter 13Chapter 13
Chapter 13
 
HTML 5 Canvas & SVG
HTML 5 Canvas & SVGHTML 5 Canvas & SVG
HTML 5 Canvas & SVG
 
Computer Graphics in Java and Scala - Part 1
Computer Graphics in Java and Scala - Part 1Computer Graphics in Java and Scala - Part 1
Computer Graphics in Java and Scala - Part 1
 
MATLAB PLOT.pdf
MATLAB PLOT.pdfMATLAB PLOT.pdf
MATLAB PLOT.pdf
 
Basic Graphics in Java
Basic Graphics in JavaBasic Graphics in Java
Basic Graphics in Java
 
Lectures r-graphics
Lectures r-graphicsLectures r-graphics
Lectures r-graphics
 
Kulum alin-11 jan2014
Kulum alin-11 jan2014Kulum alin-11 jan2014
Kulum alin-11 jan2014
 
Line Detection using Hough transform .pptx
Line Detection using Hough transform .pptxLine Detection using Hough transform .pptx
Line Detection using Hough transform .pptx
 
Introduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User GroupIntroduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User Group
 
Introduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User GroupIntroduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User Group
 

Mehr von Samuel Santos

Javascript - Numbers
Javascript   - NumbersJavascript   - Numbers
Javascript - NumbersSamuel Santos
 
Javascript - Arrays - mutator functions
Javascript  - Arrays - mutator functionsJavascript  - Arrays - mutator functions
Javascript - Arrays - mutator functionsSamuel Santos
 
Javascript - Arrays - accessor functions
Javascript   - Arrays - accessor functionsJavascript   - Arrays - accessor functions
Javascript - Arrays - accessor functionsSamuel Santos
 
Javascript - Array - Writing
Javascript - Array - WritingJavascript - Array - Writing
Javascript - Array - WritingSamuel Santos
 
Javascript - Array - Creating Array
Javascript - Array - Creating ArrayJavascript - Array - Creating Array
Javascript - Array - Creating ArraySamuel Santos
 
Javascript - Arithmetic in Javascript
Javascript - Arithmetic in JavascriptJavascript - Arithmetic in Javascript
Javascript - Arithmetic in JavascriptSamuel Santos
 
Javascript ADT - List
Javascript   ADT - ListJavascript   ADT - List
Javascript ADT - ListSamuel Santos
 
Javascript - ADT - List - Implementation
Javascript - ADT -  List - ImplementationJavascript - ADT -  List - Implementation
Javascript - ADT - List - ImplementationSamuel Santos
 

Mehr von Samuel Santos (11)

Javascript stack
Javascript   stackJavascript   stack
Javascript stack
 
Javascript - Numbers
Javascript   - NumbersJavascript   - Numbers
Javascript - Numbers
 
Javascript - Arrays - mutator functions
Javascript  - Arrays - mutator functionsJavascript  - Arrays - mutator functions
Javascript - Arrays - mutator functions
 
Javascript - Arrays - accessor functions
Javascript   - Arrays - accessor functionsJavascript   - Arrays - accessor functions
Javascript - Arrays - accessor functions
 
Javascript - Array - Writing
Javascript - Array - WritingJavascript - Array - Writing
Javascript - Array - Writing
 
Javascript - Array - Creating Array
Javascript - Array - Creating ArrayJavascript - Array - Creating Array
Javascript - Array - Creating Array
 
Javascript - Arithmetic in Javascript
Javascript - Arithmetic in JavascriptJavascript - Arithmetic in Javascript
Javascript - Arithmetic in Javascript
 
Javascript ADT - List
Javascript   ADT - ListJavascript   ADT - List
Javascript ADT - List
 
Javascript - ADT - List - Implementation
Javascript - ADT -  List - ImplementationJavascript - ADT -  List - Implementation
Javascript - ADT - List - Implementation
 
Variables
VariablesVariables
Variables
 
Java Stack (Pilha)
Java Stack (Pilha)Java Stack (Pilha)
Java Stack (Pilha)
 

Kürzlich hochgeladen

Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 

Kürzlich hochgeladen (20)

Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 

Javascript Canvas API

  • 1. By : Samuel Santos | email : thiagsamuel@gmail.com Blog : http://samueltcsantos.blogspot.com The canvas drawing API
  • 2. Canvas • In the real world things exist in space. In the HTML5 world the equivalent is that objects exist on the canvas element.
  • 3. The canvas coordinate system • To know how to position objects on canvas, it is necessary to understand the canvas coordinate system.
  • 4. The canvas coordinate system • The canvas coordinate system is somewhat different from the usual Cartesian system of coordinates in math.
  • 6. The canvas coordinate system • Another oddity in the canvas coordinate system is that angles are measured in a clockwise sense from the direction of the positive x-axis
  • 8. The canvas drawing API • The canvas drawing application programming interface (API) allows you to draw things such as shapes and fills using JavaScript.
  • 9. The canvas context • The object that allows access to the canvas drawing API is the canvas rendering context.
  • 10. The canvas context • The API is nothing but a collection of properties and methods of that object.
  • 11. The canvas context • how to access the canvas context: var canvas = document.getElementById('canvas'); var context = canvas.getContext('2d');
  • 12. Drawing lines and curves • The following are a few essential properties and methods of the canvas context for drawing basic shapes using lines and curves.
  • 13. Drawing lines and curves • The strokeStyle property specifies the line color in CSS-style format. • The default value is '#000000' (black). context.strokeStyle = '#0000ff';
  • 14. Drawing lines and curves • The lineWidth property specifies the line thickness in pixels. The default value is 1. context.lineWidth = 2;
  • 15. Drawing lines and curves • The beginPath() method resets the current path. A path is a collection of subpaths. • Each subpath is a set of points connected by straight or curved lines. context.beginPath() ;
  • 16. Drawing lines and curves • The closePath() method closes the current subpath and starts a new one from the end of the closed subpath. context.closePath() ;
  • 17. Drawing lines and curves • The moveTo(x, y) method moves the cursor to the specified location (x, y) without drawing anything, that is, it creates a new subpath from the specified point. context.moveTo(x,y) ;
  • 18. Drawing lines and curves • The lineTo(x, y) method draws a straight line from the current location to the new location (x, y) , that is, it adds a new point to a subpath and connects that point to the previous point in the subpath with a straight line. context.lineTo(x,y) ;
  • 19. Drawing lines and curves • The arc (x, y, radius, startAngle, endAngle, anticlockwise) method adds an arc to the path with center (x, y), and of the specified radius. The starting and ending angles are in radians. The anticlockwise parameter is a boolean: if true, the arc is drawn in a counterclockwise direction; if false, it is drawn in a clockwise direction. context.arc(x, y, radius, startAngle, endAngle, anticlockwise);
  • 20. Drawing lines and curves • The rect(x, y, w, h) method creates a new closed rectangular subpath with the upper- left corner at (x, y) and width w and height h. context.rect(x, y, w, h);
  • 21. Drawing lines and curves • The strokeRect(x, y, w, h) method combines the last two methods to render an outline of the specified rectangle. context.stroke Rect(x,y,w,h);
  • 22. Drawing lines and curves • The stroke() method renders the current subpath using the current stroke styles. context.stroke ();
  • 23. Creating fills • The fillStyle property gets or sets the style for filling shapes. It can be a color or a gradient. context.fillStyle = ‘#333’;
  • 24. Creating fills • The fill() method fills subpaths using the current fill style. context.fill();
  • 25. Creating fills • The fillRect(x, y, w, h) method creates a filled rectangle with the upper-left corner at (x, y) and width w and height h, using the current fill style. context. fillRect(x, y, w, h) ;