Categories

Partners
  • Website Templates

  • Adobe Photoshop Tutorials

  • Bittorent and
    Google desktop programs

  • Free Stock Photos and Images

  • Adobe Photoshop Tutorials

  • Photoshop, Flash, 3dsmax tutorials
  • Search


    Advanced Search




    Subscribe

    SVG Viewer
    (Page 1 of 7)   « Back | 1 | 2 | 3 | 4 | 5 | Next »



    » SVG Animation - Animation Attributes
    Published 07/17/2006
    These animation attributes apply to the elements set, animate, animateMotion, animateColor and animateTranform.

    Animation

    Attribute
    Values
    Initial
    Comments
    xlink:href
    xlink
    -
    The reference to the SVG object to animate. Overrides direct parent. See note.

    Note: If the animation element is the direct child of the the object being animated then using this attribute is redundant. The direct parent of an animation element is the target unless this is set otherwise.

    AnimationAttribute

    Attribute
    Values
    Initial
    Comments
    attributeName
    Attribute Name
    -
    The name of the target attribute to animate.
    attributeType
    (xml, css, auto)
    auto
    Sets the namespace used to xml or css. The default, 'auto', ensures the change occurs.

    AnimationTiming

    Attribute
    Values
    Initial
    Comments
    begin
    #event-list
    none
    The event list to begin the animation on.
    dur
    #duration
    0s
    The duration of the animation.
    end
    #event-list
    none
    The event list to end the animation on.
    min
    #duration
    0
    Minimum active duration. The animation will ignore end events until this time is reached. Unsupported by Adobe SVG plugin.
    max
    #duration
    indefinite
    Maximum active duration animating. The animation will end when this time is reached. Related to repeatCount. Unsupported by Adobe SVG plugin.
    restart
    (always | whenNotActive | never)
    always
    Sets when the animation can be restarted.
    repeatCount
    (# | indefinite)
    0
    The number of times to repeat the animation. Fractions are permitted.
    repeatDur
    (#duration | indefinite)
    indefinite
    The total duration to repeat the animation for.
    fill
    (freeze | remove)
    remove
    Sets if the animation's final value sticks or not, respectively.

    AnimationValue

    Attribute
    Values
    Initial
    Comments
    calcMode
    (discrete | linear | paced | spline)
    linear
    Sets how to interpolate the animation.
    values
    list
    -
    semicolon-separated list of values to set the attribute to. See SMIL standard
    keyTimes
    list
    -
    keySplines
    list
    -
    from
    attribute-value
    current
    The starting value animated from.
    to
    attribute-value
    -
    The ending value animated to.
    by
    #duration
    -
    Used with addition. Sets the value added to the animated attribute's value by time the animation duration is completed.

    AnimationAddition

    Attribute
    Values
    Initial
    Comments
    additive
    (replace | sum)
    replace
    Sets if this animation adds to value of the attribute and other animations or replaces the value.
    accumulate
    (none | sum)
    none
    Sets if repeat iterations are cumulative.

    AnimationMotion

    Attribute
    Values
    Initial
    Comments
    path
    #path
    The path the motion follows. Not used to reference a path. Use a child 'mpath' element with 'xlink:href' attribute to reference.
    calcMode
    -
    paced
    keyPoints
    list 0->1
    -
    Semicolon-separated list of values from 0 to 1 which is the percent along the path at the corresponding keyTimes.
    rotate
    (angle | auto | auto-reverse)
    0
    Sets if the object is rotated along the path. auto makes x-axis parallel with path.
    origin
    default
    none
    Unused by SVG.

    These attributes apply only to the animateMotion element.

    animateTransform

    Attribute
    Values
    Initial
    Comments
    type
    (translate | scale | rotate | skewX | skewY)
    translate
    Sets the transformation animated.

    This attribute applies only to the animateTransform element.

    » SVG Animation - Animating SVG Documents
    Published 07/17/2006
    Animating SVG Documents

    The easiest way to animate something in SVG is using SMIL. This is yet another standard from W3C that SVG uses. SMIL (pronouced 'smile') stands for Synchronized Multimedia Integration Language. It is a highly adaptable animation langauge which is extended and adapted for SVG. SMIL is very convient but it constrains you to how it wants to work.

    SMIL Animation

    A SMIL animation element in SVG associates event(s) with a change or series of changes to an attribute of the SVG object they are linked to. The next example shows the animation element mouse events rectangles which change color when event occurs to it.

    Example 1. Mouse events triggering animation. (Download)

    <rect id="ani1" x="10" y="10" width="80" height="55" rx="10" ry="10" fill="blue" >

    <set begin="click" attributeName="fill" to="yellow" />

    </rect>
    Code 1. Code extract from example 1

    The 'begin' attribute is a semi-colan seperated list of events (or times) to start the animation at. To start or end on a event on an object other than the direct parent element the id of the source of the event must be added. (Example: begin="object.click")

    Animation Element - set

    This is a short-hand version of the 'animate' element which always has an animation duration of 0s. Any duration given to this tag will be ignored and the 'to' value applied immediately when a begin event is triggered.

    <set begin="click" attributeName="fill" to="yellow" />
    Example of the 'set' animation element.

    Animation Element - animate

    This is the main animation element. All animation but motion on a path and animated transforms can be done with this element. By default, the start value (initial or 'from' attribute) and end value ('to' or 'values' attribute) is linearly interpolated between.

    Example 2. Click to begin. (Download)

    <rect id="pulser" x="40" y="25" width="120" height="50" rx="10" ry="10" fill="blue"
       stroke="black" filter="url(#closeDropShadow)" >
    <animate begin="mouseover" end="mouseout;click" dur="2s"
              repeatCount="indefinite" attributeName="fill" from="blue" 
              values="lightblue; blue; lightblue" fill="freeze" />

    <animate begin="click" dur="1.0s" repeatCount="5" attributeName="fill"
    values="red; peachpuff; lightgoldenrodyellow; plum; white; red" fill="freeze" />

    <animate begin="click+4.5s" dur="2.0s" attributeName="y" calcMode="linear"
        values="0; 1; 2; 4; 8; 16; 32; 64; 128; 256;" additive="sum" fill="freeze" /> <set begin="click+6.4s"
       attributeName="opacity" to="0" fill="freeze" />

    <set begin="click+12.0s" attributeName="fill" to="blue" />

    <set begin="click+12.0s" attributeName="opacity" to="1" />
    </rect>
    Code 2. Examples of the 'animate' animation element.

    Animation Element - animateMotion

    This element is an addition to the SMIL standard to allow you to animate an object along a path.

    Example 3. Click the green box to animate on the path. (Download)

    <animateMotion begin="startButton.click" dur="10s" repeatCount="1" rotate="auto" fill="freeze" >

    <mpath xlink:href="#myAniPath" />

    </animateMotion>
    Code 3. Example of the 'animateMotion' animation element.

    Animation Element - animateColor

    This element is included for compatibility with the SMIL standard. It is identical to the 'animate' element except that the 'to', 'from' and 'by' attributes must be colors.

    Animation Element - animateTransform

    Since the other animation elements only animate a single attribute, a different way to animate transformations is required. To animate a transformation you use the animateTransform element which adds a 'type' attribute so that you can specify what type of transformation you are animating.

    Note: You still need to specify the 'attributeName' attribute with this element or no animation occurs.

    Example 4. Click the green box to animate the snowflake. (Download)

    <animateTransform begin="startButton.click" attributeName="transform"
                     type="translate" from="10,10" to="140,180" dur="5s" 
                     additive="sum" fill="freeze" xlink:href="#snow" />

    <animateTransform begin="startButton.click" attributeName="transform"
                      type="rotate" from="0" to="270" dur="5s"
                      additive="sum" fill="freeze" xlink:href="#snow" />
    Code 4. Example of the 'animateTransform' animation element.

    The above example uses the attribute 'additive' with the value 'sum' so the second animation doesn't replace the first. The default value of 'replace' would result in the 2nd animation overwriting changes made to the 'transform' attribute by the 1rst animation.

    Offset Timing

    Example 5. Offset timing from an event.(Download)

    <set begin="ani1.click+2.0s" attributeName="fill" to="yellow" />
    Code 5. Example of offset timing.

    Javascript Animation

    The second way to animate in SVG is using the built in scripting language, ECMAScript (Javascript), and doing the animation by using a timer and directly changing the values. The animated 3D cube works by computing new values for the polygons each time the timer fires.

    » SVG Basics - JavaScript in SVG
    Published 07/17/2006
    JavaScript in SVG

    The other sections of the tutorial deal with how to use SVG to make beautiful shapes. In this section, let's put those shapes to work doing some real work by using Javascript to glue them together. Most SVG viewers support JavaScript (ECMAScript) as their main scripting language but SVG is not limited to only that language.

    Adding Javascript

    JavaScript can either be embeded or in an external file. The next code example shows both styles.

    <script type="text/ecmascript" xlink:href="unseth/unseth.js" />

    <script type="text/ecmascript"><![CDATA[

    ...

    ]]></script>
    Code 1. Adding JavaScript (EcmaScript) to a SVG document.

    Events and Javascript

    To preform an action when an event occurs you just add the event handler to the associated object. This is much like HTML except the event names must be all lowercase letters.

    Event
    When Called
    onclick When the object is clicked (mouse button down and up)
    onmousedown When the mouse button is pushed down on the object
    onmouseup When the mouse button is released on the object
    onmouseover When the mouse cursor moves over the object
    onmousemove When the mouse moves in the object
    onmouseout When the mouse cursors leaves the object

    Table 1. Events for Graphical Elements.



    Example
    Code
    <script type="text/ecmascript">
    <![CDATA[ ... function updateStats()
    { svgDocument.getElementById("clicks").firstChild.data
    = "onclick = " + click;
    svgDocument.getElementById("mousedowns").firstChild.data
    = "onmousedown = " + mouseDown; ... }
    function msClick (evt)
    { click++; updateStats(); } ... ]]>
    </script> <circle cx="50%" cy="25%" r="40"
    fill="lightyellow" onclick="msClick()"
    onmousedown="msDown()" onmouseup="msUp()"
    onmouseover="msOver()" onmousemove="msMove()"
    onmouseout="msOut()" />
    Example 1. Calling a function on an event. (Download)

    Find the SVG Document Root

    The current version of the Adobe SVG plugin automatically sets the variable "svgDocument" to be the SVG document root. This is a useful nonstandard feature of the viewer but to ensure compatibility with older versions of the plugin you should set the variable if it isn't present. To do this, add an init function which is called when the onload event occurs which extracts and sets the document root from the event.

    <svg onload="init(evt)" ...>
    <script type="text/ecmascript"><![CDATA[
    function init(evt) {
    if ( window.svgDocument == null )
    svgDocument = evt.target.ownerDocument;
    }
    ]]></script>
    Code 2. Find and set the document root.

    The Batik SVG viewer sets the variable "window.document" to be the SVG document root and is incompatible with the above code.

    JavaScript Animation

    If SMIL animation doesn't quite handle how you want to animate something in SVG then the alternative is using JavaScript (EcmaScript). SMIL animation is very handy but there are plenty of behaviours that can be much more easily modeled by using JavaScript.

    » SVG Basics - Path Element
    Published 07/17/2006

    SVG Path


    The path element is the single most useful tag for creating professional looking SVG documents and it's the most difficult tag to hand-code in SVG. It is quite hard to visualize anything but the most simple of paths.

    <path>
    Attribute
    Explanation
    d
    A set of commands which define the path. (See below)
    pathLength
    If present then the path will be scaled so that the computed path length of the points equals this value. A negative value is an error. (Note: Unsupported by Adobe's plugin)
    transform
    A list of transformations.
    Presentation Attributes
    Color, FillStroke, Graphics, Markers
    Path Data

    The path is defined in the 'd' attribute of the 'path' tag by a string of white space seperated commands and coordinates.

    Path commands are case-sensitive, An uppercase command's points use absolute postioning and a lowercase command's points are relative the last point. The one exception to this is the first point always uses absolute postioning.

    The path is defined in the 'd' attribute of the 'path' tag by a string of white space seperated commands and coordinates.

    Path commands are case-sensitive, An uppercase command's points use absolute postioning and a lowercase command's points are relative the last point. The one exception to this is the first point always uses absolute postioning.

    Command
    Parameters
    Repeat
    Explanation
    M
    x,y
    Yes
    moveto: Moves the pen to a new location. No line is drawn. All path data must begin with a 'moveto' command.
    Line Commands
    L
    x,y
    Yes
    lineto: Draws a line from the current point to the point (x,y).
    H
    x
    Yes
    horizontal lineto: Draws a horizontal line from the current point to x.
    V
    y
    Yes
    vertical lineto: Draws a vertical line from the current point to y.
    Cubic Bezier Curve Commands
    C
    x1 y1 x2 y2 x y
    Yes
    curveto: Draw a cubic bezier curve to the point (x,y) where the points (x1,y1) and (x2,y2) are the start and end control points, respectively.
    S
    x2 y2 x y
    Yes
    shorthand/smooth curveto: Draw a curve to the point (x,y) where the point (x2,y2) is the end control point and the start control point is the reflection of the last point's end control point.
    Quadratic Bezier Curve Commands
    Q
    x1 y1 x y
    Yes
    Quadratic Bezier curveto: Draw a quadratic bezier between the last point and point (x,y) using the point (x1,y1) as the control point.
    T
    x y
    Yes
    Shorthand/smooth quadratic Bezier curveto: Draw a quadratic bezier between the last point and point (x,y) using the reflection of the last control point as the control point.
    Elliptical Arc Curve Commands
    A
    **
    Yes
    elliptical arc: Draws and arc from the current point to x, y. The actual scale factor and position of the arc needed to bridge the two points is computed by the SVG viewer.
    End Path Commands
    z
    -
    No
    closepath: Closes the path. A line is drawn from the last point to the first.
    ** rx ry x-axis-rotation large-arc-flag sweep-flag x y

    Note: To use relative positioning simply use a lowercase letter for the command.

    Line Example

    Example 1. A path made using lineto commands (Download)

    <path d="M100,10 L100,10 40,180 190,60 10,60 160,180 z"
                               stroke="blue" fill="darkblue" stroke-width="4" />
    Code 1. The path used in the above example.

    Cubic Bezier Example

    Example 2. A path made using cubic curves. The control points are circled in red. (Download)

    <path d="M40,140 L40,100 10,100 C10,10 90,10 90,
          100 L60,100 60,140 M140,50 C70,180 195,180 190,100 "
           stroke="darkgreen" stroke-width="4" fill="url(#hill)"
    />
    Code 2. The path used in the above example.

    Quadratic Bezier Example

    Example 3. A path made using quadratic bezier curves. The control point is circled in red (click to view). (Download)

    <path id="playButton" d="M50,50 Q-30,100 50,150 100,
         230 150,150 230,100 150,50 100,-30 50,50" stroke="darkblue"
         stroke-width="4" fill="url(#myFillGrad)"
    />
    Code 3. The path used in the above example.

    Elliptical Arc Example

    Example 4. A path made using arcs. (Download)

    <path d="M10,150 A15 15 180 0 1 70 140 A15 25 180 0 0 130 130
                    A15 55 180 0 1 190 120" stroke="lightgreen" stroke-width="4"
                    fill="none" marker-mid="url(#marker2)" marker-end="url(#marker1)"
    />
    Code 4. The path used in the above example.

    Text on a Path

    Placing text on a path is accomplished by defining a path and inside a 'text' element using a 'textPath' element to reference the path.

    Example 5. Text on a path. The path is shown in red. (Download)

    <path id="path1" d="M25, 100 C10,10 175,10 175,100" />
    Code 5. The path used in the above example.
    » SVG Basics - Masking - The 'mask' element
    Published 07/17/2006
    Masking - The 'mask' element

    Masking is a combination of opacity values and clipping. Like clipping you can use shapes, text or paths to define sections of the mask. The default state of a mask is fully transparent which is the opposite of clipping plane. The graphics in a mask sets how opaque portions of the mask are.

    The luminosity of the color at a pixel determines how opaque the pixel will be. White is the most luminous color and black is the least luminous. Thus, the highest luminosity value, white, is opaque and the lowest, black, is transparent. This is backwards to physics (black absorbs all light) but matches how you define colors and mixing fractions of the new color with the colors below.

    What is a color's luminosity? It is a value which says how "bright" a color is. If you only use grayscale colors for the mask you can just say it's the percentage of how white it is. Most graphic programs like Adobe Photoshop(tm) use this method.

    SVG allows any color to be used in a mask. How you turn red or blue or even grayscale colors into a luminosity isn't that easy. You have to deal with how eyes perceive colors. Blue is less luminous than green so rgb(0,255,0) is more luminous than rgb(0,0,255). SVG likely uses 30% red, 59% green and 11% blue to calculate the luminance.

    Masks are fully transparent black by default. You must add objects to the mask for anything to show when you use a mask. There are no restrictions on what you can add to a mask.

    Example 1. The relative luminosity of colors. (Download)

    <mask>
    Attribute
    Explanation
    maskUnits
    Set whether the clipping plane is relative the full view port or object. See: x, y, width, height. 'userSpaceOnUse' or 'objectBoundingBox' (default: 'objectBoundingBox')
    maskContentUnits
    Use the second with percentages to make mask graphic positions relative the object. 'userSpaceOnUse' or 'objectBoundingBox' (default: 'userSpaceOnUse')
    x, y
    The clipping plane of the mask. (default: -10%)
    width, height
    The clipping plane of the mask. (default: 120%)
    The 'mask' element
    PSDTop offers Royalty Free files like PSDs and JPGs. PSD files are prepared for instant use in collages, banners, animations and other computer graphic related tasks - PSD files : PSD stock images & much more...!!! Files are multi layered and isolated. Just download a file, imort it to a program able to read .psd format (Adobe Photoshop, GIMP, other) and that's it - a new layer is added. PSD files are zipped to make transfer faster.
    WiFiReview.com - your guide to the wireless world