summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2022-01-18 22:31:22 +0100
committerErich Eckner <git@eckner.net>2022-01-18 22:31:22 +0100
commitc187e6817f07151c6a074bbe68a0787c5024f323 (patch)
treea339307a8c927be51c373a4cf8942dea78bdd26a
parentaf9720021680bf6a0f196b25c5d0511925e34a09 (diff)
downloadPenrose-c187e6817f07151c6a074bbe68a0787c5024f323.tar.xz
geht erst mal - Farben sind noch Quatsch
-rwxr-xr-xpenrosebin0 -> 26443368 bytes
-rw-r--r--penrose.lpi6
-rw-r--r--penrose.lpr2
-rw-r--r--penrose.lps182
-rw-r--r--penroseunit.pas161
-rw-r--r--unit1.lfm20
-rw-r--r--unit1.pas21
7 files changed, 383 insertions, 9 deletions
diff --git a/penrose b/penrose
new file mode 100755
index 0000000..c4d8278
--- /dev/null
+++ b/penrose
Binary files differ
diff --git a/penrose.lpi b/penrose.lpi
index f31ac51..94f79d2 100644
--- a/penrose.lpi
+++ b/penrose.lpi
@@ -30,7 +30,7 @@
<PackageName Value="LCL"/>
</Item1>
</RequiredPackages>
- <Units Count="2">
+ <Units Count="3">
<Unit0>
<Filename Value="penrose.lpr"/>
<IsPartOfProject Value="True"/>
@@ -42,6 +42,10 @@
<ResourceBaseClass Value="Form"/>
<UnitName Value="Unit1"/>
</Unit1>
+ <Unit2>
+ <Filename Value="penroseunit.pas"/>
+ <IsPartOfProject Value="True"/>
+ </Unit2>
</Units>
</ProjectOptions>
<CompilerOptions>
diff --git a/penrose.lpr b/penrose.lpr
index f362a29..16a59f9 100644
--- a/penrose.lpr
+++ b/penrose.lpr
@@ -7,7 +7,7 @@ uses
cthreads,
{$ENDIF}{$ENDIF}
Interfaces, // this includes the LCL widgetset
- Forms, Unit1
+ Forms, Unit1, penroseunit
{ you can add units after this };
{$R *.res}
diff --git a/penrose.lps b/penrose.lps
index 2956bcd..a3e1982 100644
--- a/penrose.lps
+++ b/penrose.lps
@@ -3,7 +3,7 @@
<ProjectSession>
<Version Value="11"/>
<BuildModes Active="Default"/>
- <Units Count="2">
+ <Units Count="9">
<Unit0>
<Filename Value="penrose.lpr"/>
<IsPartOfProject Value="True"/>
@@ -17,15 +17,191 @@
<Filename Value="unit1.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="Form1"/>
+ <HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="Unit1"/>
- <IsVisibleTab Value="True"/>
+ <CursorPos X="48" Y="37"/>
<UsageCount Value="20"/>
<Loaded Value="True"/>
<LoadedDesigner Value="True"/>
</Unit1>
+ <Unit2>
+ <Filename Value="penroseunit.pas"/>
+ <IsPartOfProject Value="True"/>
+ <IsVisibleTab Value="True"/>
+ <EditorIndex Value="1"/>
+ <TopLine Value="101"/>
+ <CursorPos X="69" Y="116"/>
+ <UsageCount Value="20"/>
+ <Loaded Value="True"/>
+ </Unit2>
+ <Unit3>
+ <Filename Value="/usr/share/lazarus/lcl/extctrls.pp"/>
+ <UnitName Value="ExtCtrls"/>
+ <EditorIndex Value="-1"/>
+ <TopLine Value="505"/>
+ <CursorPos X="14" Y="535"/>
+ <UsageCount Value="10"/>
+ </Unit3>
+ <Unit4>
+ <Filename Value="/usr/share/lazarus/lcl/graphics.pp"/>
+ <UnitName Value="Graphics"/>
+ <EditorIndex Value="-1"/>
+ <TopLine Value="951"/>
+ <CursorPos X="3" Y="966"/>
+ <UsageCount Value="10"/>
+ </Unit4>
+ <Unit5>
+ <Filename Value="../units/matheunit.pas"/>
+ <EditorIndex Value="2"/>
+ <TopLine Value="82"/>
+ <UsageCount Value="10"/>
+ <Loaded Value="True"/>
+ </Unit5>
+ <Unit6>
+ <Filename Value="../units/lowlevelunit.pas"/>
+ <EditorIndex Value="-1"/>
+ <TopLine Value="135"/>
+ <CursorPos X="10" Y="151"/>
+ <UsageCount Value="10"/>
+ </Unit6>
+ <Unit7>
+ <Filename Value="/usr/lib/fpc/src/rtl/inc/mathh.inc"/>
+ <EditorIndex Value="-1"/>
+ <TopLine Value="96"/>
+ <CursorPos X="16" Y="112"/>
+ <UsageCount Value="10"/>
+ </Unit7>
+ <Unit8>
+ <Filename Value="/usr/lib/fpc/src/rtl/objpas/classes/classesh.inc"/>
+ <EditorIndex Value="-1"/>
+ <TopLine Value="2191"/>
+ <CursorPos X="10" Y="2206"/>
+ <UsageCount Value="10"/>
+ </Unit8>
</Units>
- <JumpHistory HistoryIndex="-1"/>
+ <JumpHistory Count="30" HistoryIndex="29">
+ <Position1>
+ <Filename Value="penroseunit.pas"/>
+ <Caret Line="121" TopLine="96"/>
+ </Position1>
+ <Position2>
+ <Filename Value="penroseunit.pas"/>
+ <Caret Line="120" TopLine="96"/>
+ </Position2>
+ <Position3>
+ <Filename Value="penroseunit.pas"/>
+ <Caret Line="121" TopLine="96"/>
+ </Position3>
+ <Position4>
+ <Filename Value="penroseunit.pas"/>
+ <Caret Line="120" TopLine="96"/>
+ </Position4>
+ <Position5>
+ <Filename Value="penroseunit.pas"/>
+ <Caret Line="115" TopLine="96"/>
+ </Position5>
+ <Position6>
+ <Filename Value="penroseunit.pas"/>
+ <Caret Line="35" Column="20" TopLine="29"/>
+ </Position6>
+ <Position7>
+ <Filename Value="penroseunit.pas"/>
+ <Caret Line="107" Column="33" TopLine="91"/>
+ </Position7>
+ <Position8>
+ <Filename Value="penroseunit.pas"/>
+ <Caret Line="134" Column="41" TopLine="107"/>
+ </Position8>
+ <Position9>
+ <Filename Value="penroseunit.pas"/>
+ <Caret Line="132" Column="21" TopLine="107"/>
+ </Position9>
+ <Position10>
+ <Filename Value="penroseunit.pas"/>
+ <Caret Line="134" Column="112" TopLine="110"/>
+ </Position10>
+ <Position11>
+ <Filename Value="penroseunit.pas"/>
+ <Caret Line="110" Column="65" TopLine="82"/>
+ </Position11>
+ <Position12>
+ <Filename Value="penroseunit.pas"/>
+ <Caret Line="101" Column="26" TopLine="70"/>
+ </Position12>
+ <Position13>
+ <Filename Value="penroseunit.pas"/>
+ <Caret Line="108" Column="15" TopLine="86"/>
+ </Position13>
+ <Position14>
+ <Filename Value="penroseunit.pas"/>
+ <Caret Line="102" Column="5" TopLine="86"/>
+ </Position14>
+ <Position15>
+ <Filename Value="penroseunit.pas"/>
+ <Caret Line="115" Column="14" TopLine="98"/>
+ </Position15>
+ <Position16>
+ <Filename Value="penroseunit.pas"/>
+ <Caret Line="102" Column="5" TopLine="86"/>
+ </Position16>
+ <Position17>
+ <Filename Value="penroseunit.pas"/>
+ <Caret Line="105" Column="30" TopLine="86"/>
+ </Position17>
+ <Position18>
+ <Filename Value="penroseunit.pas"/>
+ <Caret Line="110" Column="23" TopLine="85"/>
+ </Position18>
+ <Position19>
+ <Filename Value="penroseunit.pas"/>
+ <Caret Line="101" Column="30" TopLine="94"/>
+ </Position19>
+ <Position20>
+ <Filename Value="penroseunit.pas"/>
+ <Caret Line="102" Column="31" TopLine="86"/>
+ </Position20>
+ <Position21>
+ <Filename Value="penroseunit.pas"/>
+ <Caret Line="108" Column="48" TopLine="87"/>
+ </Position21>
+ <Position22>
+ <Filename Value="penroseunit.pas"/>
+ <Caret Line="116" Column="90" TopLine="101"/>
+ </Position22>
+ <Position23>
+ <Filename Value="penroseunit.pas"/>
+ <Caret Line="118" Column="64" TopLine="91"/>
+ </Position23>
+ <Position24>
+ <Filename Value="penroseunit.pas"/>
+ <Caret Line="102" Column="5" TopLine="86"/>
+ </Position24>
+ <Position25>
+ <Filename Value="penroseunit.pas"/>
+ <Caret Line="108" Column="69" TopLine="92"/>
+ </Position25>
+ <Position26>
+ <Filename Value="penroseunit.pas"/>
+ <Caret Line="101" Column="3" TopLine="87"/>
+ </Position26>
+ <Position27>
+ <Filename Value="penroseunit.pas"/>
+ <Caret Line="109" Column="72" TopLine="93"/>
+ </Position27>
+ <Position28>
+ <Filename Value="penroseunit.pas"/>
+ <Caret Line="115" Column="63" TopLine="99"/>
+ </Position28>
+ <Position29>
+ <Filename Value="penroseunit.pas"/>
+ <Caret Line="116" Column="42"/>
+ </Position29>
+ <Position30>
+ <Filename Value="../units/matheunit.pas"/>
+ <Caret TopLine="82"/>
+ </Position30>
+ </JumpHistory>
<RunParams>
<FormatVersion Value="2"/>
<Modes Count="0" ActiveMode=""/>
diff --git a/penroseunit.pas b/penroseunit.pas
new file mode 100644
index 0000000..eac0a69
--- /dev/null
+++ b/penroseunit.pas
@@ -0,0 +1,161 @@
+unit penroseunit;
+
+{$mode objfpc}{$H+}
+
+interface
+
+uses
+ Classes, SysUtils, Graphics, lowlevelunit, matheunit;
+
+type
+ tTeil = record
+ Drachen: boolean;
+ Ursprung: tExtPoint;
+ Richtung,Groesze: extended;
+ id: int64;
+ end;
+
+ tPenrose = class
+ private
+ teile: array of tTeil;
+ function teilEcken(i: longint): tExtPointArray;
+ function id2color(id: int64): tColor;
+ public
+ constructor create(level: longint);
+ procedure Zeichnen(breite, hoehe: longint; Canvas: TCanvas);
+ end;
+
+implementation
+
+uses
+ math;
+
+constructor tPenrose.create(level: longint);
+var
+ i,j: longint;
+begin
+ setlength(teile,5);
+ for j:=0 to 4 do begin
+ teile[j].Drachen:=true;
+ teile[j].Ursprung:=extPoint(0,0);
+ teile[j].Richtung:=2*pi/5*j;
+ teile[j].Groesze:=1;
+ teile[j].id:=0;
+ end;
+ for i:=0 to level-1 do
+ for j:=length(teile)-1 downto 0 do begin
+ if teile[j].Richtung<0 then
+ teile[j].Richtung:=teile[j].Richtung + 2*pi;
+ if teile[j].Richtung>=2*pi then
+ teile[j].Richtung:=teile[j].Richtung - 2*pi;
+ if teile[j].Drachen then begin
+ setlength(teile,length(teile)+2);
+ teile[length(teile)-1].Drachen:=false;
+ teile[length(teile)-1].Ursprung:=teile[j].Ursprung;
+ teile[length(teile)-1].Richtung:=teile[j].Richtung + 36/180*pi;
+ teile[length(teile)-1].Groesze:=teile[j].Groesze / 2 / cos(36/180*pi);
+ teile[length(teile)-1].id:=2*teile[j].id;
+ teile[length(teile)-2].Drachen:=true;
+ teile[length(teile)-2].Ursprung:=teile[j].Ursprung + teile[j].Groesze *
+ extPoint(cos(teile[j].Richtung + 36/180*pi),sin(teile[j].Richtung + 36/180*pi));
+ teile[length(teile)-2].Richtung:=teile[j].Richtung - 108/180*pi;
+ teile[length(teile)-2].Groesze:=teile[j].Groesze / 2 / cos(36/180*pi);
+ teile[length(teile)-2].id:=2*teile[j].id+1;
+ teile[j].Ursprung:=teile[j].Ursprung + teile[j].Groesze *
+ extPoint(cos(teile[j].Richtung - 36/180*pi),sin(teile[j].Richtung - 36/180*pi));
+ teile[j].Richtung:=teile[j].Richtung + 108/180*pi;
+ teile[j].Groesze:=teile[j].Groesze / 2 / cos(36/180*pi);
+ teile[j].id:=2*teile[j].id+1;
+ end
+ else begin
+ setlength(teile,length(teile)+1);
+ teile[length(teile)-1].Drachen:=true;
+ teile[length(teile)-1].Ursprung:=teile[j].Ursprung;
+ teile[length(teile)-1].Richtung:=teile[j].Richtung;
+ teile[length(teile)-1].Groesze:=teile[j].Groesze / 2 / cos(36/180*pi);
+ teile[length(teile)-1].id:=2*teile[j].id+1;
+ teile[j].Ursprung:=teile[j].Ursprung + teile[j].Groesze *
+ extPoint(cos(teile[j].Richtung - 36/180*pi),sin(teile[j].Richtung - 36/180*pi));
+ teile[j].Richtung:=teile[j].Richtung + 144/180*pi;
+ teile[j].Groesze:=teile[j].Groesze / 2 / cos(36/180*pi);
+ teile[j].id:=2*teile[j].id;
+ end;
+ end;
+end;
+
+function tPenrose.teilEcken(i: longint): tExtPointArray;
+var
+ j: longint;
+begin
+ setLength(result,4);
+ result[0]:=extPoint(0,0);
+ result[1]:=extPoint(cos(36/180*pi),sin(36/180*pi));
+ result[2]:=extPoint(cos(36/180*pi) + (2*byte(teile[i].Drachen)-1)*sin(36/180*pi)*tan(18/180*pi),0);
+ result[3]:=extPoint(cos(-36/180*pi),sin(-36/180*pi));
+ for j:=0 to 3 do
+ result[j]:=teile[i].Groesze * rotationsMatrix(teile[i].Richtung) * result[j] + teile[i].Ursprung;
+end;
+
+function tPenrose.id2color(id: int64): tColor;
+const
+ steps = 256;
+var
+ farben: array[0..6] of tExt3dPoint;
+ r: tExt3dPoint;
+var
+ i: integer;
+begin
+ for i:=0 to 2 do
+ farben[2*i]:=ext3dPoint($ff*byte(i=2),$ff*byte(i=1),$ff*byte(i=0));
+ for i:=0 to 2 do
+ farben[7-2*i]:=ext3dPoint($ff,$ff,$ff)-farben[2*i];
+ farben[6]:=farben[0];
+ id:=id mod (steps*(length(farben)-1));
+ i:=id div steps;
+ r:=(id/steps - i) * farben[i+1] + (1+i-id/steps) * farben[i];
+ result:=round(r['x']) + (round(r['y']) shl 8) + (round(r['z']) shl 16)
+end;
+
+procedure tPenrose.Zeichnen(breite, hoehe: longint; Canvas: TCanvas);
+var
+ lo,ru: tExtPoint;
+ ecken: tExtPointArray;
+ i,j: longint;
+ c: char;
+ Groesze: extended;
+ Verschiebung: tExtPoint;
+ points: array of tPoint;
+begin
+ lo:=extPoint(0,0);
+ ru:=lo;
+ for i:=0 to length(teile)-1 do begin
+ ecken:=teilEcken(i);
+ for j:=0 to length(ecken)-1 do
+ for c:='x' to 'y' do begin
+ lo[c]:=min(lo[c],ecken[j][c]);
+ ru[c]:=max(ru[c],ecken[j][c]);
+ end;
+ end;
+ Groesze:=min(
+ (breite-1) / (ru['x']-lo['x']),
+ (hoehe-1) / (ru['y']-lo['y'])
+ );
+ Verschiebung:=-Groesze * lo;
+
+ canvas.brush.Color:=$ffffff;
+ canvas.rectangle(-10,-10,breite+10,hoehe+10);
+ for i:=0 to length(teile)-1 do begin
+ ecken:=teilEcken(i);
+ setLength(points,length(ecken));
+ for j:=0 to length(ecken)-1 do begin
+ ecken[j]:=Verschiebung + Groesze * ecken[j];
+ points[j]:=point(round(ecken[j]['x']),round(ecken[j]['y']));
+ end;
+ canvas.brush.Color:=id2color(teile[i].id);
+ canvas.pen.Color:=canvas.brush.Color;
+ canvas.Polygon(points);
+ end;
+end;
+
+end.
+
diff --git a/unit1.lfm b/unit1.lfm
index bdd5c9b..099a630 100644
--- a/unit1.lfm
+++ b/unit1.lfm
@@ -1,9 +1,25 @@
object Form1: TForm1
Left = 1690
- Height = 268
+ Height = 665
Top = 180
- Width = 357
+ Width = 1021
Caption = 'Form1'
+ ClientHeight = 665
+ ClientWidth = 1021
DesignTimePPI = 107
LCLVersion = '2.0.12.0'
+ object Image1: TImage
+ Left = 8
+ Height = 608
+ Top = 40
+ Width = 988
+ end
+ object SpinEdit1: TSpinEdit
+ Left = 8
+ Height = 25
+ Top = 8
+ Width = 256
+ OnChange = SpinEdit1Change
+ TabOrder = 0
+ end
end
diff --git a/unit1.pas b/unit1.pas
index ec73033..2a39e11 100644
--- a/unit1.pas
+++ b/unit1.pas
@@ -5,12 +5,19 @@ unit Unit1;
interface
uses
- Classes, SysUtils, Forms, Controls, Graphics, Dialogs;
+ Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, Spin,
+ Penroseunit;
type
+
+ { TForm1 }
+
TForm1 = class(TForm)
+ Image1: TImage;
+ SpinEdit1: TSpinEdit;
+ procedure SpinEdit1Change(Sender: TObject);
private
-
+ P: tPenrose;
public
end;
@@ -22,5 +29,15 @@ implementation
{$R *.lfm}
+{ TForm1 }
+
+procedure TForm1.SpinEdit1Change(Sender: TObject);
+begin
+ P:=TPenrose.create(SpinEdit1.Value);
+ P.Zeichnen(Image1.Width,Image1.Height,Image1.Canvas);
+ P.Free;
+ form1.caption:=floattostr(cos(90));
+end;
+
end.