Fix coding violations, improve variable naming, remove strange float constants

like 4.f.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40109 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ryan Leavengood
2011-01-04 16:14:25 +00:00
parent bdb262352e
commit 3107597abe
2 changed files with 15 additions and 15 deletions
@@ -7,8 +7,8 @@
*/ */
#include "Butterfly.h" #include "Butterfly.h"
#include <stdlib.h>
#include <math.h> #include <math.h>
#include <stdlib.h>
#include <sys/time.h> #include <sys/time.h>
#include <View.h> #include <View.h>
@@ -16,7 +16,7 @@
#include <BuildScreenSaverDefaultSettingsView.h> #include <BuildScreenSaverDefaultSettingsView.h>
const float kOneSixth = 0.1666666666666666666f; // 1/2 * 1/3 const float kOneSixth = 0.5 * (1.0/3.0); // 1/2 * 1/3
extern "C" BScreenSaver* extern "C" BScreenSaver*
@@ -55,12 +55,12 @@ Butterfly::StartSaver(BView* view, bool preview)
struct timeval tv; struct timeval tv;
gettimeofday(&tv, NULL); gettimeofday(&tv, NULL);
fT = tv.tv_usec * 0.01f; fBase = tv.tv_usec * 0.01;
// calculate transformation // calculate transformation
BRect bounds = view->Bounds(); BRect bounds = view->Bounds();
fScale = MIN(bounds.Width(), bounds.Height()) * 0.1f; fScale = MIN(bounds.Width(), bounds.Height()) * 0.1;
fTrans.Set(bounds.Width() * 0.5f, bounds.Height() * 0.5f); fTrans.Set(bounds.Width() * 0.5, bounds.Height() * 0.5);
fBounds = bounds; fBounds = bounds;
fLast[0] = _Iterate(); fLast[0] = _Iterate();
@@ -84,8 +84,8 @@ Butterfly::Draw(BView* view, int32 frame)
view->SetHighColor(0, 0, 0, 4); view->SetHighColor(0, 0, 0, 4);
view->FillRect(fBounds); view->FillRect(fBounds);
} }
// create a color from a hue of (fT * 15) degrees // create a color from a hue of (fBase * 15) degrees
view->SetHighColor(_HueToColor(fT * 15.f)); view->SetHighColor(_HueToColor(fBase * 15.0));
BPoint p = _Iterate(); BPoint p = _Iterate();
// cubic Hermite interpolation from fLast[1] to fLast[2] // cubic Hermite interpolation from fLast[1] to fLast[2]
@@ -114,7 +114,7 @@ inline rgb_color
Butterfly::_HueToColor(float hue) Butterfly::_HueToColor(float hue)
{ {
// convert from [0..360) to [0..1530) // convert from [0..360) to [0..1530)
int h = static_cast<int>(fmodf(hue, 360) * 4.25f); int h = static_cast<int>(fmodf(hue, 360) * 4.25);
int x = 255 - abs(h % 510 - 255); int x = 255 - abs(h % 510 - 255);
rgb_color result = {0, 0, 0, 255}; rgb_color result = {0, 0, 0, 255};
@@ -144,18 +144,17 @@ Butterfly::_HueToColor(float hue)
inline BPoint inline BPoint
Butterfly::_Iterate() Butterfly::_Iterate()
{ {
float r = powf(2.718281828f, cosf(fT)) float r = powf(M_E, cosf(fBase)) - 2.0 * cosf(4.0 * fBase)
- 2.f * cosf(4.f * fT) - powf(sinf(fBase / 12.0), 5.0);
- powf(sinf(fT / 12.f), 5.f);
// rotate and move it a bit // rotate and move it a bit
BPoint p(sinf(fT * 1.01f) * r + cosf(fT * 1.02f) * 0.2f, BPoint p(sinf(fBase * 1.01) * r + cosf(fBase * 1.02) * 0.2,
cosf(fT * 1.01f) * r + sinf(fT * 1.02f) * 0.2f); cosf(fBase * 1.01) * r + sinf(fBase * 1.02) * 0.2);
// transform to view coordinates // transform to view coordinates
p.x *= fScale; p.x *= fScale;
p.y *= fScale; p.y *= fScale;
p += fTrans; p += fTrans;
// move on // move on
fT += 0.05f; fBase += 0.05;
return p; return p;
} }
@@ -21,7 +21,8 @@ public:
virtual void Draw(BView* view, int32 frame); virtual void Draw(BView* view, int32 frame);
private: private:
float fT; // base value for calculating the curves on each iteration
float fBase;
// previously calculated points // previously calculated points
BPoint fLast[3]; BPoint fLast[3];
// transformation from graph coordinates to view coordinates // transformation from graph coordinates to view coordinates