- Questions?
- Setting up your work environment
- HTML/CSS/SVG basics
August 25, 2022
I’ll be using the Developer Tools in Google Chrome.
Open Google Chrome and click on the View > Developer > Developer Tools option.
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"/> <title>Your title goes here</title> <!-- header information goes here --> </head> <body> <!-- content goes here --> </body> </html>
There are lots of sloppy ways to code HTML that your browser frequently will be able to handle.
That said, a syntax checker can often be helpful in debugging: http://validator.w3.org/
The nested structure of tags form a tree, with the root element being <html></html> and then all of its children contained within
Inline css applied to the document using the <style> tag
selector { property1: value1; property2: value2; }
Selectors can be:
Names (to apply to all tags of that name)
IDs (applying to specific tags with that unique id)
Classes (to allow for user-defined groups)
For more on this visit https://www.w3schools.com/html/html_css.asp
First we need to create a canvas for our shapes and text.
<svg width="500" height="500"> </svg>
We can add a circle, with needs the coordinates for the circle center (cx
and cy
) and a radius (r
):
<svg width="500" height="500"> <circle cx="250" cy="250" r="50" /> </svg>
Move the circle around, what do you notice about where (0, 0) is in the canvas?
We can use CSS syntax to style our shapes.
<svg width="500" height="500"> <circle cx="250" cy="250" r="50" style="fill:yellow; stroke:black; stroke-width=5px"/> </svg>
Other shapes include:
<svg width="500" height="500"> <rect x="50" y="50" width="200" height="100" style="fill:red; stroke:black; stroke-width:3px"/> </svg>
Other shapes include:
<svg width="500" height="500"> <line x1="30" y1="30" x2="200" y2="80"/> </svg>
<svg width="500" height="500"> <text x="100" y="100">Some text</text> </svg>
Challenge: Draw a smiling face with the shapes we’ve talked about thus far
For paths, you start by “moving your pen” to coordinates x and y (M 150 200) and then you can specify lines to different points (L 200 300) and close the path with a z
.
<svg width="500" height="500"> <path d="M 150 250 L 200 300 L 250 250 z" /> </svg>
We can create groups, which is especially handy for transformations (scaling the image, and flipping the y axis, for example).
<svg width="500" height="500"> <g transform="translate(0, 500) scale(10, -10)"> <circle cx="5" cy="5" r=".3"/> <circle cx="8" cy="8" r=".3"/> <circle cx="11" cy="5" r=".3"/> <circle cx="14" cy="9" r=".3"/> </g> </svg>