{"id":100,"date":"2007-12-18T01:18:15","date_gmt":"2007-12-18T01:18:15","guid":{"rendered":"http:\/\/pblog.ru\/lab\/?p=15"},"modified":"2007-12-18T01:18:15","modified_gmt":"2007-12-18T01:18:15","slug":"games189","status":"publish","type":"post","link":"http:\/\/pblog.ru\/lab\/?p=100","title":{"rendered":"\u041f\u043e\u0432\u043e\u0440\u043e\u0442 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438"},"content":{"rendered":"<p>\u041a\u0430\u043a \u043f\u043e\u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443 \u043d\u0430 \u043d\u0443\u0436\u043d\u044b\u0439 \u0443\u0433\u043e\u043b?<br \/>\n<!--more--><\/p>\n<pre class=\"alt2\" style=\"margin:0px; padding:6px; border:1px inset; width:580px; height:320px; overflow:auto\"><div>procedure RotateBitmap(Bitmap: TBitmap; Angle: Double; BackColor: TColor);\ntype TRGB = record\n       B, G, R: Byte;\n     end;\n     pRGB = ^TRGB;\n     pByteArray = ^TByteArray;\n     TByteArray = array[0..32767] of Byte;\n     TRectList = array [1..4] of TPoint;\n\nvar x, y, W, H, v1, v2: Integer;\n    Dest, Src: pRGB;\n    VertArray: array of pByteArray;\n    Bmp: TBitmap;\n\n  procedure SinCos(AngleRad: Double; var ASin, ACos: Double);\n  begin\n    ASin := Sin(AngleRad);\n    ACos := Cos(AngleRad);\n  end;\n\n  function RotateRect(const Rect: TRect; const Center: TPoint; Angle: Double): TRectList;\n  var DX, DY: Integer;\n      SinAng, CosAng: Double;\n    function RotPoint(PX, PY: Integer): TPoint;\n    begin\n      DX := PX - Center.x;\n      DY := PY - Center.y;\n      Result.x := Center.x + Round(DX * CosAng - DY * SinAng);\n      Result.y := Center.y + Round(DX * SinAng + DY * CosAng);\n    end;\n  begin\n    SinCos(Angle * (Pi \/ 180), SinAng, CosAng);\n    Result[1] := RotPoint(Rect.Left, Rect.Top);\n    Result[2] := RotPoint(Rect.Right, Rect.Top);\n    Result[3] := RotPoint(Rect.Right, Rect.Bottom);\n    Result[4] := RotPoint(Rect.Left, Rect.Bottom);\n  end;\n\n  function Min(A, B: Integer): Integer;\n  begin\n    if A < B then Result := A\n             else Result := B;\n  end;\n\n  function Max(A, B: Integer): Integer;\n  begin\n    if A > B then Result := A\n             else Result := B;\n  end;\n\n  function GetRLLimit(const RL: TRectList): TRect;\n  begin\n    Result.Left := Min(Min(RL[1].x, RL[2].x), Min(RL[3].x, RL[4].x));\n    Result.Top := Min(Min(RL[1].y, RL[2].y), Min(RL[3].y, RL[4].y));\n    Result.Right := Max(Max(RL[1].x, RL[2].x), Max(RL[3].x, RL[4].x));\n    Result.Bottom := Max(Max(RL[1].y, RL[2].y), Max(RL[3].y, RL[4].y));\n  end;\n\n  procedure Rotate;\n  var x, y, xr, yr, yp: Integer;\n      ACos, ASin: Double;\n      Lim: TRect;\n  begin\n    W := Bmp.Width;\n    H := Bmp.Height;\n    SinCos(-Angle * Pi\/180, ASin, ACos);\n    Lim := GetRLLimit(RotateRect(Rect(0, 0, Bmp.Width, Bmp.Height), Point(0, 0), Angle));\n    Bitmap.Width := Lim.Right - Lim.Left;\n    Bitmap.Height := Lim.Bottom - Lim.Top;\n    Bitmap.Canvas.Brush.Color := BackColor;\n    Bitmap.Canvas.FillRect(Rect(0, 0, Bitmap.Width, Bitmap.Height));\n    for y := 0 to Bitmap.Height - 1 do begin\n      Dest := Bitmap.ScanLine[y];\n      yp := y + Lim.Top;\n      for x := 0 to Bitmap.Width - 1 do begin\n        xr := Round(((x + Lim.Left) * ACos) - (yp * ASin));\n        yr := Round(((x + Lim.Left) * ASin) + (yp * ACos));\n        if (xr > -1) and (xr < W) and (yr > -1) and (yr < H) then begin\n          Src := Bmp.ScanLine[yr];\n          Inc(Src, xr);\n          Dest^ := Src^;\n        end;\n        Inc(Dest);\n      end;\n    end;\n  end;\n\nbegin\n  Bitmap.PixelFormat := pf24Bit;\n  Bmp := TBitmap.Create;\n  try\n    Bmp.Assign(Bitmap);\n    W := Bitmap.Width - 1;\n    H := Bitmap.Height - 1;\n    if Frac(Angle) <> 0.0\n      then Rotate\n      else\n    case Trunc(Angle) of\n      -360, 0, 360, 720: Exit;\n      90, 270: begin\n        Bitmap.Width := H + 1;\n        Bitmap.Height := W + 1;\n        SetLength(VertArray, H + 1);\n        v1 := 0;\n        v2 := 0;\n        if Angle = 90.0 then v1 := H\n                        else v2 := W;\n        for y := 0 to H do VertArray[y] := Bmp.ScanLine[Abs(v1 - y)];\n        for x := 0 to W do begin\n          Dest := Bitmap.ScanLine[x];\n          for y := 0 to H do begin\n            v1 := Abs(v2 - x)*3;\n            with Dest^ do begin\n              B := VertArray[y, v1];\n              G := VertArray[y, v1+1];\n              R := VertArray[y, v1+2];\n            end;\n            Inc(Dest);\n          end;\n        end\n      end;\n      180: begin\n        for y := 0 to H do begin\n          Dest := Bitmap.ScanLine[y];\n          Src := Bmp.ScanLine[H - y];\n          Inc(Src, W);\n          for x := 0 to W do begin\n            Dest^ := Src^;\n            Dec(Src);\n            Inc(Dest);\n          end;\n        end;\n      end;\n      else Rotate;\n    end;\n  finally\n    Bmp.Free;\n  end;\nend;\n\n\/\/ \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\nRotateBitmap(Image1.Picture.Bitmap, StrToInt(Edit1.Text), clWhite);\n<\/div><\/pre>\n<p><a href=\"http:\/\/www.programmersforum.ru\/member.php?u=5\">zetrix<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u041a\u0430\u043a \u043f\u043e\u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443 \u043d\u0430 \u043d\u0443\u0436\u043d\u044b\u0439 \u0443\u0433\u043e\u043b?<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[16,361],"tags":[244,283],"_links":{"self":[{"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/posts\/100"}],"collection":[{"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=100"}],"version-history":[{"count":0,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/posts\/100\/revisions"}],"wp:attachment":[{"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=100"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=100"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=100"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}