当前位置:网站首页>【用C语言绘制直角坐标系】
【用C语言绘制直角坐标系】
2022-07-26 22:50:00 【清风清晨】
前言
直角坐标系如下图所示:
一、代码如下
#include <graphics.h>
#include
//定义全局变量,用于存储直角坐标系原点位置和坐标比例
int xk, yk, sk;
//自定义画线函数,参数为直角坐标系中的起止点坐标
void myLine(float x1, float y1, float x2, float y2);
//自定义文字输出函数,参数为直角坐标系中的坐标及文字
void myOutTextXY(float x, float y, const char s[]);
//自定义绘制坐标系函数,参数为直角坐标系原点在绘图坐标系中的位置及坐标比例
void myZB(int x, int y, int s);
int main()
{
initgraph(500, 500);
setbkcolor(WHITE);
setcolor(BLACK);
setfont(40, 0, “Times New Roman”);
myZB(150, 350, 50); //绘制坐标系
myLine(-1, -2, 5, 4); //绘制直线
myOutTextXY(4, 5, “y=x-1”); //标记直线
getch();
closegraph();
}
//自定义画线函数,参数为直角坐标系中的起止点坐标
void myLine(float x1, float y1, float x2, float y2)
{
line(xk + x1 * sk, yk - y1 * sk, xk + x2 * sk, yk - y2 * sk);
}
//自定义文字输出函数,参数为直角坐标系中的坐标及文字
void myOutTextXY(float x, float y, const char s[])
{
outtextxy(xk + x * sk, yk - y * sk, s);
}
//自定义绘制坐标系函数,参数为直角坐标系原点在绘图坐标系中的位置及坐标比例
void myZB(int x, int y, int s)
{
xk = x; //设置直角坐标系原点的位置
yk = y;
sk = s; //设置直角坐标系坐标比例
myOutTextXY(-0.6,0,“0”); //标记原点
myOutTextXY(6, 0, “x”); //标记x轴
myOutTextXY(-0.6, 6, “y”); //标记y轴
myLine(-2, 0, 6, 0); //绘制坐标轴
myLine(0, -2, 0, 6);
myLine(6, 0, 5.6, -0.1);
myLine(6, 0, 5.6, 0.1);
myLine(0, 6, -0.1, 5.6);
myLine(0, 6, 0.1, 5.6);
for (int i = -1; i < 6; i++)
{
myLine(i, 0, i, 0.4); //绘制刻度
myLine(0, i, 0.4, i);
}
}
总结
以上就是今天要讲的内容,用C语言配合EGE函数库画直角坐标系。
边栏推荐
- ESP8266Wi-Fi数据通讯
- HCIP oSPF知识总结
- 求解100~200之间的素数
- Golang implements TCP chat room
- Codeforces Round #807 (Div. 2), problem: (C) Mark and His Unfinished Essay
- The basic configuration of static routing (planning of IP address and configuration of static routing) realizes the accessibility of the whole network.
- Ogeek meetup phase I, together with cubefs, is hot
- NB-IOT接入云平台
- Lesson 5 - key control LED
- Hcip first day static routing comprehensive experiment
猜你喜欢
NPM reports an error, error: eperm: operation not permitted, MKDIR

RS-485总线通信应用

OSPF basic configuration application (comprehensive experiment: interference election default routing area summary authentication -- interface authentication)

C language - array, string handler, strlen, strcpy and strncpy, strcat and strncat, StrCmp and strncmp

C language - assignment operator, compound assignment operator, self increasing and self decreasing operator, comma operator, conditional operator, goto statement, comment

Esp8266wi fi data communication

【C语言】阶乘实现

求解100~200之间的素数

【自此文之后,学习链表一片坦途】

多线程中 synchronized 锁升级的原理是什么?
随机推荐
ESP8266Wi-Fi接入云平台
HCIP-第三天-广域网拓扑实验
MGRE、PPP、HDLC综合实验
C language -- nesting of relational and logical operators, if statements, switch statements, and branch structures
Wechat applet: user wechat login process (attached: flow chart + source code)
HCIP-第四天-OSPF路由协议
Tim output comparison - PWM
CF 1333C Eugene and an array
C language - array, string handler, strlen, strcpy and strncpy, strcat and strncat, StrCmp and strncmp
记录HandsomeBlog的star用户
光光光仔的CSDN之旅
Nb-iot networking communication
Hcip OSPF knowledge summary
Timer interrupt experiment
NAT network address conversion experiment
STM32 introductory tutorial lesson 2
Golang implements TCP chat room
NAT网络地址转化实验
C语言的常数知识讲解
C language -- while statement, dowhile statement, for loop and loop structure, break statement and continue statement