svg.htm 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2. <html>
  3. <head>
  4. <link href="synrc.css" type="text/css" rel="stylesheet">
  5. </head>
  6. <body border=0>
  7. <script>
  8. function template_engine(html, data) {
  9. var re = /{([^}]+)?}/g, code = 'var r=[];', cursor = 0;
  10. var add = function(line,js) {
  11. js? (code += 'r.push(' + line + ');') :
  12. (code += line != '' ? 'r.push("' + line.replace(/"/g, '\\"') + '");' : '');
  13. return add; }
  14. while(match = re.exec(html)) {
  15. add(html.slice(cursor, match.index))(match[1],true);
  16. cursor = match.index + match[0].length; }
  17. add(html.substr(cursor, html.length - cursor));
  18. code += 'return r.join("");';
  19. return new Function(code.replace(/[\r\t\n]/g, '')).apply(data); }
  20. function loadFile(name, cont, element) {
  21. if (localStorage.getItem(name) == null) {
  22. var client = new XMLHttpRequest();
  23. client.open('GET', name, true);
  24. client.onload = function() {
  25. localStorage.setItem(name,client.responseText);
  26. if (cont != null) (cont)(); else reload(name,element); }
  27. client.send(); } else { if (cont != null) (cont)(); else reload(name,element); } }
  28. </script>
  29. <div class="threecol">
  30. <div class="left">
  31. <div class="hints"></div>
  32. <div class="main">
  33. <h1>Full SVG Application</h1>
  34. <br>
  35. <svg id="Refined" width="900px" height="450px" viewBox="200 0 1000 700" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sketch="http://www.bohemiancoding.com/sketch/ns">
  36. </svg>
  37. <code>Refined and Distilled File to download: <a href="Kakaranet-7-Refined.svg">Kakaranet-7-Refined.svg</a></code>
  38. <p><font color=red style="font-weight:bold;">Please make sure your Vector Editor correctly opens this file!</font></p>
  39. <h1>Refined Object Names</h1>
  40. <code>
  41. Mustafa-Persona Facebook-Login Have-8-Tashes
  42. Gabrielo-Persona Online-Users Settings
  43. Alina-Person Kakaranet-Logo Pause
  44. Gabrielo-Deck Point-Table
  45. Alina-Deck Table Create
  46. Mustafa-Deck Gosterge Play
  47. Gabrielo-Discard Slot-1,1..15 Promos
  48. You-Discard Slot-2,1..15 Tournaments
  49. Alina-Discard Place-Card Okey
  50. Mustafa-Discard Center-Cards
  51. You-Deck Detailed-Houses
  52. Stupid-Cards Sky
  53. Mustafa-+-Timer Deck-Cards Sun
  54. You-+-Timer City
  55. Gabrielo
  56. Alina
  57. Right-Menu
  58. Left-Menu
  59. </code>
  60. <h1>SVG Templates Storage</h1>
  61. <code>
  62. function template_engine(html, data) {
  63. var re = /{([^}]+)?}/g, code = 'var r=[];', cursor = 0;
  64. var add = function(line,js) {
  65. js? (code += 'r.push(' + line + ');') :
  66. (code += line != '' ? 'r.push("' + line.replace(/"/g, '\\"') + '");' : '');
  67. return add; }
  68. while(match = re.exec(html)) {
  69. add(html.slice(cursor, match.index))(match[1],true);
  70. cursor = match.index + match[0].length; }
  71. add(html.substr(cursor, html.length - cursor));
  72. code += 'return r.join("");';
  73. return new Function(code.replace(/[\r\t\n]/g, '')).apply(data); }
  74. function storeTemplate(name, cont) {
  75. var client = new XMLHttpRequest();
  76. client.open('GET', name, true);
  77. client.onload = function() { localStorage.setItem("card",client.responseText); (cont)(); }
  78. client.send(); }
  79. function svg(html) { return new DOMParser().parseFromString(html, "text/xml").firstChild; }
  80. </code>
  81. <h1>The Card</h1>
  82. <code>
  83. templates/Card.svg:
  84. &lt;g xmlns="http://www.w3.org/2000/svg" id="Slot-<font color=yellow>{this.pos}</font>"
  85. transform="translate(<font color=yellow>{this.x}</font>,<font color=yellow>{this.y}</font>)"&gt;mbership,
  86. &lt;rect fill="#FFFFFF" x="0" y="0" width="40" height="60" rx="4"/&gt;
  87. &lt;text dx="20" x="0" y="26.4873125"
  88. font-family="Lucida Grande" font-size="24"
  89. font-weight="bold" letter-spacing="-2" text-anchor="middle"
  90. fill="<font color=yellow>{this.suit}</font>"&gt;<font color=yellow>{this.value}</font>&lt;/text&gt;
  91. &lt;circle fill="<font color=yellow>{this.suit}</font>" cx="20" cy="43" r="7"&gt;
  92. &lt;animate begin="0" fill="freeze" attributeName="r"
  93. values="4;5;6;7;8;6;5;4" dur="1s"
  94. calcMode="linear" repeatCount="indefinite"/&gt;&lt;/circle&gt;&lt;/g&gt;
  95. function card(line,pos,col,v) { return template_engine(localStorage.getItem("templaes/Card.svg"),
  96. { pos: line + ',' + pos, suit: color[col-1], value: v, y: line*73, x: pos*43 }); }
  97. <svg id="Scene" width="200px" height="200px" viewBox="0 0 40 60">
  98. <g xmlns="http://www.w3.org/2000/svg" id="Slot"
  99. transform="translate(0,0)">
  100. <rect fill="#FFFFFF" x="0" y="0"
  101. width="40" height="60" rx="4"/>
  102. <text dx="20" x="0" y="26.4873125"
  103. font-family="Lucida Grande" font-size="24"
  104. font-weight="bold" letter-spacing="-2" text-anchor="middle"
  105. fill="#CE290F">12</text>
  106. <circle id="Color-{this.pos}" fill="#CE290F" cx="20" cy="43" r="7">
  107. <animate begin="0" fill="freeze" attributeName="r"
  108. values="4;5;6;7;8;6;5;4" dur="1s"
  109. calcMode="linear" repeatCount="indefinite"/></circle></g></svg>
  110. </code>
  111. <h1>Draw Deck</h1>
  112. <code>
  113. okey.js:
  114. var color = ['#CE290F','#3B5998','#48AF5E','#FFEC00'];
  115. function rand(lo,hi) { return Math.floor((Math.random()*hi)+lo); }
  116. function drawCards() { for (var i=1;i<16;i++) { place_card(rand(1,2),i,rand(1,4),rand(1,13)); } }
  117. function place_card(x,y,c,v) { var slot = document.getElementById("Slot-"+y+","+x);
  118. slot.parentNode.replaceChild(svg(card(x-1,y-1,c,v)),slot); }
  119. loadFile('templates/Card.svg', drawCards);
  120. <svg id="Scene" width="630px" height="200px" viewBox="-3 0 634 130">
  121. <rect id="Deck" fill="#AF7B58" x=-5 y=-2 width=635 height=133></rect>
  122. <rect id="Deck" fill="#BC8864" x=-5 y=62 width=635 height=5></rect>
  123. <g id="1Slot-1,1"/> <g id="1Slot-1,2"/> <g id="1Slot-1,3"/>
  124. <g id="1Slot-1,4"/> <g id="1Slot-1,5"/> <g id="1Slot-1,6"/>
  125. <g id="1Slot-1,7"/> <g id="1Slot-1,8"/> <g id="1Slot-1,9"/>
  126. <g id="1Slot-1,10"/><g id="1Slot-1,11"/><g id="1Slot-1,12"/>
  127. <g id="1Slot-1,13"/><g id="1Slot-1,14"/><g id="1Slot-1,15"/>
  128. <g id="1Slot-2,1"/> <g id="1Slot-2,2"/> <g id="1Slot-2,3"/>
  129. <g id="1Slot-2,4"/> <g id="1Slot-2,5"/> <g id="1Slot-2,6"/>
  130. <g id="1Slot-2,7"/> <g id="1Slot-2,8"/> <g id="1Slot-2,9"/>
  131. <g id="1Slot-2,10"/><g id="1Slot-2,11"/><g id="1Slot-2,12"/>
  132. <g id="1Slot-2,13"/><g id="1Slot-2,14"/><g id="1Slot-2,15"/>
  133. </svg>
  134. <script>
  135. var color = ['#CE290F','#3B5998','#48AF5E','#FFEC00'];
  136. function card(line,pos,col,v) {
  137. return template_engine(
  138. localStorage.getItem("templates/Card.svg"),
  139. { pos: line + ',' + pos,
  140. suit: color[col-1],
  141. value: v,
  142. y: line*69,
  143. x: pos*42 }); }
  144. function place_card(x,y,c,v) {
  145. var slot = document.getElementById("Slot-"+y+","+x);
  146. var slotSample = document.getElementById("1Slot-"+y+","+x);
  147. slot.parentNode.replaceChild(svg(card(y-1,x-1,c,v)),slot);
  148. slotSample.parentNode.replaceChild(svg(card(y-1,x-1,c,v)),slotSample); }
  149. function empty_card(x,y) { var slot = document.getElementById("Slot-"+y+","+x);
  150. var html = '<g xmlns="http://www.w3.org/2000/svg" id="Slot-'+y+','+x+'"/>';
  151. slot.parentNode.replaceChild(svg(html),slot); }
  152. function svg(html) { return new DOMParser().parseFromString(html, "text/xml").firstChild; }
  153. function rand(lo,hi) { return Math.floor((Math.random()*hi)+lo); }
  154. function drawCards() { for (var i=1;i<14;i++) { place_card(i,rand(1,2),rand(1,4),rand(1,13)); } }
  155. function reload(file, name) { var slot = document.getElementById(name);
  156. slot.parentNode.replaceChild(svg(localStorage.getItem(file)),slot);}
  157. function scaleScene() {
  158. reload("Kakaranet-7-Refined.svg", "Refined");
  159. for (var i=1;i<14;i++) { empty_card(i,2); empty_card(i,1);}
  160. loadFile('templates/Card.svg', drawCards);
  161. }
  162. loadFile('Kakaranet-7-Refined.svg', scaleScene);
  163. </script>
  164. </code>
  165. <h1>Mustafa</h1>
  166. <code>
  167. > document.getElementById("Mustafa-Persona");
  168. <svg width="400px" height="400px" viewBox="450 120 150 200">
  169. <g id="Mustafa-Selection-Sample"/>
  170. <g id="Mustafa-Persona-Sample"/>
  171. </svg>
  172. > document.getElementById("Mustafa-Selection").style.display = "none";
  173. </code>
  174. <button id="MustafaSelection" style="font-size:28pt;">Toggle Mustafa Selection</button>
  175. <script>
  176. loadFile('templates/Mustafa-Persona.svg', null, "Mustafa-Persona-Sample");
  177. loadFile('templates/Mustafa-Selection.svg', null, "Mustafa-Selection-Sample");
  178. document.getElementById("MustafaSelection").addEventListener('click',function() {
  179. var style = document.getElementById("Mustafa-Selection-Sample").style;
  180. if (style.display == 'none') style.display = 'block'; else style.display = 'none';
  181. });</script>
  182. <code style="font-size: 6pt;">
  183. &lt;g id="Mustafa-Persona" sketch:type="MSLayerGroup" transform="translate(467.000000, 150.000000)"&gt;
  184. &lt;path d="M135.729,120.296 C118.005,95.269 108.839,85.517 85.519,85.517 L45.641,85.517 C22.321,85.517 11.022,103.055 0.272,120.296
  185. L135.729,120.296 L135.729,120.296 Z" id="Mustafa-Body" fill="#8DCED7"&gt;&lt;/path&gt;
  186. &lt;path d="M52.283,65.674 L48.134,81.099 L62.961,92.715 C62.961,92.715 68.155,92.749 68.329,92.691 C68.505,92.63 82.401,82.215
  187. 82.401,82.215 L78.093,65.59 L52.283,65.674 L52.283,65.674 Z" id="Mestafa-Neck" fill="#FFD191"&gt;&lt;/path&gt;
  188. &lt;path d="M56.035,1.351 C55.251,1.787 55.519,2.374 56.04,2.389 C57.252,2.419 58.102,2.639 58.81,3.7 C59.027,4.136 60.433,8.259 53.572,9.985
  189. C44.985,11.985 31.101,25.204 40.796,45.629 C41.402,46.905 42.03,48.031 42.676,49.019 C65.907,47.218 68.327,47.042
  190. 89.399,45.259 C106.855,15.955 69.488,-5.38 56.035,1.351 L56.035,1.351 Z" id="Mustafa-Hair" fill="#3F372E"&gt;&lt;/path&gt;
  191. &lt;path d="M88.417,44.449 C88.417,44.312 88.394,44.178 88.365,44.053 C88.288,43.666 88.116,43.387 87.864,43.196 C87.553,42.909 87.148,42.73 86.69,42.73
  192. L85.381,42.73 C85.263,42.73 85.152,42.752 85.039,42.764 L85.039,40.178 C85.039,29.368 76.272,20.604 65.456,20.604 C54.639,20.604 45.871,29.369
  193. 45.871,40.178 L45.871,42.739 C45.838,42.739 45.808,42.73 45.772,42.73 C44.099,42.73 42.742,42.844 42.742,44.518 L42.742,53.114 C42.742,54.788
  194. 44.099,56.141 45.772,56.141 C45.807,56.141 45.837,56.132 45.871,56.132 L45.871,62.719 C45.871,72.543 52.695,79.145 61.763,82.679 C62.161,84.207
  195. 63.533,85.34 65.189,85.34 C66.759,85.34 68.081,84.313 68.547,82.897 C78.753,79.063 85.038,72.831 85.038,62.719 L85.038,56.108 C85.15,56.118
  196. 85.262,56.141 85.38,56.141 C87.054,56.141 88.415,54.787 88.415,53.114 L88.415,44.518 C88.415,44.502 88.408,44.498 88.408,44.488 C88.41,44.474
  197. 88.417,44.462 88.417,44.449 L88.417,44.449 Z" id="Mustafa-Face" fill="#FFE0A5"&gt;&lt;/path&gt;
  198. &lt;path d="M62.358,88.807 C62.251,88.775 51.594,85.661 47.004,79.336 C46.652,78.854 46.035,78.639 45.46,78.799 C42.924,79.506 42.006,84.223 42.402,86.014
  199. C44.687,96.295 58.986,102.323 59.593,102.574 C59.772,102.644 59.957,102.686 60.144,102.686 C60.384,102.686 60.624,102.624 60.839,102.503 C61.22,102.289
  200. 61.486,101.916 61.557,101.484 L63.378,90.417 C63.496,89.699 63.059,89.006 62.358,88.807 L62.358,88.807 Z" id="Mustafa-Left-Collar" fill="#EFEFEF"&gt;&lt;/path&gt;
  201. &lt;path d="M85.984,78.799 C85.408,78.639 84.79,78.854 84.439,79.336 C79.851,85.66 69.2,88.774 69.088,88.807 C68.393,89.006 67.953,89.7 68.067,90.417
  202. L69.888,101.484 C69.96,101.916 70.223,102.289 70.606,102.503 C70.822,102.624 71.065,102.686 71.308,102.686 C71.492,102.686
  203. 71.677,102.644 71.854,102.574 C72.458,102.323 86.754,96.296 89.039,86.014 C89.441,84.223 88.521,79.506 85.984,78.799
  204. L85.984,78.799 Z" id="Mustafa-Right-Collar" fill="#EFEFEF"&gt;&lt;/path&gt;
  205. &lt;path d="M45.821,47.087 C45.821,47.087 48.215,47.551 48.588,44.092 C49.207,39.158 47.304,25.716 54.907,27.976 C62.513,30.241 67.131,31.426 72.271,28.758
  206. C77.406,26.085 80.23,30.547 81.311,33.531 C82.352,36.408 80.573,46.199 85.095,45.786 C85.121,44.68 85.073,43.809 85.116,42.687 C87.802,41.369
  207. 87.042,36.324 87.118,28.9 C86.626,22.662 83.987,16.503 69.765,16.263 C68.323,16.263 52.084,15.646 48.18,21.195 C44.276,26.742 45.621,35.719
  208. 45.621,35.719 L45.821,47.087 L45.821,47.087 Z" id="Mustafa-Hair-2" fill="#3F372E"&gt;&lt;/path&gt;
  209. &lt;path d="M60.429,52.326 C59.764,52.326 59.226,51.787 59.226,51.122 C59.226,50.295 58.551,49.619 57.72,49.619 C56.89,49.619 56.217,50.295 56.217,51.122
  210. C56.217,51.787 55.676,52.326 55.014,52.326 C54.347,52.326 53.81,51.787 53.81,51.122 C53.81,48.967 55.563,47.213 57.72,47.213 C59.88,47.213
  211. 61.634,48.967 61.634,51.122 C61.634,51.787 61.094,52.326 60.429,52.326 L60.429,52.326 Z" id="Mustafa-Left-Eye" fill="#3F372E"&gt;&lt;/path&gt;
  212. &lt;path d="M75.899,52.326 C75.231,52.326 74.695,51.787 74.695,51.122 C74.695,50.295 74.021,49.619 73.188,49.619 C72.361,49.619 71.688,50.295 71.688,51.122
  213. C71.688,51.787 71.146,52.326 70.484,52.326 C69.818,52.326 69.278,51.787 69.278,51.122 C69.278,48.967 71.037,47.213 73.188,47.213 C75.346,47.213
  214. 77.101,48.967 77.101,51.122 C77.102,51.787 76.559,52.326 75.899,52.326 L75.899,52.326 Z" id="Mustafa-Right-Eye" fill="#3F372E"&gt;&lt;/path&gt;
  215. &lt;path d="M76.4456778,62.3565674 C78.1319071,63.7008727 74.4204926,66.9530814 72.7733273,68.0499695 C71.126162,69.1468575 68.0660971,70.5763405
  216. 65.8852394,70.5763405 C63.7043817,70.5763405 59.6097044,68.9318757 58.3813209,68.0499693 C57.1529374,67.1680629 53.4953577,63.8108791
  217. 54.8127441,62.3565674 C56.1301305,60.9022556 58.2236035,63.1233233 59.4535298,63.9693678 C60.6834562,64.8154119 63.4038036,66.1736356
  218. 65.6591608,66.1736357 C67.2722666,66.1736358 69.8272118,65.4283507 71.0461488,64.5069182 C72.2650857,63.5854857 74.7594486,61.012262
  219. 76.4456778,62.3565674 Z" id="Mustafa-Mouth" fill="#E6BE7C"&gt;&lt;/path&gt;&lt;/g&gt;
  220. </code>
  221. <h2>Abstract</h2>
  222. <p>Основна ідея мати чистий SVG фреймворк що усі елементи були однотипними,
  223. і підхід був уніфікований, кнопки будь якого розміру, форми і які легко
  224. було би змінити в майбутньому. HTML/CSS підхід в подальшому не даcть
  225. змогу легко замінити контрольні елементи, карти і таке інше, доведеть
  226. повністью розбирати CSS елементи і верску. Уявіть що ми захочемо в
  227. майбутньому просто відкрити SVG у векторному редакторі, перемалювати
  228. і зберегти з тими самими element ID. У випадку з CSS при зміні дизайну ми
  229. постійно будемо змушені пестворювати верстку, знову наймати одноразову ручну роботу.
  230. У випадку з SVG нам доведеться тільки замінити елементи SVG.</P>
  231. <h2>SVG Integration Process</h2>
  232. <p>Підхід який пропонується нагадуеє уніфіковану роботу з векторними
  233. XML елементами, як це є в WPF наприклад. Тут справа не в байтах, в
  234. інтеграції процессу між дизайнерами, розробниками, верстальниками і
  235. серверними програмістами. Як наприклад Expression Blend у Microsoft для WPF.
  236. Саме з цих міркувань була вибрана технологія SVG.</p>
  237. <h2>SVG DOM Control</h2>
  238. <p>Інша частина це інтеграція SVG DOM і управління ним на сервері.
  239. Ми хочемо мати можливість модифікувати SVG DOM з сервера. Для цього
  240. нам потрібно прозорий та уніфікований підхід до усіх елементів.
  241. Це дасть нам змогу використовувати підхід як товстого (гра повністю в браузері),
  242. так і тонкого клієнту (коли стан гри повнітю контролюється сервером).</p>
  243. <h2>Sample Client</h2>
  244. <p>Прототип тонкого клієнту на елементах HTML/CSS викладений тут:<p>
  245. <code><a href="http://srv5.kakaranet.com:8080">http://srv5.kakaranet.com:8080</a></code>
  246. </div>
  247. <div class="contents">
  248. <iframe src="contents.htm" frameborder=0 width=340 height=2190></iframe>
  249. </div>
  250. </div>
  251. </body>
  252. </html>