Blog Design Development Mobile Inspiration CSS Javascript News Opinions Politics Menu

Canvas Cheat Sheet

HTML5 Canvas Cheat Sheet
HTML5 Canvas Text Font, Size, and Style Tutorial
HTML5 has brought some exciting new advantages to the HTML coding world. Canvas allows you to render graphics powered by Javascript. So throw away that flash code and dive into Canvas. Here you will find the best tutorials and resources to learn Canvas and other HTML5 aspects.

  • Fitness App Development Essentials
    To create text with HTML5 Canvas, we can use the fillText() method. Text is defined with a string value and a position.
    context.fillText("Hello World!", x, y);
    

    HTML5 Canvas Text Example


    Open in new window
    <!DOCTYPE HTML>
    <html>
    <head>
    <script>
    
    function init() {
    	var canvas=document.getElementById("myCanvas");
    	var context=canvas.getContext("2d");
    
    	var x = 250;
    	var y = 200;
    	context.fillText("Hello World!", x, y);
    }
    
    
    
    <body onload="init()">
    	<canvas id="myCanvas" width="578" height="200">
    
    
    

  • Empowering Developers: Optimizing Global Money Transfers through Coding Mastery

    To crop an image using HTML5 Canvas, we can add six additional arguments to the drawImage() method, sourceX, sourceY, sourceWidth, sourceHeight, destWidth and destHeight.  These arguments define the location and size of a rectangle that we want to cut out of an image.


    Reference: www.whatwg.org


  • The Future of Web Design: How Coding and Webflow Are Revolutionizing Digital Agencies

    To set the size of an image using HTML5 Canvas, we can add two additional arguments to the drawImage() method, width and height.


  • Crafting Tomorrow: The Symbiosis of Content Creation and Artificial Intelligence

    To draw an image using HTML5 Canvas, we can use the drawImage() method which requires an image object and a destination point. The destination point defines the top left corner of the image relative to the top left corner of the canvas.

    Since the drawImage() method requires an image object, we must first create an image and wait for it to load before instantiating drawImage().  We can accomplish this by using the onload property of the image object.


  • The Digital Evolution of Art: From Pixels to Paint and Beyond

    To create an oval using HTML5 Canvas, we can save the context state, stretch the canvas context horizontally, draw a circle, restore the canvas state, and then applying styling.


  • JavaScript Design Lab: Exploring the Intersection of Art and Code

    To create a semicircle with HTML5 Canvas, we can create an arc using the arc() method and define the ending angle has startAngle + PI.


  • Mastering Object-Oriented Programming (OOP) in PHP: Unveiling the Power of Code Reusability and Organization

    To draw a circle with HTML5 Canvas, we can create a full arc using the arc() method by defining the starting angle as 0 and the ending angle as 2 * PI.


  • Which Online Marketing Strategies Are Best For Lead Generation?

    To create a rectangle using HTML5 Canvas, we can use the rect() method rather than constructing the shape with 4 connecting lines.  An HTML5 Canvas rectangle is positioned with x and y parameters, and is sized with width and height parameters.  The rectangle is positioned about its top left corner.


  • The List Of Top 6 Cities To Live And Work As A Programmer

    To create a radial gradient with HTML5 Canvas, we can use the createRadialGradient() method. Radial gradients are defined with two imaginary circles - a starting circle and an ending circle, in which the gradient starts with the start circle and moves towards the end circle.


  • Website development best practices 2023

    To create a linear gradient with HTML5 Canvas, we can use the createLinearGradient() method. Linear gradients are defined by an imaginary line which defines the direction of the gradient. Once we've created our gradient, we can insert colors using the addColorStop property.

    The direction of the linear gradient moves from the starting point to the ending point of the imaginary line defined with createLinearGradient().  In this tutorial, we've used two color stops, a light blue that originates at the starting point of the gradient, and a dark blue that ends with the ending point. Color stops are placed along the imaginary line somewhere between 0 and 1, where 0 is at the starting point, and 1 is at the ending point.