Zurück   Flashforum > Flash > ActionScript > ActionScript 1

Antwort
 
LinkBack Themen-Optionen Ansicht
Alt 09-10-2003, 10:25   #1 (permalink)
Pixelschubser
 
Registriert seit: Aug 2002
Ort: Utopia
Beiträge: 416
Question per as linie um ein einfaches viereck ziehen lassen?

Hi, ich habe ein einfaches viereck, darum möchte ich per as eine einfache linie ziehen lassen, wie mach ich so etwas? die linie soll oben anfangen und einmal rumgehen...
__________________
WebDeveloper: enative
LordCash ist offline   Mit Zitat antworten
Alt 09-10-2003, 10:57   #2 (permalink)
Neuer User
 
Registriert seit: Jun 2001
Ort: Zürich
Beiträge: 1.776
z.B. entwickelt von Joemoe u.a. so

ActionScript:
  1. /*    GLOBALE VEKTOR FUNKTIONEN             */
  2.  
  3.  
  4. // Distance 2er Punkte
  5. _global.point_distance = function( pstart_x, pstart_y, phead_x, phead_y )
  6. {
  7.         var pvec_x = phead_x - pstart_x;
  8.         var pvec_y = phead_y - pstart_y;
  9.         var pvec_len = Math.sqrt( Math.pow( pvec_x, 2 ) + Math.pow( pvec_y, 2 ) )
  10.         return pvec_len;
  11. }
  12.  
  13. // NormVektor 2er Punkte
  14. _global.normal_vec = function( start_x, start_y, head_x, head_y )
  15. {
  16.         var vec_x = head_x - start_x;
  17.         var vec_y = head_y - start_y;
  18.         var vec_len = Math.sqrt( Math.pow( vec_x, 2 ) + Math.pow( vec_y, 2 ) )
  19.         var normal_x = vec_x / vec_len;
  20.         var normal_y = vec_y / vec_len;
  21.         return ( { normal_x: normal_x, normal_y: normal_y } );
  22. }
  23.  
  24. //Mal Funktion
  25. function draw_something( cont_mc, name_str, depth,  points_array, steps, line_color, fill_color, x, y )
  26. {
  27.         drawing_mc = cont_mc.createEmptyMovieClip( name + "_mc", depth );
  28.         drawing_mc._x = x;
  29.         drawing_mc._y = y;
  30.         drawing_mc.points_array = points_array;
  31.         drawing_mc.steps = steps;
  32.         drawing_mc.moveTo( points_array[ 0 ][ 0 ], points_array[ 0 ][ 1 ] );
  33.         drawing_mc.offset = 1;
  34.         drawing_mc.faktor = 1;
  35.         drawing_mc.fill_color = fill_color;
  36.         //drawing_mc.beginFill( fill_color, 100 );
  37.         drawing_mc.lineStyle( 1, line_color, 100 );
  38.         drawing_mc.onEnterFrame = function()
  39.         {
  40.                 var last_point_x = this.points_array[ this.offset - 1 ][ 0 ];
  41.                 var last_point_y = this.points_array[ this.offset - 1 ][ 1 ];
  42.                 var next_point_x = this.points_array[ this.offset ][ 0 ];
  43.                 var next_point_y = this.points_array[ this.offset ][ 1 ];
  44.                 var normal = normal_vec( last_point_x, last_point_y, next_point_x, next_point_y );
  45.                 var next_x = last_point_x + normal.normal_x * this.faktor * this.steps;
  46.                 var next_y = last_point_y + normal.normal_y * this.faktor * this.steps;
  47.                 var dist_crea = point_distance( last_point_x, last_point_y, next_x, next_y ) ;
  48.                 var dist_point = point_distance( last_point_x, last_point_y, next_point_x, next_point_y );
  49.                 if( dist_crea < dist_point )
  50.                 {
  51.                         this.faktor++;
  52.                 }
  53.                 else
  54.                 {
  55.                         this.offset++;
  56.                         this.faktor = 1;
  57.                         next_x = next_point_x;
  58.                         next_y = next_point_y;
  59.                 }
  60.                
  61.                 this.lineTo( next_x, next_y );
  62.                
  63.                 if( this.offset == this.points_array.length )
  64.                 {
  65.                         //this.endFill();
  66.                         this.moveTo( this.points_array[ 0 ][ 0 ], this.points_array[ 0 ][ 1 ] );
  67.                         this.beginFill( this.fill_color, 100 );
  68.                         for( var i = 1; i < this.points_array.length; i++ )
  69.                         {
  70.                                 this.lineTo( this.points_array[ i ][ 0 ], this.points_array[ i ][ 1 ] );
  71.                         }
  72.                         this.endFill();
  73.                         delete this.onEnterFrame;
  74.                 }
  75.         }
  76. }
  77.  
  78.  
  79. //TestGerät
  80. p_array = new Array();
  81. for( var i = 0; i < 20; i++ )
  82. {
  83.         var actual_angle = 2 * Math.PI / 20 * i;
  84.         var radius = ( i % 2 == 0 ) ? 100 : 20;
  85.         var new_x = Math.cos( actual_angle ) * radius;
  86.         var new_y = Math.sin( actual_angle ) * radius;
  87.         p_array.push( [ new_x, new_y ] );
  88. }
  89. p_array[ p_array.length ] = p_array[ 0 ];
  90.  
  91.  
  92. //malen
  93. draw_something( this, "test", 10,  p_array, 1, 0xFF0000, 0x0000FF, 200, 200 );

in dem o.g. thread stehen auch einfachere lösungen z.B. für rechtecke...
fresh ist offline   Mit Zitat antworten
Alt 09-10-2003, 11:10   #3 (permalink)
Pixelschubser
 
Registriert seit: Aug 2002
Ort: Utopia
Beiträge: 416
Thumbs up

danke, damit kann ich was anfangen...
__________________
WebDeveloper: enative
LordCash ist offline   Mit Zitat antworten
Antwort

Lesezeichen

Themen-Optionen
Ansicht

Forumregeln
Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks sind an
Pingbacks sind an
Refbacks sind an



Alle Zeitangaben in WEZ +1. Es ist jetzt 00:27 Uhr.

Domains, Webhosting & Vserver von Host Europe
Unterstützt das Flashforum!
Adobe User Group


Copyright ©1999 – 2012 Marc Thiele