#ifndef SPIRALLINESGLWIDGET_H
#define SPIRALLINESGLWIDGET_H

#include "GLWidget.h"
#include <cmath>

class SpiralLinesGLWidget : public GLWidget
{
public:
	SpiralLinesGLWidget(QWidget* parent = 0);
protected:
	void initializeGL();
	void render();
};

SpiralLinesGLWidget::SpiralLinesGLWidget(QWidget* parent) : GLWidget(parent) {}

void SpiralLinesGLWidget::initializeGL()
{
	GLWidget::initializeGL();
	setXRotation(-45);
	setYRotation(15);
	setZRotation(45);
}

void SpiralLinesGLWidget::render()
{
	// How many revolutions of the spiral are rendered.
	static const float REVOLUTIONS = 10;
	static const float PI = 3.14159;

	// How many vertices per revolution.
	static const float SLICES = 10;

	glBegin(GL_LINE_STRIP);
	for (int i = 0; i <= REVOLUTIONS * SLICES; i++) {
		const float angle = i * 2 * PI / SLICES;
		glVertex2f(
			angle * (float) sin(angle),
			angle * (float) cos(angle));
	}
	glEnd();
}

#endif // SPIRALLINESGLWIDGET_H

#ifndef SPIRALLINESGLWIDGET_H
#define SPIRALLINESGLWIDGET_H

#include "GLWidget.h"
#include <cmath>

class SpiralLinesGLWidget : public GLWidget
{
public:
	SpiralLinesGLWidget(QWidget* parent = 0);
protected:
	void initializeGL();
	void render();
};

SpiralLinesGLWidget::SpiralLinesGLWidget(QWidget* parent) : GLWidget(parent) {}

void SpiralLinesGLWidget::initializeGL()
{
	GLWidget::initializeGL();
	setXRotation(-45);
	setYRotation(15);
	setZRotation(45);
}

void SpiralLinesGLWidget::render()
{
	// How many revolutions of the spiral are rendered.
	static const float REVOLUTIONS = 10;
	static const float PI = 3.14159;

	glBegin(GL_LINE_STRIP);
	for (float angle = 0; angle < 2*PI*REVOLUTIONS; angle +=  PI / (2 * REVOLUTIONS * 10)) {
		glVertex2f(
			angle * (float) sin(angle),
			angle * (float) cos(angle));
	}
	glEnd();
}

#endif // SPIRALLINESGLWIDGET_H

--- 
+++ 
@@ -29,8 +29,12 @@
 	static const float REVOLUTIONS = 10;
 	static const float PI = 3.14159;
 
+	// How many vertices per revolution.
+	static const float SLICES = 10;
+
 	glBegin(GL_LINE_STRIP);
-	for (float angle = 0; angle < 2*PI*REVOLUTIONS; angle +=  PI / (2 * REVOLUTIONS * 10)) {
+	for (int i = 0; i <= REVOLUTIONS * SLICES; i++) {
+		const float angle = i * 2 * PI / SLICES;
 		glVertex2f(
 			angle * (float) sin(angle),
 			angle * (float) cos(angle));
Use integers instead of floats in for-loop

While this adds a few more lines to the program, I think it makes it
more explicit where the constants come from. It also faciliates
easier modification of the example.

It's also safer to use an integer instead of a float as a conditional
in a for-loop. This is because floating point values are imprecise.
As a result, you may end up with one more or one fewer iteration than
you anticipated. Integers don't have this disadvantage.
