| 1 |
package |
|---|
| 2 |
{ |
|---|
| 3 |
import com.nitoyon.potras.*; |
|---|
| 4 |
import flash.display.*; |
|---|
| 5 |
import flash.text.*; |
|---|
| 6 |
import flash.net.*; |
|---|
| 7 |
import flash.events.*; |
|---|
| 8 |
import flash.utils.*; |
|---|
| 9 |
import flash.ui.Keyboard; |
|---|
| 10 |
import flash.utils.setTimeout; |
|---|
| 11 |
|
|---|
| 12 |
[SWF(width="480", height="360", backgroundColor="#ffffff")] |
|---|
| 13 |
public class Slide extends Sprite |
|---|
| 14 |
{ |
|---|
| 15 |
[Embed(source="assets/techni.jpg")] |
|---|
| 16 |
private var TechniImage:Class; |
|---|
| 17 |
|
|---|
| 18 |
[Embed(source="assets/data2.gif")] |
|---|
| 19 |
private var Data2Image:Class; |
|---|
| 20 |
|
|---|
| 21 |
[Embed(source="bin/Main2.swf")] |
|---|
| 22 |
private var Main2Swf:Class; |
|---|
| 23 |
|
|---|
| 24 |
[Embed(source="../algorithm/bin/1-TraceTest.swf")] |
|---|
| 25 |
private var Algorithm1Swf:Class; |
|---|
| 26 |
|
|---|
| 27 |
[Embed(source="../algorithm/bin/2-LonTest.swf")] |
|---|
| 28 |
private var Algorithm2Swf:Class; |
|---|
| 29 |
|
|---|
| 30 |
[Embed(source="../algorithm/bin/3-BestPoligonTest.swf")] |
|---|
| 31 |
private var Algorithm3Swf:Class; |
|---|
| 32 |
|
|---|
| 33 |
[Embed(source="../algorithm/bin/4-AjustVertex.swf")] |
|---|
| 34 |
private var Algorithm4Swf:Class; |
|---|
| 35 |
|
|---|
| 36 |
[Embed(source="../algorithm/bin/5-Main.swf")] |
|---|
| 37 |
private var Algorithm5Swf:Class; |
|---|
| 38 |
|
|---|
| 39 |
private var page:Array = |
|---|
| 40 |
[ |
|---|
| 41 |
{title : true}, |
|---|
| 42 |
{size : 30, scale : 3.5, color : 0xff0000, text : "自己紹介\nIntro"}, |
|---|
| 43 |
{size : 40, scale : 1.0, color : 0x000066, text : "にとよんです。\nMy name is nitoyon."}, |
|---|
| 44 |
{size : 40, scale : 1.4, color : 0x000066, text : "「てっく煮」\nやってます。\ntech.nitoyon.com"}, |
|---|
| 45 |
{image : TechniImage}, |
|---|
| 46 |
{size : 40, scale : 1.4, color : 0x000066, text : "Flash っぽい\n表現勉強中。"}, |
|---|
| 47 |
{size : 30, scale : 2.0, color : 0x660066, text : "今日のネタ\nToday's topic"}, |
|---|
| 48 |
{size : 30, scale : 4.0, color : 0xff0000, text : "PotrAS"}, |
|---|
| 49 |
{size : 70, scale : 1.4, color : 0x000066, text : "Potrace\n+\nAS3"}, |
|---|
| 50 |
{size : 70, scale : 1.4, color : 0x009900, text : "What is\nPotrace?"}, |
|---|
| 51 |
{size : 35, scale : 1.0, color : 0x000066, text : "potrace.sourceforge.net"}, |
|---|
| 52 |
{size : 40, scale : 1.4, color : 0x0000ff, text : "Raster→Vector"}, |
|---|
| 53 |
{size : 20, scale : 1.4, color : 0x000066, text : "Cで書かれている\nWritten in C."}, |
|---|
| 54 |
{size : 20, scale : 1.4, color : 0x000066, text : "のを"}, |
|---|
| 55 |
{size : 20, scale : 1.4, color : 0xffffff, lineColor : 0, text : "AS3 に移植した!\nI Ported it to AS3!"}, |
|---|
| 56 |
{size : 40, scale : 1.4, color : 0xffffff, lineColor : 0, text : "AS3 に移植した!\nI Ported it to AS3!"}, |
|---|
| 57 |
{size : 60, scale : 1.4, color : 0xffffff, lineColor : 0, text : "AS3 に移植した!\nI Ported it to AS3!"}, |
|---|
| 58 |
{size : 30, scale : 3.5, color : 0xff0000, text : "Example"}, |
|---|
| 59 |
{image : Data2Image}, |
|---|
| 60 |
{size : 40, scale : 1.4, color : 0x000066, text : "Let's Convert it\nto vector data!!"}, |
|---|
| 61 |
{image : Main2Swf}, |
|---|
| 62 |
{size : 30, scale : 3.0, color : 0x000000, text : "How does\nit work?"}, |
|---|
| 63 |
{image : Algorithm1Swf}, |
|---|
| 64 |
{image : Algorithm2Swf}, |
|---|
| 65 |
{image : Algorithm3Swf}, |
|---|
| 66 |
{image : Algorithm4Swf}, |
|---|
| 67 |
{image : Algorithm5Swf}, |
|---|
| 68 |
{size : 30, scale : 3.0, color : 0x000000, text : "Letter\nTracing"}, |
|---|
| 69 |
{size : 25, scale : 1.4, color : 0x000066, text : "fontSize: 25"}, |
|---|
| 70 |
{size : 25, scale : 5.0, color : 0x000066, text : "超絶"}, |
|---|
| 71 |
{size : 25, scale : 1.4, color : 0x000066, text : "fontSize: 50"}, |
|---|
| 72 |
{size : 50, scale : 3.0, color : 0x000066, text : "超絶"}, |
|---|
| 73 |
{size : 25, scale : 1.4, color : 0x000066, text : "fontSize: 100"}, |
|---|
| 74 |
{size : 100, scale : 1.2, color : 0x000066, text : "超絶"}, |
|---|
| 75 |
{size : 25, scale : 1.4, color : 0x000066, text : "fontSize: 200"}, |
|---|
| 76 |
{size : 200, scale : 1.2, color : 0x000066, text : "超絶"}, |
|---|
| 77 |
{size : 30, scale : 2.5, color : 0x000000, text : "応用例\nApplication"}, |
|---|
| 78 |
{size : 30, scale : 2.0, color : 0x999999, lineColor : 0x333333, text : "1. THIS SLIDE"}, |
|---|
| 79 |
{size : 30, scale : 2.0, color : 0x999999, lineColor : 0x333333, text : "2. TITLE"}, |
|---|
| 80 |
{title : true}, |
|---|
| 81 |
{size : 30, scale : 1.5, color : 0x999999, lineColor : 0x333333, text : "3. SEIZOU Filter"}, |
|---|
| 82 |
{size : 30, scale : 1.5, color : 0x999999, lineColor : 0x333333, text : "4. KANA TYPE"}, |
|---|
| 83 |
{size : 30, scale : 4.4, color : 0xffffff, lineColor : 0x003399, text : "Thank\nyou!"}, |
|---|
| 84 |
]; |
|---|
| 85 |
|
|---|
| 86 |
private var index:int = 0; |
|---|
| 87 |
private var so:SharedObject; |
|---|
| 88 |
private var typingNumber:int; |
|---|
| 89 |
|
|---|
| 90 |
public function Slide() |
|---|
| 91 |
{ |
|---|
| 92 |
stage.align = "TL"; |
|---|
| 93 |
stage.scaleMode = "showAll"; |
|---|
| 94 |
|
|---|
| 95 |
so = SharedObject.getLocal("slide"); |
|---|
| 96 |
index = so.data.index; |
|---|
| 97 |
|
|---|
| 98 |
stage.addEventListener("keyDown", keyDownHandler); |
|---|
| 99 |
setTimeout(function():void{show()}, 0); |
|---|
| 100 |
} |
|---|
| 101 |
|
|---|
| 102 |
private function keyDownHandler(event:KeyboardEvent):void |
|---|
| 103 |
{ |
|---|
| 104 |
switch(event.keyCode) |
|---|
| 105 |
{ |
|---|
| 106 |
case Keyboard.RIGHT: |
|---|
| 107 |
next(); |
|---|
| 108 |
break; |
|---|
| 109 |
case Keyboard.LEFT: |
|---|
| 110 |
prev(); |
|---|
| 111 |
break; |
|---|
| 112 |
case Keyboard.HOME: |
|---|
| 113 |
index = 0; |
|---|
| 114 |
show(); |
|---|
| 115 |
break; |
|---|
| 116 |
case Keyboard.END: |
|---|
| 117 |
index = page.length - 1; |
|---|
| 118 |
show(); |
|---|
| 119 |
break; |
|---|
| 120 |
case Keyboard.ENTER: |
|---|
| 121 |
if(typingNumber != -1) |
|---|
| 122 |
{ |
|---|
| 123 |
index = typingNumber; |
|---|
| 124 |
show(); |
|---|
| 125 |
} |
|---|
| 126 |
break; |
|---|
| 127 |
} |
|---|
| 128 |
|
|---|
| 129 |
if(48 <= event.keyCode && event.keyCode < 58) |
|---|
| 130 |
{ |
|---|
| 131 |
if(typingNumber == -1) typingNumber = 0; |
|---|
| 132 |
typingNumber = typingNumber * 10 + event.keyCode - 48; |
|---|
| 133 |
} |
|---|
| 134 |
else |
|---|
| 135 |
{ |
|---|
| 136 |
typingNumber = -1; |
|---|
| 137 |
} |
|---|
| 138 |
} |
|---|
| 139 |
|
|---|
| 140 |
private function prev():void |
|---|
| 141 |
{ |
|---|
| 142 |
if(index >= 0) index--; |
|---|
| 143 |
show(); |
|---|
| 144 |
} |
|---|
| 145 |
|
|---|
| 146 |
private function next():void |
|---|
| 147 |
{ |
|---|
| 148 |
if(index < page.length - 1) index++; |
|---|
| 149 |
show(index); |
|---|
| 150 |
} |
|---|
| 151 |
|
|---|
| 152 |
private function show(index:int = -1):void |
|---|
| 153 |
{ |
|---|
| 154 |
if(index == -1) |
|---|
| 155 |
{ |
|---|
| 156 |
index = this.index; |
|---|
| 157 |
} |
|---|
| 158 |
index = Math.max(0, index); |
|---|
| 159 |
index = Math.min(index, page.length - 1); |
|---|
| 160 |
|
|---|
| 161 |
so.data.index = index; |
|---|
| 162 |
so.flush(); |
|---|
| 163 |
|
|---|
| 164 |
clear(); |
|---|
| 165 |
|
|---|
| 166 |
if(page[index].title) |
|---|
| 167 |
{ |
|---|
| 168 |
createTitle(); |
|---|
| 169 |
} |
|---|
| 170 |
else if(page[index].image) |
|---|
| 171 |
{ |
|---|
| 172 |
createImage(index); |
|---|
| 173 |
} |
|---|
| 174 |
else |
|---|
| 175 |
{ |
|---|
| 176 |
createText(index); |
|---|
| 177 |
} |
|---|
| 178 |
} |
|---|
| 179 |
|
|---|
| 180 |
private function createText(index:int):void |
|---|
| 181 |
{ |
|---|
| 182 |
var w:int = loaderInfo.width; |
|---|
| 183 |
var h:int = loaderInfo.height; |
|---|
| 184 |
var text:String = page[index].text; |
|---|
| 185 |
var size:int = page[index].size; |
|---|
| 186 |
var scale:Number = page[index].scale; |
|---|
| 187 |
var color:int = page[index].color || 0; |
|---|
| 188 |
var lineColor:int = page[index].lineColor != null ? page[index].lineColor : color; |
|---|
| 189 |
var lines:Array = text.split(/\n/); |
|---|
| 190 |
|
|---|
| 191 |
for(var i:int = 0; i < lines.length; i++) |
|---|
| 192 |
{ |
|---|
| 193 |
var line:String = lines[i]; |
|---|
| 194 |
var lineSprite:Sprite = new Sprite(); |
|---|
| 195 |
var x:int = 0; |
|---|
| 196 |
var y:int = (h - lines.length * size * scale) / 2; |
|---|
| 197 |
|
|---|
| 198 |
var list:ClosedPathList = PotrAs.traceLetter(line, size); |
|---|
| 199 |
var sprite:Sprite = new Sprite(); |
|---|
| 200 |
sprite.graphics.beginFill(color); |
|---|
| 201 |
sprite.graphics.lineStyle(1, lineColor); |
|---|
| 202 |
list.draw(sprite.graphics); |
|---|
| 203 |
sprite.graphics.endFill(); |
|---|
| 204 |
sprite.scaleX = sprite.scaleY = scale; |
|---|
| 205 |
sprite.y = y; |
|---|
| 206 |
center(sprite); |
|---|
| 207 |
addChild(sprite).y = y + size * i * scale; |
|---|
| 208 |
} |
|---|
| 209 |
} |
|---|
| 210 |
|
|---|
| 211 |
private function createImage(index:int):void |
|---|
| 212 |
{ |
|---|
| 213 |
var w:int = loaderInfo.width; |
|---|
| 214 |
var h:int = loaderInfo.height; |
|---|
| 215 |
|
|---|
| 216 |
if(page[index].image is Class) |
|---|
| 217 |
{ |
|---|
| 218 |
var img:DisplayObject = new page[index].image; |
|---|
| 219 |
center(img, true); |
|---|
| 220 |
addChild(img); |
|---|
| 221 |
} |
|---|
| 222 |
else if(page[index].image is String) |
|---|
| 223 |
{ |
|---|
| 224 |
var url:String = page[index].image; |
|---|
| 225 |
var loader:Loader = new Loader(); |
|---|
| 226 |
var req:URLRequest = new URLRequest(url); |
|---|
| 227 |
loader.load(req); |
|---|
| 228 |
loader.contentLoaderInfo.addEventListener("complete", function(event:*):void |
|---|
| 229 |
{ |
|---|
| 230 |
center(loader, true); |
|---|
| 231 |
}); |
|---|
| 232 |
addChild(loader); |
|---|
| 233 |
} |
|---|
| 234 |
} |
|---|
| 235 |
|
|---|
| 236 |
private function center(s:DisplayObject, vertical:Boolean = false):void |
|---|
| 237 |
{ |
|---|
| 238 |
var w:int = loaderInfo.width; |
|---|
| 239 |
var x:Number = (w - s.width) / 2; |
|---|
| 240 |
s.x = x; |
|---|
| 241 |
|
|---|
| 242 |
if(vertical) |
|---|
| 243 |
{ |
|---|
| 244 |
var h:int = loaderInfo.height; |
|---|
| 245 |
var y:Number = (h - s.height) / 2; |
|---|
| 246 |
s.y = y; |
|---|
| 247 |
} |
|---|
| 248 |
} |
|---|
| 249 |
|
|---|
| 250 |
private function clear():void |
|---|
| 251 |
{ |
|---|
| 252 |
while(numChildren) |
|---|
| 253 |
{ |
|---|
| 254 |
removeChildAt(0); |
|---|
| 255 |
} |
|---|
| 256 |
} |
|---|
| 257 |
|
|---|
| 258 |
private function createTitle():void |
|---|
| 259 |
{ |
|---|
| 260 |
var list:ClosedPathList; |
|---|
| 261 |
var sprite:Sprite; |
|---|
| 262 |
|
|---|
| 263 |
var box:Sprite = new Sprite(); |
|---|
| 264 |
|
|---|
| 265 |
list = PotrAs.traceLetter("超", 30); |
|---|
| 266 |
sprite = new Sprite(); |
|---|
| 267 |
sprite.graphics.beginFill(0xcc99cc); |
|---|
| 268 |
sprite.graphics.lineStyle(1, 0x000000); |
|---|
| 269 |
list.draw(sprite.graphics); |
|---|
| 270 |
sprite.graphics.endFill(); |
|---|
| 271 |
box.addChild(sprite); |
|---|
| 272 |
|
|---|
| 273 |
list = PotrAs.traceLetter("絶", 30); |
|---|
| 274 |
sprite = new Sprite(); |
|---|
| 275 |
sprite.graphics.beginFill(0xff0000); |
|---|
| 276 |
sprite.graphics.lineStyle(1, 0x000000); |
|---|
| 277 |
list.draw(sprite.graphics); |
|---|
| 278 |
sprite.graphics.endFill(); |
|---|
| 279 |
sprite.x = 35; |
|---|
| 280 |
sprite.y = -2; |
|---|
| 281 |
sprite.rotation = 10; |
|---|
| 282 |
box.addChild(sprite); |
|---|
| 283 |
|
|---|
| 284 |
list = PotrAs.traceLetter("A", 30); |
|---|
| 285 |
sprite = new Sprite(); |
|---|
| 286 |
sprite.graphics.beginFill(0x006699); |
|---|
| 287 |
sprite.graphics.lineStyle(1, 0x000000); |
|---|
| 288 |
list.draw(sprite.graphics); |
|---|
| 289 |
sprite.graphics.endFill(); |
|---|
| 290 |
sprite.x = 5; |
|---|
| 291 |
sprite.y = 30; |
|---|
| 292 |
box.addChild(sprite); |
|---|
| 293 |
|
|---|
| 294 |
list = PotrAs.traceLetter("S", 30); |
|---|
| 295 |
sprite = new Sprite(); |
|---|
| 296 |
sprite.graphics.beginFill(0x006699); |
|---|
| 297 |
sprite.graphics.lineStyle(1, 0x000000); |
|---|
| 298 |
list.draw(sprite.graphics); |
|---|
| 299 |
sprite.graphics.endFill(); |
|---|
| 300 |
sprite.x = 35; |
|---|
| 301 |
sprite.y = 30; |
|---|
| 302 |
box.addChild(sprite); |
|---|
| 303 |
|
|---|
| 304 |
addChild(box); |
|---|
| 305 |
box.scaleX = box.scaleY = 6; |
|---|
| 306 |
center(box); |
|---|
| 307 |
} |
|---|
| 308 |
} |
|---|
| 309 |
} |
|---|