source: trunk/PerlinNoise.pas

Last change on this file was 77, checked in by chronos, 8 months ago
  • Modified: Fixed czech translation.
File size: 995 bytes
Line 
1unit PerlinNoise;
2
3interface
4
5uses
6 Classes, SysUtils;
7
8function IntNoise(X: Integer): Double;
9
10function LinearInterpolate(A, B, X: Double): Double;
11function CosineInterpolate(A, B, X: Double): Double;
12function CubicInterpolate(V0, V1, V2, V3, X: Double): Double;
13
14
15implementation
16
17function IntNoise(X: Integer): Double;
18var
19 Xl: Integer;
20begin
21 Xl := (X shl 13) xor X;
22 Result := (Xl * (Xl * Xl * 15731 + 789221) + 1376312589) and $7fffffff;
23 Result := 1.0 - (Result / 1073741824.0);
24end;
25
26function LinearInterpolate(A, B, X: Double): Double;
27begin
28 Result := A * (1 - X) + B * X;
29end;
30
31function CosineInterpolate(A, B, X: Double): Double;
32var
33 F, Ft: Double;
34begin
35 Ft := X * Pi;
36 F := (1.0 - Cos(Ft)) * 0.5;
37 Result := A * (1 - F) + B * F;
38end;
39
40function CubicInterpolate(V0, V1, V2, V3, X: Double): Double;
41var
42 P, Q, R, S: Double;
43begin
44 P := (V3 - V2) - (V0 - V1);
45 Q := (V0 - V1) - P;
46 R := V2 - V0;
47 S := V1;
48
49 Result := P * X * X * X + Q * X * X + R * X + S;
50end;
51
52end.
Note: See TracBrowser for help on using the repository browser.