「Mojocolors」とは、ActionScriptで色相、彩度、明るさ(HSB: Hue, Saturation, Brightness)などを簡単、自然な方法で操作するオープンソースのActionScriptライブラリです。
「Mojocolors」を使うと、ch.badmojo.color.Colorで一つの色もしくはch.badmojo.color.ColorWheelの様のセットの色の動作ができます。
カラー理論/調和のルールはライブラリの中にラップされているので、開発者たちはその方面を気にならず、アプリケーションのロジックのみでOKです。
以下は簡単なグラデーションの例の一つです。まずはコンパイルしたSWFはそうなん感じで。
1)、Colorsオブジェクトを生成
- // create the first color object, a nice blue:
- var blue : Color = new Color(16, 34, 43);
- // then the second color
- var orange : Color = new Color(226, 240, 214);
2)、グラデーション
- // you can now use the .gradient method on color to create a gradient. A
- // ColorWheel is created which stores all colors from blue to orange.
- var gradient : ColorWheel = blue.gradientTo(orange);
3)、ループで描画
- // now we paint rectangles for each color in the wheel.
- // you do not have to access a color in the colorwheel by an index. If
- // you use the ColorWheel in a loop, then getColor not only gives you
- // the current color, it also “rotates” the wheel to the next color.
- // When the wheel went through all colors, it starts at it’s beginning.
- for (var i : int = 0;i < gradient.length(); i++) {
- // get the current color
- var currentColor : Color = gradient.getColor();
- // to get the hex values of the color, use getHex
- this.graphics.beginFill(currentColor.getHex());
- this.graphics.drawRect(i * 10, 0, 10, this.stage.stageHeight / 2);
- this.graphics.endFill();
- }
もっと多いとなると、
- // when you create a ColorWheel with the gradientTo method, all
- // colors are sorted. you can mix your ColorWheel by
- // calling shuffle():
- gradient.shuffle();
- var theX : Number = 250;
- for (var k : int = 0;k < gradient.length(); k++) {
- // get the current color
- currentColor = gradient.getColor();
- // draw the bars again with a offset.
- this.graphics.beginFill(currentColor.getHex());
- var random : Number = Math.random()*30;
- this.graphics.drawRect(theX, 0, 5 +random, this.stage.stageHeight / 2);
- this.graphics.endFill();
- theX += random;
- }
[関連リンク]
http://code.google.com/p/mojocolors/ 公式ページ
メインコンテンツEND ■
Posted on Tuesday, 19th May 2009 by admin
Tags: Mojocolors, オープンソース, ライブラリ
Posted in ActionScript, Flash Project | Comments (0) | 1,657 views
