﻿uses
  GraphABC;

var
  N, size: integer;
  angle: real;


function getPolygon(corners, radius, x, y: integer; difangle: real): array of GraphABC.Point;
var
  angle: real;
begin
  SetLength(Result, corners);
  angle := 360 / corners;
  
  for var i := 0 to N - 1 do
    Result[i] := new GraphABC.Point(
      Round(x + radius * cos(DegToRad(i * angle + difangle))),
      Round(y + radius * sin(DegToRad(i * angle + difangle)))
  );
end;

procedure onKeyUp(x: integer);
var
  b: boolean;

begin
  GraphABC.ClearWindow();
  
  if (N = 15) then b := true else b := false;
  
  if (x = GraphABC.VK_Left) and (N > 2) then
    N := N - 1;
  
  if (x = GraphABC.VK_Right) then
    N := N + 1;
  
  if b and (N > 15) then
    Window.Maximize()
  else if b and (N < 15) then
    Window.Normalize();
  
  angle := 180 / N + 90;
  
  GraphABC.Pen.Color := Color.FromArgb(255, Color.LightBlue.R - 50, Color.LightBlue.G - 50, Color.LightBlue.B + 20);
  GraphABC.Brush.Color := Color.LightBlue;
  GraphABC.Polygon(getPolygon(N, size, Window.Center.X, Window.Center.Y, angle));
  
  GraphABC.Redraw();
  
  Sleep(10);
end;

procedure onResize();
begin
  size := Window.Height div 2 - Window.Height div 10;
  onKeyUp(0);
end;

begin
  GraphABC.LockDrawing;
  
  N := 7; 
  size := Window.Height div 2 - Window.Height div 10;
  
  GraphABC.OnKeyUp := onKeyUp;
  GraphABC.OnResize := onResize;
  
  onKeyUp(0);
end.