当前位置:网站首页>[draw sherpinski triangle in C language]
[draw sherpinski triangle in C language]
2022-07-27 02:27:00 【Breezy morning】
Shelpensky triangle
The serpinsky triangle is shown below :
One 、 The code is as follows
#include <graphics.h>
#include
// Custom function , Draw the shelpinski triangle , Parameter is 3 Vertex coordinates
void sb(float x1, float y1, float x2, float y2, float x3, float y3)
{
if (abs(x1 - x2) + abs(x2 - x3) + abs(x3 - x1) + abs(y1 - y2) + abs(y2 - y3) +
abs(y3 - y1) < 20)
{
moveto(x1, y1);
lineto(x2, y2); // Draw triangle
lineto(x3, y3);
lineto(x1, y1);
}
else// Otherwise draw 3 A small serpinsky triangle
{
sb(x1, y1, (x1 + x2) / 2, (y1 + y2) / 2, (x1 + x3) / 2, (y1 + y3) / 2);
sb((x1 + x2) / 2, (y1 + y2) / 2, x2, y2, (x2 + x3) / 2, (y2 + y3) / 2);
sb((x1 + x3) / 2, (y1 + y3) / 2, (x2 + x3) / 2, (y2 + y3) / 2, x3, y3);
}
}
int main()
{
initgraph(1000, 750);
setbkcolor(WHITE);
setcolor(BLACK);
sb(500, 100, 150, 700, 900, 600); // Call custom functions , Draw a scherpinsky triangle
getch();
closegraph();
return 0;
}
summary
This code uses a recursive algorithm , Recursive algorithm for complex graphics , It can be drawn with very little code .
边栏推荐
- On the first day of staying in the blog [for 80000]!
- Codeforces Round #796 (Div. 2), problem: (1688C) Manipulating History
- (CF1691D) Max GEQ Sum
- (题意+详细思路+加注释代码) Codeforces Round #805 (Div. 3)F. Equate Multisets
- Hcip bidirectional republication and routing strategy
- 数字芯片的面积优化:第三届“华为杯”研究生创芯大赛数字方向上机题1详解
- JVM interview questions (necessary for interview)
- Prometheus 运维工具 Promtool (三) Debug 功能
- (prefix and / thinking) codeforces round 806 (Div. 4) F Yet Another Problem About Pairs Satisfying an Inequality
- NB-IOT接入云平台
猜你喜欢

The latest JD SMS login + silly girl robot nanny level deployment tutorial (July 24, 2022)

C language -- nesting of relational and logical operators, if statements, switch statements, and branch structures

Codeforces Round #807 (Div. 2), problem: (C) Mark and His Unfinished Essay

Nb-iot networking communication

C language - first program, print, variables and constants

Esp8266wi fi access cloud platform

三个整数从大到小排序(详细介绍多种方法)

OSPF basic experimental configuration

C语言——二维数组、指针

C language - value range of data type and basic data type
随机推荐
Lecture 3 - GPIO input / output library function usage and related routines
HCIP-第五天-OSPF扩展配置实验
Find a specific number in an ordered array
What is the principle of synchronized lock escalation in multithreading?
RS-485总线通信应用
睡不着时闭眼躺着,到底有没有用?
Hcip bidirectional republication and routing strategy
HCIP oSPF知识总结
(title + detailed idea + annotated code) codeforces round 805 (Div. 3) F Equate Multisets
CF 1333C Eugene and an array
HandsomeForum学习论坛
Writing a pacesetter frequently -- yunxiaojing
Ogeek meetup phase I, together with cubefs, is hot
JUC concurrent programming
HCIP-第二天
通过ensp让静态路由实现全网可达
多点双向重发布和路由策略-拓扑实验
(prefix and / thinking) codeforces round 806 (Div. 4) F Yet Another Problem About Pairs Satisfying an Inequality
【C语言程序设计】分支结构
Plato Farm有望通过Elephant Swap,进一步向外拓展生态