basicelements.html 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <!DOCTYPE HTML>
  2. <html>
  3. <!--
  4. Copyright 2007 The Closure Library Authors. All Rights Reserved.
  5. Use of this source code is governed by the Apache License, Version 2.0.
  6. See the COPYING file for details.
  7. -->
  8. <head>
  9. <meta http-equiv="X-UA-Compatible" content="IE=edge" >
  10. <title>Graphics Basic Elements Demo Page</title>
  11. <style>
  12. .type { font-size:14px; font-weight:bold; font-family:arial; background-color:#f7f7f7; text-align:center }
  13. </style>
  14. <script type="text/javascript" src="../../base.js"></script>
  15. <script type="text/javascript">
  16. goog.require('goog.dom');
  17. goog.require('goog.graphics');
  18. goog.require('goog.graphics.Font');
  19. </script>
  20. <script type="text/javascript">
  21. function drawElements() {
  22. var graphics = goog.graphics.createSimpleGraphics(600, 200);
  23. // Basic shapes
  24. var fill = new goog.graphics.SolidFill('yellow');
  25. var stroke = new goog.graphics.Stroke(2, 'green');
  26. graphics.drawRect(30, 10, 100, 80, stroke, fill);
  27. stroke = new goog.graphics.Stroke(4, 'green');
  28. // Image shapes
  29. graphics.drawImage(30, 110, 276, 110,
  30. 'http://www.google.com/intl/en_ALL/images/logo.gif');
  31. graphics.drawCircle(190, 70, 50, stroke, fill);
  32. stroke = new goog.graphics.Stroke(6, 'green');
  33. graphics.drawEllipse(300, 140, 80, 40, stroke, fill);
  34. // A path
  35. var path = new goog.graphics.Path();
  36. path.moveTo(320, 30);
  37. path.lineTo(420, 130);
  38. path.lineTo(480, 30);
  39. path.close();
  40. stroke = new goog.graphics.Stroke(1, 'green');
  41. graphics.drawPath(path, stroke, fill);
  42. // Clipped shapes
  43. var redFill = new goog.graphics.SolidFill('red');
  44. graphics.drawCircle(540, 10, 50, null, redFill);
  45. graphics.drawCircle(540, 10, 30, null, fill);
  46. graphics.drawCircle(560, 210, 30, stroke, fill);
  47. graphics.drawCircle(560, 210, 45, stroke, null); // No fill
  48. graphics.drawCircle(600, 90, 30, stroke, fill);
  49. graphics.render(document.getElementById('shapes'));
  50. // ---------------------------------------------------------------------
  51. // Text elements
  52. graphics = goog.graphics.createGraphics(600, 200);
  53. fill = new goog.graphics.SolidFill('blue');
  54. stroke = null;
  55. var font = new goog.graphics.Font(30, 'Times');
  56. graphics.drawText('Large Top Center', 0, 0, 600, 200, 'center', null,
  57. font, stroke, fill);
  58. font = new goog.graphics.Font(24, 'Times');
  59. font.bold = true;
  60. graphics.drawText('In Bold', 0, 30, 600, 200, 'center', null,
  61. font, stroke, fill);
  62. font.bold = false;
  63. font.italic = true;
  64. graphics.drawText('Italics', 0, 54, 600, 200, 'center', null,
  65. font, stroke, fill);
  66. font = new goog.graphics.Font(14, 'Arial');
  67. graphics.drawText('Top-Left', 0, 0, 600, 200, 'left', null,
  68. font, stroke, fill);
  69. graphics.drawText('Top-right', 0, 0, 600, 200, 'right', null,
  70. font, stroke, fill);
  71. graphics.drawText('Bottom-right', 0, 0, 600, 200, 'right', 'bottom',
  72. font, stroke, fill);
  73. graphics.drawText('Right-Middle', 0, 0, 600, 200, 'right', 'center',
  74. font, stroke, fill);
  75. graphics.drawTextOnLine('Going down left', 130, 0, 130, 200, 'left',
  76. font, stroke, fill);
  77. graphics.drawTextOnLine('Going down center', 150, 0, 150, 200, 'center',
  78. font, stroke, fill);
  79. graphics.drawTextOnLine('Going down right', 170, 0, 170, 200, 'right',
  80. font, stroke, fill);
  81. graphics.drawTextOnLine('Going up left', 430, 200, 430, 0, 'left',
  82. font, stroke, fill);
  83. graphics.drawTextOnLine('Going up center', 450, 200, 450, 0, 'center',
  84. font, stroke, fill);
  85. graphics.drawTextOnLine('Going up right', 470, 200, 470, 0, 'right',
  86. font, stroke, fill);
  87. font = new goog.graphics.Font(18, 'Arial');
  88. graphics.drawTextOnLine('Diagonal text', 200, 180, 400, 60, 'center',
  89. font, stroke, fill);
  90. graphics.render(document.getElementById('text'));
  91. // ---------------------------------------------------------------------
  92. // Path elements
  93. graphics = goog.graphics.createSimpleGraphics(600, 200);
  94. fill = new goog.graphics.SolidFill('yellow');
  95. stroke = new goog.graphics.Stroke(1, 'black');
  96. path = new goog.graphics.Path();
  97. path.moveTo(80, 80);
  98. path.arc(80, 80, 100, 100, 15, -300, true);
  99. path.close();
  100. graphics.drawPath(path, stroke, fill);
  101. stroke = new goog.graphics.Stroke(3, 'black');
  102. path = new goog.graphics.Path()
  103. .moveTo(200, 180)
  104. .lineTo(230, 100)
  105. .lineTo(280, 30)
  106. .lineTo(280, 80)
  107. .lineTo(200, 90);
  108. graphics.drawPath(path, stroke, null);
  109. path = new goog.graphics.Path()
  110. .moveTo(300, 150)
  111. .curveTo(370, 0, 420, 200, 500, 150);
  112. graphics.drawPath(path, stroke, null);
  113. graphics.render(document.getElementById('paths'));
  114. // ---------------------------------------------------------------------
  115. // Colors
  116. graphics = goog.graphics.createSimpleGraphics(600, 200);
  117. fill = new goog.graphics.SolidFill('red');
  118. stroke = new goog.graphics.Stroke(1, 'black');
  119. graphics.drawRect(30, 10, 100, 80, stroke, fill);
  120. fill = new goog.graphics.LinearGradient(200, 10, 400, 190,
  121. '#000080', '#800000');
  122. graphics.drawRect(200, 10, 200, 180, stroke, fill);
  123. fill = new goog.graphics.LinearGradient(30, 110, 30, 200,
  124. '#8080ff', '#000080');
  125. graphics.drawRect(30, 110, 100, 80, stroke, fill);
  126. fill = new goog.graphics.SolidFill('blue');
  127. graphics.drawCircle(500, 60, 40, stroke, fill);
  128. fill = new goog.graphics.SolidFill('red', 0.5);
  129. graphics.drawCircle(500, 90, 40, stroke, fill);
  130. fill = new goog.graphics.SolidFill('green', 0.2);
  131. graphics.drawCircle(500, 120, 40, stroke, fill);
  132. graphics.render(document.getElementById('colors'));
  133. // ---------------------------------------------------------------------
  134. // Coordinates
  135. graphics = goog.graphics.createSimpleGraphics(1200, 300, 12000, 3000);
  136. fill = new goog.graphics.SolidFill('yellow');
  137. stroke = new goog.graphics.Stroke('3px', 'black');
  138. path = new goog.graphics.Path();
  139. path.moveTo(300, 300);
  140. path.arc(300, 300, 1000, 1000, 15, 60, true);
  141. path.close();
  142. graphics.drawPath(path, stroke, fill);
  143. stroke = new goog.graphics.Stroke(3, 'black');
  144. path = graphics.createPath()
  145. .moveTo(2000, 1800)
  146. .lineTo(2300, 1000)
  147. .lineTo(2800, 300)
  148. .lineTo(2800, 800)
  149. .lineTo(2000, 900);
  150. graphics.drawPath(path, stroke, null);
  151. path = new goog.graphics.Path()
  152. .moveTo(3000, 1500)
  153. .curveTo(3700, 0, 4200, 2000, 5000, 1500);
  154. graphics.drawPath(path, stroke, null);
  155. stroke = new goog.graphics.Stroke(20, 'green');
  156. graphics.drawRect(5300, 100, 1000, 800, stroke, fill);
  157. stroke = new goog.graphics.Stroke(4, 'green');
  158. graphics.drawImage(5300, 1100, 2760, 1100,
  159. 'http://www.google.com/intl/en_ALL/images/logo.gif');
  160. graphics.drawCircle(6900, 700, 500, stroke, fill);
  161. stroke = new goog.graphics.Stroke(60, 'green');
  162. graphics.drawEllipse(8000, 1400, 800, 400, stroke, fill);
  163. font = new goog.graphics.Font(140, 'Arial');
  164. fill = new goog.graphics.SolidFill('blue');
  165. graphics.drawTextOnLine('Going up center', 11000, 2000, 11000, 0,
  166. 'center', font, null, fill);
  167. graphics.render(document.getElementById('coords'));
  168. }
  169. </script>
  170. </head>
  171. <body onload="drawElements()">
  172. <table border="1">
  173. <tr valign="top">
  174. <td class="type">
  175. Text: fonts, alignment, vertical-alignment, direction
  176. </td>
  177. <td class="type">
  178. Basic shapes: Rectangle, Circle, Ellipses, Path, Clip to canvas
  179. </td>
  180. </tr>
  181. <tr>
  182. <td>
  183. <span id="text"></span>
  184. </td>
  185. <td>
  186. <span id="shapes"></span>
  187. </td>
  188. </tr>
  189. <tr valign="top">
  190. <td class="type">
  191. Paths: Lines, arcs, curves
  192. </td>
  193. <td class="type">
  194. Colors: solid, gradients, transparency
  195. </td>
  196. </tr>
  197. <tr>
  198. <td>
  199. <span id="paths"></span>
  200. </td>
  201. <td>
  202. <span id="colors"></span>
  203. </td>
  204. </tr>
  205. <tr>
  206. <td colspan="2" class="type">
  207. Coordinate scaling + stroke types
  208. </td>
  209. </tr>
  210. <tr>
  211. <td colspan="2" class="type">
  212. <span id="coords"></span>
  213. </td>
  214. </tr>
  215. </table>
  216. </body>
  217. </html>