unit dgen_shapes;

interface

uses
  dcolors,
  dvector2f,
  dscreenbuffer,
  dtexture2d_generator;

type
TTexCheckboard = class(TTexGen1f)
  Size: TVec2f;
  function Get(const V: TVec2f): Single; override;
end;

function Checkboard1f(const Size: TVec2f): TTexCheckboard; overload;
function Checkboard1f(const Size: Single): TTexCheckboard; overload;

implementation

function TTexCheckboard.Get(const V: TVec2f): Single;
begin
  if ((Trunc(V.X / Size.X) + Trunc(V.Y / Size.Y)) mod 2) > 0 then
    Result := 1.0
  else
	Result := 0.0;
end;

function Checkboard1f(const Size: TVec2f): TTexCheckboard;
begin
  Result := TTexCheckboard.Create;
  Result.Size := Size;
end;

function Checkboard1f(const Size: Single): TTexCheckboard;
begin
  Result := Checkboard1f(Vec2f(Size, Size));
end;

end.
