「Mojocolors」とは、ActionScriptで色相、彩度、明るさ(HSB: Hue, Saturation, Brightness)などを簡単、自然な方法で操作するオープンソースのActionScriptライブラリです。

「Mojocolors」を使うと、ch.badmojo.color.Colorで一つの色もしくはch.badmojo.color.ColorWheelの様のセットの色の動作ができます。

カラー理論/調和のルールはライブラリの中にラップされているので、開発者たちはその方面を気にならず、アプリケーションのロジックのみでOKです。

以下は簡単なグラデーションの例の一つです。まずはコンパイルしたSWFはそうなん感じで。

Mojocolors

1)、Colorsオブジェクトを生成

  1. // create the first color object, a nice blue:
  2. var blue : Color = new Color(16, 34, 43);
  3.  
  4. // then the second color
  5. var orange : Color = new Color(226, 240, 214);

2)、グラデーション

  1. // you can now use the .gradient method on color to create a gradient. A
  2. //  ColorWheel is created which stores all colors from blue to orange.
  3. var gradient : ColorWheel = blue.gradientTo(orange);

3)、ループで描画

  1. //      now we paint rectangles for each color in the wheel.
  2. //      you do not have to access a color in the colorwheel by an index. If
  3. //      you use the ColorWheel in a loop, then getColor not only gives you
  4. //      the current color, it also “rotates” the wheel to the next color.
  5. //      When the wheel went through all colors, it starts at it’s beginning.
  6.  
  7. for (var i : int = 0;i < gradient.length(); i++) {
  8.  
  9. //              get the current color
  10.         var currentColor : Color = gradient.getColor();
  11. //              to get the hex values of the color, use getHex                        
  12.         this.graphics.beginFill(currentColor.getHex());
  13.         this.graphics.drawRect(i * 10, 0, 10, this.stage.stageHeight / 2);
  14.         this.graphics.endFill();
  15. }

もっと多いとなると、

  1. //              when you create a ColorWheel with the gradientTo method, all
  2. //              colors are sorted. you can mix your ColorWheel by
  3. //              calling shuffle():
  4. gradient.shuffle();
  5. var theX : Number250;
  6. for (var k : int = 0;k < gradient.length(); k++) {
  7.  
  8. //                      get the current color
  9.         currentColor = gradient.getColor();
  10.  
  11. //                      draw the bars again with a offset.
  12.         this.graphics.beginFill(currentColor.getHex());
  13.         var random : Number = Math.random()*30;
  14.         this.graphics.drawRect(theX, 0, 5 +random, this.stage.stageHeight / 2);
  15.         this.graphics.endFill();
  16.         theX += random;
  17. }

[関連リンク]

http://code.google.com/p/mojocolors/ 公式ページ

メインコンテンツEND ■
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Posted on Tuesday, 19th May 2009 by admin

Tags: , ,
Posted in ActionScript, Flash Project | Comments (0) | 1,687 views

Related Posts

Leave a Reply