Monday, May 11, 2015

HP Prime and TI-84 Plus C Silver Edition: Pie Charts

HP Prime and TI-84 Plus C Silver Edition:  Pie Charts

Both programs take an argument a list up to 15 segments long.  

PIECHART, HP Prime


HP Prime:  PIECHART

Notes:
* The % character is either retrieved by pressing [Shift], [Vars] (Chars), or typed if you are using the emulator.
*  The program sets the calculator to Radian and Standard modes. 

EXPORT PIECHART(l1)
BEGIN
// Pie Chart EWS
// 2015-05-11

// initialization
LOCAL l2,l3,colors,s,k,θ,c;

// Radian mode
HAngle:=0;

// Standard Mode
HFormat:=0;

// set colors (15)
colors:={#FFh,#FF0000h,#0h,
#FF00FFh,#FF00h,#FFA500h,
#964B00h,#80h,#87CEEBh,
#FFFF00h,#FFFFFFh,#C0C0C0h,
#808080h,#404040h,#101010h};
c:=1;

// error conditions
IF SIZE(l1)>15 THEN
MSGBOX("The list is too long.");
KILL;
END;

// calculations
l2:=l1;
FOR k FROM 2 TO SIZE(l1) DO
l2[k]:=l2[k]+l2[k-1];
END;

l2:=2*π*l2/ΣLIST(l1);
l2:=CONCAT({0},l2);
s:=SIZE(l2);

// window setup
Xmin:=−10; Xmax:=10;
Ymin:=−10; Ymax:=10;
RECT();

// draw pie graph
FOR k FROM 1 TO s-1 DO
FOR θ FROM l2[k] TO l2[k+1]
STEP π/200 DO
LINE(2.5,0,5*COS(θ)+2.5,5*SIN(θ),
colors[c]);
END;
c:=c+1;
END;

// display legends and percentages
l3:=l1/ΣLIST(l1)*100;

FOR k FROM 1 TO SIZE(l1) DO
TEXTOUT(STRING(l1[k]),-10,10-(k-1),
2,colors[k]);
TEXTOUT(STRING(l3[k],2,1)+"%",
-6,10-(k-1),2,colors[k]);
END;

WAIT(0);
END;

 
Pie Chart (PIE84), TI 84 Plus C Silver Edition

TI-84 Plus C Silver Edition

Notes:
*  Comments in this program will be marked with double slashes (//).  Do not type them in.  They are there only to explain parts of the program.  I intend to leave comments in every program publish from here on out if explanation is warranted.
* To type the percentage sign:  [ 2ND ], [ANGLE], 1 (°), [ ÷ ], [ . ].  There is no native percent sign (%) on the TI-84, this is the best I can do. 
*  Float and Radian modes are set.


// Initialization, turn off axes
FnOff
Float
Radian
AxesOff

// ask for list of data
Input L₁
If dim(L₁)>15:Then
Disp "L₁>15":Stop
End

// calculation
2π*cumSum(L₁)/sum(L₁)→L₂
augment({0},L₂)→L₂
dim(L₂)→S

// set color variables
10→C
10→D
L₁/sum(L₁)*100→L₃

// prepare draw screen
ZStandard
ClrDraw

// draw the pie chart
For(I,1,S-1)
For(θ,L₂(I),L₂(I+1),π/100)
Line(2.5,0,5cos(θ)+2.5,5sin(θ),1,C)
End
C+1→C
End

// draw the legend, draw commands have to remain together
For(K,1,dim(L₃))
TextColor(D)
Text(12K,0,round(L₃(K),1))
Text(12K,30,"°/.")
D+1→D
End
Pause

// turn axes on, Disp by itself just shows the home screen
AxesOn
FnOn
Disp



Hope you find this program useful! 

In TI-84 Plus CE news.  I heard back from the company I ordered my CE from and I am to expect delivery around May 25.  I plan to give a review of it at the end of May if not early June.

Take care,

Eddie



This blog is property of Edward Shore.  2015.

Casio fx-CG50 and Swiss Micros DM32: HP 16C’s Bit Summation

  Casio fx-CG50 and Swiss Micros DM32: HP 16C’s Bit Summation The HP 16C’s #B Function The #B function is the HP 16C’s number of...