void draw_I(int x, int y, int height) { int width=height/2; gfx_line(x,y,x+width,y); gfx_line(x,y+height,x+width,y+height); gfx_line(x+width/2,y,x+width/2,y+height); }
void draw_five(int x, int y, int h) { gfx_line(x + h/4, y - h/2, x - h/4, y - h/2); gfx_line(x - h/4, y - h/2, x - h/4, y); gfx_line(x - h/4, y, x, y); draw_circ(x, y+h/4, h/4, h/4, -(M_PI), (M_PI)/2); }
void draw_eight( int x, int y, int height, int width) { gfx_line( x, y, x+width, y) ; gfx_line( x, y, x, y+height) ; gfx_line( x+width, y, x+width, y+height) ; gfx_line( x, y+height/2, x+width, y+height/2) ; gfx_line(x, y+height, x+width, y+height) ; }
void draw_F(int x, int y, int height) { int width=height/2; gfx_line(x,y,x,y+height); gfx_line(x,y,x+width,y); gfx_line(x,y+height/3,x+width,y+height/3); }
void draw_H(int x, int y, int height) { int width=height/2; gfx_line(x,y,x,y+height); gfx_line(x,y+height/2,x+width,y+height/2); gfx_line(x+width,y,x+width,y+height); }
int main() { int xsize = 500; int ysize = 300; char c; // Open a new window for drawing. gfx_open(xsize, ysize, "Example Graphics Program"); // Clear the background. gfx_clear(); // Set the current drawing color gfx_color(0,200,100); // Draw a triangle on the screen. gfx_line(100,100,200,100); gfx_line(200,100,150,150); gfx_line(150,150,100,100); // change color, and draw a circle gfx_color(200,100,50); gfx_circle(300,150,40); while(1) { // Wait for the user to press a character. c = gfx_wait(); // Quit if it is the letter q. if(c=='q') break; } return 0; }
void yAxis(int x, int y) { int i; gfx_line(x / 2, 0, x / 2, y); for(i = 1; i <= 21; i++) { gfx_line((x / 2) - 10, i * (y / 22.), (x / 2) + 10, i * (y / 22.)); gfx_text((x / 2) - 15, (22 - i) * (y / 22.), num2str(i - 11)); } }
void xAxis(int x, int y) { int i; gfx_line(0, y / 2, x, y / 2); for(i = 1; i <=21; i++) { gfx_line(i * (x / 22.), (y / 2) - 10, i * (x / 22.), (y / 2) + 10); gfx_text(i * (x / 22.), (y / 2) + 15, num2str(i - 11)); } }
void draw_button(int x, int y,int height,int width) { //draws a button gfx_line(x,y,x,y+height); gfx_line(x,y+height,x+width,y+height); gfx_line(x+width,y+height,x+width,y); gfx_line(x+width,y,x,y); }
void draw_width(float width, float x,float y,float nx,float ny){ //draws thicker lines int M; float F; float plusang=M_PI/2; float angle=atan((ny-y)/(x-nx)); for(F=0;F<width;F+=.2){ gfx_line(x+F*cos(angle+plusang),y-F*sin(angle+plusang),nx+F*cos(angle+plusang),ny-F*sin(angle+plusang)); gfx_line(x-F*cos(angle+plusang),y+F*sin(angle+plusang),nx-F*cos(angle+plusang),ny+F*sin(angle+plusang)); } }
void yAxis(){ int i,j; gfx_color(0,0,255); gfx_line(250,0,250,500); for(i=0,j=-10;i<=500,j<=10;i+=25,j++){ gfx_line(240,i,260,i); gfx_color(255,255,255); gfx_text(225,i, num2str(j)); } }
void xAxis(){ int i,j; gfx_color(0,0,255); gfx_line(0,250,500,250); for(i=0,j=-10;i <= 500,j<=10; i+=25,j++){ gfx_line(i,240,i,260); gfx_color(255,255,255); gfx_text(i,275, num2str(j)); } }
/** * Draw the perimeter of an hollow rectangle. * * \note The bottom-right corner of the rectangle is drawn at (x2-1;y2-1). * \note This function does \b not update the current pen position. */ void gfx_rectDraw(Bitmap *bm, coord_t x1, coord_t y1, coord_t x2, coord_t y2) { /* Sort coords (needed for correct bottom-right semantics) */ if (x1 > x2) SWAP(x1, x2); if (y1 > y2) SWAP(y1, y2); /* Draw rectangle */ gfx_line(bm, x1, y1, x2-1, y1); gfx_line(bm, x2-1, y1, x2-1, y2-1); gfx_line(bm, x2-1, y2-1, x1, y2-1); gfx_line(bm, x1, y2-1, x1, y1); }
void drawRocket(float xc, float yc, float rotatet, int r) { int i, j; // Draw Box gfx_color(255,255,255); for(i=1;i<=7;i+=2){ gfx_line(xc+r*cos(rotatet+(i*pi)/4), yc+r*sin(rotatet+(i*pi)/4), xc+r*cos(rotatet+((i+2)*pi)/4), yc+r*sin(rotatet+((i+2)*pi)/4)); } // Draw Triangle for(j=-1;j<=1;j+=2){ gfx_line(xc+r*cos(rotatet+(j*pi)/4), yc+r*sin(rotatet+(j*pi)/4), xc+1.6*r*cos(rotatet), yc+1.6*r*sin(rotatet)); } }
void drawship(double x, double y, double theta, int go) { int i; gfx_line(x, y, x+20*cos(theta+4*PI/3), y-20*sin(theta+4*PI/3)); //draws long 2 lines that make up ship gfx_line(x, y, x+20*cos(theta+5*PI/3), y-20*sin(theta+5*PI/3)); gfx_line( x+16*cos(theta+4*PI/3), y-16*sin(theta+4*PI/3), x-16*cos(theta+5*10*PI/3), y-16*sin(theta+5*PI/3)); //draws back of ship if(go>0){ //go will be greater than 1 if ship is being propulsed forward gfx_color(255, 69, 0); for(i=0; i<5; i++){ gfx_line( x+(17+i)*cos(theta+4*PI/3), y-(17+i)*sin(theta+4*PI/3), x-(17+i)*cos(theta+5*10*PI/3), y-(17+i)*sin(theta+5*PI/3)); } } gfx_color(255, 255, 255); }
void shrinkSquares(int xcenter,int ycenter, int half){//half is length of half a side if(half<=1) return; //check for base case int x1=xcenter-half,x2=xcenter+half,y1=ycenter-half,y2=ycenter+half; //draws squares gfx_line(xcenter-half,ycenter+half,xcenter-half,ycenter-half);//left side gfx_line(xcenter+half,ycenter+half,xcenter+half,ycenter-half);//right side gfx_line(xcenter-half,ycenter+half,xcenter+half,ycenter+half);//top side gfx_line(xcenter-half,ycenter-half,xcenter+half,ycenter-half);//bottom side int newHalf=half/2; //recursive steps (one for each corner) shrinkSquares(x1,y1,newHalf);//top left shrinkSquares(x2,y1,newHalf);//top right shrinkSquares(x1,y2,newHalf);//botttom left shrinkSquares(x2,y2,newHalf);//bottom right }
void draw_B(int x, int y, int height) { int width=height/2; gfx_line(x,y,x+width,y); gfx_line(x,y,x,y+height); gfx_line(x+width,y,x+width*1.2,y+3); gfx_line(x,y+height/2,x+width,y+height/2); gfx_line(x+width,y+height/2,x+width*1.2,y+height/2-3); gfx_line(x+width*1.2,y+height/2-3,x+width*1.2,y+3); gfx_line(x,y+height,x+width,y+height); gfx_line(x+width,y+height,x+width*1.2,y+height-3); gfx_line(x+width,y+height/2,x+width*1.2,y+height/2+3); gfx_line(x+width*1.2,y+height-3,x+width*1.2,y+height/2+3); }
void tree(int x1,int y1,int x2,int y2,double angle,int length){ //angle is angle from vertical y axis if(length<=0) return; //check for base case int i,xnew[2],ynew[2]; //drawing case, two lines double newAngle[2]={angle+M_PI/6,angle-M_PI/6}; int newLength=length*2/3; gfx_line(x1,y1,x2,y2);//base line for(i=0;i<2;i++){ xnew[i]=x2-sin(newAngle[i])*length; ynew[i]=y2-cos(newAngle[i])*length; gfx_line(x2,y2,xnew[i],ynew[i]); tree(x2,y2,xnew[i],ynew[i],newAngle[i],newLength);//recursive case } }
void draw_axes(int x, int y) { gfx_line(0, y/2, x, y/2) ; //draws x axis gfx_line(x/2, 0, x/2, y) ; //draws y axis int xcounter = 0, ycounter = 0 ; //draw tick marks on x axis for (xcounter ; xcounter <= x ; xcounter+= x/20) { draw_vtick(xcounter, y/2, 10) ; } //draw tick marks on y axis for (ycounter; ycounter <= y ; ycounter+= y/20) { draw_htick(x/2, ycounter, 10) ; } //draw numeric labels int h = x/100 , w = x/100 ; //height and width of numbers int n ; //numbers on +x axis for (n = 1; n< 10; n++) { draw_numeral(x*(10+n)/20 - w/2 , y/2 + 10, n, h, w) ; } draw_ten(x - 2*w, y/2+10, h, w) ; //numbers on +y axis for (n = 1; n < 10; n++) { draw_numeral(x/2+10, y*n/20 - h/2, 10-n , h, w) ; } draw_ten(x/2+10, 0, h, w) ; //numbers on -x axis for ( n = 1; n < 10 ; n++) { draw_numeral(x*n/20, y/2+10, 10-n, h, w) ; } draw_ten(w, y/2+10, h, w) ; for (n = 1 ; n<10 ; n++) { draw_htick(x*n/20 - 5, y/2+15, w/2) ; } draw_htick(w-2, y/2+15, w/2) ; //numbers on -y axis for (n = 1; n < 10 ; n++) { draw_numeral(x/2+10, y*(10+n)/20 - h/2, n, h, w) ; } draw_ten(x/2+20, y - 1.5*h, h, w) ; for (n = 1 ; n<10 ; n++) { draw_htick(x/2+15, y*(10+n)/20, w/2) ; } draw_htick(x/2+15, y-h, w/2) ; }
void draw_circ(int x, int y, int rx, int ry, float startRad, float endRad) { float i, di=.01; for (i=startRad; i<=endRad; i+=di) { gfx_line(x + rx*cos(i), y + ry*-sin(i), x + rx*cos(i+di), y + ry*-sin(i+di)); } }
void spiralSquares(int x,int y,double angle,int length){ if(length/5<=0) return; //check for base case //length/5 in the above is the length of half a square's side int xcenter=x+length*cos(angle); //drawing case (1 square per case) int ycenter=y-length*sin(angle); int half=length/5; //this draws a square (copied from shrinkSquares) int x1=xcenter-half,x2=xcenter+half,y1=ycenter-half,y2=ycenter+half; gfx_line(xcenter-half,ycenter+half,xcenter-half,ycenter-half);//left side gfx_line(xcenter+half,ycenter+half,xcenter+half,ycenter-half);//right side gfx_line(xcenter-half,ycenter+half,xcenter+half,ycenter+half);//top side gfx_line(xcenter-half,ycenter-half,xcenter+half,ycenter-half);//bottom side double newAngle=angle-M_PI/5; int newLength=length*9/10; spiralSquares(x,y,newAngle,newLength); //recursive step }
void plot(int x, int y, int n) { int originX = x / 2; int originY = y / 2; float i; double yValue, yValue2; for(i = -10; i <= 10; i = i + .05) { yValue = -1 * taylor(n, i); yValue2 = -1 * taylor(n, i + .05); gfx_line(originX + i * (x / 22.), originY + yValue * (y / 22.), originX + (i + .05) * (x / 22.), originY + yValue2 * (y / 22.)); } }
int main() { int ysize = 300; int xsize = 300; char c; // Open a new window for drawing. gfx_open(xsize,ysize,"Example Graphics Program"); // Set the current drawing color to green. gfx_color(0,200,100); // Draw a triangle on the screen. gfx_line(100,100,200,100); gfx_line(200,100,150,150); gfx_line(150,150,100,100); while(1) { // Wait for the user to press a character. c = gfx_wait(); if(c=='n') gfx_line(200,200,300,200); gfx_line(300,200,250,250); gfx_line(250,250,200,200); // Quit if it is the letter q. if(c=='q') break; } return 0; }
void drawPerson(){ //make body - half circle gfx_color(204, 0, 102); gfx_circle(250, 550, 100); usleep(500); //make head gfx_color(255, 255, 0); gfx_circle(250, 400, 50); usleep(500); //make face gfx_point(225, 400); //eye usleep(500); gfx_point(275, 400); //eye usleep(500); //make arms gfx_line(200, 460, 150, 370); gfx_line(300, 460, 350, 370); usleep(500); }
void snowflake(int xcenter, int ycenter, int length){ if(length<1) return; //check for base case float angle=2*M_PI/5; //drawing step int i,xnew[5],ynew[5]; for(i=1;i<=5;i++){ xnew[i-1]=xcenter+length*cos(i*angle+3*M_PI/2); ynew[i-1]=ycenter+length*sin(i*angle+3*M_PI/2); gfx_line(xcenter,ycenter,xnew[i-1],ynew[i-1]); } int newLength=length*.38; //recursive step for(i=0;i<5;i++) snowflake(xnew[i],ynew[i],newLength); }
void draw_D(int x, int y, int height) { int width=height/2; gfx_line(x,y,x,y+height); gfx_line(x,y,x+width/1.2,y); gfx_line(x+width/1.2,y,x+width,y+5); gfx_line(x,y+height,x+width/1.2,y+height); gfx_line(x+width/1.2,y+height,x+width,y+height-5); gfx_line(x+width,y+height-5,x+width,y+5); }
void fern(int x1,int y1,int length,double angle){ if(length<=1) return; //base case int x2[4],y2[4],i; double newAngle=M_PI/6; int newLength=length/3; for(i=1;i<=4;i++){ x2[i-1]=x1-length*sin(angle)*i/4; //tabulates points for next fern branch y2[i-1]=y1-length*cos(angle)*i/4; } gfx_line(x1,y1,x2[3],y2[3]); //draws next fern branch for(i=0;i<4;i++){ //recursive step (8 total steps in 4 loops) fern(x2[i],y2[i],newLength,angle+newAngle); fern(x2[i],y2[i],newLength,angle-newAngle); } }
void drawPoly(int sides, int xpos, int ypos){ //Initialize variables for function float i = 0; float angle = (M_PI*2)/sides; float r = 20; float x1; float x2; float y1; float y2; for(i=0;i<2*M_PI;i+=angle){ x1 = r * cos(i) + xpos; y1 = r * -sin(i) + ypos; x2 = r * cos(i+angle) + xpos; y2 = r * -sin(i+angle) + ypos; gfx_line(x1,y1,x2,y2); } }
void plot_triangle(int xsize, int ysize, float xl, float xu, float dx) { double x = xl, y1, y2 ; int xpos = 0 ; //original position in terms of coordinates of pixels int ypos1, ypos2; //positions of y in terms of coordinates of pixels while (x < xu ) { y1 = triangle_waveform(1.0/5, 3*.8 , x) + triangle_waveform(2.0/5, 3*.2, x) ; x+= dx ; y2 = triangle_waveform(1.0/5, 3*.8, x) + triangle_waveform(2.0/5, 3*.2, x) ; xpos = xpos + dx*xsize/(xu-xl) ; ypos1 = ysize/2 - (y1*ysize/(xu-xl)) ; ypos2 = ysize/2 - (y2*ysize/(xu-xl)) ; if ((ypos1 <= ysize && ypos1 >= 0) || (ypos2 <= ysize && ypos2 >= 0) ) { gfx_line(xpos - dx*xsize/(xu-xl) , ypos1, xpos, ypos2) ; } } }
int main(){ char m; int x, y, r; float t, dt, ax, ay, bx, by; gfx_open(500, 400, "Symbol.c"); while(m != 'q') { m = gfx_wait(); switch(m){ case 'c': x = gfx_xpos(); y = gfx_ypos(); gfx_color(255, 255, 255); gfx_circle(x, y, 20); gfx_flush; break; case 't': x = gfx_xpos(); y = gfx_ypos(); gfx_color(0, 255, 0); r = 20; t = 0; for(dt = 0; dt <= 2*M_PI+1; dt += (2*M_PI)/3){ ax = x + r*cos(t); ay = y + r*sin(t); bx = x + r*cos(dt); by = y + r*sin(dt); gfx_line(ax, ay, bx, by); t = dt; } break; case 1: x = gfx_xpos(); y = gfx_ypos(); gfx_color(0, 0, 200); r = 20; t = 0; for(dt = 0; dt <= 2*M_PI+1; dt += (2*M_PI)/4){ ax = x + r*cos(t); ay = y + r*sin(t); bx = x + r*cos(dt); by = y + r*sin(dt); gfx_line(ax, ay, bx, by); t = dt; } break; case '3': x = gfx_xpos(); y = gfx_ypos(); gfx_color(200, 0, 200); r = 20; t = 0; for(dt = 0; dt <= 2*M_PI+1; dt += (2*M_PI)/3){ ax = x + r*cos(t); ay = y + r*sin(t); bx = x + r*cos(dt); by = y + r*sin(dt); gfx_line(ax, ay, bx, by); t = dt; } break; case '4': x = gfx_xpos(); y = gfx_ypos(); gfx_color(255, 0, 255); r = 20; t = 0; for(dt = 0; dt <= 2*M_PI+1; dt += (2*M_PI)/4){ ax = x + r*cos(t); ay = y + r*sin(t); bx = x + r*cos(dt); by = y + r*sin(dt); gfx_line(ax, ay, bx, by); t = dt; } break; case '5': x = gfx_xpos(); y = gfx_ypos(); gfx_color(255, 0, 255); r = 20; t = 0; for(dt = 0; dt <= 2*M_PI+1; dt += (2*M_PI)/5){ ax = x + r*cos(t); ay = y + r*sin(t); bx = x + r*cos(dt); by = y + r*sin(dt); gfx_line(ax, ay, bx, by); t = dt; } break; case '6': x = gfx_xpos(); y = gfx_ypos(); gfx_color(255, 0, 255); r = 20; t = 0; for(dt = 0; dt <= 2*M_PI+1; dt += (2*M_PI)/6){ ax = x + r*cos(t); ay = y + r*sin(t); bx = x + r*cos(dt); by = y + r*sin(dt); gfx_line(ax, ay, bx, by); t = dt; } break; case '7': x = gfx_xpos(); y = gfx_ypos(); gfx_color(255, 0, 255); r = 20; t = 0; for(dt = 0; dt <= 2*M_PI+1; dt += (2*M_PI)/7){ ax = x + r*cos(t); ay = y + r*sin(t); bx = x + r*cos(dt); by = y + r*sin(dt); gfx_line(ax, ay, bx, by); t = dt; } break; case '8': x = gfx_xpos(); y = gfx_ypos(); gfx_color(255, 0, 255); r = 20; t = 0; for(dt = 0; dt <= 2*M_PI+1; dt += (2*M_PI)/8){ ax = x + r*cos(t); ay = y + r*sin(t); bx = x + r*cos(dt); by = y + r*sin(dt); gfx_line(ax, ay, bx, by); t = dt; } break; case '9': x = gfx_xpos(); y = gfx_ypos(); gfx_color(255, 0, 255); r = 20; t = 0; for(dt = 0; dt <= 2*M_PI+1; dt += (2*M_PI)/9){ ax = x + r*cos(t); ay = y + r*sin(t); bx = x + r*cos(dt); by = y + r*sin(dt); gfx_line(ax, ay, bx, by); t = dt; } break; } } }