﻿uses graphabc;

var
  i, x, y, w, h: integer;
  arx, ary, len, mov: integer;

procedure snowfall(x0, y0, r, n: integer);
var
  i, j, tx, ty: integer;
begin
  for i := 1 to 6 do
  begin
    x := x0 + round(r * cos(i * (pi / 3)));
    y := y0 - round(r * sin(i * (pi / 3)));
    line(x0, y0, x, y);
    for j := 1 to 6 do
    begin
      tx := x + round((r div 4) * cos(j * (pi / 3)));
      ty := y - round((r div 4) * sin(j * (pi / 3)));
      line(x, y, tx, ty);
    end;
  end;
end;

begin
  pen.color := clWhite;
  w := 500; //Ширина окна
  h := 600; //Высота окна
  window.Init(0, 0, w, h, clwhite);
  window.IsFixedSize := false;
  mov := random(-1, 1);
  len := random(10, 20); //Размер снежинки
  ary := -random(0, h);
  arx := random(0, w - len);
  i := 0;
  lockdrawing;
  var time := millisecondsdelta();
  while true do
  begin
    time := millisecondsdelta();
    time := time div 2;
    window.Clear(clskyblue);
    pen.color := clyellow;
    brush.Color := clyellow;
    circle(w div 2, 0, h div 5);
    pen.color := clWhite;
    if(len > 15) then pen.Width := 3
    else pen.Width := 2;
    ary := ary + round(0.7 * time); //Скорость падения снежинки
    arx := arx + (mov * time div 4);
    if(ary - 2 * len > h) or (arx - 2 * len > w) or (arx + 2 * len < 0) then 
    begin
      len := random(10, 20);
      ary := -len; 
      arx := random(0, w - len); 
      mov := random(-1, 1); 
    end;
    snowfall(arx, ary, len, 2);
    redraw; 
    sleep(1);
  end;
end.