13 #ifndef OGLPLUS_IMAGES_NEWTON_1107121519_HPP
14 #define OGLPLUS_IMAGES_NEWTON_1107121519_HPP
53 if(d == 0.0f)
return a;
55 (a.x()*b.x() + a.
y()*b.
y()) / d,
56 (a.
y()*b.x() - a.x()*b.
y()) / d
61 static T _mix(
T a,
T b,
float coef)
63 return a*(1.0f - coef) + b*coef;
66 template <
typename Function,
typename Mixer, std::
size_t N>
78 auto p = this->_begin<GLfloat>();
80 for(GLsizei i=0; i!=width; ++i)
81 for(GLsizei j=0; j!=height; ++j)
84 _mix(lb.x(), rt.x(), float(i)/float(width-1)),
85 _mix(lb.
y(), rt.
y(), float(j)/float(height-1))
87 std::size_t n, max = 256;
88 for(n = 0; n != max; ++n)
94 if(Distance(zn, z) < 0.00001f)
break;
100 mixer(
float(n) /
float(max-1))
104 assert(p != this->_end<GLfloat>());
109 assert(p == this->_end<GLfloat>());
118 n.x()*n.x()*n.x() - 3.f*n.x()*n.
y()*n.
y() - 1.f,
119 -n.
y()*n.
y()*n.
y() + 3.f*n.x()*n.x()*n.
y()
126 n.x()*n.x() - n.
y()*n.
y(),
138 n.x()*n.x()*n.x()*n.x() +
139 n.
y()*n.
y()*n.
y()*n.
y() -
140 6.f*n.x()*n.x()*n.
y()*n.
y() - 1.f,
141 4.f*n.x()*n.x()*n.x()*n.
y() -
142 4.f*n.x()*n.
y()*n.
y()*n.
y()
149 n.x()*n.x()*n.x() - 3.f*n.x()*n.
y()*n.
y(),
150 -n.
y()*n.
y()*n.
y() + 3.f*n.x()*n.x()*n.
y()
159 template <
typename T>
160 T operator()(
T value)
const
170 PowMixer(
float exponent)
171 : _exponent(exponent)
174 template <
typename T>
175 T operator()(
T value)
const
177 return std::pow(value,
T(_exponent));
181 typedef NoopMixer DefaultMixer;
183 #if OGLPLUS_DOCUMENTATION_ONLY || !OGLPLUS_NO_FUNCTION_TEMPLATE_DEFAULT_ARGS
202 typename Function = DefaultFunction,
203 typename Mixer = DefaultMixer
212 Function func = Function(),
213 Mixer mixer = Mixer()
214 ):
Image(width, height, 1, 3, (GLfloat*)0)
216 _make(width, height, func, mixer, lb, rt, c1, c2);
229 typename Function = DefaultFunction,
230 typename Mixer = DefaultMixer
235 Function func = Function(),
236 Mixer mixer = Mixer()
237 ):
Image(width, height, 1, 1, (GLfloat*)0)
248 template <
typename Function,
typename Mixer>
258 ):
Image(width, height, 1, 3, (GLfloat*)0)
260 _make(width, height, func, mixer, lb, rt, c1, c2);
263 template <
typename Function,
typename Mixer>
269 ): Image(width, height, 1, 1, (GLfloat*)0)
285 #endif // include guard
The X^4-1 function and its derivation.
Definition: newton.hpp:133
NewtonFractal(GLsizei width, GLsizei height, Vec3f c1, Vec3f c2, Vec2f lb=Vec2f(-1.0f,-1.0f), Vec2f rt=Vec2f(1.0f, 1.0f), Function func=Function(), Mixer mixer=Mixer())
Creates a RGB texture using c1 and c2 for colorizing of the fractal.
Definition: newton.hpp:205
Vector< GLfloat, 2 > Vec2f
2D float vector
Definition: vector.hpp:73
T At(const Vector &vector, std::size_t i) const T x(void) const
Returns the value of the i-th coordinate of the vector.
Definition: vector.hpp:221
NewtonFractal(GLsizei width, GLsizei height, Function func=Function(), Mixer mixer=Mixer())
Creates a Red texture colorized from black to red.
Definition: newton.hpp:232
T y(void) const
Returns the 1-st component.
Definition: vector.hpp:231
A generator of Newton fractal 2D images.
Definition: newton.hpp:45
Wrapper for (texture) image data.
Definition: image.hpp:45
Basic template for vector types.
Definition: fwd.hpp:43
The X^3-1 function and its derivation.
Definition: newton.hpp:113
Vector< GLfloat, 1 > Vec1f
1D float (degenerate) vector
Definition: vector.hpp:67