Commencement du labo Mandelbrot et Julia.
[GPU.git] / WCudaMSE / Student_Cuda_Image / src / cpp / core / 02_Mandelbrot_Julia / moo / device / math / FractalMath.h
1 #ifndef FRACTAL_MATH_H_
2 #define FRACTAL_MATH_H_
3
4 #include <cmath>
5
6 #include "CalibreurF.h"
7 #include "ColorTools.h"
8
9 /*----------------------------------------------------------------------*\
10 |* Declaration *|
11 \*---------------------------------------------------------------------*/
12
13 /*--------------------------------------*\
14 |* Public *|
15 \*-------------------------------------*/
16
17 class FractalMath
18 {
19
20 /*--------------------------------------*\
21 |* Constructor *|
22 \*-------------------------------------*/
23
24 public:
25
26 __device__
27 FractalMath(int n)
28 : n(n), calibreur(IntervalF(-1, 1), IntervalF(0, 1))
29 {
30 }
31
32 /*--------------------------------------*\
33 |* Methodes *|
34 \*-------------------------------------*/
35
36 public:
37 /**
38 * x=pixelI
39 * y=pixelJ
40 */
41 __device__
42 void colorXY(uchar4* ptrColor, float x, float y, float t)
43 {
44 float z = f(x, y, t);
45
46 calibreur.calibrer(z);
47 float hue01 = z;
48
49 ColorTools::HSB_TO_RVB(hue01, ptrColor); // update color
50
51 ptrColor->w = 255; // opaque
52 }
53
54 private:
55 __device__
56 float f(float x, float y,float t)
57 {
58 return sin(x * n + t) * cos(y * n + t);
59 }
60
61
62 /*--------------------------------------*\
63 |* Attributs *|
64 \*-------------------------------------*/
65
66 private:
67 // Input
68 int n;
69
70 // Tools
71 CalibreurF calibreur;
72 };
73
74 #endif
75
76 /*----------------------------------------------------------------------*\
77 |* End *|
78 \*---------------------------------------------------------------------*/