{
public :
draw(){}
void run()
{
Drawing(10,40,0,3.1415926535897932384626433832795/4,200,200,d);
}
void Drawing
(int n,
double d,
double q1,
double q2,
int x,
int y,
QPainter *dr
) {
if (n > 0)
{
int x1 = x - (sin(q1) * d);
int y1 = y - (cos(q1) * d);
dr->drawLine(x, y, x1, y1);
t->repaint();
int x2 = x1- (cos(q1) * d);
int y2 = y1 + (sin(q1) * d);
dr->drawLine(x1, y1, x2, y2);
t->repaint();
int x3 = x2 + (sin(q1) * d);
int y3 = y2 + (cos(q1) * d);
dr->drawLine(x2 , y2 , x3 , y3);
t->repaint();
dr->drawLine(x3 , y3 , x , y );
t->repaint();
double d1 = d / sqrt( 2.0 ); //d1 = d/?2
int x4 = x1 - ( cos(q2) * d1);
int y4 = y1 - ( sin(q2) * d1);
Drawing(n - 1, d1, q1 - 3.1415926535897932384626433832795/4, q2 + 3.1415926535897932384626433832795/4 , x1 , y1,dr);
Drawing(n - 1, d1, q1 + 3.1415926535897932384626433832795/4, q2 - 3.1415926535897932384626433832795/4 , x4 , y4,dr);
}
}
};
void MainWindow::on_pushButton_clicked()
{
image
=new QPixmap(this
->geometry
().
width(),this
->geometry
().
height());
image->fill(this,0,0);
r=this->geometry();
draw d;
d.d=dr;
d.t=this;
d.run();
delete dr;
}
{
p.drawPixmap(r,*this->image);
}
class draw:public QThread
{
public :
QPainter *d;
QWidget *t;
draw(){}
void run()
{
Drawing(10,40,0,3.1415926535897932384626433832795/4,200,200,d);
}
void Drawing(int n,double d,double q1,double q2,int x,int y,QPainter *dr)
{
if (n > 0)
{
int x1 = x - (sin(q1) * d);
int y1 = y - (cos(q1) * d);
dr->drawLine(x, y, x1, y1);
t->repaint();
int x2 = x1- (cos(q1) * d);
int y2 = y1 + (sin(q1) * d);
dr->drawLine(x1, y1, x2, y2);
t->repaint();
int x3 = x2 + (sin(q1) * d);
int y3 = y2 + (cos(q1) * d);
dr->drawLine(x2 , y2 , x3 , y3);
t->repaint();
dr->drawLine(x3 , y3 , x , y );
t->repaint();
double d1 = d / sqrt( 2.0 ); //d1 = d/?2
int x4 = x1 - ( cos(q2) * d1);
int y4 = y1 - ( sin(q2) * d1);
Drawing(n - 1, d1, q1 - 3.1415926535897932384626433832795/4, q2 + 3.1415926535897932384626433832795/4 , x1 , y1,dr);
Drawing(n - 1, d1, q1 + 3.1415926535897932384626433832795/4, q2 - 3.1415926535897932384626433832795/4 , x4 , y4,dr);
}
}
};
void MainWindow::on_pushButton_clicked()
{
image=new QPixmap(this->geometry().width(),this->geometry().height());
image->fill(this,0,0);
dr=new QPainter(this->image);
r=this->geometry();
draw d;
d.d=dr;
d.t=this;
d.run();
delete dr;
}
void MainWindow::paintEvent(QPaintEvent *e)
{
QPainter p(this);
p.drawPixmap(r,*this->image);
}
To copy to clipboard, switch view to plain text mode
Bookmarks