-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmandelprot.pl
More file actions
316 lines (250 loc) · 9.98 KB
/
Copy pathmandelprot.pl
File metadata and controls
316 lines (250 loc) · 9.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
% prolog ascii art mandelbrot maker, makes cheesy mandelbrot ascii art in prolog
% ck, januar 2010
%:- dynamic state/7.
:- dynamic storedvalue/3.
drawanddebug:-
guitracer, trace,
set(5,5,-1.4,1.4,-2,2,20).
% start state
default:-
abolish(storedvalue/3),
(dynamic storedvalue/3),
set(170,40,-1.4,1.4,-2,2,20).
% paint a nice spiral arm somewhere in the fold between the two primary bulbs
default2:-
set(240,120,0.131004,0.131402,-0.743567,-0.743965,750).
default3:-
set(170,90,0.131004,0.131402,-0.743567,-0.743965,120).
% set parameters, redraw
set(Xres,Yres,Imv,Imb,Rev,Reb,Iterations) :-
retractall(state),
abolish(state/7), %ugly? mh.
(dynamic state/7),
asserta(state(Xres,Yres,Imv,Imb,Rev,Reb,Iterations)),!,
main(Xres,Yres,(Imv:Imb),(Rev:Reb),Iterations),!.
% navigation shortcuts
left :- left(4).
right :- right(4).
up :- up(4).
down :- down(4).
zoomin :- zoom(1.25).
zoomout :- zoom(0.85).
helper :- writeln(' to get the start state: default. \n to get a nice picture: default2. \n move: left. right. up. down. all move by one quarter of the screen, can move arbitrarily with e.g. left(8), moving one eighth. \n zoom: zoomin. zoomout. or relative zoom(0<x<whathaveyou). zoom is somewhat broken, but, too lazy. \n set number iterations with iter(X). increase,decrease number of iterations by 5 with finer. simpler. \n change resolution with setres(X,Y) \n
set everything manually with set(X_resolution_in_charactes,Y_resolution,Complex_neg_boundary,Complex_pos_boundary,Real_neg_boundary,Real_pos_boundary,Number_of_iterations).').
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% iterate over the given number of pixels, get a value, and draw it.
main(Xres,Yres,(Imv:Imb),(Rev:Reb),Iterations) :-
writeln(Xres:Yres:'--':Iterations:'--':Imv:Imb:',':Rev:Reb),
between(1,Yres,Currentrow),
between(1,Xres,Currentcolumn),
zoomandc((Imv:Imb),(Rev:Reb),Xres,Yres,Im:Re,Currentcolumn:Currentrow),
getvalue(0,0,Im,Re,Iterations,Iterations,Value),
%write(Value),
draw(Value,Iterations),
%draw(5,5),
%draw(Currentpixel,Currentrow,Value).
((Currentcolumn < Xres) -> fail ; write('\n')),
((Currentrow < Yres) -> fail ; write('this: set('),write(Xres),write(','),write(Yres),write(','),write(Imv),write(','),write(Imb),write(','),write(Rev),write(','),write(Reb),write(','),write(Iterations),write(').') ).
% the mandelbrot set definition hides somwhere in here.
% infinity is 2, maxiterations is infinitely many iterations,
% the other values are there for recursion and stuff.
% Iterations is _how many iterations are left_ in the recursion
getvalue(_,_,Im,Re,Iterations,Iterations,Value):-
storedvalue(Im,Re,Value),!.
getvalue(_,_,Im,Re,Iterations,Iterations,Iterations):- Im > -0.5, Im < 0.5, Re > -0.5, Re < 0.2,!.
getvalue(ZnR,ZnI,Im,Re,Maxiterations,Iterations,Value):-
complexsquare(ZnR,ZnI,ZnsquareR,ZnsquareI),
complexadd(ZnsquareR,ZnsquareI,Re,Im,Znp1R,Znp1I),
((abs(Znp1I) < 2, abs(Znp1R) < 2, Iterations > 0) ->
Iminus1 is Iterations -1,
getvalue(Znp1R,Znp1I,Im,Re,Maxiterations,Iminus1,Value)
; (Value is Maxiterations - Iterations,(dynamic state/7),assert(storedvalue(Im,Re,Value)),!)
),!.
% give section of the complex plane, total resolution in pixels
% get the respective complex coordinates to certain pixels
% zoomandc(+(Imv:Imb),+(Rev:Reb),+Xres,+Yres,-Im:Re,+X:Y) :-
zoomandc((Imv:Imb),(Rev:Reb),Xres,Yres,Im:Re,X:Y) :-
Re is Rev + (abs(Rev - Reb) * X/Xres),
Im is Imv + (abs(Imv - Imb) * Y/Yres).
complexadd(Re1,Im1,Re2,Im2,Re,Im):-
Re is Re1 + Re2,
Im is Im1 + Im2.
complexsquare(Rein,Imin,Reout,Imout):-
Reout is ((Rein * Rein) - (Imin * Imin)),
Imout is ((Rein * Imin) * 2).
/*
complexmult(Re1,Im1,Re2,Im2,Re,Im):-
Re is ((Re1 * Re2) - (Im1 * Im2))
Im is ((Re1 * Im2) + (Im1 * Re2)).
*/
% map values between 1 and unknown to dots and letters, and write them
draw(1,_) :- write('.'),!.
draw(2,_) :- write('.'),!.
draw(3,_) :- write(';'),!.
draw(X,Iterations) :- X =< Iterations/10, write(';'),!.
draw(X,Iterations) :- X =< (2* Iterations/10) + 2, write('+'),!.
draw(X,Iterations) :- X =< (3* Iterations/10) + 1, write('π'),!.
draw(X,Iterations) :- X =< (4* Iterations/10) + 1, write('Z'),!.
draw(X,Iterations) :- X =< (5* Iterations/10) , write('X'),!.
draw(X,Iterations) :- X =< (6* Iterations/10) , write('#'),!.
draw(X,Iterations) :- X =< (7* Iterations/10) , write('$'),!.
draw(X,Iterations) :- X < (8* Iterations/10) , write('M'),!.
draw(_,_) :- write('-'),!.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% move about.
left(Factor) :-
state(Xres,Yres,Imv,Imb,Rev,Reb,Iterations),!,
writeln(state(Xres,Yres,Imv,Imb,Rev,Reb,Iterations)),
retractall(state),
abolish(state/7),
(dynamic state/7),
RevN is Rev - (abs(Rev - Reb) / Factor),
RebN is Reb - (abs(Rev - Reb) / Factor) ,
%ImvN is Imv + (abs(Imv - Imb) / Factor) ,
%ImbN is Imb + (abs(Imv - Imb) / Factor) ,
asserta(state(Xres,Yres,Imv,Imb,RevN,RebN,Iterations)),!,
main(Xres,Yres,(Imv:Imb),(RevN:RebN),Iterations),!.
right(Factor) :-
state(Xres,Yres,Imv,Imb,Rev,Reb,Iterations),!,
writeln(state(Xres,Yres,Imv,Imb,Rev,Reb,Iterations)),
retractall(state),
abolish(state/7),
(dynamic state/7),
RevN is Rev + (abs(Rev - Reb) / Factor),
RebN is Reb + (abs(Rev - Reb) / Factor) ,
%ImvN is Imv + (abs(Imv - Imb) / Factor) ,
%ImbN is Imb + (abs(Imv - Imb) / Factor) ,
asserta(state(Xres,Yres,Imv,Imb,RevN,RebN,Iterations)),!,
main(Xres,Yres,(Imv:Imb),(RevN:RebN),Iterations),!.
up(Factor) :-
state(Xres,Yres,Imv,Imb,Rev,Reb,Iterations),!,
writeln(state(Xres,Yres,Imv,Imb,Rev,Reb,Iterations)),
retractall(state),
abolish(state/7),
(dynamic state/7),
% RevN is Rev - (abs(Rev - Reb) / Factor),
% RebN is Reb - (abs(Rev - Reb) / Factor) ,
ImvN is Imv - (abs(Imv - Imb) / Factor) ,
ImbN is Imb - (abs(Imv - Imb) / Factor) ,
asserta(state(Xres,Yres,ImvN,ImbN,Rev,Reb,Iterations)),!,
main(Xres,Yres,(ImvN:ImbN),(Rev:Reb),Iterations),!.
down(Factor) :-
state(Xres,Yres,Imv,Imb,Rev,Reb,Iterations),!,
writeln(state(Xres,Yres,Imv,Imb,Rev,Reb,Iterations)),
retractall(state),
abolish(state/7),
(dynamic state/7),
% RevN is Rev - (abs(Rev - Reb) / Factor),
% RebN is Reb - (abs(Rev - Reb) / Factor) ,
ImvN is Imv + (abs(Imv - Imb) / Factor) ,
ImbN is Imb + (abs(Imv - Imb) / Factor) ,
asserta(state(Xres,Yres,ImvN,ImbN,Rev,Reb,Iterations)),!,
main(Xres,Yres,(ImvN:ImbN),(Rev:Reb),Iterations),!.
zoom(Factor) :-
state(Xres,Yres,Imv,Imb,Rev,Reb,Iterations),!,
retractall(state),
abolish(state/7),
(dynamic state/7),
abolish(storedvalue/3),
(dynamic storedvalue/3),
Imspan is abs(Imv - Imb),
Respan is abs(Rev - Reb),
ImvN is Imb - Imspan / Factor,
ImbN is Imv + Imspan / Factor,
RevN is Reb - Respan / Factor,
RebN is Rev + Respan / Factor,
asserta(state(Xres,Yres,ImvN,ImbN,RevN,RebN,Iterations)),!,
main(Xres,Yres,(ImvN:ImbN),(RevN:RebN),Iterations),!.
iter(IterationsN) :-
state(Xres,Yres,Imv,Imb,Rev,Reb,_),!,
retractall(state),
abolish(state/7),
(dynamic state/7),
abolish(storedvalue/3),
(dynamic storedvalue/3),
asserta(state(Xres,Yres,Imv,Imb,Rev,Reb,IterationsN)),!,
main(Xres,Yres,(Imv:Imb),(Rev:Reb),IterationsN),!.
setres(Xres,Yres) :-
state(_,_,Imv,Imb,Rev,Reb,Iterations),!,
retractall(state),
abolish(state/7),
retractall(state),
(dynamic state/7),
abolish(storedvalue/3),
(dynamic storedvalue/3),
asserta(state(Xres,Yres,Imv,Imb,Rev,Reb,Iterations)),!,
main(Xres,Yres,(Imv:Imb),(Rev:Reb),Iterations),!.
finer :-
state(Xres,Yres,Imv,Imb,Rev,Reb,Iterations),!,
retractall(state),
abolish(state/7),
(dynamic state/7),
abolish(storedvalue/3),
(dynamic storedvalue/3),
IterationsN is Iterations + 5,
asserta(state(Xres,Yres,Imv,Imb,Rev,Reb,IterationsN)),!,
main(Xres,Yres,(Imv:Imb),(Rev:Reb),IterationsN),!.
simpler :-
state(Xres,Yres,Imv,Imb,Rev,Reb,Iterations),!,
((Iterations < 6) -> Iterations = IterationsN ; (
retractall(state),
abolish(state/7),
(dynamic state/7),
abolish(storedvalue/3),
(dynamic storedvalue/3),
IterationsN is Iterations - 5,
asserta(state(Xres,Yres,Imv,Imb,Rev,Reb,IterationsN)),!)),
main(Xres,Yres,(Imv:Imb),(Rev:Reb),IterationsN),!.
/*
draw(X,Iterations) :- X < Iterations -6, X > Iterations/2, write(;),!.
draw(X,Iterations) :- X is Iterations-6, write('x'),!.
draw(X,Iterations) :- X is Iterations-5, write('X'),!.
draw(X,Iterations) :- X is Iterations-4, write('Z'),!.
draw(X,Iterations) :- X is Iterations-3, write('#'),!.
draw(X,Iterations) :- X is Iterations-2, write('M'),!.
draw(X,Iterations) :- X is Iterations-1, write('§'),!.
draw(_,_) :- write('-'),!.
*/
%draw(X,Y,Value) :-
/*
e.g. x at Im -0.75, Re 0.9
0 80
| 2
|
|
x |
|
----------------|-----------------
-2 | 2
|
|
|
| -2
80
0,0 => -1,3
40,40 =>
0 80
| 3
|
|
|
|
x |
|
----------|-----------------------
-1 | 3
|
| -1
80
x 0 => 1
x 1 => 1 + (1/80) * 1.5 -1
pixel Re
0 Rev
1 Rev + 1/80 * Rev -Reb
X Rev + (abs(Rev - Reb) * X/Xpixels)
0 80
2
1 1.5
1.5
80
*/