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