This blog will be associated with eclipse, Java Micro Edition, Android, etc... My premiere blogging date began from March, 25th, 2009
5/13/2009
Make my own Roulette image...
Making roulette game will have not an easy task. Probably, the task should be included some mathematic routines. I don't know yet what sort of mathematic should be needed for....
At the moment, I will introduce one method how can make roulette image by Delphi 6 and Graphics32. Of course, there are many ways we can make it by using other development tools. To make an executable file with this source, Delphi 6 Standard and Graphics32 Component should be needed.
Uses
..., Math, GR32_Image, GR32; // Add this in Uses
// Conversion double rgb color value to TColor value
Function MakeColor(b, g, r: Double): Integer;
begin
result := Trunc(r * 255) shl 16 + Trunc(b * 255) shl 8 + Trunc(g * 255);
end;
// In order to display text by angle
procedure TextRotate(bitmap: TBitmap32; x, y, angle: integer; atext: string;afont: TFont);
var
lf:LogFont;
begin
//Please Change with your country font, test with a different font to get better result...
Bitmap.Font.Name := '궁서체';
Bitmap.Font.Size := 12;
Windows.GetObject(Bitmap.Font.Handle, sizeof(LOGFONT), @lf);
lf.lfEscapement := angle * 10;
lf.lfOrientation := angle * 10;
Bitmap.Font.Handle := CreateFontIndirect(lf);
Bitmap.Canvas.Brush.Style := bsClear;
Bitmap.Textout(x, y, atext);
end;
// Button event for drawing roulette Image
procedure TForm1.BitBtn1Click(Sender: TObject);
{ Draw 1 pixcel width line }
procedure DrawLine(X1, Y1, X2, Y2 : Integer; vBitmap: TBitmap32);
Begin
{ Fill area by drawing lines }
vBitmap.Canvas.MoveTo(X1,Y1);
vBitmap.Canvas.LineTo(X2,Y2);
End;
const
DEG2RAD : double = (3.14159/180);
var
vBitmap : TBitmap32;
dAngle, degInRad, dAngleX : Double;
x1, y1, i, centerx, centery : Integer;
Color0, Color1, Color2 : Integer;
Angle, X, Y, H, H2, W, X3 : Integer;
Step : Real;
ValueT : Array of String;
begin
vBitmap := TBitmap32.Create;
vBitmap.Width := 256;
vBitmap.Height := 256;
centerx := 128;
centery := 128;
vBitmap.Canvas.Pen.Width := 2;
vBitmap.Canvas.Pen.Color := MakeColor(0.66, 0.82, 0.82);
vBitmap.Canvas.Ellipse(10, 10, vBitmap.Width-10, vBitmap.Height-10);
dAngleX := 360 / 37;
for i := 0 to 36 do begin
dAngle := dAngleX * i;
degInRad := dAngle * DEG2RAD;
x1 := centerx - trunc(cos(degInRad) * (centerx-10));
Y1 := centery - trunc(sin(degInRad) * (centery-10));
vBitmap.Canvas.MoveTo(centerx, centery);
vBitmap.Canvas.LineTo(X1, Y1);
end;
vBitmap.Canvas.Ellipse(40, 40, vBitmap.Width-40, vBitmap.Height-40);
Color0 := MakeColor(1.0, 0.0, 0.0);
Color1 := MakeColor(0.0, 1.0, 0.0);
Color2 := MakeColor(0.0, 0.0, 0.0);
for i := 0 to 36 do begin
dAngle := dAngleX * i + 5;
degInRad := dAngle * DEG2RAD;
if(i = 0) then
vBitmap.Canvas.Brush.Color := Color0
else begin
if(i mod 2 = 1) then vBitmap.Canvas.Brush.Color := Color1
else vBitmap.Canvas.Brush.Color := Color2;
end;
x1 := centerx - trunc(cos(degInRad) * 110);
Y1 := centery - trunc(sin(degInRad) * 110);
vBitmap.Canvas.FloodFill(x1, y1, vBitmap.Canvas.Pen.Color, fsBorder);
end;
{ Get form size }
H:=vBitmap.Height;
W:=vBitmap.Width;
Angle := 0;
vBitmap.Canvas.Pen.Color := clBlue;
while (Angle<360) do begin
X := centerx - Round(cos(Angle*DEG2RAD) * 88);
Y := centery - Round(sin(Angle*DEG2RAD) * 88);
vBitmap.Canvas.Pen.Color:=RGB(255, 255,abs(255-Angle));
DrawLine(centerx, centery, X, Y, vBitmap);
Inc(Angle);
end;
Angle := 0;
vBitmap.Canvas.Pen.Color := clBlue;
while (Angle<360) do begin
X := centerx - Round(cos(Angle*DEG2RAD) * 48);
Y := centery - Round(sin(Angle*DEG2RAD) * 48);
vBitmap.Canvas.Pen.Color:=RGB(abs(255-Angle),abs(255-Angle),abs(255-Angle));
DrawLine(centerx, centery, X, Y, vBitmap);
Inc(Angle);
end;
vBitmap.Canvas.Brush.Color := RGB($DC, $B4, $8C);
vBitmap.Canvas.Pen.Color := RGB($DC, $B4, $8C);
vBitmap.Canvas.Rectangle(126, 128-62, 130, 128+62);
vBitmap.Canvas.Rectangle(128-62, 126, 128+62, 130);
vBitmap.Canvas.Rectangle(124, 128-62, 132, 128-22);
vBitmap.Canvas.Rectangle(124, 128+22, 132, 128+62);
vBitmap.Canvas.Rectangle(128-62, 124, 128-22, 132);
vBitmap.Canvas.Rectangle(128+22, 124, 128+62, 132);
vBitmap.Font.Color := RGB($FF, $FF, $FF);
vBitmap.Canvas.Brush.Style := bsClear;
Angle := 90;
Setlength(ValueT, 37);
ValueT[0] := '0'; ValueT[1] := '32'; ValueT[2] := '15'; ValueT[3] := '19';
ValueT[4] := '4'; ValueT[5] := '21'; ValueT[6] := '2'; ValueT[7] := '25';
ValueT[8] := '17'; ValueT[9] := '34'; ValueT[10] := '6'; ValueT[11] := '27';
ValueT[12] := '13'; ValueT[13] := '36'; ValueT[14] := '11'; ValueT[15] := '30';
ValueT[16] := '8'; ValueT[17] := '23'; ValueT[18] := '10'; ValueT[19] := '5';
ValueT[20] := '24'; ValueT[21] := '16'; ValueT[22] := '33'; ValueT[23] := '1';
ValueT[24] := '20'; ValueT[25] := '14'; ValueT[26] := '31'; ValueT[27] := '9';
ValueT[28] := '22'; ValueT[29] := '18'; ValueT[30] := '29'; ValueT[31] := '7';
ValueT[32] := '28'; ValueT[33] := '12'; ValueT[34] := '35'; ValueT[35] := '5';
ValueT[36] := '26';
for i := 0 to 36 do begin
if(length(ValueT[i]) = 1) Then
dAngle := dAngleX * i + 3
else
dAngle := dAngleX * i;
degInRad := dAngle * DEG2RAD;
x1 := centerx - trunc(cos(degInRad) * 110);
Y1 := centery - trunc(sin(degInRad) * 110);
TextRotate(vbitmap, x1, y1, Angle, ValueT[i], vBitmap.Font);
Angle := Angle - 10;
if(Angle = 0) then Angle := 360;
end;
PaintBox01.Canvas.CopyRect(Bounds(0, 0, vBitmap.Width, vBitmap.Height), vBitmap.Canvas,
Bounds(0, 0, vBitmap.Width, vBitmap.Height));
vBitmap.SaveToFile('image.bmp');
vBitmap.Free;
end;
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment