CIS 119 - SVG (Scalable Vector Graphics)

Objectives

Resources

Overview

Some basic SVG elements

Some common SVG style attributes

Beyond what was covered

Rotation

There are a number of transformations you can apply to SVG objects, such as scale, skewX, skewY, rotate, translate, and matrix. The example given below is for rotation.

    <line id="line1" x1="0" y1="-140" x2="0" y2="-125" transform="rotate(0)" />
JavaScript code later to rotate the line 90 degrees clockwise about the origin:
    document.getElementById('line1').setAttribute('transform', 'rotate(90)');
Or you could skip the rotation and change x1, y1, x2, y2:
    document.getElementById('line1').setAttribute('x1', '275');
    document.getElementById('line1').setAttribute('y1', '150');
    document.getElementById('line1').setAttribute('x2', '290');
    document.getElementById('line1').setAttribute('y2', '150');

Examples demonstrating some topics covered on this page

  1. svg1.html: SVG element with two lines and a circle
  2. svg2.html: svg1.html using inline CSS for styling
  3. svg3.html: Simple animation using JavaScript and SVG
  4. svg4.html: Text and rectangle elements, opacity
  5. svg5.html: Ellipse and opacity
  6. svg6.html: Drawing a cube using five polygons
  7. svg7.html: Drawing a cube using four polylines
  8. svg8.html: Drawing a cube using paths and a "g" element
  9. svg9.html: Taking advantage of path to draw dashed hidden lines
  10. svg10.html: Path version again, but using some H and V directions