CSS147色を並べる – wonderfl build flash online
プログラムで色を出すときには、RGBの方が扱いやすいんだけど、「もうちょっと明るい色」みたいに調整する時にはHSVでの値指定の方が明らかに扱いやすい。
ちょっとはHSVに慣れておいた方がいいかなと思っていじってみた。
調べていくと色を扱うのは、不合理なところが多いのでめんどくさかったり、面白かったりする。
今回扱ったCSS147色では白系が多すぎる気がするし、名前は違うのに同じ色を指していたり、grayとgreyが混在していて、文化というか歴史的経緯の塊であることがわかる。
でも、コンピューターで色を扱うこと自体に、妥協というか限界があったりもするのでしょうがないよね、という気もしてくる。そもそも人間の光の感じ方が不均一だったり、人によって違っている。人間が使うものだから、文化に規定されるのは当たり前の話だ。
ところで、当初このコードでやりたかったのは、そんな話じゃなくて、構造体の使い方だったりする。
よく、命名規則の話で(アプリケーション)ハンガリアン記法の例として、priceDolとpriceYenを足すようなことを防止するため、という例が出てくる。もちろんそれは良いと思うけど、そもそもDolクラスやYenクラスでしかお金を扱えないようにしておけば、足すような事故が起きない。
RGBを例として作り出した、はずなのにぜんぜん違うものになってしまった(RGBColorクラス辺りがその残骸)。まあ、その不合理なところが面白い、はず。
参考
Converting between RGB and HSV color space
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 |
package { import flash.display.Sprite; import flash.events.Event; /** * ... * @author umhr */ [SWF(width = 465, height = 465, backgroundColor = 0x777777, frameRate = 30)] public class WonderflMain extends Sprite { public function WonderflMain():void { if (stage) init(); else addEventListener(Event.ADDED_TO_STAGE, init); } private function init(e:Event = null):void { removeEventListener(Event.ADDED_TO_STAGE, init); // entry point graphics.beginFill(0x777777); graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight); graphics.endFill(); addChild(new ColorCanvas()); } } } import a24.tween.Ease24; import a24.tween.Tween24; import com.bit101.components.RadioButton; import com.bit101.components.Style; import flash.display.Sprite; import flash.events.Event; import flash.events.MouseEvent; import flash.filters.DropShadowFilter; import flash.geom.Point; /** * ... * @author umhr */ class ColorCanvas extends Sprite { private var _centerInformation:CenterInformation = new CenterInformation(); private var _colorChipList:Vector.<ColorChip> = new Vector.<ColorChip>(); private var _currentRadio:String; public function ColorCanvas() { init(); } private function init():void { if (stage) onInit(); else addEventListener(Event.ADDED_TO_STAGE, onInit); } private function onInit(event:Event = null):void { removeEventListener(Event.ADDED_TO_STAGE, onInit); // entry point var rgbColorList:Vector.<RGBColor> = ColorPalette.rgbColorList; _centerInformation.x = stage.stageWidth * 0.5; _centerInformation.y = stage.stageHeight * 0.5; addChild(_centerInformation); var n:int = rgbColorList.length; for (var i:int = 0; i < n; i++) { addColorCircle(rgbColorList[i]); } setPosition("Hue"); addRadioButton(); stage.addEventListener(MouseEvent.MOUSE_MOVE, stage_mouseMove); } private function addRadioButton():void { Style.embedFonts = false; Style.fontSize = 12; Style.BACKGROUND = 0xFF0000; Style.LABEL_TEXT = 0xFFFFFF; new RadioButton(this, 8, 10, "Hue(色相)", true, onRadio); new RadioButton(this, 8, 30, "Saturation(彩度)", false, onRadio); new RadioButton(this, 8, 50, "Value(明度)", false, onRadio); new RadioButton(this, 8, 70, "Name", false, onRadio); } private function onRadio(event:MouseEvent):void { var radioButton:RadioButton = event.target as RadioButton; var name:String = radioButton.label; name = name.split("(")[0]; setPosition(name); } private function stage_mouseMove(e:MouseEvent):void { var object:* = getObjectsUnderPoint(new Point(mouseX, mouseY)).pop(); if (object == "[object ColorChip]") { var n:int = _colorChipList.length; for (var i:int = 0; i < n; i++) { _colorChipList[i].filters = []; } var colorChip:ColorChip = object as ColorChip; colorChip.filters = [new DropShadowFilter(0)]; var rgbColor:RGBColor = colorChip.rgbColor; _centerInformation.setRGBColor(rgbColor); } } private function addColorCircle(rgbColor:RGBColor):void { var colorChip:ColorChip = new ColorChip(rgbColor); colorChip.x = stage.stageWidth * 0.5; colorChip.y = stage.stageHeight * 0.5; addChild(colorChip); _colorChipList.push(colorChip); } private function setPosition(name:String):void { if (_currentRadio == name) { return; } _currentRadio = name; var colorChip:ColorChip; var d:Number; var n:int = _colorChipList.length; var num:Number; var indexList:Vector.<int> = ColorPalette["indexListBy" + name]; var tweenList:Array/*Tween24*/ = []; var k:int; for (var i:int = 0; i < n; i++) { d = i % 3; num = i / n; k = indexList[i]; tweenList[i] = Tween24.tween(_colorChipList[k], 0.5, Ease24._2_QuadOut); tweenList[i].x(stage.stageWidth * 0.5 + Math.cos(num * 2 * Math.PI) * (170 + d * 22)); tweenList[i].y(stage.stageHeight * 0.5 + Math.sin(num * 2 * Math.PI) * (170 + d * 22)); tweenList[i].delay(d * 0.1); } Tween24.parallel.apply(null, tweenList).play(); } } import flash.display.Sprite; import flash.events.Event; import flash.filters.DropShadowFilter; import flash.text.TextField; import flash.text.TextFormat; import flash.text.TextFormatAlign; /** * ... * @author umhr */ class CenterInformation extends Sprite { public var _textField:TextField = new TextField(); public function CenterInformation() { init(); } private function init():void { if (stage) onInit(); else addEventListener(Event.ADDED_TO_STAGE, onInit); } private function onInit(event:Event = null):void { removeEventListener(Event.ADDED_TO_STAGE, onInit); // entry point addTextField(); } private function addTextField():void { var textFormat:TextFormat = new TextFormat("_sans", 12, 0xFFFFFF); textFormat.align = TextFormatAlign.CENTER; _textField.defaultTextFormat = textFormat; _textField.text = "\n\n\n\n"; _textField.wordWrap = true; _textField.multiline = true; _textField.width = 200; _textField.autoSize = "center"; _textField.x = -_textField.width * 0.5; _textField.y = -_textField.height * 0.5; _textField.filters = [new DropShadowFilter(0, 0, 0x000000, 1, 4, 4, 2)]; addChild(_textField); } public function setRGBColor(rgbColor:RGBColor):void { graphics.clear(); graphics.beginFill(rgbColor.rgb); graphics.drawCircle(0, 0, 100); graphics.endFill(); var text:String = ""; text += "Name:" + rgbColor.name + "\n"; text += "RGB:0x" + rgbColor.rgb.toString(16).toUpperCase() + "\n"; text += "Hue:" + Math.floor(rgbColor.hue) + "\n"; text += "Saturation:" + Math.floor(rgbColor.saturation) + "\n"; text += "Value:" + Math.floor(rgbColor.value) + "\n"; _textField.text = text; } } /** * CSS色 * http://www.color-sample.com/popular/htmlcolor/ * ... * @author umhr */ class ColorPalette { static public const ALICE_BLUE:int = 0xF0F8FF; static public const ANTIQUE_WHITE:int = 0xFAEBD7; static public const AQUA:int = 0x00FFFF; static public const AQUAMARINE:int = 0x7FFFD4; static public const AZURE:int = 0xF0FFFF; static public const BEIGE:int = 0xF5F5DC; static public const BISQUE:int = 0xFFE4C4; static public const BLACK:int = 0x000000; static public const BLANCHED_ALMOND:int = 0xFFEBCD; static public const BLUE:int = 0x0000FF; static public const BLUE_VIOLET:int = 0x8A2BE2; static public const BRASS:int = 0xB5A642; static public const BROWN:int = 0xA52A2A; static public const BURLY_WOOD:int = 0xDEB887; static public const CADET_BLUE:int = 0x5F9EA0; static public const CHARTREUSE:int = 0x7FFF00; static public const CHOCOLATE:int = 0xD2691E; static public const COOLCOPPER:int = 0xD98719; static public const COPPER:int = 0xBF00DF; static public const CORAL:int = 0xFF7F50; static public const CORNFLOWER:int = 0xBFEFDF; static public const CORNFLOWER_BLUE:int = 0x6495ED; static public const CORNSILK:int = 0xFFF8DC; static public const CRIMSON:int = 0xDC143C; static public const CYAN:int = 0x00FFFF; static public const DARK_BLUE:int = 0x00008B; static public const DARK_BROWN:int = 0xDA0B00; static public const DARK_CYAN:int = 0x008B8B; static public const DARK_GOLDENROD:int = 0xB8860B; static public const DARK_GRAY:int = 0xA9A9A9; static public const DARK_GREEN:int = 0x006400; static public const DARK_KHAKI:int = 0xBDB76B; static public const DARK_MAGENTA:int = 0x8B008B; static public const DARK_OLIVE_GREEN:int = 0x556B2F; static public const DARK_ORANGE:int = 0xFF8C00; static public const DARK_ORCHID:int = 0x9932CC; static public const DARK_RED:int = 0x8B0000; static public const DARK_SALMON:int = 0xE9967A; static public const DARK_SEA_GREEN:int = 0x8FBC8F; static public const DARK_SLATE_BLUE:int = 0x483D8B; static public const DARK_SLATE_GRAY:int = 0x2F4F4F; static public const DARK_TURQUOISE:int = 0x00CED1; static public const DARK_VIOLET:int = 0x9400D3; static public const DEEP_PINK:int = 0xFF1493; static public const DEEP_SKY_BLUE:int = 0x00BFFF; static public const DIM_GRAY:int = 0x696969; static public const DODGER_BLUE:int = 0x1E90FF; static public const FELDSPER:int = 0xFED0E0; static public const FIRE_BRICK:int = 0xB22222; static public const FLORAL_WHITE:int = 0xFFFAF0; static public const FOREST_GREEN:int = 0x228B22; static public const FUCHSIA:int = 0xFF00FF; static public const GAINSBORO:int = 0xDCDCDC; static public const GHOST_WHITE:int = 0xF8F8FF; static public const GOLD:int = 0xFFD700; static public const GOLDENROD:int = 0xDAA520; static public const GRAY:int = 0x808080; static public const GREEN:int = 0x008000; static public const GREEN_YELLOW:int = 0xADFF2F; static public const HONEYDEW:int = 0xF0FFF0; static public const HOT_PINK:int = 0xFF69B4; static public const INDIAN_RED:int = 0xCD5C5C; static public const INDIGO:int = 0x4B0082; static public const IVORY:int = 0xFFFFF0; static public const KHAKI:int = 0xF0E68C; static public const LAVENDER:int = 0xE6E6FA; static public const LAVENDER_BLUSH:int = 0xFFF0F5; static public const LAWN_GREEN:int = 0x7CFC00; static public const LEMON_CHIFFON:int = 0xFFFACD; static public const LIGHT_BLUE:int = 0xADD8E6; static public const LIGHT_CORAL:int = 0xF08080; static public const LIGHT_CYAN:int = 0xE0FFFF; static public const LIGHT_GOLDENROD_YELLOW:int = 0xFAFAD2; static public const LIGHT_GREEN:int = 0x90EE90; static public const LIGHT_GREY:int = 0xD3D3D3; static public const LIGHT_PINK:int = 0xFFB6C1; static public const LIGHT_SALMON:int = 0xFFA07A; static public const LIGHT_SEA_GREEN:int = 0x20B2AA; static public const LIGHT_SKY_BLUE:int = 0x87CEFA; static public const LIGHT_SLATE_GRAY:int = 0x778899; static public const LIGHT_STEEL_BLUE:int = 0xB0C4DE; static public const LIGHT_YELLOW:int = 0xFFFFE0; static public const LIME:int = 0x00FF00; static public const LIME_GREEN:int = 0x32CD32; static public const LINEN:int = 0xFAF0E6; static public const MAGENTA:int = 0xFF00FF; static public const MAROON:int = 0x800000; static public const MEDIUM_AQUAMARINE:int = 0x66CDAA; static public const MEDIUM_BLUE:int = 0x0000CD; static public const MEDIUM_ORCHID:int = 0xBA55D3; static public const MEDIUM_PURPLE:int = 0x9370DB; static public const MEDIUM_SEA_GREEN:int = 0x3CB371; static public const MEDIUM_SLATE_BLUE:int = 0x7B68EE; static public const MEDIUM_SPRING_GREEN:int = 0x00FA9A; static public const MEDIUM_TURQUOISE:int = 0x48D1CC; static public const MEDIUM_VIOLET_RED:int = 0xC71585; static public const MIDNIGHT_BLUE:int = 0x191970; static public const MINT_CREAM:int = 0xF5FFFA; static public const MISTY_ROSE:int = 0xFFE4E1; static public const MOCCASIN:int = 0xFFE4B5; static public const NAVAJO_WHITE:int = 0xFFDEAD; static public const NAVY:int = 0x000080; static public const OLD_LACE:int = 0xFDF5E6; static public const OLIVE:int = 0x808000; static public const OLIVE_DRAB:int = 0x6B8E23; static public const ORANGE:int = 0xFFA500; static public const ORANGE_RED:int = 0xFF4500; static public const ORCHID:int = 0xDA70D6; static public const PALE_GOLDENROD:int = 0xEEE8AA; static public const PALE_GREEN:int = 0x98FB98; static public const PALE_TURQUOISE:int = 0xAFEEEE; static public const PALE_VIOLET_RED:int = 0xDB7093; static public const PAPAYA_WHIP:int = 0xFFEFD5; static public const PEACH_PUFF:int = 0xFFDAB9; static public const PERU:int = 0xCD853F; static public const PINK:int = 0xFFC0CB; static public const PLUM:int = 0xDDA0DD; static public const POWDER_BLUE:int = 0xB0E0E6; static public const PURPLE:int = 0x800080; static public const RED:int = 0xFF0000; static public const RICHBLUE:int = 0x0CB0E0; static public const ROSY_BROWN:int = 0xBC8F8F; static public const ROYAL_BLUE:int = 0x4169E1; static public const SADDLE_BROWN:int = 0x8B4513; static public const SALMON:int = 0xFA8072; static public const SANDY_BROWN:int = 0xF4A460; static public const SEA_GREEN:int = 0x2E8B57; static public const SEASHELL:int = 0xFFF5EE; static public const SIENNA:int = 0xA0522D; static public const SILVER:int = 0xC0C0C0; static public const SKY_BLUE:int = 0x87CEEB; static public const SLATE_BLUE:int = 0x6A5ACD; static public const SLATE_GRAY:int = 0x708090; static public const SNOW:int = 0xFFFAFA; static public const SPRING_GREEN:int = 0x00FF7F; static public const STEEL_BLUE:int = 0x4682B4; static public const TAN:int = 0xD2B48C; static public const TEAL:int = 0x008080; static public const THISTLE:int = 0xD8BFD8; static public const TOMATO:int = 0xFF6347; static public const TURQUOISE:int = 0x40E0D0; static public const VIOLET:int = 0xEE82EE; static public const WHEAT:int = 0xF5DEB3; static public const WHITE:int = 0xFFFFFF; static public const WHITE_SMOKE:int = 0xF5F5F5; static public const YELLOW:int = 0xFFFF00; static public const YELLOW_GREEN:int = 0x9ACD32; /** * 名前順リスト */ static public const NAME_LIST:Vector.<String> = Vector.<String>(["ALICE_BLUE", "ANTIQUE_WHITE", "AQUA", "AQUAMARINE", "AZURE", "BEIGE", "BISQUE", "BLACK", "BLANCHED_ALMOND", "BLUE", "BLUE_VIOLET", "BRASS", "BROWN", "BURLY_WOOD", "CADET_BLUE", "CHARTREUSE", "CHOCOLATE", "COOLCOPPER", "COPPER", "CORAL", "CORNFLOWER", "CORNFLOWER_BLUE", "CORNSILK", "CRIMSON", "CYAN", "DARK_BLUE", "DARK_BROWN", "DARK_CYAN", "DARK_GOLDENROD", "DARK_GRAY", "DARK_GREEN", "DARK_KHAKI", "DARK_MAGENTA", "DARK_OLIVE_GREEN", "DARK_ORANGE", "DARK_ORCHID", "DARK_RED", "DARK_SALMON", "DARK_SEA_GREEN", "DARK_SLATE_BLUE", "DARK_SLATE_GRAY", "DARK_TURQUOISE", "DARK_VIOLET", "DEEP_PINK", "DEEP_SKY_BLUE", "DIM_GRAY", "DODGER_BLUE", "FELDSPER", "FIRE_BRICK", "FLORAL_WHITE", "FOREST_GREEN", "FUCHSIA", "GAINSBORO", "GHOST_WHITE", "GOLD", "GOLDENROD", "GRAY", "GREEN", "GREEN_YELLOW", "HONEYDEW", "HOT_PINK", "INDIAN_RED", "INDIGO", "IVORY", "KHAKI", "LAVENDER", "LAVENDER_BLUSH", "LAWN_GREEN", "LEMON_CHIFFON", "LIGHT_BLUE", "LIGHT_CORAL", "LIGHT_CYAN", "LIGHT_GOLDENROD_YELLOW", "LIGHT_GREEN", "LIGHT_GREY", "LIGHT_PINK", "LIGHT_SALMON", "LIGHT_SEA_GREEN", "LIGHT_SKY_BLUE", "LIGHT_SLATE_GRAY", "LIGHT_STEEL_BLUE", "LIGHT_YELLOW", "LIME", "LIME_GREEN", "LINEN", "MAGENTA", "MAROON", "MEDIUM_AQUAMARINE", "MEDIUM_BLUE", "MEDIUM_ORCHID", "MEDIUM_PURPLE", "MEDIUM_SEA_GREEN", "MEDIUM_SLATE_BLUE", "MEDIUM_SPRING_GREEN", "MEDIUM_TURQUOISE", "MEDIUM_VIOLET_RED", "MIDNIGHT_BLUE", "MINT_CREAM", "MISTY_ROSE", "MOCCASIN", "NAVAJO_WHITE", "NAVY", "OLD_LACE", "OLIVE", "OLIVE_DRAB", "ORANGE", "ORANGE_RED", "ORCHID", "PALE_GOLDENROD", "PALE_GREEN", "PALE_TURQUOISE", "PALE_VIOLET_RED", "PAPAYA_WHIP", "PEACH_PUFF", "PERU", "PINK", "PLUM", "POWDER_BLUE", "PURPLE", "RED", "RICHBLUE", "ROSY_BROWN", "ROYAL_BLUE", "SADDLE_BROWN", "SALMON", "SANDY_BROWN", "SEA_GREEN", "SEASHELL", "SIENNA", "SILVER", "SKY_BLUE", "SLATE_BLUE", "SLATE_GRAY", "SNOW", "SPRING_GREEN", "STEEL_BLUE", "TAN", "TEAL", "THISTLE", "TOMATO", "TURQUOISE", "VIOLET", "WHEAT", "WHITE", "WHITE_SMOKE", "YELLOW", "YELLOW_GREEN"]); static private var _rgbColorList:Vector.<RGBColor>; static private var _rgbListByName:Vector.<int>; static private var _rgbListByValue:Vector.<int>; static private var _rgbListBySaturation:Vector.<int>; static private var _rgbListByHue:Vector.<int>; static private var _indexListByValue:Vector.<int>; static private var _indexListBySaturation:Vector.<int>; static private var _indexListByHue:Vector.<int>; static private var _indexListByName:Vector.<int>; /** * 明度順リスト */ static public function get rgbListByName():Vector.<int> { if (_rgbListByName) { return _rgbListByName; } var n:int = rgbColorList.length; _rgbListByName = new Vector.<int>(n, true); _indexListByName = new Vector.<int>(n, true); for (var i:int = 0; i < n; i++) { _rgbListByName[i] = _rgbColorList[i].rgb; _indexListByName[i] = i; } return _rgbListByName; } static public function get rgbListByValue():Vector.<int> { if (_rgbListByValue) { return _rgbListByValue; } return setList(_rgbListByValue, "value", "_indexListByValue"); } static public function get rgbListByHue():Vector.<int> { if (_rgbListByHue) { return _rgbListByHue; } return setList(_rgbListByHue, "hue", "_indexListByHue"); } static public function get rgbListBySaturation():Vector.<int> { if (_rgbListBySaturation) { return _rgbListBySaturation; } return setList(_rgbListBySaturation, "saturation", "_indexListBySaturation"); } static private function setList(list:Vector.<int>, prop:String, indexName:String):Vector.<int> { var valueList:Array = []; var indexList:Vector.<int>; var n:int = rgbColorList.length; for (var i:int = 0; i < n; i++) { valueList[i] = _rgbColorList[i][prop]; } indexList = Vector.<int>(valueList.sort(Array.NUMERIC | Array.RETURNINDEXEDARRAY)); list = new Vector.<int>(n, true); for (i = 0; i < n; i++) { list[i] = _rgbColorList[indexList[i]].rgb; } ColorPalette[indexName] = indexList; return list; } static public function get rgbColorList():Vector.<RGBColor> { if (_rgbColorList) { return _rgbColorList; } var n:int = NAME_LIST.length; _rgbColorList = new Vector.<RGBColor>(n, true); for (var i:int = 0; i < n; i++) { _rgbColorList[i] = new RGBColor(ColorPalette[NAME_LIST[i]]); _rgbColorList[i].name = NAME_LIST[i]; } return _rgbColorList; } static public function get indexListByHue():Vector.<int> { if (!_indexListByHue) { rgbListByHue; } return _indexListByHue; } static public function get indexListByName():Vector.<int> { if (!_indexListByName) { rgbListByName; } return _indexListByName; } static public function get indexListBySaturation():Vector.<int> { if (!_indexListBySaturation) { rgbListBySaturation; } return _indexListBySaturation; } static public function get indexListByValue():Vector.<int> { if (!_indexListByValue) { rgbListByValue; } return _indexListByValue; } public function ColorPalette() { } } import flash.display.Sprite; /** * ... * @author umhr */ class ColorChip extends Sprite { public var rgbColor:RGBColor; public function ColorChip(rgbColor:RGBColor) { this.rgbColor = rgbColor; name = rgbColor.name; init(); } private function init():void { graphics.beginFill(rgbColor.rgb); //graphics.drawRect(-28, -3, 56, 6); graphics.drawCircle(0, 0, 10); graphics.endFill(); } } import flash.geom.ColorTransform; /** * Converting between RGB and HSV color space * RGBとHSVの相互変換 * http://www.technotype.net/tutorial/tutorial.php?fileId=%7BImage%20processing%7D§ionId=%7B-converting-between-rgb-and-hsv-color-space%7D * ... * @author umhr */ class RGBColor { private var _alpha:Number; private var _a:int; public var red:int; public var green:int; public var blue:int; public var hue:Number; public var saturation:Number; public var value:Number; private var _rgb:int; public var name:String; public function RGBColor(rgb:int = NaN) { if (!isNaN(rgb)) { this.rgb = rgb; } } private function setHSV():void { var max:int = Math.max(red, green, blue); var min:int = Math.min(red, green, blue); // h if(max == min){ hue = 0; } else if(max == red){ hue = (60 * (green - blue) / (max - min) + 360) % 360; } else if(max == green){ hue = (60 * (blue - red) / (max - min)) + 120; } else if(max == blue){ hue = (60 * (red - green) / (max - min)) + 240; } // s if(max == 0){ saturation = 0; } else{ saturation = (255 * ((max - min) / max)); } // v value = max; } public function setByHSV(hue:int, saturation:int, value:int):void { this.hue = hue; this.saturation = saturation; this.value = value; var i:int = Math.floor(hue / 60) % 6; var f:Number = (hue / 60) - Math.floor(hue / 60); var p:int = Math.round(value * (1 - (saturation / 255))); var q:int = Math.round(value * (1 - (saturation / 255) * f)); var t:int = Math.round(value * (1 - (saturation / 255) * (1 - f))); switch(i){ case 0 : red = value; green = t; blue = p; break; case 1 : red = q; green = value; blue = p; break; case 2 : red = p; green = value; blue = t; break; case 3 : red = p; green = q; blue = value; break; case 4 : red = t; green = p; blue = value; break; case 5 : red = value; green = p; blue = q; break; } rgb = ColorUtils.rgbCombination(red, green, blue); } public function toString(radix:* = 10):String { return rgb.toString(radix); } /** * 0~1の値を返します。 */ public function get alpha():Number { return _alpha; } public function set alpha(value:Number):void { _alpha = value; _a = value * 255; } /** * 0~255の値を返します。 */ public function get a():int { return _a; } public function set a(value:int):void { _a = value; _alpha = value / 255; } public function get rgb():int { return _rgb; } public function set rgb(value:int):void { _rgb = value; red = value >> 16 & 0xFF; green = value >> 8 & 0xFF; blue = value & 0xFF; setHSV(); } } import flash.geom.ColorTransform; /** * ... * @author umhr */ class ColorUtils { public function ColorUtils() { } static public function colorTransform(rgb:int):ColorTransform { var colorTransform:ColorTransform = new ColorTransform(); colorTransform.redMultiplier = colorTransform.blueMultiplier = colorTransform.greenMultiplier = 0; colorTransform.redOffset = rgb >> 16;//16bit右にずらす。 colorTransform.greenOffset = rgb >> 8 & 0xff;//8bit右にずらして、下位8bitのみを取り出す。 colorTransform.blueOffset = rgb & 0xff;//下位8bitのみを取り出す。 return colorTransform; } static public function rgbCombination(red:int, green:int, blue:int):int { return red << 16 | green << 8 | blue; } /** * rgbをargbにして返します。 * @param rgb * @param alpha * @return */ static public function addAlpha(rgb:uint, alpha:int = 0xFF):uint { return alpha << 24 | rgb; } static public function removeAlpha(argb:uint):int { return argb & 0xFFFFFF; } static public function rgbSeparater(rgb:int):Vector.<int> { return Vector.<int>([rgb >> 16 & 0xFF, rgb >> 8 & 0xFF, rgb & 0xFF]); } static public function rgbSeparaterArray(rgb:int):Array { return [rgb >> 16 & 0xFF, rgb >> 8 & 0xFF, rgb & 0xFF]; } static public function rgbSeparaters(rgb:int, r:int, g:int, b:int):void { r = rgb >> 16 & 0xFF; g = rgb >> 8 & 0xFF; b = rgb & 0xFF; } /** * フィールドカラーに変色します. * 6桁16進数から、2桁ぶんずつを取り出す。 * 色情報は24bit。r8bit+g8bit+b8bit。24桁の二進数 * @param rgb * @param ratio * @return */ static public function colorTransformFromRGB(rgb:int, ratio:Number = 1):ColorTransform { //ratioが1以外の場合、明度変更関数へ if(ratio != 1){rgb = rgbBrightness(rgb,ratio)}; var color:ColorTransform = new ColorTransform(); color.redMultiplier = color.blueMultiplier = color.greenMultiplier = 0; color.redOffset = rgb >> 16;//16bit右にずらす。 color.greenOffset = rgb >> 8 & 0xff;//8bit右にずらして、下位8bitのみを取り出す。 color.blueOffset = rgb & 0xff;//下位8bitのみを取り出す。 return color; } /** * 色の明度を相対的に変える関数。 * rgb値と割合を与えて、結果を返す。 * rgbは、0xffffff段階の値。 * ratioが0の時に0x000000に、1の時にそのまま、2の時には0xffffffになる。 * 相対的に、ちょっと暗くしたい時には、ratioを0.8に、 * ちょっと明るくしたい時にはratioを1.2などに設定する。 */ static public function rgbBrightness(rgb:int, ratio:Number):int { if(ratio < 0 || 2 < ratio){ratio = 1;trace("function colorBrightness 範囲外")} var _r:int = rgb >> 16;//16bit右にずらす。 var _g:int = rgb >> 8 & 0xff;//8bit右にずらして、下位8bitのみを取り出す。 var _b:int = rgb & 0xff;//下位8bitのみを取り出す。 if(ratio <= 1){ _r *= ratio; _g *= ratio; _b *= ratio; }else{ _r = (255 - _r)*(ratio-1)+_r; _g = (255 - _g)*(ratio-1)+_g; _b = (255 - _b)*(ratio-1)+_b; } return _r << 16 | _g << 8 | _b; } } |