Canvas - GunnarThorunnarson/FORR3JS05DU GitHub Wiki

Canvas sýnidæmi

<!DOCTYPE html>
<html>
<head>
    <meta charset='utf-8'>
    <title>Canvas sýnidæmi</title>
    <meta name='viewport' content='width=device-width, initial-scale=1'>  
</head>
<body>
    <!-- breyttu breidd og hæð -->
    <canvas id="tutorial" width="150" height="150"></canvas>
    
    <script>
    // canvas er breyta sem geymir vísun á <canvas> í html skrá.
    let canvas = document.getElementById('tutorial');
    let ctx = canvas.getContext('2d');

    ctx.fillStyle = 'rgb(200, 0, 0)';  // rauður fylltur litur
    ctx.fillRect(10, 10, 50, 50);      // rétthyrningur með rauðum fylltum lit
    </script>
</body>
</html>

Sjá nánar Halló heimur með JavaScript í HTML


Tutorials:

  1. Creating and resizing your Canvas myndband
  2. Drawing Elements myndband (rectangles, lines, arcs/circles)

Drawing shapes


⚠️ **GitHub.com Fallback** ⚠️