January 19, 2020, 02:35:01 pm

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Experimenting with colors III - Pie Charts.

Started by Egil, August 11, 2016, 12:23:37 pm

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Egil

The last of the workshop programs today was also converted from MiniBASIC. (But I know I also have done it with EB some time).
It shows how to make a Pie Chart. If the Pie Chart need explanation, the Legend subroutine can be copied from the BarGraph code posted below. We'll leave that up to you.


Have Fun!

Code Select
'
'-------------------------------------------------------------------------------------
' CB_PieChart.CBA
'-------------------------------------------------------------------------------------
AutoDefine "Off"

DECLARE "gdi32.dll",AngleArc(hdc:INT, x:INT, y:INT, dwRadius:INT,startangle:float,endangle:float),INT
DECLARE About(wnd:window)
DECLARE AskExit(wnd:window)
DECLARE MyMenu(wnd:window)
DECLARE cosd(ang:float)
DECLARE sind(ang:float)
DECLARE Pie(wnd:window,cntx:int,cnty:int,rds:int,startangle:float,endangle:float,cr:int,cg:int,cb:int)

def win:window 
def run:int 

Window win,-480,0,480,300,0,0,"    CB Skeleton Window",messages 

move win,180,10
print win,"Right-Click for Menu"

Pie(win,240,150,70,0,20,0,128,255)
Pie(win,240,150,70,20,45,255,0,128)
Pie(win,240,150,70,45,80,0,255,128)
Pie(win,240,150,70,80,120,255,128,128)

Pie(win,240,150,70,120,360,252,252,202)

run = 1 

WAITUNTIL run = 0
CLOSEWINDOW win 
END 

'
SUB messages()
'-------------------------------------------------------------------------------------
' Main Loop
'-------------------------------------------------------------------------------------
'
SELECT @class

CASE @idcreate 
centerwindow win 

CASE @idclosewindow 
run = 0 

CASE @IDKEYDOWN
if GETKEYSTATE(0x1B) <> 0 then AskExit(win) :' ESC pressed - want to exit?

CASE @IDRBUTTONUP
MyMenu(win)
CASE @IDMENUPICK
SELECT @MENUNUM
case 10
About(win)
case 20
system "http://www.ionicwind.com/forums/"
case 30
AskExit(win)
ENDSELECT

ENDSELECT 
RETURN
'---------------------------------------------------------------------------------------

'
SUB Pie(wnd:window,cntx:int,cnty:int,rds:int,startangle:float,sweep:float,cr:int,cg:int,cb:int)
'---------------------------------------------------------------------------------------
' HOW TO USE:
'   wnd        = window handle
'   cntx,cnty  = coordinates of circle center
'   rds        = radius
'   StartAngle = starting angle of the sector in degrees
'   EndAngle   = EndAngle of sector in degrees
'   cr, cg, cb = sector colors
'
' NB:
'   Zero degrees at due east (to the right)....
'   Positive angle values move anticlockwise - negative angle values move clockwise
'---------------------------------------------------------------------------------------
def hdc,ffx,ffy:int

FRONTPEN wnd,RGB(255,255,254) :' At least one parameter MUST have value below 255 to obtain "invisible" lines!
:' If all of then are set to 255, the window looks like a mess - try it yourself...
move(wnd,cntx,cnty)
hdc = GetHDC wnd
AngleArc(hdc,cntx,cnty,rds,startangle,endangle)
move(wnd,cntx,cnty)
AngleArc(hdc,cntx,cnty,rds,endangle,-1)

   ffx = cntx + ((rds/2) * cosd(startangle+1))
   ffy = cnty - ((rds/2) * sind(startangle+1))
move(wnd,ffx,ffy)
FLOODFILL wnd,ffx,ffy,RGB(cr,cg,cb)
RELEASEHDC(wnd,hdc)
FRONTPEN wnd,RGB(0,0,0)

RETURN


'
SUB cosd(ang:float)
'----------------------------------------------------------------------------------------
' cosd
'----------------------------------------------------------------------------------------
def ret,pi:float
pi = 4 * atan(1)
ret = ang*pi/180
RETURN cos(ret)

'
SUB sind(ang:float)
'----------------------------------------------------------------------------------------
' sind
'---------------------------------------------------------------------------------------- 
def ret,pi:float
pi = 4 * atan(1)
ret = ang*pi/180
RETURN sin(ret)


SUB MyMenu(wnd:window)
'----------------------------------------------------------------------------------------
' Contextmenu - Popping up at pointer location
'----------------------------------------------------------------------------------------
'
CONTEXTMENU wnd,@MOUSEX,@MOUSEY,"I,About,0,10","I,IonicWind User Forums,0,20","I,Exit,0,30"

RETURN

'
SUB AskExit(wnd:window)
'----------------------------------------------------------------------------------------
' Ask if you really want to exit
'----------------------------------------------------------------------------------------
'
def txt0$,txt1$,crlf$:string
crlf$=chr$(10)+chr$(13)
txt0$=""
txt1$="        Do you really want to exit? "
if MESSAGEBOX(wnd,txt1$,txt0$,0x30|0x04) = 0x06 then  run = 0
RETURN

'
SUB About(wnd:window)
'----------------------------------------------------------------------------------------
' Showing messagebox
'----------------------------------------------------------------------------------------
'
def txt0$,txt1$,crlf$:string
crlf$=chr$(10)+chr$(13)
txt0$="      Coded with Creative Basic          "
txt1$="      ENJOY!  "
MESSAGEBOX wnd,txt1$,txt0$,0x40
RETURN


Support Amateur Radio  -  Have a ham  for dinner!