Demo Hoa 6 cánh quay trong Đồ họa C++
March 07, 2023
Bản Demo hoa 6 cánh xoay quanh tâm không cần dùng đến phép quay:
Bài Giải
Bài Giải
/*
Name: Hoa 6 canh xoay
Copyright: None
Author: Tran Anh
Description: https://gimi.vn
*/
#include<conio.h>
#include<stdio.h>
#include<iostream>
#include<graphics.h>
#include<math.h>
using namespace std;
struct Point
{
int x,y;
Point()
{
x=y=0;
}
Point(int u, int v)
{
x=u;
y=v;
}
};
Point Fixation(Point centre, int R, int i)
{
Point k;
k.x=centre.x+R*cos(i*M_PI/180);
k.y=centre.y+R*sin(i*M_PI/180);
return k;
}
void Draw(Point O, int R)
{
int color[6][6];
int i=0;
for(int t=10;t<=60;t=t+10)
{
int ti=0;
int xk=120-t,yk=240-t;
for(i=t;i<=360;i=i+60){
Point Q=Fixation(O,R,i);
setlinestyle(0,0,2);
ellipse(Q.x,Q.y,xk,yk,R,R);
(xk!=0)?xk=xk-60:xk=360-60;
(yk!=0)?yk=yk-60:yk=360-60;
color[ti][0]=(int)(Q.x+O.x)/2;
color[ti][1]=(int)(Q.y+O.y)/2;
ti++;
}
for (i=0;i<6;i++)
{
setfillstyle(1,GREEN);
putpixel(color[i][0],color[i][1],RED);
floodfill(color[i][0],color[i][1],15);
}
delay(300);
cleardevice();
}
}
main()
{
initwindow(800,600);
Point O(400,300);
int R=150;
while(1)
{
Draw(O,R);
}
getch();
return 0;
}
Name: Hoa 6 canh xoay
Copyright: None
Author: Tran Anh
Description: https://gimi.vn
*/
#include<conio.h>
#include<stdio.h>
#include<iostream>
#include<graphics.h>
#include<math.h>
using namespace std;
struct Point
{
int x,y;
Point()
{
x=y=0;
}
Point(int u, int v)
{
x=u;
y=v;
}
};
Point Fixation(Point centre, int R, int i)
{
Point k;
k.x=centre.x+R*cos(i*M_PI/180);
k.y=centre.y+R*sin(i*M_PI/180);
return k;
}
void Draw(Point O, int R)
{
int color[6][6];
int i=0;
for(int t=10;t<=60;t=t+10)
{
int ti=0;
int xk=120-t,yk=240-t;
for(i=t;i<=360;i=i+60){
Point Q=Fixation(O,R,i);
setlinestyle(0,0,2);
ellipse(Q.x,Q.y,xk,yk,R,R);
(xk!=0)?xk=xk-60:xk=360-60;
(yk!=0)?yk=yk-60:yk=360-60;
color[ti][0]=(int)(Q.x+O.x)/2;
color[ti][1]=(int)(Q.y+O.y)/2;
ti++;
}
for (i=0;i<6;i++)
{
setfillstyle(1,GREEN);
putpixel(color[i][0],color[i][1],RED);
floodfill(color[i][0],color[i][1],15);
}
delay(300);
cleardevice();
}
}
main()
{
initwindow(800,600);
Point O(400,300);
int R=150;
while(1)
{
Draw(O,R);
}
getch();
return 0;
}
Post a Comment