Unit BGRAGradients

📄 Source code

Description

Helper functions for gradients and shadows, as well as Phong shading

Uses

Overview

Structures

Name Description
Record TnGradientInfo Functions to draw multiple gradients.
Class TPhongShading Renders shape and height maps using Phong shading.

Functions and Procedures

function CreateConeMap(size: integer): TBGRABitmap;
function CreateConePreciseMap(width,height: integer): TBGRABitmap;
function CreateCyclicPerlinNoiseMap(AWidth, AHeight: integer; HorizontalPeriod: Single = 1; VerticalPeriod: Single = 1; Exponent: Double = 1; ResampleFilter: TResampleFilter = rfCosine): TBGRABitmap;
function CreateHorizontalCylinderPreciseMap(width,height: integer): TBGRABitmap;
function CreatePerlinNoiseMap(AWidth, AHeight: integer; HorizontalPeriod: Single = 1; VerticalPeriod: Single = 1; Exponent: Double = 1; ResampleFilter: TResampleFilter = rfCosine): TBGRABitmap;
function CreateRectangleMap(width,height,border: integer; options: TRectangleMapOptions = []): TBGRABitmap;
function CreateRectanglePreciseMap(width,height,border: integer; options: TRectangleMapOptions = []): TBGRABitmap;
function CreateRectanglePreciseMap(width, height, borderWidth, borderHeight: integer; options: TRectangleMapOptions): TBGRABitmap;
function CreateRoundRectangleMap(width,height,border: integer; options: TRectangleMapOptions = []): TBGRABitmap;
function CreateRoundRectanglePreciseMap(width,height,border: integer; options: TRectangleMapOptions = []): TBGRABitmap;
function CreateRoundRectanglePreciseMap(width,height,borderWidth,borderHeight: integer; options: TRectangleMapOptions = []): TBGRABitmap;
function CreateSphereMap(width,height: integer): TBGRABitmap;
function CreateSpherePreciseMap(width,height: integer): TBGRABitmap;
function CreateVerticalConePreciseMap(width,height: integer): TBGRABitmap;
function CreateVerticalCylinderPreciseMap(width,height: integer): TBGRABitmap;
function DoubleGradientAlphaFill(AWidth,AHeight: Integer; AStart1,AStop1,AStart2,AStop2: TBGRAPixel; ADirection1,ADirection2,ADir: TGradientDirection; AValue: Single): TBGRABitmap; overload;
function DoubleGradientAlphaFill(ARect: TRect; AStart1,AStop1,AStart2,AStop2: TBGRAPixel; ADirection1,ADirection2,ADir: TGradientDirection; AValue: Single): TBGRABitmap; overload;
procedure DoubleGradientAlphaFill(ABitmap: TBGRABitmap; ARect: TRect; AStart1,AStop1,AStart2,AStop2: TBGRAPixel; ADirection1,ADirection2,ADir: TGradientDirection; AValue: Single); overload;
procedure DoubleGradientAlphaFill(ACanvas: TCanvas; ARect: TRect; AStart1,AStop1,AStart2,AStop2: TBGRAPixel; ADirection1,ADirection2,ADir: TGradientDirection; AValue: Single); overload;
function nGradientAlphaFill(AWidth, AHeight: Integer; ADir: TGradientDirection; const AGradient: array of TnGradientInfo): TBGRABitmap; overload;
function nGradientAlphaFill(ARect: TRect; ADir: TGradientDirection; const AGradient: array of TnGradientInfo): TBGRABitmap; overload;
procedure nGradientAlphaFill(ABitmap: TBGRABitmap; ARect: TRect; ADir: TGradientDirection; const AGradient: array of TnGradientInfo); overload;
procedure nGradientAlphaFill(ACanvas: TCanvas; ARect: TRect; ADir: TGradientDirection; const AGradient: array of TnGradientInfo); overload;
function nGradientInfo(StartColor, StopColor: TBGRAPixel; Direction: TGradientDirection; EndPercent: Single): TnGradientInfo;
function TextShadow(AWidth,AHeight: Integer; AText: String; AFontHeight: Integer; ATextColor,AShadowColor: TBGRAPixel; AOffSetX,AOffSetY: Integer; ARadius: Integer = 0; AFontStyle: TFontStyles = []; AFontName: String = 'Default'; AShowText: Boolean = True): TBGRABitmap;

Types

TRectangleMapOption = (...);
TRectangleMapOptions = set of TRectangleMapOption;

Description

Functions and Procedures

function CreateConeMap(size: integer): TBGRABitmap;

Create a grayscale height map for a cone (may not be precise enough)

function CreateConePreciseMap(width,height: integer): TBGRABitmap;

Create a precise height map for a cone (not grayscale anymore but more precise)

function CreateCyclicPerlinNoiseMap(AWidth, AHeight: integer; HorizontalPeriod: Single = 1; VerticalPeriod: Single = 1; Exponent: Double = 1; ResampleFilter: TResampleFilter = rfCosine): TBGRABitmap;

Creates a tilable random grayscale image.

Example filling a form with Perlin noise:

createcyclicperlinnoisemap

uses
  BGRABitmap, BGRABitmapTypes, BGRAGradients;

procedure TForm1.FormPaint(Sender: TObject);
var
  image,tex: TBGRABitmap;

begin
    image := TBGRABitmap.Create(ClientWidth,ClientHeight);

    tex := CreateCyclicPerlinNoiseMap(100,100);
    image.FillRect(0,0,image.Width,image.Height, tex, dmSet);
    tex.free;

    image.Draw(Canvas,0,0,True);
    image.free;
end;

See also tutorial on creating textures.

function CreateHorizontalCylinderPreciseMap(width,height: integer): TBGRABitmap;

Create a precise height map for an horizontal cylinder (not grayscale anymore but more precise)

function CreatePerlinNoiseMap(AWidth, AHeight: integer; HorizontalPeriod: Single = 1; VerticalPeriod: Single = 1; Exponent: Double = 1; ResampleFilter: TResampleFilter = rfCosine): TBGRABitmap;

Creates a non-tilable random grayscale image

function CreateRectangleMap(width,height,border: integer; options: TRectangleMapOptions = []): TBGRABitmap;

Create a rectangle height map with a border

function CreateRectanglePreciseMap(width,height,border: integer; options: TRectangleMapOptions = []): TBGRABitmap;

Create a precise height map for a rectangle height map with a border (not grayscale anymore but more precise)

function CreateRectanglePreciseMap(width, height, borderWidth, borderHeight: integer; options: TRectangleMapOptions): TBGRABitmap;

This item has no description.

function CreateRoundRectangleMap(width,height,border: integer; options: TRectangleMapOptions = []): TBGRABitmap;

Create a round rectangle height map with a border

function CreateRoundRectanglePreciseMap(width,height,border: integer; options: TRectangleMapOptions = []): TBGRABitmap;

Create a precise height map for a round rectangle height map with a border (not grayscale anymore but more precise)

function CreateRoundRectanglePreciseMap(width,height,borderWidth,borderHeight: integer; options: TRectangleMapOptions = []): TBGRABitmap;

This item has no description.

function CreateSphereMap(width,height: integer): TBGRABitmap;

Create a grayscale height map for a sphere (may not be precise enough)

function CreateSpherePreciseMap(width,height: integer): TBGRABitmap;

Create a precise height map for a sphere (not grayscale anymore but more precise)

function CreateVerticalConePreciseMap(width,height: integer): TBGRABitmap;

Create a precise height map for a vertical cone (not grayscale anymore but more precise)

function CreateVerticalCylinderPreciseMap(width,height: integer): TBGRABitmap;

Create a precise height map for a vertical cylinder (not grayscale anymore but more precise)

function DoubleGradientAlphaFill(AWidth,AHeight: Integer; AStart1,AStop1,AStart2,AStop2: TBGRAPixel; ADirection1,ADirection2,ADir: TGradientDirection; AValue: Single): TBGRABitmap; overload;

This item has no description.

function DoubleGradientAlphaFill(ARect: TRect; AStart1,AStop1,AStart2,AStop2: TBGRAPixel; ADirection1,ADirection2,ADir: TGradientDirection; AValue: Single): TBGRABitmap; overload;

This item has no description.

procedure DoubleGradientAlphaFill(ABitmap: TBGRABitmap; ARect: TRect; AStart1,AStop1,AStart2,AStop2: TBGRAPixel; ADirection1,ADirection2,ADir: TGradientDirection; AValue: Single); overload;

This item has no description.

procedure DoubleGradientAlphaFill(ACanvas: TCanvas; ARect: TRect; AStart1,AStop1,AStart2,AStop2: TBGRAPixel; ADirection1,ADirection2,ADir: TGradientDirection; AValue: Single); overload;

This item has no description.

function nGradientAlphaFill(AWidth, AHeight: Integer; ADir: TGradientDirection; const AGradient: array of TnGradientInfo): TBGRABitmap; overload;

This item has no description.

function nGradientAlphaFill(ARect: TRect; ADir: TGradientDirection; const AGradient: array of TnGradientInfo): TBGRABitmap; overload;

This item has no description.

procedure nGradientAlphaFill(ABitmap: TBGRABitmap; ARect: TRect; ADir: TGradientDirection; const AGradient: array of TnGradientInfo); overload;

This item has no description.

procedure nGradientAlphaFill(ACanvas: TCanvas; ARect: TRect; ADir: TGradientDirection; const AGradient: array of TnGradientInfo); overload;

This item has no description.

function nGradientInfo(StartColor, StopColor: TBGRAPixel; Direction: TGradientDirection; EndPercent: Single): TnGradientInfo;

This item has no description.

function TextShadow(AWidth,AHeight: Integer; AText: String; AFontHeight: Integer; ATextColor,AShadowColor: TBGRAPixel; AOffSetX,AOffSetY: Integer; ARadius: Integer = 0; AFontStyle: TFontStyles = []; AFontName: String = 'Default'; AShowText: Boolean = True): TBGRABitmap;

Creates a bitmap with the specified text horizontally centered and with a shadow

Types

TRectangleMapOption = (...);

———————————————————————-

Values
  • rmoNoLeftBorder
  • rmoNoTopBorder
  • rmoNoRightBorder
  • rmoNoBottomBorder
  • rmoLinearBorder
TRectangleMapOptions = set of TRectangleMapOption;

This item has no description.