Skip to content

Commit 9f161a2

Browse files
authored
Merge pull request #6 from jackyarndley/testing
Add in series approximation and glitch correction.
2 parents da734a5 + a73e4d0 commit 9f161a2

17 files changed

+784
-150
lines changed

Cargo.lock

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pbr = "1.0.2"
1212
rayon = "1.3.0"
1313
packed_simd = "0.3.3"
1414
rug = "1.7.0"
15-
mantexp = { path = "../rust-mantexp/" }
15+
float-extended = { path = "../rust-float-extended/" }
1616

1717
#Additional commands that can improve performance (maybe by around 5-10%)
1818
#[profile.release]

output.png

739 KB
Loading

src/bin/main.rs

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::time::Instant;
2-
use rust_fractal::renderer::ImageRenderer;
2+
use rust_fractal::renderer2::FractalRenderer;
33

44
fn main() {
55
println!("Mandelbrot Renderer");
@@ -13,26 +13,63 @@ fn main() {
1313
// "0.0");
1414
// let zoom = 1.0;
1515

16-
let center = (
17-
"-0.749999987350877481864108888020013802837969258626230419972587823828734338471228477079750588709551510361714463695461745528645748607681279674273355384334270208362211787387351792878073779449767292692440",
18-
"0.001000038688236832013124581230049849132759425863378894883003211011278068229551274712347955044740933397589760194545872789087012331273586364914484522575986336846199522726507205442204060303594956029930");
19-
let zoom = 3.7E191;
16+
// let center = (
17+
// "-0.749999987350877481864108888020013802837969258626230419972587823828734338471228477079750588709551510361714463695461745528645748607681279674273355384334270208362211787387351792878073779449767292692440",
18+
// "0.001000038688236832013124581230049849132759425863378894883003211011278068229551274712347955044740933397589760194545872789087012331273586364914484522575986336846199522726507205442204060303594956029930");
19+
// let zoom = 3.7E191;
2020

2121
// let center = (
2222
// "-1.689573325432279612075987864633746594591438093139394112928000260",
2323
// "0.000000000000000000000000000000000145514706909258179374258");
2424
// let zoom = 1.2980742146337048E34;
2525

26-
let mut renderer = ImageRenderer::new(
26+
// let center = (
27+
// "-1.999999999138270118722935763129859470012913240693218269085000",
28+
// "-0.000000000000000000322680215517275822769282166130504217892606");
29+
// let zoom = 1.63e030;
30+
31+
// let center = (
32+
// "-1.76904090125288168240284276810365472222460651367280300612031519864776551390840630119504817227707689276670981344397551593371805167279428144061791279408701383958080000000000000000000000002e+00",
33+
// "-3.1605400272558568759745268636087334444350515177571908056976983793515506960262149704114708190147368048572976192049103272074188848768835600195188510326583157513e-03");
34+
// let zoom = 7.5E139;
35+
36+
// let center = (
37+
// "-1.7685304554715107439359975226423287998937254896566074423088827415719065562223946222490318219590860313620613389226996388",
38+
// "0.0059445386042946892550190097831583153039526746987365071641624831873576346016435037438597231970921541448697901394734283301");
39+
// let zoom = 2.00000000000E113;
40+
41+
// let center = (
42+
// "-0.74977496303986055825690204249855929432518723234763348374372443797716597482713646451452176727030299366505937952743219986590574037612687173829307656886118099999999999999999999999",
43+
// "-0.06638008421017090687747407166586874456952046519386815946449195256714882710925246541317934635067121915196760463342031197755105049354085337445454326026704199999999999999999999999");
44+
// let zoom = 4.70017300819E149;
45+
46+
// let center = (
47+
// "-1.99996619445037030418434688506350579675531241540724851511761922944801584242342684381376129778868913812287046406560949864353810575744772166485672496092803920095332176654846785710146671838403830455177782981641506704068474778442",
48+
// "-0.000000000000000000000000000000000300138243679093832407249730397759249873468311907733352701742572801204749756148235811856472992884140755192241865049781816254785289455481579902975133989545509287024987599289178526901586954397865");
49+
// let zoom = 8.80307862787E167;
50+
51+
let center = (
52+
"-1.479796270901760024425279934770411525645551054432599517909807632824286254403907594526888466099962805022975196472549771681831234491695559852583955204986197762293872769474806903995564259040667568599770094383157857518790853771783314763231302599999999999999999999999998",
53+
"-0.001199443952813447746281973233374468444560314114132538362037569205657422216739564521471119107626453330996365067987088146663639996715939831819152248618042255824652268918299630897525386638029428706473919823922522752497780934312003352081931299999999999999999999999998");
54+
let zoom = 3.27799999998E235;
55+
56+
// let center = (
57+
// "-0.74962449737876168207862620426836138684529527812364025754481571424558286479672801698750203976779135608148687747196595174858125388297577788573082753210469806739721377901297451172624762450940529814713048377873612297220313016947039287469999999999999999",
58+
// "0.03427010874046016945172951545749474868051534672439111853174854738370595772935930171842999778713222794215453436628998200591914208207632674780780978496784843807690510401829301309069542198413574392425885166367231192087416338497065495509999999999999999");
59+
// let zoom = 7.58065474756E227;
60+
61+
62+
let mut renderer = FractalRenderer::new(
2763
1000,
2864
1000,
2965
zoom,
30-
5000000,
66+
150000,
3167
center.0,
3268
center.1,
3369
1000,
3470
0.001,
35-
true
71+
false,
72+
64
3673
);
3774

3875
let time = Instant::now();

src/colouring.rs

Lines changed: 93 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
use crate::util::point::Point;
1+
use crate::util::image::Image;
2+
use crate::util::PixelData;
23

34
pub enum ColourMethod {
45
Iteration,
5-
IterationSquareRoot,
6-
Histogram
6+
// IterationSquareRoot,
7+
// Histogram
78
}
89

910
impl ColourMethod {
10-
pub fn run<T>(&self, points: &Vec<Point<T>>, image: &mut Vec<u8>, maximum_iterations: usize, display_glitches: bool) {
11+
pub fn run(&self, pixels: &Vec<PixelData>, image: &mut Image, maximum_iterations: usize) {
1112
// Palette is temporarily here
1213
let mut colours = Vec::new();
1314

@@ -55,112 +56,101 @@ impl ColourMethod {
5556

5657
match self {
5758
ColourMethod::Iteration => {
58-
for point in points {
59-
let index = point.index;
60-
61-
if point.glitched && display_glitches {
62-
image[3 * index] = 255u8;
63-
image[3 * index + 1] = 0u8;
64-
image[3 * index + 2] = 0u8;
65-
} else if point.iterations >= maximum_iterations {
66-
image[3 * index] = 0u8;
67-
image[3 * index + 1] = 0u8;
68-
image[3 * index + 2] = 0u8;
59+
for pixel in pixels {
60+
let (red, green, blue) = if pixel.glitched && image.display_glitches {
61+
(255, 0, 0)
62+
} else if pixel.iteration >= maximum_iterations {
63+
(0, 0, 0)
6964
} else {
7065
// 0.1656
71-
let hue = 0.1656 * (point.iterations as f32 + point.smooth) % 8192.0;
72-
73-
let colour = colours[(hue.floor() as usize) % 8192];
74-
let colour2 = colours[(hue.floor() as usize + 1) % 8192];
75-
76-
let red = (colour.0 + ((colour2.0 - colour.0) * hue.fract())) as u8;
77-
let green = (colour.1 + ((colour2.1 - colour.1) * hue.fract())) as u8;
78-
let blue = (colour.2 + ((colour2.2 - colour.2) * hue.fract())) as u8;
79-
80-
image[3 * index] = red;
81-
image[3 * index + 1] = green;
82-
image[3 * index + 2] = blue;
83-
}
84-
}
85-
},
86-
ColourMethod::IterationSquareRoot => {
87-
for point in points {
88-
let index = point.index;
66+
let hue = (0.1656 * pixel.iteration as f64) as usize % 8192;
8967

90-
if point.glitched && display_glitches {
91-
image[3 * index] = 255u8;
92-
image[3 * index + 1] = 0u8;
93-
image[3 * index + 2] = 0u8;
94-
} else if point.iterations >= maximum_iterations {
95-
image[3 * index] = 0u8;
96-
image[3 * index + 1] = 0u8;
97-
image[3 * index + 2] = 0u8;
98-
} else {
99-
let hue = 1600.0 * (point.iterations as f32 + point.smooth).sqrt() % 8192.0;
100-
101-
let colour = colours[(hue.floor() as usize) % 8192];
102-
let colour2 = colours[(hue.floor() as usize + 1) % 8192];
68+
let colour = colours[hue];
10369

104-
let red = (colour.0 + ((colour2.0 - colour.0) * hue.fract())) as u8;
105-
let green = (colour.1 + ((colour2.1 - colour.1) * hue.fract())) as u8;
106-
let blue = (colour.2 + ((colour2.2 - colour.2) * hue.fract())) as u8;
70+
(colour.0 as u8, colour.1 as u8, colour.2 as u8)
71+
};
10772

108-
image[3 * index] = red;
109-
image[3 * index + 1] = green;
110-
image[3 * index + 2] = blue;
111-
}
73+
image.plot(pixel.image_x, pixel.image_y, red, green, blue);
11274
}
11375
},
114-
ColourMethod::Histogram => {
115-
let mut iteration_counts = vec![0usize; maximum_iterations + 1];
116-
117-
for point in points {
118-
iteration_counts[point.iterations as usize] += 1
119-
}
120-
121-
for i in 1..iteration_counts.len() {
122-
iteration_counts[i] += iteration_counts[i - 1];
123-
}
124-
125-
let total = iteration_counts[maximum_iterations - 1];
126-
127-
for point in points {
128-
let index = point.index;
129-
130-
if point.glitched && display_glitches {
131-
image[3 * index] = 255u8;
132-
image[3 * index + 1] = 0u8;
133-
image[3 * index + 2] = 0u8;
134-
} else if point.iterations >= maximum_iterations {
135-
image[3 * index] = 0u8;
136-
image[3 * index + 1] = 0u8;
137-
image[3 * index + 2] = 0u8;
138-
} else {
139-
let factor = if point.smooth == std::f32::NAN || point.iterations as f32 + point.smooth < 0.0 {
140-
point.iterations as f32
141-
} else {
142-
point.iterations as f32 + point.smooth
143-
};
144-
145-
let v1 = iteration_counts[factor as usize] as f32 / total as f32;
146-
let v2 = iteration_counts[factor as usize + 1] as f32 / total as f32;
147-
148-
// the hue is used to smooth the histogram bins. The hue is in the range 0.0-1.0
149-
let hue = (v1 + (v2 - v1) * factor.fract()) * 8192.0;
150-
151-
let colour = colours[hue.floor() as usize % 8192];
152-
let colour2 = colours[(hue.floor() as usize + 1) % 8192];
153-
154-
let red = (colour.0 + ((colour2.0 - colour.0) * factor.fract())) as u8;
155-
let green = (colour.1 + ((colour2.1 - colour.1) * factor.fract())) as u8;
156-
let blue = (colour.2 + ((colour2.2 - colour.2) * factor.fract())) as u8;
157-
158-
image[3 * index] = red;
159-
image[3 * index + 1] = green;
160-
image[3 * index + 2] = blue;
161-
}
162-
}
163-
}
76+
// ColourMethod::IterationSquareRoot => {
77+
// for point in points {
78+
// let index = point.index;
79+
//
80+
// if point.glitched && display_glitches {
81+
// image[3 * index] = 255u8;
82+
// image[3 * index + 1] = 0u8;
83+
// image[3 * index + 2] = 0u8;
84+
// } else if point.iterations >= maximum_iterations {
85+
// image[3 * index] = 0u8;
86+
// image[3 * index + 1] = 0u8;
87+
// image[3 * index + 2] = 0u8;
88+
// } else {
89+
// let hue = 1600.0 * (point.iterations as f32 + point.smooth).sqrt() % 8192.0;
90+
//
91+
// let colour = colours[(hue.floor() as usize) % 8192];
92+
// let colour2 = colours[(hue.floor() as usize + 1) % 8192];
93+
//
94+
// let red = (colour.0 + ((colour2.0 - colour.0) * hue.fract())) as u8;
95+
// let green = (colour.1 + ((colour2.1 - colour.1) * hue.fract())) as u8;
96+
// let blue = (colour.2 + ((colour2.2 - colour.2) * hue.fract())) as u8;
97+
//
98+
// image[3 * index] = red;
99+
// image[3 * index + 1] = green;
100+
// image[3 * index + 2] = blue;
101+
// }
102+
// }
103+
// },
104+
// ColourMethod::Histogram => {
105+
// let mut iteration_counts = vec![0usize; maximum_iterations + 1];
106+
//
107+
// for point in points {
108+
// iteration_counts[point.iterations as usize] += 1
109+
// }
110+
//
111+
// for i in 1..iteration_counts.len() {
112+
// iteration_counts[i] += iteration_counts[i - 1];
113+
// }
114+
//
115+
// let total = iteration_counts[maximum_iterations - 1];
116+
//
117+
// for point in points {
118+
// let index = point.index;
119+
//
120+
// if point.glitched && display_glitches {
121+
// image[3 * index] = 255u8;
122+
// image[3 * index + 1] = 0u8;
123+
// image[3 * index + 2] = 0u8;
124+
// } else if point.iterations >= maximum_iterations {
125+
// image[3 * index] = 0u8;
126+
// image[3 * index + 1] = 0u8;
127+
// image[3 * index + 2] = 0u8;
128+
// } else {
129+
// let factor = if point.smooth == std::f32::NAN || point.iterations as f32 + point.smooth < 0.0 {
130+
// point.iterations as f32
131+
// } else {
132+
// point.iterations as f32 + point.smooth
133+
// };
134+
//
135+
// let v1 = iteration_counts[factor as usize] as f32 / total as f32;
136+
// let v2 = iteration_counts[factor as usize + 1] as f32 / total as f32;
137+
//
138+
// // the hue is used to smooth the histogram bins. The hue is in the range 0.0-1.0
139+
// let hue = (v1 + (v2 - v1) * factor.fract()) * 8192.0;
140+
//
141+
// let colour = colours[hue.floor() as usize % 8192];
142+
// let colour2 = colours[(hue.floor() as usize + 1) % 8192];
143+
//
144+
// let red = (colour.0 + ((colour2.0 - colour.0) * factor.fract())) as u8;
145+
// let green = (colour.1 + ((colour2.1 - colour.1) * factor.fract())) as u8;
146+
// let blue = (colour.2 + ((colour2.2 - colour.2) * factor.fract())) as u8;
147+
//
148+
// image[3 * index] = red;
149+
// image[3 * index + 1] = green;
150+
// image[3 * index + 2] = blue;
151+
// }
152+
// }
153+
// }
164154
}
165155
}
166156
}

src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
pub mod renderer;
1+
// pub mod renderer;
2+
pub mod renderer2;
23
pub mod util;
34
pub mod colouring;
45
pub mod math;

src/math/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
mod perturbation_f64;
2-
mod perturbation_f64_vectorised;
1+
// pub mod perturbation_f64;
2+
// pub mod perturbation_f64_vectorised;
3+
pub mod perturbation;
4+
pub mod reference;
5+
pub mod series_approximation;

0 commit comments

Comments
 (0)