From 3ee6641584ed6d9a28bb563f7b7220dd3f4e2462 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Sat, 31 Mar 2007 13:27:00 +0000 Subject: [PATCH] *** empty log message *** --- vscreensaver.cc | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/vscreensaver.cc b/vscreensaver.cc index f979f63..d633d9f 100644 --- a/vscreensaver.cc +++ b/vscreensaver.cc @@ -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); } } -- 2.39.5