]> git.vomp.tv Git - vompclient.git/commitdiff
*** empty log message ***
authorChris Tallon <chris@vomp.tv>
Sat, 31 Mar 2007 13:27:00 +0000 (13:27 +0000)
committerChris Tallon <chris@vomp.tv>
Sat, 31 Mar 2007 13:27:00 +0000 (13:27 +0000)
vscreensaver.cc

index f979f63aa97592291135dba0f10322657662126e..d633d9fe8f37332897962beca70781c45e003417 100644 (file)
@@ -53,10 +53,12 @@ int VScreensaver::handleCommand(int command)
 
 void VScreensaver::threadMethod()
 {
+  srand(time(NULL));
+
   threadSetKillable();
 
   // Config
-  int h = 50;  // length of line
+  const int h = 50;  // length of line
   float deviation = 0.2;  // how quickly can it change direction
 
 
@@ -64,36 +66,27 @@ void VScreensaver::threadMethod()
   int x[h];
   int y[h];
   int i;
+  int head = -1;
+  int tail;
   float direction = 0;
-  float fx;
-  float fy;
-  float dd;
-  const float pi = 3.14159;
+  float fx, fy, dd;
   const float pi2 = 6.28318;
   float halfdeviation = deviation / 2;
 
-  for(i = 1; i < h; i++)
-  {
-    x[i] = -1;
-    y[i] = -1;
-  }
+  for(i = 0; i < h; i++) x[i] = -1;
 
   fx = x[0] = 50;
   fy = y[0] = 50;
 
   while(1)
   {
-    // Undraw oldest pixel
-    if ((x[h-1] != -1) && (y[h-1] != -1))
-    {
-      surface->drawPixel(x[h-1], y[h-1], Colour::BLACK.rgba());
-    }
+    if (++head == h) head = 0;
+
+    tail = head + 1;
+    if (tail == h) tail = 0;
 
-    for(i = h - 1; i > 0; i--)
-    {
-      x[i] = x[i-1];
-      y[i] = y[i-1];
-    }
+    // Undraw oldest pixel
+    if (x[tail] != -1) surface->drawPixel(x[tail], y[tail], Colour::BLACK.rgba());
 
     dd = ((rand() / (double)RAND_MAX) * deviation) - halfdeviation;
     direction += dd;
@@ -109,10 +102,10 @@ void VScreensaver::threadMethod()
     if (fy < 0) fy += screenHeight;
     if (fy >= screenHeight) fy -= screenHeight;
 
-    x[0] = (int)fx;
-    y[0] = (int)fy;
+    x[head] = (int)fx;
+    y[head] = (int)fy;
 
-    surface->drawPixel(x[0], y[0], Colour::SELECTHIGHLIGHT.rgba());
+    surface->drawPixel(x[head], y[head], Colour::SELECTHIGHLIGHT.rgba());
     MILLISLEEP(10);
   }
 }