2008年8月30日星期六

actionscript3 代码片段4 ――绘制3D bar

代码从openflashchart中取出

import flash.display.Sprite;
import flash.filters.DropShadowFilter;
import flash.geom.Matrix;

/**
* ...
* @author DefaultUser (Tools -> Custom Arguments...)
*/
public class Snippet3D_5 extends Sprite
{
private var col:Number = 0x3e4e4;// , 0x3ef43e];
public function Snippet3D_5()
{
var dropShadow:DropShadowFilter = new flash.filters.DropShadowFilter();
dropShadow.blurX = 5;
dropShadow.blurY = 5;
dropShadow.distance = 3;
dropShadow.angle = 45;
dropShadow.quality = 2;
dropShadow.alpha = 0.4;
this.filters = [dropShadow];
}
public function draw3Dbar(w:Number, h:Number,color:Number):void
{
this.col = color;
this.graphics.clear();
draw_top(w, h);
draw_front(w, h);
draw_side(w, h);
}
private function draw_top( w:Number, h:Number ):void {

this.graphics.lineStyle(0, 0, 0);
//set gradient fill

var lighter:Number = Lighten( this.col );

var colors:Array = [this.col,lighter];
var alphas:Array = [1,1];
var ratios:Array = [0,255];
var matrix:Matrix = new Matrix();
matrix.createGradientBox(w + 12, 12, (270 / 180) * Math.PI );
this.graphics.beginGradientFill('linear' /*GradientType.Linear*/, colors, alphas, ratios, matrix, 'pad'/*SpreadMethod.PAD*/ );


var y:Number = 0;
if( h<0 )
y = h;

this.graphics.moveTo(0, y);
this.graphics.lineTo(w, y);
this.graphics.lineTo(w-12, y+12);
this.graphics.lineTo(-12, y+12);
this.graphics.endFill();
}

private function draw_front( w:Number, h:Number ):void {
//
var rad:Number = 7;

var lighter:Number = Lighten( this.col );

// Darken a light color
//var darker:Number = this.colour;
//darker &= 0x7F7F7F;

var colors:Array = [lighter,this.col];
var alphas:Array = [1,1];
var ratios:Array = [0, 127];

var matrix:Matrix = new Matrix();
matrix.createGradientBox(w - 12, h+12, (90 / 180) * Math.PI );
this.graphics.beginGradientFill('linear' /*GradientType.Linear*/, colors, alphas, ratios, matrix, 'pad'/*SpreadMethod.PAD*/ );

this.graphics.moveTo(-12, 12);
this.graphics.lineTo(-12, h+12);
this.graphics.lineTo(w-12, h+12);
this.graphics.lineTo(w-12, 12);
this.graphics.endFill();
}

private function draw_side( w:Number, h:Number ):void {
//
var rad:Number = 7;

var lighter:Number = Lighten( this.col );

var colors:Array = [this.col,lighter];
var alphas:Array = [1,1];
var ratios:Array = [0,255];
var matrix:Matrix = new Matrix();
matrix.createGradientBox(w, h+12, (270 / 180) * Math.PI );
this.graphics.beginGradientFill('linear' /*GradientType.Linear*/, colors, alphas, ratios, matrix, 'pad'/*SpreadMethod.PAD*/ );


this.graphics.lineStyle(0, 0, 0);
this.graphics.moveTo(w, 0);
this.graphics.lineTo(w, h);
this.graphics.lineTo(w-12, h+12);
this.graphics.lineTo(w-12, 12);
this.graphics.endFill();
}
public function Lighten( col:Number ):Number {
var rgb:Number = col; //decimal value for a purple color
var red:Number = (rgb & 16711680) >> 16; //extacts the red channel
var green:Number = (rgb & 65280) >> 8; //extacts the green channel
var blue:Number = rgb & 255; //extacts the blue channel
var p:Number = 2;
red += red/p;
if( red > 255 )
red = 255;

green += green/p;
if( green > 255 )
green = 255;

blue += blue/p;
if( blue > 255 )
blue = 255;

return red << 16 | green << 8 | blue;
}
}

见: http://xiao-yifang.blogspot.com

2008年8月28日星期四

修改web.config,app.config

1,修改web.config
Configuration config = WebConfigurationManager.OpenWebConfiguration("~");
config.AppSettings.Settings["a1"].Value = "new value";
config.Save(ConfigurationSaveMode.Modified);

2,修改app.config

Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings["a1"].Value = "new value";
config.Save(ConfigurationSaveMode.Modified);

2008年8月27日星期三

2008年8月26日星期二

actionscript3 代码片段2

1,pie切片

var radius:Number = 100;
var TO_RADIANS:Number = Math.PI / 180;
graphics.clear();
graphics.lineStyle(2, 0x45ef98, 1);
graphics.beginFill(0xf0f0f0, 1);
graphics.moveTo(0, 0);
graphics.lineTo(radius, 0);

var angle:Number = 50;
var a:Number = Math.tan((angle/2)*TO_RADIANS);

var endx:Number;
var endy:Number;
var ax:Number;
var ay:Number;

endx = radius*Math.cos(angle*TO_RADIANS);
endy = radius*Math.sin(angle*TO_RADIANS);
ax = endx+radius*a*Math.cos((angle-90)*TO_RADIANS);
ay = endy+radius*a*Math.sin((angle-90)*TO_RADIANS);
graphics.curveTo(ax, ay, endx, endy);
graphics.endFill();
graphics.lineTo(0, 0);

2,donut,甜甜圈
var colors:Array = [0x87347e, 0x0000ef, 0x8D6433];
var alphas:Array = [100, 100, 100];
var ratios:Array = [0, 110, 255];
var matrix:Matrix = new Matrix();// { a:300, b:0, c:50, d:0, u:300, v:0, tx: -3, ty:3, w:1 };
graphics.beginGradientFill("radial", colors, alphas, ratios, matrix);
drawdonut(86, 36, 100, 94);
graphics.endFill();
其中drawdonut函数
public function drawdonut(r1:Number, r2:Number, x:Number, y:Number):void {
var TO_RADIANS:Number = Math.PI/180;
this.graphics.moveTo(0, 0);
this.graphics.lineTo(r1, 0);

// draw the 30-degree segments
var a:Number = 0.268; // tan(15)
var i:Number;
var endx:Number;
var endy:Number;
var ax:Number;
var ay:Number;
for ( i=0; i < 12; i++) {
endx = r1*Math.cos((i+1)*30*TO_RADIANS);
endy = r1*Math.sin((i+1)*30*TO_RADIANS);
ax = endx+r1*a*Math.cos(((i+1)*30-90)*TO_RADIANS);
ay = endy+r1*a*Math.sin(((i+1)*30-90)*TO_RADIANS);
this.graphics.curveTo(ax, ay, endx, endy);
}

// cut out middle (draw another circle before endFill applied)
this.graphics.moveTo(0, 0);
this.graphics.lineTo(r2, 0);

for ( i =0; i < 12; i++) {
endx = r2*Math.cos((i+1)*30*TO_RADIANS);
endy = r2*Math.sin((i+1)*30*TO_RADIANS);
ax = endx+r2*a*Math.cos(((i+1)*30-90)*TO_RADIANS);
ay = endy+r2*a*Math.sin(((i+1)*30-90)*TO_RADIANS);
this.graphics.curveTo(ax, ay, endx, endy);
}

this.x = x;
this.y = y;
}


效果:

2008年8月24日星期日

ActionScript3 代码片段1

1,自定义图形绘制填充
var param3:Number = 10;
var mapData:BitmapData = new BitmapData(param3, param3, true, 0);
var shape:Shape = new Shape;
shape.graphics.beginFill(0,0);
shape.graphics.lineStyle(1,0.5,1,true);
shape.graphics.moveTo(0, param3 / 2);
shape.graphics.lineTo(param3, param3 / 2);
shape.graphics.moveTo(param3 / 2, 0);
shape.graphics.lineTo(param3 / 2, param3);
shape.width = 10;
shape.height = 10;
shape.graphics.endFill();
mapData.draw(shape);
graphics.beginBitmapFill(mapData, new Matrix(), true);
graphics.lineStyle(1);
graphics.drawRect(100, 100, 400, 10);
graphics.endFill();

效果:


2,tweener 片段
使用的tweener为http://code.google.com/p/tweener/

public function Snippet2()
{
graphics.beginFill(0x777777);
graphics.lineStyle(2, 0x3efa0);
graphics.drawCircle(0, 0, 10);
graphics.endFill();
this.addEventListener(MouseEvent.MOUSE_OVER, this.mouseOver);
this.addEventListener(MouseEvent.MOUSE_OUT, this.mouseOut);
}
public function mouseOver(event:Event):void {
Tweener.addTween(this, { _scale:2, transition:Equations.easeOutElastic});
}

public function mouseOut(event:Event):void {
// stop the pulse, then fade in
Tweener.addTween(this, { _scale:1,alpha:0.33, transition:Equations.easeOutElastic } );
}

效果如下:

2008年8月23日星期六

ActionScript3 20分钟速览(不是教程)


对有其他编程经验的人。
1,变量
var 变量名:数据类型=值;

数据类型分基本数据类型和复杂数据类型
基本数据类型有Boolean,int,Number,String和unit,
复杂数据类型有Array,Date,Error,Function,RegExp,XML和自定义的类型。

声明方式如:

var i:int=2;
var name:String="name";

Array的赋值可以使用[],如var arr:Array=[1,"3",[5,6]]
Object的赋值可以使用{},使用上与javascript的类似

2,运算符,表达式
如其他语言的相同,除了部分细节方面的处理不一样,不影响第一次使用
3,流程控制
if else,switch,while,do while,for ,return,break
for多了用法 for each ,for in,对第一此使用的人,可以先不管。
4,函数定义
function 函数名 (参数1:参数类型,参数2:参数类型):返回值
{
函数体
}
5,类
class,类及接口的继承方式
其他诸如命名空间,包导入之类可以调过,不影响使用。
6,事件

掌握以上应该就可以进行基本的编码了。


2008年8月22日星期五

图表组件

用以绘制直线,饼状,柱状之类的2D,3D图形的一些软件列表
1,SharpGraph.net
可视化设计支持比较好。
2,dotnetcharting
非常专业,从图表数量和质量来说。
3,ComponentArt WebChart
几个flash相关的
4,AnyChart
5,ampie
6,NetAdvantage中的Chart控件
7,DevExpress中的Chart控件

.net 平台 行为测试框架 ,Rhino Mocks ,

2008年8月19日星期二

asp.net网页动态生成图形



//1,生成Graphics对象

Bitmap newBitmap = new Bitmap(200, 200, PixelFormat.Format32bppArgb);
Graphics g = Graphics.FromImage(newBitmap);
//2,图形绘制



//3,输出到页面
MemoryStream tempStream = new MemoryStream();
newBitmap.Save(tempStream, ImageFormat.Png);
Response.ClearContent();
Response.ContentType = "image/png";
Response.BinaryWrite(tempStream.ToArray());
Response.Flush();

2008年8月9日星期六

兔子爱上猫(There She is 3)


http://www.sambakza.net/amalloc/amalloc_frameset.htm

2008年8月3日星期日

清理一下不常用的组件

1,ZipForge.NET
解压缩
2.cpSphereLicense
授权
3.Mentalis Security
加解密
4.Mentalis IniReader
ini文件读写
5.PDFLIB
PDF文件创建
6.Garbe.Sound
声音文件处理
7.Mentalis Multimedia
多媒体文件处理
8..NET Communication Library
通讯处理,邮件
9.BossWare SMTPClient
邮件类,不过.net 2.0中有同功能类。
10.cpSphere.Mail
邮件处理
11.FTPComponent
FTP封装类
12.Mentalis ICMP
13.Mentalis ProxySocket
代理类,允许穿越防火墙
14.ScandPortal
根据IP查询国家
15.Whois
16.FreeTextBox
在线多功能编辑器
17.PieChart Component
asp.net 图表
18.SourceGrid
自定义Grid
19.Lumisoft UI Controls
UI控件
20.XSChart
21.TreeGrid control