04.07.2013 Views

Building Web Applications with SVG - Cdn.oreilly.com

Building Web Applications with SVG - Cdn.oreilly.com

Building Web Applications with SVG - Cdn.oreilly.com

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Collage involving &lt;rect&gt; , &lt;circle&gt; and &lt;ellipse&gt; <br />

<br />

<br />

<br />

The element, like the , can have fill, stroke, stroke-width, and other attributes.<br />

The x and y attributes specify the rectangle’s upper-left corner, and height and width specify<br />

its size. Because you want the top of the rectangle to coincide <strong>with</strong> the center of the window,<br />

you can set x to “50%”. You also want it centered on the screen horizontally, so the distance of<br />

its rightmost extent (specified by x + width) to the right edge of the window should equal x.<br />

By experimenting a bit <strong>with</strong> different values of x and the corresponding value of width (determined<br />

by the centering constraint), you can visually estimate the values above (or similar values).<br />

Note that 100% – (80% + 10%) = 10%, which means that the rectangle will be centered<br />

horizontally, even though it is not centered vertically. The values for stroke-width and fill can<br />

likewise be estimated through experimentation.<br />

7. Put an oval atop everything and fill it <strong>with</strong> a transparent shade of yellow, while keeping its<br />

stroke opaque:<br />

<br />

Collage involving &lt;rect&gt; , &lt;circle&gt; and &lt;ellipse&gt; <br />

<br />

<br />

<br />

<br />

An ellipse, like a circle, has a center defined by cx and cy. However, owing to the difference<br />

in its vertical and horizontal extents, it has two radii: ry and rx, respectively. Because this oval<br />

is taller than it is wide, you can approximate the values above fairly closely by testing a few<br />

values and seeing what happens. Alternatively, you could actually measure the drawing on the<br />

screen to duplicate the effect more precisely.<br />

28 <strong>Building</strong> <strong>Web</strong> <strong>Applications</strong> <strong>with</strong> <strong>SVG</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!