Digital Tech and Innovations Canvas Tag Test Flashcards
What is the canvas tag
The canvas elects provides web pages with a place where they can draw free-form graphics of all kinds
How does the canvas coordinate system work
- starts in the upper left corner of the canvas
- ## increasing values going from left to right on x axis and top to bottom on y axis
how does the canvas id work
- you have to declare your canvas with a “canvas id” because you will be accessing it from script
What attributes does the canvas tag declare
width, height, style (solid border), thickness, colour
Write a canvas tag
<canvas id=”myCanvas” width=”800” height=”600” style=”border:1px solid black”;></canvas>
What two things do you need to draw on the canvas
- Retrieve a reference to the canvas element
- get the drawing context from the element using getContext
var canvas = document.getElementById(“myCanvas”)
var dt = canvas.getContext(“2d”)
What is an API
application programming interface
allows us to draw shapes, text etc
how do you set a fill colour to something
dt.fillStyle = “rgba()”
dt.fillStyle = “green”
dt.fillStyle = “#fA918t”
dt.fillStyle = colour1
How do you draw a square/rectangle
dt.fillRect
What do the coordinates in fillRect mean
(x, y, width, height)
starting x and y coordinates from the top left, width and height of the rectangle
How do you declare the width of a line
dt.lineWidth =
What does strokeRect do?
- it outlines the outside of your rectangle
- it uses the same coordinates and ways as fillRect of the rectangle
How do you declare the colour of the outline your shape
dt.strokeStyle =
how do you draw a rectangle with only an outline
dt.strokeStyle - outline colour
dt.lineWidth - width in px
dt.strokeRect - drawing the rectangle (same coordinates as usual)
How do you draw a fully filled rectangle
dt.fillStyle - fill colour
dt.fillRect - drawing it, same coordinates
How do you draw a stroked and full rectangle
dt.strokeStyle
dt.fillStyle
dt.lineWidth
dt.fillRect
dt.strokeRect
what is a clear rectangle, how do you draw it, and what can you use it for
- a rectangle that removes/notches out any other drawn object underneath
- dt.clearRect(x, y, width, length)
- you can use this in a function to removes the “trails” of your other movements
How do you draw a simple line
drawingTools.beginPath();
drawingTools.lineWidth = 1;
drawingTools.moveTo(0, 0);
drawingTools.lineTo(500, 200);
drawingTools.stroke();
What are the three different line caps and what do you code for them?
butt, round, square
dt.lineCap = “butt” (round or square)
What do the three line caps look like
butt: it appears square, but it is different because in this the stroke symbol will end exactly where the Line geometry ends
round: rounded edges and ends
square: looks square, and like butt, though the square caps will extend past the endpoint of the line and don’t end exactly at the coordinates
What is a lineJoin
the shape/common area that is formed when two lines join
what are the different line joins and how do you write them
dt.lineJoin = “round”
dt.lineJoin = “bevel”
dt.lineJoin = “miter”
what do the three linejoines look like
round: rounded edges
bevel: where it connects is a flat, like the tip is cut
miter: pointy edge
How do you draw an arc
dt.arc(x, y, r, sA, eA, aC);