Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Help- Turing Pie Chart
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
konrbear




PostPosted: Wed Apr 23, 2014 7:54 pm   Post subject: Help- Turing Pie Chart

What is it you are trying to achieve?
Need to create a piechart with users inputs.


What is the problem you are having?
Cant seem to figure out how to get the users inputs into the arcs degree.


Describe what you have tried to solve this problem
I've tried changing the type (int-real). Rewriting some of the code.

Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)


Turing:

var x : int := 10
var x2 : int := 30
var legendY : int := 305
var legendY2 : int := 315
var pieColor : int := 1
var catorgory, dataName : string
var names : array 1 .. 5 of string
var data : array 1 .. 5 of real

var endDegree : real

%Input
put "Please enter the bar graph catorgory.(Ie. Favourite Foods)"
get catorgory : *
cls
put "Please enter the bar graph data name. (Ie. Number of People)"
get dataName : *
cls

for i : 1 .. 5
    put "Please enter ", catorgory, " names."
    get names (i)
    put "Please enter the ", dataName, " for ", names (i)
    get data (i)
    cls
end for

%Output
put "" : 127, "Legend"
put "" : 120, catorgory : 20, dataName
for i : 1 .. 5
    put "" : 120, names (i) : 20, data (i)

    drawfillbox (300, legendY, 310, legendY2, i)
    legendY := legendY - 30
    legendY2 := legendY2 - 30
end for

for i : 1 .. 5
    %drawfillarc (x,y,xRadius,yRadius,intAngle,FinAngle, pieColor)
    endDegree:=data (i) * 3.6
    drawfillarc (150,100,100,100,0,endDegree, pieColor)

    pieColor := pieColor + 1
    x := x + 30
    x2 := x2 + 30
end for


Please specify what version of Turing you are using
Version 4.1.1
Sponsor
Sponsor
Sponsor
sponsor
DemonWasp




PostPosted: Wed Apr 23, 2014 11:57 pm   Post subject: RE:Help- Turing Pie Chart

Use the round, floor, or ceil functions to convert from a floating-point number (like 1.35) to integers (which are needed for drawfillarc).
evildaddy911




PostPosted: Thu Apr 24, 2014 9:12 pm   Post subject: RE:Help- Turing Pie Chart

once you solve the real-int type miss-match issue, youll notice that it doesnt form a full circle.
So lets go over the math of the pie chart. first you need to get each piece as a percentage of the whole. then you need convert each decimal into degrees. after that, you draw each angle starting at the endpoint of the previous angle.
1. the whole is quite simply the sum of each element in the data array, then % = data(i) / whole
2. to convert into degrees, you simply multiply the value you got by 360
3. heres the tricky part. you have to draw each angle with the first angle being the end angle of the previous piece. i suggest drawing your arc from prev_angle to prev_angle + angle (i)
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: