#include "CarnegieMellonGraphics.h" #include #include #include const double pi = 3.1415926; using namespace std; int main() { int i = 0; int x = 150; int y = 150; int w = 300; int h = 400; //int flip = 0; Style THICK_GREEN = Style(Color::GREEN, 3); Window test(640,480,"hi"); const char *scslogo = "scslogo.png"; const char *scs = "scs.jpg"; Image img(scslogo,Image::PNG); Image img2(scs,Image::JPEG); Image small = img2.subImage(0,0,100,200); test.disableAutoPageFlip(); test.autoFlushKeyboardQueue(false); test.autoFlushMouseQueue(false); test.autoFlushTimerQueue(false); Font myfont(Font::ROMAN,14); /*cout << "Graphics Test" << endl << "Press escape while the graphics window is active to stop the animation" << endl << "Move this window and hit enter to continue" << endl; cin.ignore();*/ Style linestyle(Color::GREEN,3); while(true) { /*if (flip > 20) { test.hide(); flip = -20; } else if (flip == 0) test.show(); flip++;*/ w = test.getWidth(); h = test.getHeight(); if(test.isKeyDown(NamedKey::ESCAPE)) break; if(test.isKeyDown('a')) cout << "a down" << endl; x = test.getMouseX(); y = test.getMouseY(); int minh=_cpp_min(h/4,y/3); int minw=_cpp_min(w/3,y/3); int wmid=w/2; int hmid=h/2; /*test.drawLine(Style::BLACK, 150 + 100*cos((double)(i-1)/(8 * pi)), 150 + mini*sin((double)(i-1)/(8 * pi)), 150 + mini*cos(pi + (double)(i-1)/(8 * pi)), 150 + 100*sin(pi + (double)(i-1)/(8 * pi)) );*/ test.drawTriangleFilled(Style::RED, x, y, 5*w/6, 5*h/8, w/6, 5*h/8); test.drawLine(linestyle, wmid + minw*cos((double)i/(8 * pi)), hmid - (h/8) + minh*sin((double)i/(8 * pi)), wmid + minw*cos(pi + (double)i/(8 * pi)), hmid - (h/8) + minh*sin(pi + (double)i/(8 * pi)) ); i++; test.drawRectangleOutline(Style::WHITE, wmid - w/30, hmid - (h/8) - h/40, wmid + w/30, hmid - (h/8) + h/40); //test.drawImage(img2,x,y,Transform(-1,1)); //test.drawImage(small,x,y,Transform(i)); // linestyle = Style(test.readPixel(5,5),3); test.flipPage(); test.drawRectangleFilled(Style::BLACK, 0, 0, w, h); test.drawText(Style::GREEN,myfont,x,y,"test",Transform(i)); //cout << test.getWidth() << " " << test.getHeight() << endl; } while (test.isKeyDown(NamedKey::ESCAPE)); while(true) { if(test.isKeyDown(NamedKey::ESCAPE)) break; w = test.getWidth(); h = test.getHeight(); /***RAINBOW RECTANGLE***/ double w1=w-20; double h1=h-10; int xcurr, xprev=10; double r=255, g=0, b=0; double tag=6*255/w1; for( ; g<256; g+=tag) { xcurr=10+g/tag; if(xcurr != xprev+1) test.drawLine(Color((int)r,(int)g,(int)b), xprev+1, 10,xprev+1, (int)h1); test.drawLine(Color((int)r,(int)g,(int)b), xcurr, 10,xcurr, (int)h1); xprev=xcurr; } g=255; for( ; r>=0; r-=tag) { xcurr=10+(w1/3)-r/tag; if(xcurr != xprev+1) test.drawLine(Color((int)r,(int)g,(int)b), xprev+1, 10, xprev+1, (int)h1); test.drawLine(Color((int)r,(int)g,(int)b), xcurr, 10, xcurr, (int)h1); xprev=xcurr; } r=0; for( ; b<256; b+=tag) { xcurr=10+(w1/3)+b/tag; if(xcurr != xprev+1) test.drawLine(Color((int)r,(int)g,(int)b), xprev+1, 10, xprev+1, (int)h1); test.drawLine(Color((int)r,(int)g,(int)b), xcurr, 10, xcurr, (int)h1); xprev=xcurr; } b=255; for( ; g>=0; g-=tag) { xcurr=10+2*(w1/3)-g/tag; if(xcurr != xprev+1) test.drawLine(Color((int)r,(int)g,(int)b), xprev+1, 10, xprev+1, (int)h1); test.drawLine(Color((int)r,(int)g,(int)b), xcurr, 10, xcurr, (int)h1); xprev=xcurr; } g=0; for( ; r<256; r+=tag) { xcurr=10+2*(w1/3)+r/tag; if (xcurr != xprev+1) test.drawLine(Color((int)r,(int)g,(int)b), xprev+1, 10, xprev+1, (int)h1); test.drawLine(Color((int)r,(int)g,(int)b), xcurr, 10, xcurr, (int)h1); xprev=xcurr; } r=255; for( ; b>=0; b-=tag) { test.drawLine(Color((int)r,(int)g,(int)b), 10+w1-b/tag, 10, 10+w1-b/tag, (int)h1); } //end RAINBOW RECTANGLE test.flipPage(); test.drawRectangleFilled(Style::WHITE, 0, 0, w, h); } /* while(true) { if(!test.isKeyboardQueueEmpty()) { KeyboardEvent event = test.getKeyboardEvent(); if(KeyboardEvent(NamedKey::ESCAPE) == event) { break; } } }*/ //cin.ignore(); return 0; }