人体生物钟程序编制(C语言)

人体生物钟程序编制(C语言),第1张

人体生物钟程序编制(C语言)

人体生物钟程序编制

人体生物钟也就是人体生物节律。人体生物节律是自然进化赋予生命的基本特征之一,人类和一切生物都要受到生物节律的控制与影响。人体生物节律是指体力节律、情绪节律和智力节律。每个人从他出生那天起一直到生命终结,都存在着体力23天、情绪28天、智力33天的周期性波动规律,称为人体生物节律。每一个周期中又存在着高潮期、低潮期和临界期。由于它具有准确的时间性,因此也称之为人体生物钟。在我们日常生活中,有人会觉得自己的体力、情绪或智力有时很好,有时很坏。人从他诞生之日起,直至生命终结,其自身的体力、情绪和智力都存在着由强至弱、由弱至强的周期性起伏变化。人们把这种现象称作生物节律,或生物节奏、生命节律等。之所以产生这种现象的原因是生物体内存在着生物钟,它自动地调节和控制着人体的行为和活动。

人体生物节律有什么作用,网上有许多介绍,对于想编程的朋友都是了解的,这里就不赘言什么了。本文就谈如何制作。就二个要点:一是输入当前日期和出生日期,此程序使用myspringc编译器自带的安卓式样日期输入控件。其他语言日期输入都很简单。二是根据这二个日期计算总天数,依数值绘出曲线。难点是曲线的绘制。本程序给出了曲线算法和绘图方法,以及绘制漂亮的界面。程序使用最基本的绘图函数DrawLine,DrawRect,DrawCircle,设置颜色SetColor(a,r,g,b)。程序有详细注释介绍绘制方法。

本程序是用简单的C语言编译调试的。主要展示该语言超强的绘图功能。如何绘制图形曲线,绘制漂亮的界面。本人喜欢用编程语言的绘图功能绘制图形图案和-漂亮的界面,能发挥你的想象力和创造力,很有趣,希望大家也喜欢。

下面的代码是用简单的C语言写的,很简洁 ,适用于初学者。

注意:我发现发布的时候计算式中的乘号 * 老是漏掉,我没法改,引用时注意⚠️ **
// myspringc v2.7 可编译安卓手机本机 app 应用
// 此样例可复制黏贴到 myspringc 编译
// 亦可用vb6, VC , Java 等改写
//******* 人体生物钟 *******************
//===== 人体生物节律曲线 == Biorhythm
//制作人:张纯叔 [email protected]
//**** myspringc v2.7 编译 *************
Canvas cs;
float pi=3.1415926535;
float src[4]; //ClearDraw (cls) clear screen
int s1,s2,s3;
int s1n,s2n,s3n;
int i,k,bx; //bx 画标尺
int alln0,alln1;
int alln; //set today-birthdate all days
int ns;
float a;
float dx,dy, x0,y0;
float x1,y1;
string s,ss,ss1,ss2,ss3,ss4,ss5,ss6;
string gs1,gs2,gs3,gs4,gs5,gs6;
int by,bm,bd; //birthdate yy,mm,dd
int ty,tm,td; //today
double bms,tms;
int d[3];
int count;
int context; //canvasProc
int obj;
int id;
int event;

main(){
setDisplay(1);
cs.Active();
//cs.SetBackground(25,25,25);
setTitle(“人体生物钟 ( Biorhythm )”);
cs.SetProc (context, mycanvasProc);
drawtable ();
while (){}
}//main()

mycanvasProc (int context,int obj,int id,int event,float x,float y){
cs.SetFillMode(0);//0不填色,1填色
//select button : input date *******
if (x>400&&x<560&&y>810&&y<880)input_date ();
//button 1 - 5 ****** test () 用于调试
// if (x>20&&x<140&&y>980&&y<1050){ test (); }
// if (x>160&&x<280&&y>980&&y<1050){ }
if (x>300&&x<420&&y>980&&y<1050){
input_date (); }
if (x>440&&x<560&&y>980&&y<1050) {
input_date (); }
if (x>580&&x<700&&y>980&&y<1050){
clearOutput();
cs.ClearDraw (0,src);
setDisplay (0);
exit (0); } //Exit
}//mycanvasProc ()

test (){ //用于程序调试,计算检测
cs.SetTextSize (24);
cs.SetFillMode(1);//0不填色,1填色
cs.SetTextStyle(0);
cs.SetColor(255,0,0,120);
ss1=intToString (s1);
ss1="s1 = "+ss1;
cs.DrawText(ss1,30,990);
ss2=intToString (s2);
ss2="s2 = "+ss2;
cs.DrawText(ss2,30,1020);
ss3=intToString (s3);
ss3="s3 = "+ss3;
cs.DrawText(ss3,30,1050);
//****
ss4=intToString (s1n);
ss4="s1n = "+ss4;
cs.DrawText(ss4,150,990);
ss4=intToString (s2n);
ss4="s2n = "+ss4;
cs.DrawText(ss4,150,1020);
ss4=intToString (s3n);
ss4="s3n = "+ss4;
cs.DrawText(ss4,150,1050);
cs.Update ();
}//test ()

drawbutton (){ //绘制按钮
cs.SetColor (255,230,230,230);
cs.DrawRect (4,940,715,1078);
cs.SetColor (255,255,255,255);
cs.DrawRect (11,960,707,963);
cs.DrawRect (11,1065,707,1068);

for (i=0;i<3;i++){   //draw 3-5 cmd_button
      cs.SetColor (255,150,150,150);
    cs.DrawRect (i*140+299,980,i*140+423,1052); 
      cs.SetColor (255,250,250,250);
    cs.DrawRect (i*140+297,978,i*140+420,1050); 
      cs.SetColor (255,200,240,250);
    cs.DrawRect (i*140+300,980,i*140+420,1050); 
                }

cs.SetTextSize (24);
cs.SetTextStyle(1);
cs.SetColor(255,50,150,220);
cs.DrawText (“输入日期”,313,1020);
cs.DrawText (“重新开始”,453,1020);
cs.DrawText (“退出程序”,595,1020);
s=“BIORHYTHM”;
cs.SetTextSize (40);
cs.SetTextStyle(1);
cs.SetColor (255,150,150,150);
cs.DrawText (s,20,1030);
cs.SetColor (255,255,255,255);
cs.DrawText (s,20+3,1030+3);

//draw Input button ****
cs.SetColor (255,250,0,150);
cs.DrawRect (399,819,561,881);
cs.SetColor (255,20,150,250);
cs.DrawRect (400,820,560,880);
cs.SetTextSize (24);
cs.SetTextStyle(0);
cs.SetColor(255,250,250,0);
cs.DrawText (“输入日期”,435,855);
cs.SetColor (255,250,0,150);
s="请输入当前日期和出生日期 >> ";
cs.DrawText (s,80,860);
cs.Update ();
}//drawbutton ()

input_date (){
//here get birth date & current date then show out
inputdd:
getDate(d);
pickDate(“输入> 当前日期”,d);
ty=d[0];
tm=d[1];
td=d[2];
//print “currentday = “,ty ,”-”,tm,"-",td;
pickDate(“输入> 出生日期”,d);
by=d[0];
bm=d[1];
bd=d[2];
//print “birthdate = “,by ,”-”,bm,"-",bd;
clearOutput (); //clear output text
cs.ClearDraw (0,src); //clear screen

// calculate (alln)= all days from birthdate to today
gs1=intToString (by);
gs2=intToString (bm);
gs3=intToString (bd);
gs4=intToString (ty);
gs5=intToString ™;
gs6=intToString (td);
if (by>ty){
ss=“输入错误 ! 重新输入当前日期,出生日期。”;
msgBox ("人体生物节律 " ,ss);
goto inputdd; }
if (bm<10)gs2=“0”+gs2;
if (bd<10)gs3=“0”+gs3;
if (tm<10)gs5=“0”+gs5;
if (td<10)gs6=“0”+gs6;
print " Input birthdate = “,gs1,” - “,gs2,” - ",gs3;
print " Input this Date = “,gs4,” - “,gs5,” - ",gs6;

//getDate and calculate past days alln ****
string yds;
string ydds;
double tms;
yds=“000031059090120151181212243273304334”;
//计算生日 alln0
ydds=subString(yds,(bm-1)3,3);
bms=stringToDouble(ydds);
alln0=(by-1900)365+((by-1900-1)/4)
+(int)(bms)+bd;
if ((by-by/4
4)==0&&bm>2)alln0=alln0+1; //加闰
print "birth = ",alln0;
//计算当前日 alln1
ydds=subString(yds,(tm-1)3,3);
tms=stringToDouble(ydds);
alln1=(ty-1900)365+((ty-1900-1)/4)
+(int)(tms)+td+1; //
**
if ((ty-ty/4*4)==0&&tm>2)alln1=alln1+1; //加闰
print "current = ",alln1;
alln=alln1-alln0;
print "all days = ",alln;
if (alln<1){ //容错
ss=“输入错误 ! 重新输入当前日期,出生日期。”;
msgBox ("人体生物钟 " ,ss);
goto inputdd; }
print " ";
drawtable (); //show…绘出曲线
}//input_date ()

drawtable(){//draw table and show
cs.ClearDraw(0,src);
cs.Update();
//get birthdate yymmdd and current yymm ***
//calculate s1,s2,s3 and draw curve **********
//drawout and show biorhythm **********
cs.SetFillMode(1);//0不填色,1填色
cs.SetColor(255,240,240,240);
cs.DrawRect(10,10,710,600);
// draw table ===============
cs.SetStrokeWidth(3);//画笔线宽
cs.SetColor(255,250,0,128);
cs.SetFillMode(0);//0不填色,1填色
cs.SetTextSize(60);
cs.SetTextStyle(0);
cs.SetStrokeWidth(2);
s=“人体生物节律曲线”;
cs.DrawText(s,50,100);
cs.SetStrokeWidth (1);
cs.SetTextSize (28);
cs.SetColor(250,250,0,0);
ss=“高潮区”;
cs.DrawText (ss,560,210);
ss="临界区 ";
cs.DrawText (ss,560,270);
ss="低潮区 ";
cs.DrawText (ss,560,410);
cs.SetFillMode(1);//0不填色,1填色
cs.SetColor(250,250,0,0);
ss=“体力 >”;
cs.DrawText (ss,200,510);
cs.SetColor(180,0,90,0);
ss=“情绪 >”;
cs.DrawText (ss,200,540);
cs.SetColor(180,0,0,180);
ss=“智力 >”;
cs.DrawText (ss,200,570);

//draw table========
cs.SetFillMode (1);
cs.SetStrokeWidth(2);
cs.SetColor(100,250,250,0);
cs.DrawRect(50,150,670,450);
cs.SetColor (100,255,120,255);
cs.DrawRect (50,150,670,235); //high low 区块
cs.SetColor(100,130,255,255);
cs.DrawRect(50,365,670,450);
cs.SetColor (255,0,120,128);
cs.DrawRect(20,296,710,304); //Xline 标尺
cs.SetColor(180,250,0,0);
cs.DrawRect (50,500,180,506); //s1
cs.SetColor(180,0,200,0);
cs.DrawRect (50,530,180,536); //s2
cs.SetColor(180,0,0,192);
cs.DrawRect (50,560,180,566); //s3

cs.SetColor (255,20,60,0);
cs.SetTextSize (20);
cs.DrawText(“0”,44,340);
cs.DrawText(“5”,143,340);
cs.DrawText(“10”,238,340);
cs.DrawText(“15”,338,340);
cs.DrawText(“20”,438,340);
cs.DrawText(“25”,538,340);
cs.DrawText(“30”,638,340);

cs.SetFillMode (0);
cs.SetColor (255,250,250,0);
cs.DrawRect(23,300,715,300);//Xline 标尺
cs.SetColor (255,0,0,128);
for (i=0;i<34;i++){ //画标尺点位
bx=50+i20;
cs.DrawLine (bx,280,bx,320); }
cs.SetColor (255,255,0,0);
for (i=0;i<7;i++){ //画标尺 5 天标线
bx=50+i
100;
cs.DrawCircle (bx,300,2);
cs.DrawLine (bx,150,bx,320);
cs.DrawLine (bx,350,bx,450); }

//draw curve : x1 +50 标尺x轴 0 位, s1*20 步长
//x0 曲线幅宽, + -130 y轴峰谷弧高, y+300 x轴y定位
//1.18 = 23d, 0.97 = 28d, 0.82 = 33d
//Draw out graph here ===========
//get birthdate & calculate thisday-birthdate
cs.SetStrokeWidth(2);
ns=td-alln; //这算法很奇特,研究一下
//s1=23, draw graph 体力
s1=ns-ns/2323; //mod (ns,23)
cs.SetColor (255,255,0,0);
for (i=-100;i<280;i++){
a=pi/360
i6;
x0=272;
x1=(float)((x0/(1.18
pi)a+50)+s120);
y1=(float)(-130*sin(a)+300);
cs.DrawCircle(x1,y1,3); }
print " s1= ",s1;

//s2=28, draw graph 情绪
s2=ns-ns/2828; //mod(ns,28)
cs.SetColor (255,0,220,0);
for (i=-100;i<280;i++){
a=pi/380
i6;
x0=272;
x1=(float)((x0/(0.97
pi)a+50)+s220);
y1=(float)(-130*sin(a)+300);
cs.DrawCircle(x1,y1,3); }
print " s2= ",s2;

//s3=33, draw graph 智力
s3=ns-ns/3333; //mod (ns,33)
cs.SetColor (205,0,0,192);
for (i=-100;i<280;i++){
a=pi/400
i6;
x0=270;
x1=(float)((x0/(0.82
pi)a+50)+s320);
y1=(float)(-130sin(a)+300);
cs.DrawCircle(x1,y1,3); }
print " s3= ",s3;
cs.SetStrokeWidth(0);
cs.SetColor (255,60,60,60);
x1=(float)(td
20+47); //draw current day当日标
cs.DrawRect (x1,146,x1+5,454);

 cs.SetFillMode (1);
 cs.SetStrokeWidth(2);
 cs.SetColor (255,255,255,255);
 cs.DrawRect (0,150,11,450);
 cs.DrawRect (709,150,720,450);
 cs.SetColor (255,164,164,164);
 cs.DrawRect (710,15,717,606);
 cs.DrawRect (15,600,716,606);
 cs.SetFillMode (0);
 cs.SetColor(255,50,0,128);
 cs.DrawRect(10,10,710,600);

//== draw data ======
cs.SetTextSize (32);
cs.SetFillMode (1);
cs.SetStrokeWidth(2);
cs.SetColor (255,0,0,200);
if (len(gs2)==1)gs2=“0”+gs2;
if (len(gs3)==1)gs3=“0”+gs3;
if (len(gs5)==1)gs5=“0”+gs5;
if (len(gs6)==1)gs6=“0”+gs6;
ss1="出生日期 : “+gs1+” 年 “+gs2+” 月 “+gs3+” 日 ";
cs.DrawText(ss1,30,680);
ss2="当前日期 : “+gs4+” 年 “+gs5+” 月 “+gs6+” 日 ";
cs.DrawText (ss2,30,730);
s=intToString (alln);
print " all days = ",alln;
ss3=“你已在这美好的世界上生活了”+s+“天。”;
if (alln<1)ss3="Welcome to using our program . ";
cs.DrawText(ss3,30,780);
ss="制作人: 张纯叔 ( [email protected] ) ";
cs.SetColor (255,150,180,250);
cs.DrawRect (5,1078,715,1080);
cs.DrawText (ss,20,1110);
//draw status 状态 ***********
cs.SetFillMode(1);//0不填色,1填色
//**** s1n s 23
s1n=alln-alln/2323 ;
cs.SetColor (255,250,220,0) ; //临界
cs.DrawRect (300,490,400,510);
if (s1n>2&&s1n<10){ //高 3 - 9
cs.SetColor(255,250,120,180);
cs.DrawRect (300,490,400,510); }
if (s1n>13&&s1n<22){ //低 14~21
cs.SetColor (255,130,250,150) ;
cs.DrawRect (300,490,400,510); }
//
*** s2n s 28
s2n=alln-alln/2828 ;
cs.SetColor (255,250,220,0) ; //临界
cs.DrawRect (300,520,400,540);
if (s2n>2&&s2n<12){ //高 3 - 11
cs.SetColor(255,250,120,180);
cs.DrawRect (300,520,400,540); }
if (s2n>16&&s2n<26){ //低 17 - 25
cs.SetColor (255,130,250,150) ;
cs.DrawRect (300,520,400,540); }
//
*** s3n s 33
s3n=alln-alln/33*33 ;
cs.SetColor (255,250,220,0) ; //临界
cs.DrawRect (300,550,400,570);
if (s3n>2&&s3n<14){ //高 3 - 13
cs.SetColor(255,250,120,180);
cs.DrawRect (300,550,400,570); }
if (s3n>19&&s3n<31){ //低 20 - 30
cs.SetColor (255,130,250,150) ;
cs.DrawRect (300,550,400,570); }
setDisplay (1); //显示
cs.Active (); //活动
drawbutton (); //绘制按钮
cs.Update(); //show out table
}//drawtable ()

//**** End ******

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5702595.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存