Сначала получилось красиво, но не совсем то, что надо.
| Код | procedure drawrotate(can:TCanvas;rot:single;x1,y1,{x2,y2,}xr,yr:integer); const r=100; var i,g:single; mx,my:integer; bm:TBitmap; p:TPoint; begin mx:=0;my:=0; bm:=TBitmap.Create; bm.Width:=1023; bm.Height:=1023; i:=0; while i<=360 do begin p.x:=x1+round(r*cos(degtorad(i))); p.y:=y1+round(r*cos(degtorad(45+i))); p.x:=xr+round(abs(xr-p.x)*cos(DegToRad(i-rot))); p.y:=yr+round(abs(yr-p.y)*sin(DegToRad(i-rot))); if p.x>mx then mx:=p.x; if p.y>my then my:=p.y; if i=0 then bm.canvas.moveto(p.x,p.y) else bm.canvas.lineto(p.x,p.y); i:=i+0.1; end; can.CopyRect(rect(0,0,mx+1,my+1),bm.Canvas,rect(0,0,mx+1,my+1)); bm.free; end;
procedure TForm1.Button1Click(Sender: TObject); begin canvas.Rectangle(clientrect); drawrotate(canvas,spinedit1.value,200,200,200,200); end;
|
А вот оно
| Код | procedure drawrotate(can:TCanvas;rot:single;x1,y1,{x2,y2,}xr,yr:integer); const r=100; var i,g,d,t:single; mx,my:integer; bm:TBitmap; p:TPoint; begin mx:=0;my:=0; bm:=TBitmap.Create; bm.Width:=1023; bm.Height:=1023; i:=0; while i<=360 do begin p.x:=x1+round(r*cos(degtorad(i))); p.y:=y1+round(r*cos(degtorad(45+i))); d:=sqrt(sqr(xr-p.x)+sqr(yr-p.y)); if (xr-p.x=0)and(yr-p.y>0) then t:=90 else if (xr-p.x=0)and(yr-p.y<0) then t:=270 else t:=RadToDeg(arctan((yr-p.y)/(xr-p.x))); if ((xr-p.x)<0)then t:=t+180; if ((yr-p.y)<0)and((xr-p.x)>0) then t:=t+360; p.x:=xr+round(d*cos(DegToRad(t-rot))); p.y:=yr+round(d*sin(DegToRad(t-rot))); if p.x>mx then mx:=p.x; if p.y>my then my:=p.y; if i=0 then bm.canvas.moveto(p.x,p.y) else bm.canvas.lineto(p.x,p.y); i:=i+0.1; end; can.CopyRect(rect(0,0,mx+1,my+1),bm.Canvas,rect(0,0,mx+1,my+1)); bm.free; end;
procedure TForm1.Timer1Timer(Sender: TObject); begin spinedit1.Value:=spinedit1.Value+10; if spinedit1.Value=360 then spinedit1.Value:=0; canvas.Rectangle(clientrect); drawrotate(canvas,spinedit1.value,200,200,230,230); end;
|
|