Niet al te net, maar ik had dit al:
code:
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
| function loadtxt(filename){
xmlbullsjit = new XML();
xmlbullsjit.onLoad = doafterload;
xmlbullsjit.load(filename);
}
function doafterload(){
values = xmlbullsjit.toString();
_root.values = values.split('|');
make_graph();
}
movieclip.prototype.make_graph = function(){
largeval = 0;
numberof = _root.values.length;
for(a=1; a<=numberof; a++){
nowval = Number(values[a]);
if(nowval>largeval){largeval = nowval};
}
totscale = largeval + ((largeval/100)*10);
xscale = 300/(numberof-1);
yscale = 300/totscale;
miny = 0;
maxy = totscale;
for(b=1; b<=numberof; b++){
newx = ((b-1) * xscale)+25;
newy = (300-(_root.values[b]*yscale))+25;
add_point(newx, newy,_root.values[b]);
if(oldy!=undefined){add_line(oldx, oldy, newx, newy)};
oldx = newx;oldy = newy;
}
}
movieclip.prototype.add_point = function(x,y,value){
_root.cp++;
_root.attachMovie( 'cp', 'cp_'+cp, _root.globd++);
_root['cp_'+cp]._x = x;
_root['cp_'+cp]._y = y;
_root['cp_'+cp].value = value;
}
movieclip.prototype.add_line = function(x1, y1, x2, y2){
line++;
xdist = x2-x1;
ydist = y2-y1;
dist = Math.sqrt((xdist*xdist)+(ydist*ydist));
_root.attachMovie('line', 'l_' + line, _root.globd++);
_root['l_' + line]._x = x1;
_root['l_' + line]._y = y1;
_root['l_' + line]._xscale = dist;
_root['l_' + line]._alpha = 50;
_root['l_' + line]._rotation = rad(Math.atan2(ydist, xdist));
}
movieclip.prototype.rad= function (degrees){
return degrees / Math.PI *180;
}
loadtxt('values.txt'); |
Hij x/y scaled de grafiek afstanden automatisch naar de hoogste waarde, en naar het aantal items.
dit is het txt file wat word ingeladen:
code:
1
| 31|27|69|55|85|87|96|46|34|33|36|9|22|26|87|93|67|17|71|53|28|12|50|22|4|3|67|69|91|6|53|15|60|70|72|51|43|10|55|83 |
Dit dit kan dus elke lengte hebben, maar ik zou hem niet al te groot maken.
De delimiter tussen de values moet dus het pipe symbol zijn.
Zal ff kijken of ik strax tijd heb om de .fla en .swf online te zetten.