nedoPC.org

Electronics hobbyists community established in 2002
Atom Feed | View unanswered posts | View active topics It is currently 27 Apr 2024 13:48



Reply to topic  [ 2 posts ] 
[PALM] clock.c on PocketC 
Author Message
Admin
User avatar

Joined: 08 Jan 2003 23:22
Posts: 22606
Location: Silicon Valley
Reply with quote
Image

Простейшие часы на PocketC, написанные на Treo-680 за один вечер:

Code:
// clock.c - Simple Clock
// Alexander@Shabarshin.com
// 13 Mar 2007

int myround(float f)
{
int i;
i=f;
if(f-i>0.5) i=i+1;
return i;
}

mycircle(int x, int y, int r)
{
int xx,yl,yi;
float yy,dx,dr;
dr=r;dr=dr*dr;yl=0;
for(xx=x-r+1;xx<=x+r;xx++)
{
dx=xx-x;
yy=sqrt(dr-dx*dx);
yi=myround(yy);
line(1,xx-1,y-yl,xx,y-yi);
line(1,xx-1,y+yl,xx,y+yi);
yl=yi;
}
}

strelka(int c, int x, int y, int l, float a)
{
line(c,x,y,x-myround(l*cos(a)),y-myround(l*sin(a)));
}

main()
{
int i,j,g,h,m,x1,y1,x2,y2;
string s;
float fa,fx,fy,fp,fs,fi,fo,fh,fm,fc;
int x=80;
int y=87;
int r=70;
int g0=51;
int g1=58;
int g2=63;
int g3=67;
int s1=35;
int s2=42;
int s3=45;
graph_on();
title("Clock");
textalign(11);
mycircle(x,y,r);
fp=2*asin(1);
fs=fp/30;
i=0;
for(fa=0;fa<fp+fp;fa=fa+fs)
{
if(i>=60) break;
fi=sin(fa);fo=cos(fa);
//puts("@"+fa+" "+fo+":"+fi+"\n");
if(i%5) g=g2;
else
{
g=g1;
j=i/5+3;
if(j>12) j=j-12;
s=j;
text(x+myround(g0*fo),y+myround(g0*fi),s);
}
line(1,x+myround(g*fo),y+myround(g*fi),x+myround(g3*fo),y+myround(g3*fi));
i++;
}
fh=0;fm=0;fc=0;j=0;
while(1)
{
while(1)
{
i=time(2);
h=i/10000;
i=i-h*10000;
m=i/100;
i=i-m*100;
if(i!=j) break;
}
j=i;
strelka(0,x,y,s3,fc);
strelka(0,x,y,s2,fm);
strelka(0,x,y,s1,fh);
fc=(i+15)*fs;
fm=(m+15)*fs;
fh=(h*5+m/12+15)*fs;
strelka(1,x,y,s1,fh);
strelka(1,x,y,s2,fm);
strelka(1,x,y,s3,fc);
}
}


Вот исходник в формате PilotDOC: clock.pdb (953 bytes)

Этот файлик можно стянуть из сети прямиком на Treo и откомпилить в PocketC

_________________
:dj: https://mastodon.social/@Shaos


Last edited by Shaos on 13 Sep 2012 13:19, edited 2 times in total.



13 Mar 2007 22:06
Profile WWW
Admin
User avatar

Joined: 08 Jan 2003 23:22
Posts: 22606
Location: Silicon Valley
Reply with quote
Post 
Прошу обратить внимание, что в данном исходнике прописана функция mycircle для рисования окружности (которой нет в PocketC API) моего собственного сочиненияю. Теперь можно переписать её с плавающей точки на фиксированную и можно переводить на RW1 для пополнения NedoPC SDK API.

_________________
:dj: https://mastodon.social/@Shaos


14 Mar 2007 17:49
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 17 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software.