SDL系列之 - 用画直线的方法来画正弦曲线

线段长度无限短后就成为点,所以,现在让我们用画直线的方法来画正弦曲线吧

 1 #include <SDL.h>
 2 #include <stdlib.h>
 3 #include <string.h>
 4 #include <math.h>
 5 #include "SDL_draw.h"           //包含SDL_draw库的头文件
 6 int main()
 7 {
 8         int i;
 9         double t;
10         double x,y;
11         double x0=320, y0=240;
12         Uint32 screen_color;
13         SDL_Surface *screen;    //一个屏幕指针
14         if(SDL_Init(SDL_INIT_VIDEO) < 0){       //初始化视频子系统失败
15                 fprintf(stderr,"无法初始化:%s\n",SDL_GetError());       //不能用printf(),因为没有包含stdio.h头文件
16                 exit(1);
17         }           
18         //设置视频模式
19         screen=SDL_SetVideoMode(640,480,16,SDL_SWSURFACE);
20         if(screen==NULL){
21                 fprintf(stderr,"无法设置视频模式:%s\n",SDL_GetError());
22                 exit(1);
23         }   
24         atexit(SDL_Quit);       //退出
25 
26         //画直线,从点(240,180)到点(400,300),颜色为白色
27         Draw_Line(screen,240,180,400,300,SDL_MapRGB(screen->format, 255,255,255));
28         //画直线,从点(400,180)到点(240,300),颜色为蓝色
29         Draw_Line(screen,400,180,240,300,SDL_MapRGB(screen->format, 0,0,255));
30         for(i=0;i<640;i+=2){
31                 x=240-120*sin(3.14*i/180);
32                 i+=2;
33                 y=240-120*sin(3.14*i/180);
34                 Draw_Line(screen,i-2,x,i,y,SDL_MapRGB(screen->format, 0,0,255));
35                 SDL_Delay(5);                   //停留5毫秒
36                 SDL_UpdateRect(screen,0,0,0,0);         //更新整个屏幕
37         }       
38         SDL_UpdateRect(screen,0,0,0,0);         //更新整个屏幕
39         SDL_Delay(3000);                        //停留5秒
40         return 0;
41 }

 

转载于:https://www.cnblogs.com/fallenmoon/p/6888665.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值