*99の指定したプログラムを*00が作るスレ

このエントリーをはてなブックマークに追加
185仕様書無しさん
program Project1;
uses  Windows, SysUtils, StdCtrls, Graphics, Forms, Math,Dialogs;
type TForm1 = class(TCustomForm)
 private
 public
  fStart:boolean;
  tim:DWORD;
  lno,sp:Integer;
  procedure Paint; override;
  procedure Idle(Sender: TObject; var Done: Boolean);
  procedure Click(Sender: TObject);
 end;
var Form1: TForm1;
var cmax:Integer=5;eno:Integer;
 procedure TForm1.Click(Sender: TObject);
 begin fStart := not fStart;sp:=10; Caption:='';
 end;
 procedure TForm1.Idle(Sender: TObject; var Done: Boolean);
 var t:DWORD;
 begin
  t:=GetTickCount;
 if (t-tim)> sp then begin
  if sp< 1000+random(1000) then begin
    if fStart then sp:=10+random(5); inc(sp,sp div 5);
    inc(lno);
    lno:=lno mod cmax;
    Invalidate;
  end else begin Caption:=Format('あたりは%dの人です',[lno+1] ); sp:=sp+1000;end;
   tim:=t;
  end;  Done:=False;
 end;
 function cc(c,b:Integer):Integer;begin Result:=(c shr b) and $1;end ;
 procedure TForm1.Paint;
 var i:Integer;
 var x0,y0,r:Integer;
 begin
  x0:=Width div 2;   y0:=Height div 2;  r:=min(x0,y0)*3 div 4;
  for i:=0 to cmax-1 do begin
  if i= lno then Canvas.Brush.Color:=clWhite else  Canvas.Brush.Color:=cc(i,0)*$FF+cc(i,1)*$FF00+cc(i,2)*$FF0000;
     Canvas.Pie(x0-r,y0-r,x0+r,y0+r
     ,x0+round(r*cos((i+1)*2*PI/cmax))
     ,y0+round(r*sin((i+1)*2*PI/cmax))
     ,x0+round(r*cos((i )*2*PI/cmax))
     ,y0+round(r*sin((i )*2*PI/cmax))  );
  Canvas.Font.Color:= Canvas.Brush.Color xor $FFFFFF;
  Canvas.TextOut(  x0+round(0.7*r*cos((i*2+1)*PI/cmax)),
  y0+round(0.7*r*sin((i*2+1)*PI/cmax)),IntToStr(i+1));
  end;
 end;
begin
 Form1:=TForm1.CreateNew(nil);
 with TButton.Create(Form1) do begin Caption:='Start/Stop'; Parent:=Form1;
 OnClick:=Form1.Click; end;
 with Form1 do try  sp:=10;  tim:=GetTickCount;
 val(InputBox('ルーレット','人数', '5'), cmax,eno);
  lno:= (tim div 33) mod cmax;  Application.OnIdle:=Form1.Idle;
 if eno>0 then exit;
  Form1.ShowModal;
 finally Form1.free;end;
end.