[haiku-commits] r40109 - haiku/trunk/src/add-ons/screen_savers/butterfly

  • From: leavengood@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 4 Jan 2011 17:14:25 +0100 (CET)

Author: leavengood
Date: 2011-01-04 17:14:25 +0100 (Tue, 04 Jan 2011)
New Revision: 40109
Changeset: http://dev.haiku-os.org/changeset/40109

Modified:
   haiku/trunk/src/add-ons/screen_savers/butterfly/Butterfly.cpp
   haiku/trunk/src/add-ons/screen_savers/butterfly/Butterfly.h
Log:
Fix coding violations, improve variable naming, remove strange float constants
like 4.f.


Modified: haiku/trunk/src/add-ons/screen_savers/butterfly/Butterfly.cpp
===================================================================
--- haiku/trunk/src/add-ons/screen_savers/butterfly/Butterfly.cpp       
2011-01-04 15:46:45 UTC (rev 40108)
+++ haiku/trunk/src/add-ons/screen_savers/butterfly/Butterfly.cpp       
2011-01-04 16:14:25 UTC (rev 40109)
@@ -7,8 +7,8 @@
  */
 #include "Butterfly.h"
 
-#include <stdlib.h>
 #include <math.h>
+#include <stdlib.h>
 #include <sys/time.h>
 
 #include <View.h>
@@ -16,7 +16,7 @@
 #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*
@@ -55,12 +55,12 @@
 
        struct timeval tv;
        gettimeofday(&tv, NULL);
-       fT = tv.tv_usec * 0.01f;
+       fBase = tv.tv_usec * 0.01;
 
        // calculate transformation
        BRect bounds = view->Bounds();
-       fScale = MIN(bounds.Width(), bounds.Height()) * 0.1f;
-       fTrans.Set(bounds.Width() * 0.5f, bounds.Height() * 0.5f);
+       fScale = MIN(bounds.Width(), bounds.Height()) * 0.1;
+       fTrans.Set(bounds.Width() * 0.5, bounds.Height() * 0.5);
        fBounds = bounds;
 
        fLast[0] = _Iterate();
@@ -84,8 +84,8 @@
                view->SetHighColor(0, 0, 0, 4);
                view->FillRect(fBounds);
        }
-       // create a color from a hue of (fT * 15) degrees
-       view->SetHighColor(_HueToColor(fT * 15.f));
+       // create a color from a hue of (fBase * 15) degrees
+       view->SetHighColor(_HueToColor(fBase * 15.0));
        BPoint p = _Iterate();
        
        // cubic Hermite interpolation from fLast[1] to fLast[2]
@@ -114,7 +114,7 @@
 Butterfly::_HueToColor(float hue)
 {
        // 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);
 
        rgb_color result = {0, 0, 0, 255};
@@ -144,18 +144,17 @@
 inline BPoint
 Butterfly::_Iterate()
 {
-       float r = powf(2.718281828f, cosf(fT))
-               - 2.f * cosf(4.f * fT)
-               - powf(sinf(fT / 12.f), 5.f);
+       float r = powf(M_E, cosf(fBase)) - 2.0 * cosf(4.0 * fBase)
+               - powf(sinf(fBase / 12.0), 5.0);
        // rotate and move it a bit
-       BPoint p(sinf(fT * 1.01f) * r + cosf(fT * 1.02f) * 0.2f,
-               cosf(fT * 1.01f) * r + sinf(fT * 1.02f) * 0.2f);
+       BPoint p(sinf(fBase * 1.01) * r + cosf(fBase * 1.02) * 0.2,
+               cosf(fBase * 1.01) * r + sinf(fBase * 1.02) * 0.2);
        // transform to view coordinates
        p.x *= fScale;
        p.y *= fScale;
        p += fTrans;
        // move on
-       fT += 0.05f;
+       fBase += 0.05;
        return p;
 }
 

Modified: haiku/trunk/src/add-ons/screen_savers/butterfly/Butterfly.h
===================================================================
--- haiku/trunk/src/add-ons/screen_savers/butterfly/Butterfly.h 2011-01-04 
15:46:45 UTC (rev 40108)
+++ haiku/trunk/src/add-ons/screen_savers/butterfly/Butterfly.h 2011-01-04 
16:14:25 UTC (rev 40109)
@@ -21,7 +21,8 @@
        virtual void            Draw(BView* view, int32 frame);
 
 private:
-                       float           fT;
+                       // base value for calculating the curves on each 
iteration
+                       float           fBase;
                        // previously calculated points
                        BPoint          fLast[3];
                        // transformation from graph coordinates to view 
coordinates


Other related posts: