当前位置:网站首页>【用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函数库画直角坐标系。
边栏推荐
- 【C语言】strlen与sizeof相关区分
- 打开编程的大门
- Explain exi interrupt through the counting experiment of infrared sensor
- JVM面试题(面试必备)
- 数字集成电路:CMOS反相器(一)静态特性
- The latest C language introduction and advanced - the most complete and detailed C language tutorial in history!! Section 1 - overview of C language
- Codeforces Round #796 (Div. 2), problem: (1688C) Manipulating History
- (前缀和/思维)Codeforces Round #806 (Div. 4)F. Yet Another Problem About Pairs Satisfying an Inequality
- SQL优化的N种方法
- Tim output comparison - PWM
猜你喜欢

Esp8266wi fi data communication

RS-485总线通信应用

The latest C language introduction and advanced - the most complete and detailed C language tutorial in history!! Section 1 - overview of C language

HCIP第一天静态路由综合实验

(title + detailed idea + annotated code) codeforces round 805 (Div. 3) F Equate Multisets

NAT network address conversion experiment

Hcip day 1

NAT网络地址转化实验

Lesson 5 - key control LED

(the most detailed in History) codeforces round 805 (Div. 3) e Split Into Two Sets
随机推荐
静态路由综合实验
(题意+详细思路+加注释代码) Codeforces Round #805 (Div. 3)F. Equate Multisets
求解整数的每一位
三个整数从大到小排序(详细介绍多种方法)
Ogeek meetup phase I, together with cubefs, is hot
NB-IOT接入云平台
Full company mGRE and star topology mGRE
求解100~200之间的素数
C语言——关系运算符和逻辑运算符、if语句、switch语句、分支结构的嵌套
睡不着时闭眼躺着,到底有没有用?
On the first day of staying in the blog [for 80000]!
TCP三次握手、四次断开
Experiment exercise of two-layer packaging technology (HDLC, ppp--pap\chap, GRE)
C语言——第一个程序、打印、变量和常量
NAT (network address translation protocol)
Lvs+keepalived project practice
Explain exi interrupt through the counting experiment of infrared sensor
(title + detailed idea + annotated code) codeforces round 805 (Div. 3) F Equate Multisets
静态路由实验配置
【自此文之后,学习链表一片坦途】