<< Chapter < Page | Chapter >> Page > |
What are you allowed to change?
There are only six things that you are allowed to change in the code in Listing 5 (pay attention to the comments) :
Multiple rect elements
You can replicate this code to define as many rect elements as you need in your drawing so long as you provide a unique name for each element (object) .
The size of the rectangle
If you carefully examine the values that I specified for the coordinates of the lower-left corner, the width, and the height, you will see that I made therectangle slightly smaller than the size of the paper so that it will fit just inside the edges of the paper.
SVG code to draw a rectangle
The use of the Java code in Listing 5 to draw a rectangle results in the SVG code shown in Listing 6 .
Listing 6 . SVG code to draw a rectangle. |
---|
<rect fill="none" stroke="black" stroke-width="1"
x="1" y="1" width="987" height="762"><title>rectangle</title></rect> |
In order to force the SVG code to fit in this publication format, it was necessary for meto insert a line break following the "1". Those two lines were originally a single line in the SVG code.
View my tutorials
SVG is simply one flavor of something called XML. I have published hundreds of online tutorials on Java programming, XML, and SVG. If youare interested in reading what I have to say in those tutorials, just Google the following keywords:
The rect element
The four lines in Listing 6 that begin with an angle bracket followed by rect and end with />constitute what is called an XML element named rect .
The rect element has a title element as its content. The title element has the word rectangle as its content.
The attributes of the rect element
The following items are known as the attributes of the rect element:
The attribute values
The text that appears in quotation marks, such as "762" are known as the values of theattribute to which they are joined by an equals character "=".
How does it all work?
When an SVG processor, such as the one incorporated into Firefox 5, sees an SVG/XML element named rect in an SVG file, it knows that it needs to draw a rectangle. It then looks to the attributes and their valuesto determine other aspects of that rectangle.
For example, in this case, the SVG processor is told to draw a rectangle consisting of an outline only (fill="none") .
The color of the outline is to be black (stroke="black") .
The thickness of the outline is to be a single SVG unit (stroke-width="1") .
The lower-left corner of the outline is to be very close to the origin when described in SVG units (x="1" and y="1") .
Notification Switch
Would you like to follow the 'Accessible physics concepts for blind students' conversation and receive update notifications?