Ascii art pie chart
JavaScript, 259
d=r*2;M=Math;R=M.round;p=[];for(y=0;y<d;y++){p[y]=[];for(x=0;x<d;x++)p[y][x]=" "}t=0;i=-1;for(f=0;f<1;f+=1/(r*20)){if(f>t)t+=v[++i];a=M.PI*2*f;for(j=0;j<r;j++)p[R(M.sin(a)*j)+r][R(M.cos(a)*j)+r]=k[i]}s="";for(y=0;y<d;y++){for(x=0;x<d;x++)s+=p[y][x];s+="\n";}s
Works in Firefox scratchpad.
First example
Input :
var k = ["#", "+", "$", "X"];
var v = [0.2, 0.4, 0.15, 0.25];
var r = 10;
Output :
$$$XXXX
$$$$$XXXXXX
$$$$$$XXXXXXX
$$$$$$$XXXXXXXX
+$$$$$$$XXXXXXXXX
++$$$$$$XXXXXXXXX
+++++$$$$XXXXXXXXXX
++++++$$$XXXXXXXXXX
+++++++$$XXXXXXXXXX
+++++++++XXXXXXXXXX
++++++++++#########
+++++++++++########
+++++++++++########
++++++++++#######
+++++++++++######
++++++++++#####
+++++++++####
++++++++###
+++++++
Second example :
Input :
var k = ["A", "B", "C" ];
var v = [0.5, 0.25, 0.25];
var r = 5;
Output :
BBCCC
BBBCCCC
BBBBCCCCC
BBBBCCCCC
BBBBCCCCC
AAAAAAAAA
AAAAAAAAA
AAAAAAA
AAAAA
Python: 255 chars - 20% = 204
from math import*
def s(k,v,a):
if not v:return ' '
if a<v[0]:return k[0]
return s(k[1:],v[1:],a-v[0])
def p(k,v,r):
d=range(-r,r)
for y in d:
t=""
for x in d:
if x*x+y*y<r*r:
a=atan2(y,x)/pi/2+.5
t=t+s(k,v,a)
else:t=t+" "
print t
Examples:
>>> pie.p("ABCD", [0.25,0.125,0.125,0.125],8)
AAABBBB
AAAAABBBBBB
AAAAAABBBBBCC
AAAAAABBBBCCC
AAAAAAABBBCCCCC
AAAAAAABBCCCCCC
AAAAAAABCCCCCCC
DDDDDDDD
DDDDDD
DDDDD
DDDD
DD
D
>>>
>>> pie.p(".$!@", [0.3,0.3,0.3,0.1],6)
.....$$
......$$$
......$$$$$
......$$$$$
......$$$$$
@@@@@$$$$$$
@@@@!!!$$$$
@@@!!!!!$$$
@!!!!!!!!!$
!!!!!!!!!
!!!!!!!
>>>