picture

picture - #include "graphlib.h" #include...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: #include "graphlib.h" #include <iostream> #include <string> #include <cctype> #include <cmath> using namespace std; void plotHorizontalLine(int r, int c, int length, char ch) { setChar(r, c, ch); int n; for (n=0; n < length; n++) { setChar (r, c+n, ch); } } void plotVerticalLine(int r, int c, int length, char ch) { setChar(r, c, ch); int n; for (n=0; n < length; n++) { setChar(r+n, c, ch); } } void plotRectangle(int r, int c, int height, int width, char ch) { int n=0; int m=0; int o=0; int p=0; if (height >= 0 && width >=0) { for (n=0; n < height; n++) //left part setChar(r+n, c, ch); for (m=0; m < height; m++) //right part setChar(r+m, c+width-1, ch); for (o=0; (o+1) < width; o++) // top part setChar(r, c+o, ch); for (p=0; (p+1) < width; p++) setChar(r+height-1, c+p, ch); // bottom part } } void plotText(int r, int c, string text) { int m; for (m=0; m < text.size(); m++) { setChar(r, c+m, text[m]); } } void plotCircle(int r, int c, int diameter, char ch) { if(diameter >0) { double k = diameter % 2; if( k == 0) diameter = diameter +1; else diameter = diameter; const double pi = 4*atan(1.0); double angle; //a for angle double i; //used 0.01 because any smaller would not really have an effect for (i=0; i < 2; i=i+0.01) { angle = pi* i; double f = (cos(angle) * diameter /2.0); double j = (sin(angle) * diameter/2.0); int q = f; int w = j; if(c+q <= 30) if(r+w <= 20) setChar(r+q, c+w, ch); } } } void clearPicture() { int n; int m; for (n=1; n<=20; n++) for (m=1; m<=30; m++) setChar(n, m, ' '); } void invertRectangle(int r, int c, int height, int width, char ch) { int n=0; int m=0; if (height >= 0 && width >=0) { while (n<height) { for (m=0; m<width; m++) { int tempRow=0; // set to zero so in case there is no ch in the original box, it won't plot anything int tempCol=0; if(getChar(r+n, c+m) == ch) { // store the first half so we still know where it is after it's replaced tempRow = r+n; tempCol = c+m; } if(getChar(r+n, c+m) == ' ') { setChar(r+n, c+m, ch); //now all the spaces are d's now you have to change the original d's to spaces } if (tempRow != 0) setChar(tempRow, tempCol, ' '); } n++; } } } void flipHorizontal(int r, int c, int height, int width) { int m =0; // take the value at c+width-1 and switch it into...
View Full Document

This note was uploaded on 11/10/2011 for the course CS 31 taught by Professor Melkanoff during the Spring '00 term at UCLA.

Page1 / 9

picture - #include "graphlib.h" #include...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online