"Real software engineers work from 9 to 5, because that is the way the job is described in the formal spec. Working late would feel like using an undocumented external procedure."
'E's fighting in there!' he stuttered, grabbing the captain's arm.
'All by himself?' said the captain.
'No, with everyone!' shouted Nobby, hopping from one foot to the other.
Ken Thompson's famous line from V6 UNIX is equaly applicable to this post:
'You are not expected to understand this'
Daar heb je gelijk in. De reden was dat ik dan zowel de taartpunten als de lijntjes in 1 loop kon tekenen. Ik heb er niet bij stil gestaan dat de volgende taartpunt dan een lijntje zal overlappen. Ik genereer voor het eerst plaatjes mbv PHP en moet nog wat wennen aan het feit dat een plaatje, net als bij PhotoShop, uit layers bestaat die boven elkaar liggen...-NMe- schreef op zondag 30 oktober 2005 @ 22:21:
[...] Waarom teken je de lijntjes niet als laatste in plaats van tussendoor? Zoals je het nu doet loop je de kans dat de volgende taartpunt je lijn overschrijft.
Het is een script dat duidelijk in ontwikkeling is
"Real software engineers work from 9 to 5, because that is the way the job is described in the formal spec. Working late would feel like using an undocumented external procedure."
Voor een cirkel met middelpunt O (0,0)
1
2
| { x= r cos a
{ y= r sin a |
Als je dit gaat opschuiven met offset x1 en offset y1 krijg je:
1
2
| { x= r cos a + x1
{ y= r sin a + y1 |
Alle punten met coördinaten (x,y) voor een bepaalde a (hoek) behoren tot de cirkel en je middelpunt is gegeven door beide offsets namelijk (x1,y1)
Zijn je X-en Y-offset ($hoofd['Xas'] en $hoofd['Yas']) identiek, want daar zit je probleem. Jouw code is wiskundig te schrijven als:
1
2
| { x = x1 + x1 cos a
{ y = y1 + y1 sin a |
Deze parametervergelijking is van de vorm:
1
2
| { x = a cos t + x1
{ y = b sin t +y1 |
Zoals je misschien wel weet, geeft dat een ellips (b is maximale uitwijking op y-as, a op de x-as).
In jouw geval zou ik gewoon een extra variabele r invoeren om het makkelijker te maken. Eventueel kun je dat gelijkstellen met één van beide offsets.
In je code geeft dat:
1
2
3
4
| $end_x = round($hoofd['Xas'] + ($hoofd['straal'] * cos($input[$a][4] * pi() / 180))); $end_y = round($hoofd['Yas'] + ($hoofd['straal'] * sin($input[$a][4] * pi() / 180))); imageline($img, $hoofd['Xas'], $hoofd['Yas'], $end_x, $end_y, $black); |
Ken Thompson's famous line from V6 UNIX is equaly applicable to this post:
'You are not expected to understand this'
Verwijderd
Dit is een volledige library om grafieken te tekenen.
Blijkbaar had je nog wat extra offsets hier en daar ingevoerd, ik zouy je dus aanraden om die ook in je variabelen te verwerken, zodat je niet overal +10 moet tellen bij de Y-waarden.
In je huidige code moet het onderstaande het juiste resultaat geven:
1
2
3
4
| $end_x = $hoofd['Xas'] + ($conf['diameter']/2 * cos($input[$a][4] * pi() / 180)); $end_y = $hoofd['Yas']+10 + ($conf['diameter']/2 * sin($input[$a][4] * pi() / 180)); imageline($img, $hoofd['Xas'], $hoofd['Yas']+10, $end_x, $end_y, $black); |
Het enige probleem zoals anderen al gezegd hebben: je lijntjes verdwijnen soms onder de gekleurde vlakken. Je zal dus het meeste halen uit een complete rewrite van je code, denk ik; probeer alles wat overzichtelijk te houden (je offset in variablen verwerken, eventueel ook in je input-array betere namen kiezen (1e index als echte index, 2e index in plaats van getallen gewoon benamingen voor de duidelijkheid zodat je de commentaar kunt laten vallen bij de declaratie) en zorg dat je afzonderlijke lussen maakt: 1e lus vlakken vullen, 2e lus lijnen tekenen.
"Real software engineers work from 9 to 5, because that is the way the job is described in the formal spec. Working late would feel like using an undocumented external procedure."
- code verkorten
- breedte van de legenda automatisch berekenen adhv langste titel
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
| function stats_pie($titel, $input, $imagename) { $pie['diameter'] = 170; $pie['legenda'] = 280; $pie['centerx'] = ($pie['diameter'] / 2) + 10; $pie['centery'] = ($pie['diameter'] / 2) + 40; $pie['colors'] = array('#7AC5CD','#66CD00','#EEB422', '#458B00', '#EEC591'); $pie['dotx'] = $pie['diameter'] + 50; $pie['titel'] = $titel; $img = imagecreate($pie['diameter'] + $pie['legenda'], ($pie['centery'] * 2) - 20); $bg = imagecolorallocate($img, 255, 255, 255); $black = imagecolorallocate($img, 0, 0, 0); $copyrt = imagecolorallocate($img, 180, 180, 180); for ($a = 0; $a < count($input); $a++) { preg_match('/(#)*([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})/', $pie['colors'][$a], $hex); $pie['colors'][$a] = imagecolorallocate($img, hexdec($hex[2]), hexdec($hex[3]), hexdec($hex[4])); } $pie['total'] = 0; for ($a = 0; $a < count($input); $a++) { $pie['total'] += $input[$a][0]; } for ($a = 0; $a < count($input); $a++) { $input[$a][2] = (($input[$a][0] / $pie['total']) * 360); $previous = ($a > 0) ? $input[$a-1][4] : 0; $input[$a][3] = $previous; $input[$a][4] = $input[$a][2] + $previous; $input[$a][5] = round((100 / $pie['total']) * $input[$a][0], 1); } imagestring($img, 3, ((($pie['diameter'] + $pie['legenda']) - (strlen($pie['titel']) * 7)) / 2), 10, $pie['titel'], $black); for ($a = 0; $a < count($input); $a++) { imagefilledarc($img, $pie['centerx'], $pie['centery'], $pie['diameter'], $pie['diameter'], $input[$a][3], $input[$a][4], $pie['colors'][$a], IMG_ARC_PIE); } for ($a = 0; $a < count($input); $a++) { $end_x = $pie['centerx'] + ($pie['diameter'] / 2 * cos($input[$a][4] * pi() / 180)); $end_y = $pie['centery'] + ($pie['diameter'] / 2 * sin($input[$a][4] * pi() / 180)); imageline($img, $pie['centerx'], $pie['centery'], $end_x, $end_y, $black); } imagearc($img, $pie['centerx'], $pie['centery'], $pie['diameter'], $pie['diameter'], 0, 360, $black); for ($a = 0; $a < count($input); $a++) { imagefilledrectangle($img, $pie['dotx'], ($a * 20) + 40, $pie['dotx'] + 10, ($a * 20) + 50, $pie['colors'][$a]); imagerectangle($img, $pie['dotx'], ($a * 20) + 40, $pie['dotx'] + 10, ($a * 20) + 50, $black); imagestring($img, 3, $pie['dotx'] + 15, ($a * 20) + 40, $input[$a][1].' ('.$input[$a][5].' %)', $black); } imagerectangle($img, 0, 0, $pie['diameter'] + $pie['legenda'] - 1, ($pie['centery'] * 2) - 21, $black); $insert = imagecreatefromgif(BASE_PATH.'system/images/stats/logo.gif'); $insert_x = imagesx($insert); $insert_y = imagesy($insert); imagecopymerge($img, $insert, ($pie['diameter'] + $pie['legenda'] - ($insert_x + 10)), ($pie['centery'] * 2) - 52, 0, 0, $insert_x, $insert_y, 100); imagestring($img, 2, ($pie['diameter'] + $pie['legenda'] - ($insert_x + 70)), ($pie['centery'] * 2) - 55, 'copyright', $copyrt); imagestring($img, 2, ($pie['diameter'] + $pie['legenda'] - ($insert_x + 82)), ($pie['centery'] * 2) - 40, 'Reveller 2006', $copyrt); imagepng($img, BASE_PATH.'system/images/stats/'.$imagename.'.png'); imagedestroy($img); return 'chart.png'; } |
[ Voor 28% gewijzigd door Reveller op 02-11-2005 22:21 ]
"Real software engineers work from 9 to 5, because that is the way the job is described in the formal spec. Working late would feel like using an undocumented external procedure."
mm je code is wazig.. je maakt je img dynamisch, maar returned een static naam
[ Voor 25% gewijzigd door BasieP op 02-11-2005 22:29 ]
This message was sent on 100% recyclable electrons.

