Skip to content

Commit 44e1b9f

Browse files
FIX: export of big images
1 parent 7d87775 commit 44e1b9f

File tree

1 file changed

+38
-29
lines changed
  • miniprojects/Wave_function_collapse/Tile_model

1 file changed

+38
-29
lines changed

miniprojects/Wave_function_collapse/Tile_model/unit1.pas

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(******************************************************************************)
22
(* Wave function collapse (tile model) 17.01.2024 *)
33
(* *)
4-
(* Version : 0.05 *)
4+
(* Version : 0.06 *)
55
(* *)
66
(* Author : Uwe Schächterle (Corpsman) *)
77
(* *)
@@ -28,6 +28,7 @@
2828
(* 0.03 - Cleanup *)
2929
(* 0.04 - Add feature stop on miss *)
3030
(* 0.05 - Export as PNG *)
31+
(* 0.06 - Export of big images *)
3132
(* *)
3233
(******************************************************************************)
3334
// Inspired by https://www.youtube.com/watch?v=rI_y2GAlQFM
@@ -119,6 +120,7 @@
119120

120121
Procedure OnCollapseCell(Sender: TObject);
121122
Procedure OnRenderTooLong(Sender: TObject);
123+
Procedure RenderWFCToCanvas(Const aCanvas: TCanvas);
122124
public
123125

124126
End;
@@ -136,7 +138,7 @@
136138

137139
Procedure TForm1.FormCreate(Sender: TObject);
138140
Begin
139-
caption := 'Wave Function Collapse Demo ver. 0.05';
141+
caption := 'Wave Function Collapse Demo ver. 0.06';
140142
// Aufräumen, der Entwickler Hilfen
141143
edit1.free;
142144
edit2.free;
@@ -199,34 +201,11 @@
199201
End;
200202

201203
Procedure TForm1.PaintBox1Paint(Sender: TObject);
202-
Var
203-
i, j: Integer;
204204
Begin
205205
// Clear Back
206-
PaintBox1.Canvas.Brush.Color := clRed;
207-
PaintBox1.Canvas.Rectangle(-1, -1, PaintBox1.Width + 1, PaintBox1.Height + 1);
208-
If Not assigned(wfc.Grid) Then exit;
209-
For i := 0 To high(wfc.Grid) Do Begin
210-
For j := 0 To high(wfc.Grid[i]) Do Begin
211-
If wfc.Grid[i, j].Index <> -1 Then Begin
212-
PaintBox1.Canvas.Draw(i * Images[0].Bitmap.Width, j * Images[0].Bitmap.Height, Images[wfc.Grid[i, j].Index].Bitmap);
213-
End;
214-
If (wfc.Grid[i, j].Forced And CheckBox2.Checked) Or
215-
(CheckBox3.Checked And (wfc.InvalidPos.X = i) And (wfc.InvalidPos.Y = j))
216-
Then Begin
217-
PaintBox1.Canvas.Pen.Color := clred;
218-
If (CheckBox3.Checked And (wfc.InvalidPos.X = i) And (wfc.InvalidPos.Y = j)) Then Begin
219-
PaintBox1.Canvas.Pen.Color := clblue;
220-
End;
221-
PaintBox1.Canvas.MoveTo((i + 0) * Images[0].Bitmap.Width, (j + 0) * Images[0].Bitmap.Height);
222-
223-
PaintBox1.Canvas.LineTo((i + 1) * Images[0].Bitmap.Width - 1, (j + 0) * Images[0].Bitmap.Height);
224-
PaintBox1.Canvas.LineTo((i + 1) * Images[0].Bitmap.Width - 1, (j + 1) * Images[0].Bitmap.Height - 1);
225-
PaintBox1.Canvas.LineTo((i + 0) * Images[0].Bitmap.Width, (j + 1) * Images[0].Bitmap.Height - 1);
226-
PaintBox1.Canvas.LineTo((i + 0) * Images[0].Bitmap.Width, (j + 0) * Images[0].Bitmap.Height);
227-
End;
228-
End;
229-
End;
206+
paintbox1.Canvas.Brush.Color := clRed;
207+
paintbox1.Canvas.Rectangle(-1, -1, PaintBox1.Width + 1, PaintBox1.Height + 1);
208+
RenderWFCToCanvas(PaintBox1.Canvas);
230209
End;
231210

232211
Procedure TForm1.Button1Click(Sender: TObject);
@@ -360,7 +339,8 @@
360339
PaintBox1.Invalidate;
361340
Application.ProcessMessages;
362341
End;
363-
bm.Canvas.CopyRect(rect(0, 0, bm.Width, bm.Height), PaintBox1.Canvas, rect(0, 0, bm.Width, bm.Height));
342+
// bm.Canvas.CopyRect(rect(0, 0, bm.Width, bm.Height), PaintBox1.Canvas, rect(0, 0, bm.Width, bm.Height));
343+
RenderWFCToCanvas(bm.Canvas);
364344
If f Then Begin
365345
CheckBox2.Checked := true;
366346
PaintBox1.Invalidate;
@@ -639,6 +619,35 @@
639619
Button6.Enabled := true;
640620
End;
641621

622+
Procedure TForm1.RenderWFCToCanvas(Const aCanvas: TCanvas);
623+
Var
624+
i, j: Integer;
625+
Begin
626+
If Not assigned(wfc.Grid) Then exit;
627+
For i := 0 To high(wfc.Grid) Do Begin
628+
For j := 0 To high(wfc.Grid[i]) Do Begin
629+
If wfc.Grid[i, j].Index <> -1 Then Begin
630+
aCanvas.Draw(i * Images[0].Bitmap.Width, j * Images[0].Bitmap.Height, Images[wfc.Grid[i, j].Index].Bitmap);
631+
End;
632+
If (wfc.Grid[i, j].Forced And CheckBox2.Checked) Or
633+
(CheckBox3.Checked And (wfc.InvalidPos.X = i) And (wfc.InvalidPos.Y = j))
634+
Then Begin
635+
aCanvas.Pen.Color := clred;
636+
If (CheckBox3.Checked And (wfc.InvalidPos.X = i) And (wfc.InvalidPos.Y = j)) Then Begin
637+
aCanvas.Pen.Color := clblue;
638+
End;
639+
aCanvas.MoveTo((i + 0) * Images[0].Bitmap.Width, (j + 0) * Images[0].Bitmap.Height);
640+
641+
aCanvas.LineTo((i + 1) * Images[0].Bitmap.Width - 1, (j + 0) * Images[0].Bitmap.Height);
642+
aCanvas.LineTo((i + 1) * Images[0].Bitmap.Width - 1, (j + 1) * Images[0].Bitmap.Height - 1);
643+
aCanvas.LineTo((i + 0) * Images[0].Bitmap.Width, (j + 1) * Images[0].Bitmap.Height - 1);
644+
aCanvas.LineTo((i + 0) * Images[0].Bitmap.Width, (j + 0) * Images[0].Bitmap.Height);
645+
End;
646+
End;
647+
End;
648+
649+
End;
650+
642651
Procedure TForm1.Button4Click(Sender: TObject);
643652
Begin
644653
If SaveDialog1.Execute Then Begin

0 commit comments

Comments
 (0)