Skip to content

Commit 78d6b90

Browse files
committed
added probe sampling option and automatically reduce series approximation terms when below certain zoom level
1 parent 099632e commit 78d6b90

File tree

4 files changed

+41
-19
lines changed

4 files changed

+41
-19
lines changed

default.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
image_width = 1920
2-
image_height = 1080
3-
frames = 1
1+
image_width = 1000
2+
image_height = 1000
3+
frames = 999
44
export = "colour"
55
glitch_tolerance = 0.001
66
zoom_scale = 2.0
77
auto_adjust_iterations = true
8-
approximation_order = 16
8+
approximation_order = 32
99
frame_offset = 0

locations/threads_colour.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
real = "-1.47414176240993896848662071528158693194984033295350953280086668957218887059547144798782958583693228230313082538417736408312283756916583038548770140907148842507795182301203312327678867411139743734088820831422587016737770172651132123623347543560592366451320269312832570538759109480956462838749508907791843703924365245276567942898938125705618894029328612293147151908041951365498962465718017136637923540348122292958335790053092495783869799482899842041593944847198560523459306518247398734178583094840989359335916427349271969694638813455484795519139180535389178899499218726674005407958574308338167164971091115429523451479626131276956228048957227740597867681604973361307242906518836130901630810235591139999999999999999999"
22
imag = "1.837028624819189477865631515035097395323927302572629030865933104000355714583818892052507681177756076074900340375874325858424795164505875785998449146862924507042300051932135130891413370393327740037629084197582966724720858559206941967648864807892583328760554952794324657809197148266317196316651597885791947076110274629246850125745470256068262793065499915106947670845209696879646797896797942904780372999446765698282800418563469062689909330151614815763561772821921612271912492631000218876452296900861545848888915227426092699498959036990046882718777435775562966053647880616647866656164419540502287729221470963175939777275863084020159079375481684880087569411323863960416637609668567855099418820244664E-94"
3-
zoom = "8.6e630"
3+
#zoom = "8.6e630"
4+
zoom = "1e20"
45
iterations = 1544151

src/math/series_approximation.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ pub struct SeriesApproximation {
1616
pub delta_top_left: ComplexExtended,
1717
pub valid_coefficients: Vec<ComplexExtended>,
1818
pub valid_iteration: usize,
19+
pub probe_sampling: usize,
1920
}
2021

2122
impl SeriesApproximation {
22-
pub fn new_central(c: &ComplexArbitrary, order: usize, maximum_iteration: usize, delta_pixel_square: FloatExtended, delta_top_left: ComplexExtended) -> Self {
23+
pub fn new_central(c: &ComplexArbitrary, order: usize, maximum_iteration: usize, delta_pixel_square: FloatExtended, delta_top_left: ComplexExtended, probe_sampling: usize) -> Self {
2324
let mut coefficients = vec![vec![ComplexExtended::new2(0.0, 0.0, 0); order as usize + 1]; 1];
2425

2526
coefficients[0][0] = to_extended(&c);
@@ -37,10 +38,17 @@ impl SeriesApproximation {
3738
delta_top_left,
3839
valid_coefficients: Vec::new(),
3940
valid_iteration: 1,
41+
probe_sampling,
4042
}
4143
}
4244

4345
pub fn generate_approximation(&mut self, center_reference: &Reference) {
46+
// Reset the coefficients
47+
self.coefficients = vec![vec![ComplexExtended::new2(0.0, 0.0, 0); self.order as usize + 1]; 1];
48+
49+
self.coefficients[0][0] = to_extended(&center_reference.c);
50+
self.coefficients[0][1] = ComplexExtended::new2(1.0, 0.0, 0);
51+
4452
let add_value = ComplexExtended::new2(1.0, 0.0, 0);
4553

4654
// Can be changed later into a better loop - this function could also return some more information
@@ -82,15 +90,13 @@ impl SeriesApproximation {
8290
self.approximation_probes = Vec::new();
8391
self.approximation_probes_derivative = Vec::new();
8492

85-
let probe_sampling = 3;
86-
87-
for i in 0..probe_sampling {
88-
for j in 0..probe_sampling {
89-
if probe_sampling % 2 == 1 && (i == probe_sampling / 2 && j == probe_sampling / 2) {
93+
for i in 0..self.probe_sampling {
94+
for j in 0..self.probe_sampling {
95+
if self.probe_sampling % 2 == 1 && (i == self.probe_sampling / 2 && j == self.probe_sampling / 2) {
9096
continue;
9197
} else {
92-
let real = (1.0 - 2.0 * (i as f64 / (probe_sampling as f64 - 1.0))) * self.delta_top_left.mantissa.re;
93-
let imag = (1.0 - 2.0 * (j as f64 / (probe_sampling as f64 - 1.0))) * self.delta_top_left.mantissa.im;
98+
let real = (1.0 - 2.0 * (i as f64 / (self.probe_sampling as f64 - 1.0))) * self.delta_top_left.mantissa.re;
99+
let imag = (1.0 - 2.0 * (j as f64 / (self.probe_sampling as f64 - 1.0))) * self.delta_top_left.mantissa.im;
94100

95101
self.add_probe(ComplexExtended::new2(real, imag, self.delta_top_left.exponent));
96102
}

src/renderer.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ impl FractalRenderer {
4343
let zoom_scale_factor = settings.get_float("zoom_scale").unwrap_or(2.0);
4444
let display_glitches = settings.get_bool("display_glitches").unwrap_or(false);
4545
let auto_adjust_iterations = settings.get_bool("auto_adjust_iterations").unwrap_or(false);
46+
let probe_sampling = settings.get_int("probe_sampling").unwrap_or(3) as usize;
4647
let data_type = match settings.get_str("export").unwrap_or(String::from("COLOUR")).to_ascii_uppercase().as_ref() {
4748
"RAW" => DataType::RAW,
4849
"COLOUR" => DataType::COLOUR,
@@ -65,7 +66,8 @@ impl FractalRenderer {
6566
auto_approximation,
6667
maximum_iteration,
6768
FloatExtended::new(0.0, 0),
68-
ComplexExtended::new2(0.0, 0.0, 0));
69+
ComplexExtended::new2(0.0, 0.0, 0),
70+
probe_sampling);
6971
let render_indices = (0..(image_width * image_height)).collect::<Vec<usize>>();
7072

7173
FractalRenderer {
@@ -94,7 +96,6 @@ impl FractalRenderer {
9496
let frame_time = Instant::now();
9597
let approximation_time = Instant::now();
9698

97-
// If we are on the first frame we need to run the central reference calculation
9899
if frame_index == 0 {
99100
self.center_reference.run();
100101
self.series_approximation.maximum_iteration = self.center_reference.current_iteration;
@@ -116,6 +117,7 @@ impl FractalRenderer {
116117

117118
print!("| {:<15}", approximation_time.elapsed().as_millis());
118119
print!("| {:<15}", self.series_approximation.valid_iteration);
120+
print!("| {:<6}", self.series_approximation.order);
119121
print!("| {:<15}", self.maximum_iteration);
120122
std::io::stdout().flush().unwrap();
121123

@@ -226,17 +228,30 @@ impl FractalRenderer {
226228

227229
pub fn render(&mut self) {
228230
// Print out the status information
229-
println!("{:<6}| {:<15}| {:<15}| {:<15}| {:<15}| {:<15}| {:<15}| {:<15}| {:<15}| {:<15}| {:<15}", "Frame", "Zoom", "Approx [ms]", "Skipped [it]", "Maximum [it]", "Packing [ms]", "Iteration [ms]", "Correct [ms]", "Saving [ms]", "Frame [ms]", "TOTAL [ms]");
231+
println!("{:<6}| {:<15}| {:<15}| {:<15}| {:<6}| {:<15}| {:<15}| {:<15}| {:<15}| {:<15}| {:<15}| {:<15}", "Frame", "Zoom", "Approx [ms]", "Skipped [it]", "Order", "Maximum [it]", "Packing [ms]", "Iteration [ms]", "Correct [ms]", "Saving [ms]", "Frame [ms]", "TOTAL [ms]");
230232

231233
let mut count = 0;
232234

233235
while self.remaining_frames > 0 && self.zoom.to_float() > 0.5 {
234-
self.render_frame(count, format!("output/{:08}_{}", count + self.frame_offset, extended_to_string_short(self.zoom)));
236+
self.render_frame(count,
237+
format!("output/{:08}_{}", count + self.frame_offset,
238+
extended_to_string_short(self.zoom)));
239+
235240
self.zoom.mantissa /= self.zoom_scale_factor;
236241
self.zoom.reduce();
237242

238-
if self.auto_adjust_iterations {
239-
if self.zoom.to_float() < 1e10 && self.maximum_iteration > 10000 {
243+
if self.zoom.to_float() < 1e10 {
244+
// SA has some problems with precision with lots of terms at lot zoom levels
245+
if self.series_approximation.order > 3 {
246+
// Overwrite the series approximation order
247+
self.series_approximation.order = 3;
248+
self.series_approximation.maximum_iteration = self.center_reference.current_iteration;
249+
self.series_approximation.generate_approximation(&self.center_reference);
250+
}
251+
252+
// Logic in here to automatically adjust the maximum number of iterations
253+
// This is done arbitrarily and could be done in a config file if required
254+
if self.auto_adjust_iterations && self.maximum_iteration > 10000 {
240255
let new_iteration_value = 10000;
241256

242257
if self.center_reference.current_iteration >= 10000 {

0 commit comments

Comments
 (0)