Omnimaga

Calculator Community => HP Calculators => Topic started by: Handmixer on December 20, 2013, 02:18:05 pm

Title: A clock
Post by: Handmixer 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;
Title: Re: A clock
Post by: Xeda112358 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!
Title: Re: A clock
Post by: Handmixer on December 20, 2013, 02:29:02 pm
Thanks for letting me know
Title: Re: A clock
Post by: fb39ca4 on December 20, 2013, 04:56:02 pm
Huh, there's a unicode character for everything.
Title: Re: A clock
Post by: DJ Omnimaga 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:

(http://img.ourl.ca//clock.png)

I can't distinguish the yellow stuff and one arrow suddenly disappeared at one point.
Title: Re: A clock
Post by: Handmixer 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.
Title: Re: Re: A clock
Post by: DJ Omnimaga 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.
Title: Re: A clock
Post by: timwessman 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!

Title: Re: A clock
Post by: Handmixer 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
Title: Re: A clock
Post by: timwessman 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;



Title: Re: A clock
Post by: DJ Omnimaga 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.
Title: Re: A clock
Post by: Handmixer on December 21, 2013, 11:15:17 am
The file above has been updated
Title: Re: A clock
Post by: DJ Omnimaga 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 ???
Title: Re: A clock
Post by: fb39ca4 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.
Title: Re: A clock
Post by: DJ Omnimaga on December 21, 2013, 12:05:28 pm
Yeah it would be nice. This was kinda annoying on Z80 calcs too.
Title: Re: A clock
Post by: Han on December 22, 2013, 10:28:03 am
Changing the user's settings is not a really good programming practice unless you can guarantee that no matter what the user does during program execution, their settings will be returned to the state prior to running the program. In your case, if the user presses the [On] key, program execution is halted and there is a chance the user's angle settings do not get restored. Instead, use the angle setting to test whether or not your own program needs to do angle conversion. If your code is written with the assumption that radians are used, and the user's calculator happens to be in degrees, then

Code: [Select]
GETANGLE(a)
BEGIN
  IF HAngle THEN
    a:=a/PI*180; // angle was assumed to be in radians when programmed; convert to degrees
  END;
  RETURN(a);
END;

So now you can just do SIN(GETANGLE( blah )) and always assume that the angle is in radians (while you program). Whether or not the user's settings is in radians won't affect the outcome as GETANGLE() will convert accordingly.
Title: Re: A clock
Post by: DJ Omnimaga on December 22, 2013, 12:00:25 pm
Oh nice, I didn't know it was possible to detect in which mode the calc is set. In TI-BASIC, we sometimes have to force mode changes because we absolutely have no other choice.
Title: Re: A clock
Post by: Han on December 25, 2013, 12:32:08 am
Oh nice, I didn't know it was possible to detect in which mode the calc is set. In TI-BASIC, we sometimes have to force mode changes because we absolutely have no other choice.

Actually, you can create a similar workaround on the TI. In place of HAngle, you can simply test SIN(PI)==0 to determine whether you are in degree mode or radian mode. If the boolean is true, then you are in radian mode. Otherwise, you are in degree mode.
Title: Re: A clock
Post by: DJ Omnimaga on January 08, 2014, 08:40:35 pm
Oh nice, thanks for the trick. :)