当前位置:网站首页>[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 .
边栏推荐
- Prompt to leave the page
- The latest JD SMS login + silly girl robot nanny level deployment tutorial (July 24, 2022)
- 猜拳小程序 基于Object-C 新手上路
- CF 1333C Eugene and an array
- 光光光仔的CSDN之旅
- 数字集成电路:CMOS反相器(一)静态特性
- HCIP-第二天
- Explain exi interrupt through the counting experiment of infrared sensor
- Codeforces Round #810 (Div. 2), problem: (B) Party
- 识时务者常用网址大全
猜你喜欢

Interesting C language

Lora communication application development

Record the star user of handsomeblog

Hcip first day static routing comprehensive experiment

(前缀和/思维)Codeforces Round #806 (Div. 4)F. Yet Another Problem About Pairs Satisfying an Inequality

(题意+详细思路+加注释代码) Codeforces Round #805 (Div. 3)F. Equate Multisets

在有序数组找具体某个数字

C language -- while statement, dowhile statement, for loop and loop structure, break statement and continue statement

数字集成电路:MOS管器件章(一)

动态路由配置
随机推荐
全连MGRE与星型拓扑MGRE
Plato Farm有望通过Elephant Swap,进一步向外拓展生态
Lecture 4 - explain GPIO_ Write function and related routines
怎么判断一个数是奇数还是偶数?
Timer interrupt experiment
HCIP oSPF知识总结
Lora通信应用开发
记录第N次SQL异常
Detailed source code of golang bufio reader
【封神演绎、十五分钟让你彻底学会栈的使用!!!】
HCIP-第二天
Record the nth SQL exception
Golang implements TCP chat room
【C语言】阶乘实现
Explain exi interrupt through the counting experiment of infrared sensor
Nb-iot access to cloud platform
TCP的三次握手、四次断开
MGRE、PPP、HDLC综合实验
猜拳小程序 基于Object-C 新手上路
C语言的常数知识讲解