五角星和三角形

#include <iostream>
#include <cmath>
#include <conio.h>
#include <time.h>
#include <graphics.h>
using namespace std;
const double _sin=0.58778525229;
void san(double x,double y,double w){
    line(x,y,x+w,y);
    line(x,y,x+w/2,y+sqrt((w*w)-(w/2*w/2)));
    line(x+w,y,x+w/2,y+sqrt((w*w)-(w/2*w/2)));
}
void star(double x,double y,double w){
    line(x,y,x+w,y);
    line(x+w,y,x+(w-sqrt((w*w)-(_sin*w*_sin*w))),y+_sin*w);
    line(x,y,x+sqrt((w*w)-(_sin*w*_sin*w)),y+_sin*w);
    line(x+(w-sqrt((w*w)-(_sin*w*_sin*w))),y+_sin*w,
        x+w/2,
        y+_sin*w-(sqrt(w*w-pow(w/2-(w-sqrt((w*w)-(_sin*w*_sin*w))),2))));
    line(x+sqrt((w*w)-(_sin*w*_sin*w)),y+_sin*w,
        x+w/2,
        y+_sin*w-(sqrt(w*w-pow(w/2-(w-sqrt((w*w)-(_sin*w*_sin*w))),2))));
}
int main(int argc, char** argv) {
    initgraph(700,700);
    san(100.0,100.0,50.0);
    star(200.0,200.0,200.0);
    -getch();
    closegraph();
    return 0;
}

 

posted @ 2025-04-12 10:02  -刘-j-x-  阅读(10)  评论(0)    收藏  举报