pos機(jī)推銷語言,C語言+SDL2

 新聞資訊  |   2023-04-24 09:43  |  投稿人:pos機(jī)之家

網(wǎng)上有很多關(guān)于pos機(jī)推銷語言,C語言+SDL2的知識,也有很多人為大家解答關(guān)于pos機(jī)推銷語言的問題,今天pos機(jī)之家(m.dsth100338.com)為大家整理了關(guān)于這方面的知識,讓我們一起來看下吧!

本文目錄一覽:

1、pos機(jī)推銷語言

pos機(jī)推銷語言

/*

SDL2+C標(biāo)準(zhǔn)庫寫的時鐘小程序

安卓系統(tǒng)下測試可行

以下是完整代碼

*/

#include "SDL2/SDL.h"

#include "SDL2/SDL_thread.h"

#include<stdio.h>

#include<math.h>

#include<time.h>

#define PI 3.1415926536

//畫可旋轉(zhuǎn)矩形,圍繞矩形中心旋轉(zhuǎn)/順時針旋轉(zhuǎn)

//相對于數(shù)學(xué)坐標(biāo)象限4/3/2/1

//參數(shù)分別是渲染器,矩形中心點(diǎn)坐標(biāo)x0/y0坐標(biāo),矩形w寬/h高,A旋轉(zhuǎn)角度/弧度值

int myrect(SDL_Renderer *render,int x0,int y0,int w,int h,double A)

{

//源矩形四個頂點(diǎn)坐標(biāo)

double Ax,Ay,Bx,By,Cx,Cy,Dx,Dy;

//以矩形中心作為暫時坐標(biāo)原點(diǎn)

Ax=-w/2.0;Ay=+h/2.0;

Bx=Ax;By=-h/2.0;

Cx=+w/2.0;Cy=By;

Dx=Cx;Dy=Ay;

SDL_Point p0[4]=

{

{Ax,Ay},//A

{Bx,By},//B

{Cx,Cy},//C

{Dx,Dy} //D

};

/*

逆時針旋轉(zhuǎn):

x'=x*cos(a)-y*sin(a);

y'=x*sin(a)+y*cos(a);

*/

//旋轉(zhuǎn)A弧度后矩形ABCD四點(diǎn)新坐標(biāo)

double A1x,A1y,B1x,B1y,C1x,C1y,D1x,D1y;

D1x=Dx*cos(A)-Dy*sin(A)+x0;

D1y=Dx*sin(A)+Dy*cos(A)+y0;

C1x=Cx*cos(A)-Cy*sin(A)+x0;

C1y=Cx*sin(A)+Cy*cos(A)+y0;

A1x=Ax*cos(A)-Ay*sin(A)+x0;

A1y=Ax*sin(A)+Ay*cos(A)+y0;

B1x=Bx*cos(A)-By*sin(A)+x0;

B1y=Bx*sin(A)+By*cos(A)+y0;

//旋轉(zhuǎn)后的矩形四個點(diǎn)坐標(biāo)

SDL_Point p1[5]=

{

{A1x,A1y},//A

{B1x,B1y},//B

{C1x,C1y},//C

{D1x,D1y}, //D

{A1x,A1y}//A

};

//畫出旋轉(zhuǎn)后矩形

SDL_RenderDrawLines(render,p1,5);

return 0;

}

//畫圓函數(shù)

int myCircle(SDL_Renderer *render,int x0,int y0,int r)

{

double x1=0.0,y1=0.0;

static double TPI=6.2831853072;

double temp=0.0;

double step=0.0031415926536;

for(int i=0;temp<TPI;i++)

{

temp=i*step;

x1=x0-r*cos(temp);

y1=y0-r*sin(temp);

SDL_RenderDrawPoint(render, x1, y1);

}

return 0;

}

//畫刻度

int myDraw(SDL_Renderer *render,int x0,int y0,int r)

{

double x1=0.0,y1=0.0;

static double TPI=6.2831853072;

double a1=0.1047197551;

double st=0.0,x2=0.0,y2=00;

//畫刻度線60個 長度15像素

//夾角弧度

SDL_SetRenderDrawColor(render, 255, 255, 255, SDL_ALPHA_OPAQUE);

for(int j=0;j<60;j++)

{

st=j*a1;

x1=x0-r*cos(st);

y1=y0-r*sin(st);

x2=x1-15.0*cos(st);

y2=y1-15.0*sin(st);

if(j%5==0 && j!=0 && j!=15 && j!=30 && j!=45)

{

myRect(render,x1,y1,30,8,j*PI/30);

}

if(j==0) //9

{

SDL_Rect rect = {x1-15,y1-4,30 , 8 };

SDL_RenderFillRect(render, &rect);

}

else if(j==15) //12

{

SDL_Rect rect = {x1-4,y1-15,8 ,30 };

SDL_RenderFillRect(render, &rect);

}

else if(j==30) //3

{

SDL_Rect rect = {x1-10,y1-4,30, 8};

SDL_RenderFillRect(render, &rect);

}

else if(j==45) //6

{

SDL_Rect rect = {x1-4,y1-10,8 ,30};

SDL_RenderFillRect(render, &rect);

}

else

{

if(j!=5 && j!=10 && j!=20 && j!=25 && j!=35 && j!=40 &&j!=50 &&j!=55)

{

SDL_Point points[2]

{

{x1, y1},

{x2, y2}

};

//畫線

SDL_RenderDrawLines(render, points, 2);

}

}

}

return 0;

}

//實(shí)時獲取東8區(qū)時間

//獲取時/分/秒

int getTime(int *hour,int *min,int *sec)

{

time_t now;

time(&now);

struct tm *info;

//獲取GMT時間

info=gmtime(&now);

*hour=(info->tm_hour+8)$;

*min=info->tm_min;

*sec=info->tm_sec;

return 0;

}

//動態(tài)畫表針

int drawHand(SDL_Renderer *ren)

{

//時/分/秒

int h=0,m=0,s=0;

//對應(yīng)弧度

float Ah,Am,As;

//獲取時間

getTime(&h,&m,&s);

//當(dāng)前時針偏轉(zhuǎn)弧度

Ah=h*PI/6.0+m*PI/360.0;

//當(dāng)前分針偏轉(zhuǎn)弧度

Am=m*PI/30.0+s*PI/1800.0;

//當(dāng)前秒針偏轉(zhuǎn)弧度

As=s*PI/30.0;

//初始化時針在12時位置 時針長200寬12

//畫時針

myRect(ren,360+100*sin(Ah),640-100*cos(Ah),12,200,Ah);

//畫分針

myRect(ren,360+120*sin(Am),640-120*cos(Am),8,240,Am);

//畫秒針

myRect(ren,360+140*sin(As),640-140*cos(As),4,280,As);

return 0;

}

int main(int agrs,char *argv[])

{

//定義窗口

SDL_Window *wnd=NULL;

//定義渲染器

SDL_Renderer *render=NULL;

//初始化所有子系統(tǒng)

SDL_Init(SDL_INIT_EVERYTHING);

// 創(chuàng)建窗口

wnd = SDL_CreateWindow(

// 標(biāo)題

"我的SDL時鐘",

// 居中

SDL_WINDOWPOS_CENTERED,

SDL_WINDOWPOS_CENTERED,

// 寬高

350, 350,

//狀態(tài)

SDL_WINDOW_SHOWN);

//檢查窗口是否創(chuàng)建成功

if (wnd == NULL)

{

printf("Could not create window: %s\", SDL_GetError());

return 1;

}

//渲染器創(chuàng)建 render=SDL_CreateRenderer(wnd,1,1);

//背景色黑色 SDL_SetRenderDrawColor(render,0,0,0,255);

//刷新屏幕

SDL_RenderClear(render);

//選擇繪制顏色

SDL_SetRenderDrawColor(render, 255, 0, 0, SDL_ALPHA_OPAQUE);

while(1){

//繪制鐘盤

myDraw(render,360,640,300);

SDL_SetRenderDrawColor(render, 255, 0, 0, SDL_ALPHA_OPAQUE);

myCircle(render,360,640,3);

myCircle(render,360,640,4);

SDL_SetRenderDrawColor(render, 0, 0, 255, SDL_ALPHA_OPAQUE);

myCircle(render,360,640,11);

myCircle(render,360,640,12);

drawHand(render);

SDL_RenderPresent(render);

}

//清理

SDL_DestroyRenderer(render);

SDL_DestroyWindow(wnd);

SDL_Quit();

return 0;

}

以上就是關(guān)于pos機(jī)推銷語言,C語言+SDL2的知識,后面我們會繼續(xù)為大家整理關(guān)于pos機(jī)推銷語言的知識,希望能夠幫助到大家!

轉(zhuǎn)發(fā)請帶上網(wǎng)址:http://m.dsth100338.com/news/32418.html

你可能會喜歡:

版權(quán)聲明:本文內(nèi)容由互聯(lián)網(wǎng)用戶自發(fā)貢獻(xiàn),該文觀點(diǎn)僅代表作者本人。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如發(fā)現(xiàn)本站有涉嫌抄襲侵權(quán)/違法違規(guī)的內(nèi)容, 請發(fā)送郵件至 babsan@163.com 舉報,一經(jīng)查實(shí),本站將立刻刪除。