/* GLOBALE VEKTOR FUNKTIONEN */
// Distance 2er Punkte
_global.point_distance = function( pstart_x, pstart_y, phead_x, phead_y )
{
var pvec_x = phead_x - pstart_x;
var pvec_y = phead_y - pstart_y;
var pvec_len = Math.sqrt( Math.pow( pvec_x, 2 ) + Math.pow( pvec_y, 2 ) )
return pvec_len;
}
// NormVektor 2er Punkte
_global.normal_vec = function( start_x, start_y, head_x, head_y )
{
var vec_x = head_x - start_x;
var vec_y = head_y - start_y;
var vec_len = Math.sqrt( Math.pow( vec_x, 2 ) + Math.pow( vec_y, 2 ) )
var normal_x = vec_x / vec_len;
var normal_y = vec_y / vec_len;
return ( { normal_x: normal_x, normal_y: normal_y } );
}
//Mal Funktion
function draw_something( cont_mc, name_str, depth, points_array, steps, line_color, fill_color, x, y )
{
drawing_mc = cont_mc.createEmptyMovieClip( name + "_mc", depth );
drawing_mc._x = x;
drawing_mc._y = y;
drawing_mc.points_array = points_array;
drawing_mc.steps = steps;
drawing_mc.moveTo( points_array[ 0 ][ 0 ], points_array[ 0 ][ 1 ] );
drawing_mc.offset = 1;
drawing_mc.faktor = 1;
drawing_mc.fill_color = fill_color;
//drawing_mc.beginFill( fill_color, 100 );
drawing_mc.lineStyle( 1, line_color, 100 );
drawing_mc.onEnterFrame = function()
{
var last_point_x = this.points_array[ this.offset - 1 ][ 0 ];
var last_point_y = this.points_array[ this.offset - 1 ][ 1 ];
var next_point_x = this.points_array[ this.offset ][ 0 ];
var next_point_y = this.points_array[ this.offset ][ 1 ];
var normal = normal_vec( last_point_x, last_point_y, next_point_x, next_point_y );
var next_x = last_point_x + normal.normal_x * this.faktor * this.steps;
var next_y = last_point_y + normal.normal_y * this.faktor * this.steps;
var dist_crea = point_distance( last_point_x, last_point_y, next_x, next_y ) ;
var dist_point = point_distance( last_point_x, last_point_y, next_point_x, next_point_y );
if( dist_crea < dist_point )
{
this.faktor++;
}
else
{
this.offset++;
this.faktor = 1;
next_x = next_point_x;
next_y = next_point_y;
}
this.lineTo( next_x, next_y );
if( this.offset == this.points_array.length )
{
//this.endFill();
this.moveTo( this.points_array[ 0 ][ 0 ], this.points_array[ 0 ][ 1 ] );
this.beginFill( this.fill_color, 100 );
for( var i = 1; i < this.points_array.length; i++ )
{
this.lineTo( this.points_array[ i ][ 0 ], this.points_array[ i ][ 1 ] );
}
this.endFill();
delete this.onEnterFrame;
}
}
}
//TestGerät
p_array = new Array();
for( var i = 0; i < 20; i++ )
{
var actual_angle = 2 * Math.PI / 20 * i;
var radius = ( i % 2 == 0 ) ? 100 : 20;
var new_x = Math.cos( actual_angle ) * radius;
var new_y = Math.sin( actual_angle ) * radius;
p_array.push( [ new_x, new_y ] );
}
p_array[ p_array.length ] = p_array[ 0 ];
//malen
draw_something( this, "test", 10, p_array, 1, 0xFF0000, 0x0000FF, 200, 200 );