Author Topic: A clock  (Read 9820 times)

0 Members and 3 Guests are viewing this topic.

Offline Handmixer

  • LV2 Member (Next: 40)
  • **
  • Posts: 21
  • Rating: +0/-0
    • View Profile
A clock
« on: December 20, 2013, 02:18:05 pm »
A Watch with Roman numbers.
Just for fun.

The code...
Code: [Select]
EXPORT Clock()
BEGIN
 LOCAL t,tt,h,m;
 LOCAL s,nums,i,x,y;
 LOCAL ux,uy,x1,y1,x2,y2;
 nums:="ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫ";
 // Init GUI
 DIMGROB_P(G1,320,240);
 REPEAT
  RECT_P(G1,#000000);
  FOR i FROM 1 TO 12 DO
   x:=152+100*SIN(i*π/6);
   y:=110-100*COS(i*π/6);
   TEXTOUT_P(CHAR(nums(i)),G1,x,y,0,#FFFF00);
  END;
  t:=Time();
  tt:=HMS→(t);
  h:=tt;
  ux:=SIN(h*π/6);
  uy:=COS(h*π/6);
  x:=160+45*ux;
  y:=120-45*uy;
  x1:=160+5*uy;
  y1:=120+5*ux;
  x2:=160-5*uy;
  y2:=120-5*ux;
  TRIANGLE_P(G1,x,y,x1,y1,x2,y2,#FFFFFF,0,0);
  m:=IP(FP(tt)*100);
  ux:=SIN(m*π/50);
  uy:=COS(m*π/50);
  x:=160+90*ux;
  y:=120-90*uy;
  x1:=160+5*uy;
  y1:=120+5*ux;
  x2:=160-5*uy;
  y2:=120-5*ux;
  TRIANGLE_P(G1,x,y,x1,y1,x2,y2,#FFFFFF,0,0);
  s:=100*FP(tt*100);
  ux:=SIN(s*π/50);
  uy:=COS(s*π/50);
  x:=160+90*ux;
  y:=120-90*uy;
  x1:=160+5*uy;
  y1:=120+5*ux;
  x2:=160-5*uy;
  y2:=120-5*ux;
  TRIANGLE_P(G1,x,y,x1,y1,x2,y2,#A0A0A0,0,0);
  BLIT_P(G0,G1);
 UNTIL ISKEYDOWN(14) ;
END;
« Last Edit: December 20, 2013, 02:28:22 pm by Handmixer »

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: A clock
« Reply #1 on: December 20, 2013, 02:26:06 pm »
Hi Handmixer! I don't have an HP calc, so I can't test it, but somebody pointed out to me that your codeblock wasn't rendering nicely. Google Chrome users have noticed that nesting code blocks inside of spoilers doesn't work well. If you wanted, I could modify your post to exclude the spoiler tags, or you could by selecting "modify" on your post.

Anyways, thanks for sharing! I know we have a group of HP Prime programmers around here that might be interested in seeing the code!

Offline Handmixer

  • LV2 Member (Next: 40)
  • **
  • Posts: 21
  • Rating: +0/-0
    • View Profile
Re: A clock
« Reply #2 on: December 20, 2013, 02:29:02 pm »
Thanks for letting me know

Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
Re: A clock
« Reply #3 on: December 20, 2013, 04:56:02 pm »
Huh, there's a unicode character for everything.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: A clock
« Reply #4 on: December 20, 2013, 06:11:23 pm »
Is it supposed to look like this? I copied the code in the emulator and this is what I got:



I can't distinguish the yellow stuff and one arrow suddenly disappeared at one point.

Offline Handmixer

  • LV2 Member (Next: 40)
  • **
  • Posts: 21
  • Rating: +0/-0
    • View Profile
Re: A clock
« Reply #5 on: December 21, 2013, 12:20:37 am »
Sorry I don't know how to post Pictures.

The code runs on my calculator and in the emulator, and it shows a clock with roman numbers.
Perhaps the pi-sign didnt copy rigth.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Re: A clock
« Reply #6 on: December 21, 2013, 05:43:35 am »
That's possible. Could you maybe upload a program copy below a post? Just go to documents and settings/yourusername/appdata/roaming/HP Prime/ then copy the .hpprgm file used for your clock.

I know that certain forums have troubles with some unicode characters when pasting them and in some cases with HP Prime programs, whitespace issues can arise too when copying code due to a bug.

Offline timwessman

  • LV3 Member (Next: 100)
  • ***
  • Posts: 94
  • Rating: +32/-0
    • View Profile
Re: A clock
« Reply #7 on: December 21, 2013, 10:26:55 am »
I'm guessing the runtime issue is that you need to be setting to radians, and restoring after.

local angle:=HAngle;

....
program body
....

HAngle:=angle;


Also, I've figured out what is going wrong here. Looks like some browsers are sticking in unicode nbsp (\u0090) in these types of blocks. I'll put that on the list of changes to handle as part of the "whitespace" skipping code. Thanks!

TW

Although I work for the HP calculator group, the comments and opinions I post here are my own.

Offline Handmixer

  • LV2 Member (Next: 40)
  • **
  • Posts: 21
  • Rating: +0/-0
    • View Profile
Re: A clock
« Reply #8 on: December 21, 2013, 10:37:20 am »
Source attached including Tim's recomendation.

EDIT: now changes mode to RAD and changes back to previous angle setting when stopped by pressing any key
EDIT: bug in calculation of seconds corrected
« Last Edit: December 21, 2013, 12:12:31 pm by Handmixer »

Offline timwessman

  • LV3 Member (Next: 100)
  • ***
  • Posts: 94
  • Rating: +32/-0
    • View Profile
Re: A clock
« Reply #9 on: December 21, 2013, 10:50:28 am »
Also, I'd recommend using something like this at the end. It will save a lot of juice since you won't be looping continually. Also will exit cleanly on any keypress.

  WAIT(1);
  UNTIL GETKEY()≠−1;



TW

Although I work for the HP calculator group, the comments and opinions I post here are my own.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: A clock
« Reply #10 on: December 21, 2013, 10:51:50 am »
Yeah I think it has to do with the forum code tags. I noticed this happening with other sites too, such as the old MoHPC forums, where almost anything pasted there would not run.

Also thanks handmixer for the upload. I'll give this a try now. :)

EDIT Yay it works! You should make the program automatically change settings to radians and maybe keep the previous setting in memory if that's possible in HP PPL, for people who don't like when programs overwrite their settings, since another program (Trailblazer) requires Degree mode to be on.
« Last Edit: December 21, 2013, 10:54:42 am by DJ Omnimaga »

Offline Handmixer

  • LV2 Member (Next: 40)
  • **
  • Posts: 21
  • Rating: +0/-0
    • View Profile
Re: A clock
« Reply #11 on: December 21, 2013, 11:15:17 am »
The file above has been updated

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: A clock
« Reply #12 on: December 21, 2013, 11:25:40 am »
There seems to be some issue with time, because I'm noticing now that the seconds arrow takes 36 seconds to loop around instead of 60 ???

Offline fb39ca4

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1749
  • Rating: +60/-3
    • View Profile
Re: A clock
« Reply #13 on: December 21, 2013, 11:43:43 am »
You should make the program automatically change settings to radians and maybe keep the previous setting in memory if that's possible in HP PPL, for people who don't like when programs overwrite their settings, since another program (Trailblazer) requires Degree mode to be on.
What is this, the 90s? You'd think we could have moved beyond global variables by then. :P I actually liked what the Nspire did, where you could add a degree sign (or a tiny r for radians) to your number. I wonder if something like this is possible with the Prime.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: A clock
« Reply #14 on: December 21, 2013, 12:05:28 pm »
Yeah it would be nice. This was kinda annoying on Z80 calcs too.