CSCI 250 Getting Started

String Art Program

 

Purpose:  To become familiar with doing graphics on a PC so we can do the other assignments without problems.  Completion of this project ensures that for later projects any problems will be with your code instead of with the compiler or operating system.

 

You are to write a program that creates string art.  You are going to generate a polygon with n sides, where n is specified by the user, and in addition, lines from the center of the polygon to each vertex.  You should then subdivide each line into an equal number of parts k, also specified by the user, as shown below for two of the lines.  In this example, both n and k are 5.

 

 

Connect the points numbered 1, the points numbered 2, etc. for each line from the center to the two sides that it connects to.

 

TurnIn:  You should turn in your code as a .cpp, and an image file as a pdf, on blackboard.

 

Extras:  Have fun and get creative…use color, or animation to make the output more interesting and dynamic.  Experiment with the GLUT menu system.  Add more interesting shapes than a single polygon.  Enjoy!

 

For those of you who’d like an example output, here is the output from a minimal implementation, with 6 sides and 10 divisions per line:

 

 

And here is some sample GLUT code that draws a simple figure: sample code.

 

And here is a more interesting example with 8 sides and 30 divisions per line:

 

 

You can get GLUT from here.  You should put the glut.h, glut.lib, and glut.dll in the same directory as your source code to get started.  If you want to put them in more permanent places, follow the instructions here:

 

From stackoverflow:

For Microsoft Visual Studio 2019 GLUT installation -

1.     Download the header, dll's and lib files from glutdlls37beta (linked in here)

2.     Paste glut.h in C:\Program Files (x86)\Microsoft Visual Studio\2019\{Community|Preview,eg}\VC\Tools\MSVC\{14.28.29304}\include\GL Create the GL folder if not present already. The {thing} may differ.

3.     Paste glut.lib in C:\Program Files (x86)\Microsoft Visual Studio\2019\ {Community|Preview,eg}\VC\Tools\MSVC\{14.28.29304}\lib\x64. Paste glut32.lib in C:\Program Files (x86)\Microsoft Visual Studio\2019\{Community|Preview,eg}\VC\Tools\MSVC\{14.28.29304}\lib\x86. The {thing} may differ.

4.     Paste glut32.dll in C:\Windows\System32. Paste glut.dll and glut32.dll in C:\Windows\SysWOW64.

5.     Go to Project -> Properties(All Configuration option)->Linker -> Input -> Additional Dependencies->edit(down arrow on the right end) Type-> opengl32.lib glu32.lib glut32.lib Hit Ok->apply.

 

And here is some code to start you off with:

 

// string art program

// Author: Don Allison

// Date: 3/9/2021

 

#include <GL/glut.h>

#include <iostream>

#include <iomanip>

using namespace std;

 

 

// Clears the current window and draws a triangle.

void display() {

 

    double i;

 

    // Set every pixel in the frame buffer to the current clear color.

    glClear(GL_COLOR_BUFFER_BIT);

 

    // Drawing is done by specifying a sequence of vertices.  The way these

    // vertices are connected (or not connected) depends on the argument to

    // glBegin.  GL_POLYGON constructs a filled polygon.0.1)

 

    glBegin(GL_LINES);

    for (i = 0; i <= 1; i = i + 0.05)

    {

        glColor3f(0, 1, 0); glVertex3f(i, 0, 0.5);          // green

        glColor3f(0, 0, 1); glVertex3f(0,1-i, 0.5);         // blue

        // flip to third quadrant

        glColor3f(0, 0, 1); glVertex3f(-i, 0, 0.5);         // blue

        glColor3f(1, 0, 0); glVertex3f(0, i-1, 0.5);        // red

 

    }

  glEnd();

 

    // Flush drawing command buffer to make drawing happen as soon as possible.

    glFlush();

}

 

 

 

int main(int argc, char** argv) {

 

    // Use a single buffered window in RGB mode (as opposed to a double-buffered

    // window or color-index mode).

    glutInit(&argc, argv);

    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);

 

    // Position window at (80,80)-(480,380) and give it a title.

    glutInitWindowPosition(80, 80);

    glutInitWindowSize(400, 300);

    glutCreateWindow("A Simple Triangle");

 

    // Tell GLUT that whenever the main window needs to be repainted that it

    // should call the function display().

    glutDisplayFunc(display);

 

    // Tell GLUT to start reading and processing events.  This function

    // never returns; the program only exits when the user closes the main

    // window or kills the process.

    glutMainLoop();

}