Omnimaga
Calculator Community => HP Calculators => Topic started by: Handmixer on December 20, 2013, 02:18:05 pm
-
A Watch with Roman numbers.
Just for fun.
The code...
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;
-
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!
-
Thanks for letting me know
-
Huh, there's a unicode character for everything.
-
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.
-
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.
-
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.
-
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!
-
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
-
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;
-
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.
-
The file above has been updated
-
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 ???
-
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.
-
Yeah it would be nice. This was kinda annoying on Z80 calcs too.
-
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
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.
-
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.
-
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.
-
Oh nice, thanks for the trick. :)