http://code.google.com/p/idlescreen/source/detail?r=207
Added:
/branches/backus_dev/src/SpiralLenz/src/SpiralBackgroundProfileWidget.h
/branches/backus_dev/src/common/spirals/PolarSpiralAlgorithm.cpp
/branches/backus_dev/src/common/spirals/PolarSpiralAlgorithm.h
Modified:
/branches/backus_dev/Makefile.in
/branches/backus_dev/src/SpiralLenz/project_files/SpiralLenz_glut.pro
/branches/backus_dev/src/SpiralLenz/resource_files/defaults.xml
/branches/backus_dev/src/SpiralLenz/src/RectangularSpiralBackgroundProfile.cpp
/branches/backus_dev/src/common/spirals/NgonSpiralAlgorithm.cpp
/branches/backus_dev/src/common/spirals/NgonSpiralAlgorithm.h
/branches/backus_dev/src/common/spirals/SpiralAlgorithm.cpp
/branches/backus_dev/src/common/spirals/SpiralAlgorithm.h
=======================================
--- /dev/null
+++ /branches/backus_dev/src/SpiralLenz/src/SpiralBackgroundProfileWidget.h
Sun Aug 2 11:49:07 2009
@@ -0,0 +1,53 @@
+/**
+ * Copyright (c) 2008 Jeff Backus.
+ *
+ * Licensed under the GNU General Public License, Version 2.0
(the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Additionally, this code makes heavy use of the Qt libraries from
+ * Trolltech. These libraries are released under the GNU
+ * General Public License, Version 2.0, as well. Please contact
+ * Trolltech for more information.
+ *
+ * http://trolltech.com/
+ *
+ */
+
+/**
+ * This class represents the configuration widget panels for the different
+ * spiral styles. Each profile is responsible for generating an
appropriate
+ * layout for this panel.
+ *
+ * @author jeff backus
+ * @date 04/03/2009
+ */
+
+#ifndef __SPIRALBACKGROUNDPROFILEWIDGET_H__
+#define __SPIRALBACKGROUNDPROFILEWIDGET_H__
+
+#include <QString>
+#include <QtXml/QDomNode>
+#include <QtXml/QDomDocument>
+#include <QWidget>
+
+#include "SpiralBackgroundProfile.h"
+
+class SpiralBackgroundProfileWidget : public QWidget {
+ Q_OBJECT
+
+public:
+ //constructor & destructor
+ ConfigWidget(QWidget* parent = 0, Qt::WindowFlags f = 0);
+ ~ConfigWidget();
+ private:
+
+};
=======================================
--- /dev/null
+++ /branches/backus_dev/src/common/spirals/PolarSpiralAlgorithm.cpp Sun
Aug 2 11:49:07 2009
@@ -0,0 +1,250 @@
+
+// debug
+#include <iostream>
+// end debug
+#include <math.h>
+using namespace std;
+
+#include "PolarSpiralAlgorithm.h"
+
+/**
+ * Constructor.
+ */
+PolarSpiralAlgorithm::PolarSpiralAlgorithm() {
+
+ // parameters
+ _colorWidth = 1;
+ _emptyWidth = 0;
+ _bConstantColor = true;
+ _bRandomColor = false;
+ _bIncrementColor = true;
+
+ // internals
+ _nextIdx = 0;
+ _currX = 0.0;
+ _currY = 0.0;
+ _rCoeff = 0.0;
+ _currR = 0.0;
+ _currTheta = 0.0;
+ _maxR = 0.0;
+
+ // misc constants
+ _maxFieldIdx = 0;
+ _screenXOffset = 0;
+ _screenYOffset = 0;
+}
+
+ /**
+ * Constructor takes initialization parameters.
+ * @param colorWidth the width of the strip of color.
+ * @param emptyWidth the width of the default color region.
+ * @param bConstantColor whether or not to hold the color index constant.
+ * @param bRandomColor whether or not the initial color is randomly
selected.
+ * @param bIncrementColor whether to increment the color as it spirals
out.
+ * @see calc()
+ */
+PolarSpiralAlgorithm::PolarSpiralAlgorithm(const int colorWidth,
+ const int emptyWidth,
+ const bool bConstantColor,
+ const bool bRandomColor,
+ const bool bIncrementColor) {
+
+ // empty constants until initialize(...) is called
+ _maxFieldIdx = 0;
+ _screenXOffset = 0;
+ _screenYOffset = 0;
+ _maxR = 0.0;
+
+ // initial values for internals
+ _nextIdx = 0;
+ _currX = 0.0;
+ _currY = 0.0;
+
+ // set parameters
+ _colorWidth = colorWidth;
+ _emptyWidth = emptyWidth;
+ _bConstantColor = bConstantColor;
+ _bRandomColor = bRandomColor;
+ _bIncrementColor = bIncrementColor;
+
+ if(_colorWidth < 0)
+ _colorWidth = 0;
+ if(_emptyWidth < 0)
+ _emptyWidth = 0;
+
+ // calculate misc constants
+ _segmentWidth = _colorWidth + (_emptyWidth<<1);
+
+ // calculate spiral constants and initial values
+ _rCoeff = double(_segmentWidth)/(2.0*SPIRALALGORITHM_PI);
+ _rCoeff *= (jrand() % 2 == 0) ? 1.0 : -1.0; // whether clockwise or not.
+ _currR = 0.0;
+
+ // for now, just start at 0.
+ _currTheta = 0.0;
+ _lastThetaStep = SPIRALALGORITHM_PI/16.0;
+
+}
+
+
+PolarSpiralAlgorithm::~PolarSpiralAlgorithm() {
+}
+
+/**
+ * Initializes the algorithm. Doesn't perform any actual generation.
+ * @param field The array of integers in which to generate the spiral
field.
+ * @param screenWidth the width of the screen in pixels.
+ * @param screenHeight the height of the screen in pixels.
+ * @param numColors the number of colors in the palette primary direction.
+ */
+void PolarSpiralAlgorithm::initialize(int* field, const int screenWidth,
+ const int screenHeight,
+ const int numColors) {
+ initializeBase(field, screenWidth, screenHeight, numColors);
+
+ if(_height <= 0)
+ return;
+ if(_width <= 0)
+ return;
+ if(_numColors <= 0)
+ return;
+
+ // calculate remaining internal constants
+ _maxFieldIdx = screenWidth * screenHeight - 1;
+ _screenXOffset = screenWidth>>1;
+ _screenYOffset = screenHeight>>1;
+
+ // calculate polar stopping condition.
+ _maxR = sqrt( _screenXOffset*_screenXOffset +
+ _screenYOffset*_screenYOffset);
+ if(_rCoeff < 0.0) {
+ _maxR *= -1.0;
+ }
+
+ // pick initial color
+ if(_bRandomColor) {
+ _nextIdx = jrand() % numColors;
+ } else {
+ _nextIdx = 0;
+ }
+
+ // begin debug
+ _stepCount = 128; //16;
+ // end debug
+
+}
+
+/**
+ * Completes one iteration of the algorithm. Returns true if the algorithm
+ * is completed.
+ */
+bool PolarSpiralAlgorithm::calc() {
+ if(_field == NULL)
+ return true;
+
+ if(_stepCount < 0)
+ return true;
+ //_stepCount--;
+
+ bool retVal = calcSpiral();
+
+ // set pixel to next color, if it is within the boundaries.
+ int px = roundDtoI(_currX)+_screenXOffset;
+ int py = roundDtoI(_currY)+_screenYOffset;
+ int fieldIdx = px+py*_width;
+ if(0 <= px && px < _width && 0 <= py && py < _height &&
+ fieldIdx < _maxFieldIdx) {
+ _field[fieldIdx] = _nextIdx;
+ }
+
+ // update color
+ if(!_bConstantColor) {
+ if(_bIncrementColor) {
+ _nextIdx = (_nextIdx+1)%_numColors;
+ } else {
+ _nextIdx = _nextIdx - 1;
+ if(_nextIdx < 0) {
+ _nextIdx = _numColors - _nextIdx;
+ }
+ }
+ }
+
+ return retVal;
+}
+
+/**
+ * Calculates a new X,Y using a polar spiral. Utilizes an adaptive
+ * algorithm to adjust thetaStep such that the new (x,y) value will
+ * be adjacent but not on the previous (x,y) value.
+ *
+ * @return True if the calculation is complete.
+ */
+bool PolarSpiralAlgorithm::calcSpiral() {
+ //cout<<"Entering calcSpiral"<<endl;
+ double newX;
+ double newY;
+ double newR;
+ double newTheta;
+ double newThetaStep = _lastThetaStep;
+
+ int iOldX = roundDtoI(_currX);
+ int iOldY = roundDtoI(_currY);
+ int iNewX;
+ int iNewY;
+
+ int escape_count = 0;
+ bool bDone = false;
+ while(!bDone) {
+ // update Theta
+ newTheta = _currTheta + newThetaStep;
+
+ // calculate the new R, X and Y
+ newR = _rCoeff * newTheta;
+ newX = newR * cos(newTheta);
+ newY = newR * sin(newTheta);
+
+ // check to see if we've calculated for an adjacent pixel
+ iNewX = roundDtoI(newX);
+ iNewY = roundDtoI(newY);
+ /*
+ cout<<"newX: "<<newX<<","<<iNewX<<endl;
+ cout<<"newY: "<<newY<<","<<iNewY<<endl;
+ cout<<"oldX: "<<*x<<","<<iOldX<<endl;
+ cout<<"oldY: "<<*y<<","<<iOldY<<endl;
+ */
+
+ bDone = true;
+ if(iNewX == iOldX && iNewY == iOldY) {
+ // theta too small
+ newThetaStep*=2.0;
+ bDone = false;
+ } else if(iNewX <= iOldX-2 || iOldX+2 <= iNewX ||
+ iNewY <= iOldY-2 || iOldY+2 <= iNewY) {
+ // theta too large
+ newThetaStep*=0.5;
+ bDone = false;
+ }
+
+ if(++escape_count >= 100) {
+ /*
+ cout<<"PolarSpiralAlgorithm::calcSpiral() Escape count
reached!"<<endl;
+ cout<<"maxR: "<<_maxR<<endl;
+ */
+ //exit(1);
+ //*r = _maxR+1.0;
+ _maxR = -1;
+ bDone = true;
+ }
+ }
+
+ // !!! NOTE NEED TO ADD IN CODE TO HANDLE _colorWidth
+
+ // send out values.
+ _currX = newX;
+ _currY = newY;
+ _currR = newR;
+ _currTheta = newTheta;
+ _lastThetaStep = newThetaStep;
+
+ return (_rCoeff < 0.0) ? (newR <= _maxR) : (newR >= _maxR);
+}
=======================================
--- /dev/null
+++ /branches/backus_dev/src/common/spirals/PolarSpiralAlgorithm.h Sun Aug
2 11:49:07 2009
@@ -0,0 +1,113 @@
+/**
+ * Copyright (c) 2009 Jeff Backus.
+ *
+ * Licensed under the GNU General Public License, Version 2.0
(the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Additionally, this code makes heavy use of the Qt libraries from
+ * Trolltech. These libraries are released under the GNU
+ * General Public License, Version 2.0, as well. Please contact
+ * Trolltech for more information.
+ *
+ * http://trolltech.com/
+ *
+ */
+
+/**
+ * This algorithm generates a polar spiral.
+ */
+
+#include "utility/misc_funcs.h"
+#include "SpiralAlgorithm.h"
+
+#ifndef __POLARSPIRALALGORITHM_H__
+#define __POLARSPIRALALGORITHM_H__
+
+class PolarSpiralAlgorithm : public SpiralAlgorithm {
+
+ public:
+
+ /**
+ * Default constructor.
+ */
+ PolarSpiralAlgorithm();
+
+ /**
+ * Constructor takes initialization parameters.
+ * @param colorWidth the width of the strip of color.
+ * @param emptyWidth the width of the default color region.
+ * @param bConstantColor whether or not to hold the color index constant.
+ * @param bRandomColor whether or not the initial color is randomly
selected.
+ * @param bIncrementColor whether to increment the color as it spirals
out.
+ * @see calc()
+ */
+ PolarSpiralAlgorithm(const int colorWidth, const int emptyWidth,
+ const bool bConstantColor, const bool bRandomColor,
+ const bool bIncrementColor);
+
+ ~PolarSpiralAlgorithm();
+
+ /**
+ * Initializes the algorithm. Doesn't perform any actual generation.
+ * @param field The array of integers in which to generate the spiral
field.
+ * @param screenWidth the width of the screen in pixels.
+ * @param screenHeight the height of the screen in pixels.
+ * @param numColors the number of colors in the palette primary
direction.
+ */
+ void initialize(int* field, const int screenWidth,
+ const int screenHeight, const int numColors);
+
+ /**
+ * Completes one iteration of the algorithm. Returns true if the
algorithm
+ * is completed.
+ */
+ bool calc();
+
+ private:
+ /**
+ * Calculates a new X,Y using a polar spiral. Utilizes an adaptive
+ * algorithm to adjust thetaStep such that the new (x,y) value will
+ * be adjacent but not on the previous (x,y) value.
+ * @return True if the calculation is complete.
+ */
+ bool calcSpiral();
+
+ // begin parameters
+ int _colorWidth;
+ int _emptyWidth;
+ bool _bConstantColor;
+ bool _bRandomColor;
+ bool _bIncrementColor;
+ // end parameters
+
+ double _rCoeff; // accounts for clockwise/counterclockwise!
+ double _currR;
+ double _currTheta;
+ double _lastThetaStep;
+ double _maxR; //!< polar stopping condition
+
+ double _currX;
+ double _currY;
+ int _nextIdx;
+
+ // begin constants to speed up calculations
+ int _screenXOffset;
+ int _screenYOffset;
+ int _segmentWidth;
+ int _maxFieldIdx; //> _sizeX * _sizeY - 1;
+ // end constants
+
+ // begin debug
+ int _stepCount;
+};
+
+#endif
=======================================
--- /branches/backus_dev/Makefile.in Sun Apr 26 17:56:58 2009
+++ /branches/backus_dev/Makefile.in Sun Aug 2 11:49:07 2009
@@ -60,7 +60,7 @@
$(MAKE) -f Makefile.PlasmaLenz_scr
bin/PlasmaLenz_glut : src/PlasmaLenz/project_files/PlasmaLenz_glut.pro
- cd $(srcdir)src/PlasmaLenz/project_files/ && $(QMAKE) PlasmaLenz_glut.pro
\
+ cd $(srcdir)/src/PlasmaLenz/project_files/ && $(QMAKE)
PlasmaLenz_glut.pro \
-o Makefile.PlasmaLenz_glut && \
$(MAKE) -f Makefile.PlasmaLenz_glut
=======================================
--- /branches/backus_dev/src/SpiralLenz/project_files/SpiralLenz_glut.pro
Sun Apr 26 17:56:58 2009
+++ /branches/backus_dev/src/SpiralLenz/project_files/SpiralLenz_glut.pro
Sun Aug 2 11:49:07 2009
@@ -20,6 +20,7 @@
SOURCES += $$COMMON_PATH/spirals/SpiralAlgorithm.cpp
SOURCES += $$COMMON_PATH/spirals/RectangularSpiralAlgorithm.cpp
SOURCES += $$COMMON_PATH/spirals/NgonSpiralAlgorithm.cpp
+SOURCES += $$COMMON_PATH/spirals/PolarSpiralAlgorithm.cpp
SOURCES += $$COMMON_PATH/IndexedPalette/IndexedPalette.cpp
SOURCES += $$COMMON_PATH/IndexedPalette/IndexedPaletteDialog.cpp
@@ -63,6 +64,7 @@
HEADERS += $$COMMON_PATH/spirals/SpiralAlgorithm.h
HEADERS += $$COMMON_PATH/spirals/RectangularSpiralAlgorithm.h
HEADERS += $$COMMON_PATH/spirals/NgonSpiralAlgorithm.h
+HEADERS += $$COMMON_PATH/spirals/PolarSpiralAlgorithm.h
HEADERS += $$COMMON_PATH/IndexedPalette/IndexedPalette.h
HEADERS += $$COMMON_PATH/IndexedPalette/IndexedPaletteDialog.h
=======================================
--- /branches/backus_dev/src/SpiralLenz/resource_files/defaults.xml Sun Apr
26 17:56:58 2009
+++ /branches/backus_dev/src/SpiralLenz/resource_files/defaults.xml Sun
Aug 2 11:49:07 2009
@@ -3,11 +3,16 @@
<BackgroundProfile>
<type>RectangularSpiralBackground</type>
<name>Classic RGB Profile</name>
- <steps_per_tick>2048</steps_per_tick>
+ <steps_per_tick>1024</steps_per_tick>
<anmiate_palette>true</anmiate_palette>
<palette_x_speed>1</palette_x_speed>
<palette_y_speed>1</palette_y_speed>
<palette>Classic RGB Palette</palette>
+ <color_width>1</color_width>
+ <empty_width>1</empty_width>
+ <constant_color>false</constant_color>
+ <random_color>false</random_color>
+ <increment_color>false</increment_color>
</BackgroundProfile>
<IndexedPaletteProfile>
<name>Classic RGB Palette</name>
@@ -98,7 +103,8 @@
</MasterProfile>
<random_master_profiles>false</random_master_profiles>
<gpl_accepted>false</gpl_accepted>
- <master_profile_history_size>3</master_profile_history_size>
+ <master_profile_history_size>0</master_profile_history_size>
+ <master_profile_history/>
<selected_master_profile_list>
<selected_entry>
<name>Classic RGB</name>
=======================================
---
/branches/backus_dev/src/SpiralLenz/src/RectangularSpiralBackgroundProfile.cpp
Sun Apr 26 17:56:58 2009
+++
/branches/backus_dev/src/SpiralLenz/src/RectangularSpiralBackgroundProfile.cpp
Sun Aug 2 11:49:07 2009
@@ -37,6 +37,7 @@
// begin tmp
#include "spirals/NgonSpiralAlgorithm.h"
+#include "spirals/PolarSpiralAlgorithm.h"
// end tmp
RectangularSpiralBackgroundProfile::RectangularSpiralBackgroundProfile() {
@@ -255,9 +256,14 @@
QHash<QString, IndexedPaletteProfile*>* palHash) {
+ PolarSpiralAlgorithm* alg =
+ new PolarSpiralAlgorithm(_colorWidth,_emptyWidth,_bConstantColor,
+ _bRandomColor, _bIncrementColor);
+ /*
NgonSpiralAlgorithm* alg =
new NgonSpiralAlgorithm(0,_colorWidth,_emptyWidth,_bConstantColor,
_bRandomColor, _bIncrementColor);
+ */
/*
RectangularSpiralAlgorithm* alg =
new RectangularSpiralAlgorithm(_colorWidth,_emptyWidth,_bConstantColor,
=======================================
--- /branches/backus_dev/src/common/spirals/NgonSpiralAlgorithm.cpp Sun Apr
26 17:56:58 2009
+++ /branches/backus_dev/src/common/spirals/NgonSpiralAlgorithm.cpp Sun
Aug 2 11:49:07 2009
@@ -120,6 +120,9 @@
// calculate polar stopping condition.
_maxR = sqrt( _screenXOffset*_screenXOffset +
_screenYOffset*_screenYOffset);
+ if(_rCoeff < 0.0) {
+ _maxR *= -1.0;
+ }
// pick initial color
if(_bRandomColor) {
@@ -142,7 +145,7 @@
if(_field == NULL)
return true;
- if(_stepCount < 0)
+ if(_stepCount < 0)
return true;
//_stepCount--;
// if N is valid, use the N-gon spiral calculations.
@@ -153,7 +156,6 @@
} else {
retVal = calcSpiral(&_currX, &_currY, &_currR, &_currTheta,
&_lastThetaStep);
- //retVal = (_currR >= _maxR);
}
// set pixel to next color, if it is within the boundaries.
@@ -240,19 +242,25 @@
}
if(++escape_count >= 100) {
+ /*
cout<<"NgonSpiralAlgorithm::calcSpiral() Escape count
reached!"<<endl;
cout<<"maxR: "<<_maxR<<endl;
+ */
//exit(1);
//*r = _maxR+1.0;
_maxR = -1;
bDone = true;
}
}
+
+ // !!! NOTE NEED TO ADD IN CODE TO HANDLE _colorWidth
+
+ // send out values.
*x = newX;
*y = newY;
*r = newR;
*theta = newTheta;
*thetaStep = newThetaStep;
- return (newR >= _maxR);
-}
+ return (_rCoeff < 0.0) ? (newR <= _maxR) : (newR >= _maxR);
+}
=======================================
--- /branches/backus_dev/src/common/spirals/NgonSpiralAlgorithm.h Sun Apr
26 17:56:58 2009
+++ /branches/backus_dev/src/common/spirals/NgonSpiralAlgorithm.h Sun Aug
2 11:49:07 2009
@@ -27,17 +27,13 @@
* spiral algorithm is used.
*/
+#include "utility/Vector2D.h"
#include "utility/misc_funcs.h"
#include "SpiralAlgorithm.h"
#ifndef __NGONSPIRALALGORITHM_H__
#define __NGONSPIRALALGORITHM_H__
-//enum NgonSpiralAlgorithmDir { UP=0, DOWN=1, LEFT=2, RIGHT=3 };
-
-#define NGONSPIRAL_PI 3.14159265f
-#define NGONSPIRAL_MAX_N 20
-
class NgonSpiralAlgorithm : public SpiralAlgorithm {
public:
@@ -94,27 +90,6 @@
bool calcSpiral(double* x, double* y, double* r, double* theta,
double* thetaStep);
- /**
- * Calculates both the corner and "straight away" segments.
- * These segments are _segmentSize x _segmentSize in size.
- * They are also oriented such that (0,0) is the bottom left corner.
- * _straightSeg is such that it flows from left to right, and
- * _cornerSeg is such that it flows from right to up if _bClockwise
- * is false, or right to down if _bClockwise is true. Note that in
- * either case, the color index offset has not been properly modulo'd
- * and should be done so after being added to the current color index,
- * if _bConstantColor is false. In the case where _bConstantColor is
- * true, the index offset will always be 0.
- */
- //void calcSegments();
-
- /**
- * Rotates and draws the specified segment at (_currX,_currY) based
- * on _dir.
- * @param seg Must be either _cornerSeg or _straightSeg.
- */
- //void drawSegment(int* seg);
-
// begin parameters
int _n;
int _colorWidth;
@@ -128,7 +103,7 @@
double _rCoeff; // accounts for clockwise/counterclockwise!
double _currR;
double _currTheta;
- double _lastThetaStep;
+ double _thetaStep;
double _maxR; //!< polar stopping condition
// end spiral specific
=======================================
--- /branches/backus_dev/src/common/spirals/SpiralAlgorithm.cpp Sun Apr 26
17:56:58 2009
+++ /branches/backus_dev/src/common/spirals/SpiralAlgorithm.cpp Sun Aug 2
11:49:07 2009
@@ -44,11 +44,21 @@
* the algorithm will continue until finished.
*/
bool SpiralAlgorithm::calc(const int numIterations) {
+
+ int i=0;
+ bool bDone = false;
+ while(i++<numIterations && !bDone) {
+ bDone = calc();
+ }
+
+ return bDone;
+ /*
for(int i=0; i<numIterations; i++) {
if(calc())
return true;
}
return false;
+ */
}
/**
=======================================
--- /branches/backus_dev/src/common/spirals/SpiralAlgorithm.h Sun Apr 26
17:56:58 2009
+++ /branches/backus_dev/src/common/spirals/SpiralAlgorithm.h Sun Aug 2
11:49:07 2009
@@ -36,6 +36,8 @@
#include <stdlib.h>
#endif
+#define SPIRALALGORITHM_PI 3.14159265f
+
class SpiralAlgorithm {
public: