掌叔
2010-01-18 20:34:41
require "gd"
n = 9;
im = gd.createTrueColor(201,201);
white = im:colorResolve(255,255,255);
red = im:colorResolve(255, 0, 0);
green = im:colorResolve( 0,255, 0);
blue = im:colorResolve( 0, 0,255);
-- im:line( 0,100,200,100, white);
-- im:line(100, 0,100,200, white);
r=100;
ox=100;
oy=100;
for u=0,2*math.pi, 2*math.pi/n do
x=r*math.cos(u)+ox;
y=r*math.sin(u)+oy;
if last_x == nil or last_y == nil then
first_x, first_y = x,y;
else
im:line( last_x, last_y, x, y, green);
end
last_x=x;
last_y=y;
end
im:line( last_x, last_y, first_x, first_y, green);
im:png("tt.png");
[attach]2422[/attach]
修改n就可以产生其他多边型