Facebook
From Ungracious Hornbill, 7 Years ago, written in C++.
Embed
Download Paste or View Raw
Hits: 244
  1. //---------------------------------------------------------------------------
  2.  
  3. #include <vcl.h>
  4. #pragma hdrstop
  5.  
  6. #include "Unit1.h"
  7. //---------------------------------------------------------------------------
  8. #pragma package(smart_init)
  9. #pragma resource "*.dfm"
  10. TForm1 *Form1;
  11. //---------------------------------------------------------------------------
  12. __fastcall TForm1::TForm1(TComponent* Owner)
  13.         : TForm(Owner)
  14. {
  15. }
  16. //---------------------------------------------------------------------------
  17.  
  18. void __fastcall TForm1::DodajClick(TObject *Sender)
  19. {
  20.         Image1->Height =300;
  21.         Image1->Width =300;
  22.         Image2->Height =300;
  23.         Image2->Width =300;
  24.  
  25.         Image1->Canvas->MoveTo((Image1->Width/2),0);
  26.         Image1->Canvas->LineTo((Image1->Width/2),(Image1->Height));
  27.         Image1->Canvas->MoveTo(0,(Image1->Height/2));
  28.         Image1->Canvas->LineTo((Image1->Width),(Image1->Height/2));
  29.  
  30.         TPoint points[4];
  31.         int x1 = StrToInt(X1->Text)+150;
  32.         int y1 = -StrToInt(Y1->Text)+150;
  33.  
  34.         int x2 = StrToInt(X2->Text)+150;
  35.         int y2 = -StrToInt(Y2->Text)+150;
  36.  
  37.         int x3 = StrToInt(X3->Text)+150;
  38.         int y3 = -StrToInt(Y3->Text)+150;
  39.  
  40.         int x4 = StrToInt(X4->Text)+150;
  41.         int y4 = -StrToInt(Y4->Text)+150;
  42.  
  43.         points[0].x = x1;
  44.         points[1].x = x2;
  45.         points[2].x = x3;
  46.         points[3].x = x4;
  47.  
  48.         points[0].y = y1;
  49.         points[1].y = y2;
  50.         points[2].y = y3;
  51.         points[3].y = y4;
  52.  
  53.         int x_min = points[0].x;
  54.         int x_max = points[0].x;
  55.         int y_min = points[0].y;
  56.         int y_max = points[0].y;
  57.  
  58.         for(int i = 0; i < 4; i++){
  59.                 x_min = x_min > points[i].x ? points[i].x : x_min;
  60.                 x_max = x_max < points[i].x ? points[i].x : x_max;
  61.                 y_min = y_min > points[i].y ? points[i].y : y_min;
  62.                 y_max = y_max < points[i].y ? points[i].y : y_max;
  63.         }
  64.  
  65.         for(int i =0 ; i < 4; i++) {
  66.                 int x = points[i].x;
  67.                 int y = points[i].y;
  68.                 int r = 1;
  69.                 Image1->Canvas->Pixels[x][y]=clBlack;
  70.         }
  71.  
  72.         float sx = (Image2->Width - 0.0f ) / ( x_max - x_min );
  73.         float sy = (Image2->Height - 0.0f ) / ( y_max - y_min );
  74.  
  75.         sx = sx < sy ? sx : sy;
  76.         sy = sx < sy ? sx : sy;
  77.  
  78.         for(int i =0 ; i < 4; i++) {
  79.                 int x = (points[i].x - x_min) * sx;
  80.                 int y = (points[i].y - y_min) * sy;
  81.  
  82.                 int r = 3;
  83.                 int rx = r * sx;
  84.                 int ry = r * sy;
  85.  
  86.                 Image2->Canvas->Ellipse(x - rx, y - ry, x + rx, y + ry);
  87.         }
  88. }
  89. //---------------------------------------------------------------------------
  90.  
  91.  
  92.