Skip to content

Commit aec23bc

Browse files
authored
Merge pull request #22 from vaelen/main
Added Mac System 6/7 version written in Pascal.
2 parents 439cf20 + 33b8322 commit aec23bc

File tree

5 files changed

+140
-0
lines changed

5 files changed

+140
-0
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mac/*.p linguist-language=Pascal

mac/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
### Mandlebrot for Classic Macs
2+
3+
![Mandlebrot Screenshot](mandlebrot.png)
4+
5+
- mandlebrot.p - This is the source code for a Pascal implementation.
6+
- mandlebrot.img - This is a disk image containing the compiled binary for the Pascal implementation. It should work on System 6+.
7+

mac/mandlebrot.img

800 KB
Binary file not shown.

mac/mandlebrot.p

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
{ Copyright 2025, Andrew C. Young }
2+
{ License: MIT }
3+
4+
program Mandlebrot;
5+
6+
var
7+
patterns: array[0..14] of Pattern;
8+
w: WindowPtr;
9+
startTime, endTime: longint;
10+
const
11+
step = 8;
12+
maxRows = 38;
13+
maxCols = 63;
14+
15+
procedure InitPatterns;
16+
begin
17+
{ Define which patterns we want to use for each value.}
18+
{ See Inside Macintosh Volume I, page 474. }
19+
20+
GetIndPattern(patterns[0], sysPatListID, 13);
21+
GetIndPattern(patterns[1], sysPatListID, 21);
22+
GetIndPattern(patterns[2], sysPatListID, 28);
23+
GetIndPattern(patterns[3], sysPatListID, 26);
24+
GetIndPattern(patterns[4], sysPatListID, 10);
25+
GetIndPattern(patterns[5], sysPatListID, 22);
26+
GetIndPattern(patterns[6], sysPatListID, 23);
27+
GetIndPattern(patterns[7], sysPatListID, 24);
28+
GetIndPattern(patterns[8], sysPatListID, 25);
29+
GetIndPattern(patterns[9], sysPatListID, 5);
30+
GetIndPattern(patterns[10], sysPatListID, 4);
31+
GetIndPattern(patterns[11], sysPatListID, 3);
32+
GetIndPattern(patterns[12], sysPatListID, 2);
33+
GetIndPattern(patterns[13], sysPatListID, 7);
34+
GetIndPattern(patterns[14], sysPatListID, 1);
35+
end;
36+
37+
procedure CreateWindow;
38+
var
39+
r: Rect;
40+
begin
41+
r.top := 40;
42+
r.left := 6;
43+
r.bottom := 340;
44+
r.right := 506;
45+
46+
w := NewWindow(nil, r, 'Mandlebrot by Andrew C. Young', TRUE, 0, nil, TRUE, noGrowDocProc);
47+
ShowWindow(w);
48+
SelectWindow(w);
49+
SetPort(w);
50+
end;
51+
52+
procedure DrawMandlebrot;
53+
var
54+
row, col, i: integer;
55+
x, y, xz, yz, xt: real;
56+
r: Rect;
57+
p: Pattern;
58+
begin
59+
for row := 0 to maxRows do
60+
begin
61+
r.top := row * step;
62+
r.bottom := r.top + step;
63+
for col := 0 to maxCols do
64+
begin
65+
r.left := col * step;
66+
r.right := r.left + step;
67+
68+
xz := (col * 3.5 / (maxCols + 1)) - 2.5;
69+
yz := (row * 2.3 / (maxRows + 1)) - 1;
70+
x := 0;
71+
y := 0;
72+
73+
for i := 0 to 14 do
74+
begin
75+
p := patterns[i];
76+
if (x * x) + (y * y) > 4 then
77+
FillRect(r, p);
78+
xt := (x * x) - (y * y) + xz;
79+
y := (2 * x * y) + yz;
80+
x := xt;
81+
end; {pattern}
82+
end; {column}
83+
end; {row}
84+
end; {DrawMandlebrot}
85+
86+
procedure EventLoop;
87+
var
88+
event: EventRecord;
89+
done: boolean;
90+
begin
91+
done := false;
92+
while done = false do
93+
begin
94+
if GetNextEvent(mDownMask, event) then
95+
begin
96+
if TrackGoAway(w, event.where) then
97+
done := true;
98+
end; {GetNextEvent}
99+
end; {while not done}
100+
end; {EventLoop}
101+
102+
procedure DrawTicks (t: longint);
103+
var
104+
secs: longint;
105+
s: Str255;
106+
r: Rect;
107+
begin
108+
{ Approximately 60 ticks per second }
109+
secs := Round(t / 60);
110+
s := StringOf('Ticks : ', t, ', Seconds: ', secs);
111+
r.Top := 280;
112+
r.Left := 20;
113+
r.Bottom := 295;
114+
r.Right := r.Left + StringWidth(s) + 10;
115+
FillRect(r, white);
116+
PenSize(1, 1);
117+
FrameRect(r);
118+
MoveTo(r.Left + 5, r.Bottom - 3);
119+
DrawString(s);
120+
end;
121+
122+
begin
123+
{Program entry point}
124+
InitPatterns;
125+
CreateWindow;
126+
startTime := TickCount;
127+
DrawMandlebrot;
128+
endTime := TickCount;
129+
DrawTicks(endTime - startTime);
130+
EventLoop;
131+
ExitToShell;
132+
end.

mac/mandlebrot.png

16.3 KB
Loading

0 commit comments

Comments
 (0)