2 6 Shapes.html Lines 15–17 insert the Structured Graphics ActiveX Control. The name attribute determines the order in which the function is called. The Pie method (lines 32–33) is similar to the Arc method, but it fills the arc with the color of the foreground, thus creating a pie shape."> 2 6 Shapes.html Lines 15–17 insert the Structured Graphics ActiveX Control. The name attribute determines the order in which the function is called. The Pie method (lines 32–33) is similar to the Arc method, but it fills the arc with the color of the foreground, thus creating a pie shape.">

Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 17 - Dynamic HTML: Structured Graphics ActiveX Control

Similar presentations


Presentation on theme: "Chapter 17 - Dynamic HTML: Structured Graphics ActiveX Control"— Presentation transcript:

1 Chapter 17 - Dynamic HTML: Structured Graphics ActiveX Control
Outline Introduction Shape Primitives Moving Shapes with Translate Rotation Mouse Events and External Source Files Scaling Internet and World Wide Web Resources

2 Lines 15–17 insert the Structured Graphics ActiveX Control.
1 <?xml version = "1.0"?> 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " 4 5 <!-- Fig 17.1: shapes.html --> 6 <!-- Creating simple shapes --> 7 8 <html xmlns = " <head> <title>Structured Graphics - Shapes</title> </head> 12 <body> 14 <object id = "shapes" style = "background-color: #CCCCFF; width: 500; height: 400" classid = "CLSID:369303C2-D7AC-11d0-89D5-00A0C90833E6"> 18 <param name = "Line0001" value = "SetLineColor( 0, 0, 0 )" /> <param name = "Line0002" value = "SetLineStyle( 1, 1 )" /> <param name = "Line0003" value = "SetFillColor( 0, 255, 255 )" /> <param name = "Line0004" value = "SetFillStyle( 1 )" /> 27 <param name = "Line0005" value = "Oval( 0, -175, 25, 50, 45 )" /> <param name = "Line0006" value = "Arc( -200, -125, 100, 100, 45, 135, 0 )" /> <param name = "Line0007" value = "Pie( 100, -100, 150, 150, 90, 120, 0 )" /> Shapes.html Lines 15–17 insert the Structured Graphics ActiveX Control. The name attribute determines the order in which the function is called. The Pie method (lines 32–33) is similar to the Arc method, but it fills the arc with the color of the foreground, thus creating a pie shape.

3 <param name = "Line0008" value = "Polygon(5, 0, 0, 10, 20, 0, -30, , -10, -10, 25)" /> <param name = "Line0009" value = "Rect( -185, 0, 60, 30, 25 )" /> <param name = "Line0010" value = "RoundRect( 200, 100, 35, 60, 10, 10, 25 )" /> 41 <param name = "Line0011" value = "SetFont( 'Arial', 65, 400, 0, 0, 0 )" /> <param name = "Line0012" value = "Text( 'Shapes', -200, 200 , -35 )" /> 46 <param name = "Line0013" value = "SetLineStyle( 2,1 )" /> <param name = "Line0014" value = "PolyLine( 5, 100, 0, 120, 175, -150, -50, , -75, 75, -75)" /> </object> 53 </body> 55 </html> Shapes.html Line-style is the first parameter of SetLineStyle. A value 1 creates a solid line (the default), 0 does not draw any lines or borders and 2 creates a dashed line. Line width is the second parameter. It is set to 1 to create a dashed line. The PolyLine method is used to draw a line with multiple line segments.

4 Arc created with the Arc method. Shape created using the pie method.
Program Output Arc created with the Arc method. Shape created using the pie method. Shape created with the Polygon method. Line segment created with the PolyLine method.

5 17.2 Shape Primitives

6 To make the ball appear to “bounce” off the walls.
1 <?xml version = "1.0"?> 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " 4 5 <!-- Fig. 17.3: bounce.html > 6 <!-- Textures and the Translate method --> 7 8 <html xmlns = " <head> <title>Structured Graphics - Translate</title> 11 <script type = "text/javascript"> <!-- var x = 15; var y = 15; var upDown = -1; var leftRight = 1; 18 function start() { window.setInterval( "run()", 50 ); } 23 function run() { // if the ball hits the top or bottom side... if ( y == -100 || y == 50 ) upDown *= -1; 29 // if the ball hits the left or right side... if ( x == -150 || x == 100 ) leftRight *= -1; 33 Bounce.html To make the ball appear to “bounce” off the walls.

7 34 // Move the ball and increment our counters
ball.Translate( leftRight * 5, upDown * 5, 0 ); y += upDown * 5; x += leftRight * 5; } // --> </script> </head> 42 <body onload = "start()"> 44 <object id = "ball" style = "background-color: ffffff; width: 300; height: 200; border-style: groove; position: absolute;" classid = "CLSID:369303C2-D7AC-11d0-89D5-00A0C90833E6"> 49 <param name = "Line0001" value = "SetLineStyle( 0 )" /> <param name = "Line0002" value = "SetTextureFill( 0, 0, 'ball.gif', 0 )" /> <param name = "Line0003" value = "Oval( 15, 15, 50, 50 )" /> </object> 56 </body> 58 </html> we use the Translate method to translate the shape—that is, to move the shape in coordinate space without deforming it. Bounce.html The SetTextureFill method (line 52) is used to fill the oval with a texture. A texture is a picture that is placed on the surface of a polygon.

8 Program Output The application creates a simulation of a ball that bouncing around inside the Structured Graphics Control box.

9 Line 34 calls function Rotate to rotate the circle around the z-axis.
1 <?xml version = "1.0"?> 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " 4 5 <!-- Fig. 17.4: gradient.html --> 6 <!-- Gradients and rotation --> 7 8 <html xmlns = " <head> <title>Structured Graphics - Gradients</title> 11 <script type = "text/javascript"> <!-- var speed = 5; var counter = 180; 16 function start() { window.setInterval( "run()", 100 ); } 21 function run() { counter += speed; 25 // accelerate half the time... if ( ( counter % 360 ) > 180 ) speed *= ( 5 / 4 ); 29 // decelerate the other half. if ( ( counter % 360 ) < 180 ) speed /= ( 5 / 4 ); 33 pies.Rotate( 0, 0, speed ); } Gradient.html Lines 26–32 in the JavaScript code provide a mechanism for varying the speed of rotation about the z axis. Line 34 calls function Rotate to rotate the circle around the z-axis.

10 // --> </script> 38 </head> 40 <body onload = "start()"> 42 <object id = "pies" style = "background-color:blue; width: 300; height: 200;" classid = "CLSID:369303C2-D7AC-11d0-89D5-00A0C90833E6"> 46 <param name = "Line0001" value = "SetFillColor( 255, 0, 0, 0, 0, 0 )" /> <param name = "Line0002" value = "SetFillStyle( 13 )" /> <param name = "Line0003" value = "Pie( -75, -75, 150, 150, 90, 120, 300 )" /> 53 <param name = "Line0004" value = "SetFillStyle( 9 )" /> <param name = "Line0005" value = "Pie( -75, -75, 150, 150, 90, 120, 180 )" /> 58 <param name = "Line0006" value = "SetFillStyle( 11 )" /> <param name = "Line0007" value = "Pie( -75, -75, 150, 150, 90, 120, 60 )" /> </object> 64 </body> 66 </html> Gradient.html The gradient fills are set with the SetFillStyle method (lines 50, 55 and 60).

11 Program Output The output displays the image in its initial position and at a new rotated position.

12 1 <?xml version = "1.0"?> 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " 4 5 <!-- Fig. 17.5: bounce2.html > 6 <!-- SourceURL and MouseEventsEnabled --> 7 8 <html xmlns = " <head> <title>Structured Graphics - Shapes</title> 11 <script for = "ball" event = "onclick" type = "text/javascript"> <!-- ball.SourceURL = "newoval.txt"; // --> </script> 18 <script type = "text/javascript"> <!-- var x = 20; var y = 20; var upDown = -1; var leftRight = 1; 25 function start() { window.setInterval( "run()", 50 ); } 30 function run() { if ( y == -100 || y == 50 ) upDown *= -1; 35 Bounce2.html Lines 12–17 designate a script for the onclick event of our Structured Graphics Control object. This event sets property SourceURL to newoval.txt—the new drawing instructions. When the new drawing instructions are assigned to the SourceURL property the ball is redrawn based on these new settings.

13 MouseEventsEnabled property allows the capturing of mouse events.
if ( x == -150 || x == 100 ) leftRight *= -1; 38 ball.Translate( leftRight * 5, upDown * 5, 0 ); y += upDown * 5; x += leftRight *5; } // --> </script> </head> 46 <body onload = "start()"> 48 <object id = "ball" style = "width: 300; height: 200; border-style: groove; position: absolute; top: 10; left: 10;" classid = "clsid:369303C2-D7AC-11d0-89D5-00A0C90833E6"> 53 <param name = "Line0001" value = "SetLineStyle(0)" /> <param name = "Line0002" value = "SetTextureFill( 0, 0, 'ball.gif', 0 )" /> <param name = "Line0003" value = "Oval( 20, 20, 50, 50 )" /> <param name = "MouseEventsEnabled" value = "1" /> </object> 61 </body> 63 </html> Bounce2.html MouseEventsEnabled property allows the capturing of mouse events. The MouseEventsEnabled property is enabled by setting value to 1.

14 Initial output of the program before the user clicks the mouse.
Program Output After the user clicks the mouse, the ball is redrawn .according to the instructions in newoval.txt. Initial output of the program before the user clicks the mouse.

15 Fig. 17.6 External source file newoval.txt for Fig. 17.5.
1 SetLineStyle( 1, 3 ) 2 SetFillStyle( 1 ) 3 Oval( 20, 20, 50, 50, 0 ) 4 5 SetLineStyle( 1, 1 ) 6 PolyLine( 2, 45, 20, 45, 70, 0 ) 7 PolyLine( 2, 45, 20, 45, 70, 90 ) 8 PolyLine( 2, 45, 20, 45, 70, 45 ) 9 PolyLine( 2, 45, 20, 45, 70, 135 ) 10 11 SetFillColor( 0, 255, 0 ) 12 Oval( 30, 30, 30, 30, 0 ) 13 SetFillColor( 255 ,0, 0 ) 14 Oval( 35, 35, 20, 20, 0 ) Newoval.txt This file contains the new directions to redraw the ball when the user clicks the mouse. Fig External source file newoval.txt for Fig

16 1 <?xml version = "1.0"?> 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " 4 5 <!-- Fig. 17.7: scaling.html --> 6 <!-- Scaling a shape > 7 8 <html xmlns = " <head> <title>Structured Graphics - Scaling</title> 11 <script type = "text/javascript"> <!-- var speedX = 0; var speedY = 0; var speedZ = 0; var scale = 1; 18 function start() { window.setInterval( "run()", 100 ); } 23 function run() { drawing.Rotate( speedX, speedY, speedZ ); drawing.Scale( scale, scale, scale ); } 29 function rotate( axis ) { axis = ( axis ? 0 : 5 ); } // --> </script> Scaling.html The Scale method modifies the size of an object while retaining its position and shape.

17 Lines 55–90 create a control for our rotating foreground.
36 </head> 38 <body onload = "start()"> 40 <div style = "position: absolute; top: 25; left: 220"> <input type = "button" value = "Rotate-X" onclick = "speedX = ( speedX ? 0 : 5 )" /><br /> <input type = "button" value = "Rotate-Y" onclick = "speedY = ( speedY ? 0 : 5 )" /><br /> <input type = "button" value = "Rotate-Z" onclick = "speedZ = ( speedZ ? 0 : 5 )" /><br /> <br /> <input type = "button" value = "Scale Up" onclick = "scale = ( scale * 10 / 9 )" /><br /> <input type = "button" value = "Scale Down" onclick = "scale = ( scale * 9 / 10 )" /> </div> 54 <object id = "drawing" style = " position: absolute; z-index: 2; width: 200; height: 300;" classid = "CLSID:369303C2-D7AC-11d0-89D5-00A0C90833E6"> 58 <param name = "Line0001" value = "SetFillColor( 0,0,0 )" /> <param name = "Line0002" value = "SetFillStyle( 0 )" /> <param name = "Line0003" value = "SetLineStyle( 1, 3 )" /> 62 <param name = "Line0004" value = "Oval( -25, -100, 50, 50, 0 )" /> 65 <param name = "Line0005" value = "PolyLine(2, 0, -50, 0, 50 )" /> 68 <param name = "Line0006" value = "PolyLine( 3, -30, -25, 0, -15, 30, -25 )" /> Scaling.html Lines create 5 buttons used to control rotation and scaling of the foreground. Lines 55–90 create a control for our rotating foreground.

18 71 <param name = "Line0007" value = "PolyLine( 3, -15, 90, 0, 50, 15, 90 )" /> 74 <param name = "Line0008" value = "SetFillColor ( 255, 0, 0 )" /> <param name = "Line0009" value = "Oval( -15, -85, 7, 7, 0 )" /> <param name = "Line0010" value = "Oval( 5, -85, 7, 7, 0 )" /> 81 <param name = "Line0011" value = "SetLineStyle( 1, 2 )" /> <param name = "Line0012" value = "SetLineColor( 255, 0, 0 )" /> <param name = "Line0013" value = "SetFont( 'Courier', 25, 200, 0, 0, 0 )" /> <param name = "Line0014" value = "Text( 'Hello', -35, -115 , 0 )" /> </object> 91 <object id = "background" style = " position:absolute; z-index: 1; width: 200; height: 300; background-color: none" classid = "CLSID:369303C2-D7AC-11d0-89D5-00A0C90833E6"> 96 <param name = "Line0001" value = "SetFillColor( 38, 250, 38 )" /> <param name = "Line0002" value = "Oval( -75, -125, 150, 250, 0 )" /> </object> </body> 103 </html> Scaling.html Lines are used to control the positioning of the oval in the background. The position and z-index CSS attributes are used to position the oval and foreground over each other.

19 Program Output Possible outputs after the upper layer (the person) is rotated along the x, y and z axis with the top three buttons.

20 Program Output Possible out put after the initial image is scaled down (left) and scaled up (right).


Download ppt "Chapter 17 - Dynamic HTML: Structured Graphics ActiveX Control"

Similar presentations


Ads by Google