Zurück   Flashforum > Flash > ActionScript > Softwarearchitektur und Entwurfsmuster

Antwort
 
LinkBack Themen-Optionen Ansicht
Alt 21-03-2003, 22:34   #1 (permalink)
ohnitsch
 
Registriert seit: Oct 2002
Ort: Wien
Beiträge: 42
fraktal

eine kleine modifizierte kochkurve von mir:

hauptfilm:

ActionScript:
  1. #include "Turtle.mx"
  2. paint = function () {
  3.     t = new Turtle(_root.createEmptyMovieClip("container", 0), 100,200);
  4.     kochkurve(t,1000, 5);
  5. };
  6. kochkurve = function (t, strecke, ebene) {
  7.     if (ebene>0) {
  8.         kochkurve(t, strecke/3, ebene-1);
  9.         t.rt(80);
  10.         kochkurve(t, strecke/3, ebene-1);
  11.         t.rt(-160);
  12.         kochkurve(t, strecke/3, ebene-1);
  13.         t.rt(80);
  14.         kochkurve(t, strecke/3, ebene-1);
  15.     } else {
  16.         t.fd(strecke);
  17.     }
  18. };
  19. paint();

Turtle.mx:

ActionScript:
  1. Turtle = function (ct, x, y) {
  2.     this.c = ct;
  3.     this.c.lineStyle(1, 0x000000, 100);
  4.     this.x = x;
  5.     this.y = y;
  6.     this.alpha = 0;
  7. };
  8. Turtle.prototype.fd = function(strecke) {
  9.     this.aa = this.alpha*Math.PI/180;
  10.     this.dx = strecke*Math.cos(this.aa);
  11.     this.dy = strecke*Math.sin(this.aa);
  12.     this.c.moveTo(this.x, this.y);
  13.     this.c.lineTo(this.x+this.dx, this.y+this.dy);
  14.     this.x += this.dx;
  15.     this.y += this.dy;
  16. };
  17. Turtle.prototype.rt = function(winkel) {
  18.     this.alpha = this.alpha-winkel;
  19. };

direkt von java geportet, hab nicht viel verändern müssen

Geändert von Klesk (22-03-2003 um 18:04 Uhr)
Klesk ist offline   Mit Zitat antworten
Alt 21-03-2003, 22:56   #2 (permalink)
helpQLODhelp
 
Benutzerbild von bokel
 
Registriert seit: Feb 2002
Ort: Köln
Beiträge: 8.505
Sehr schön,

ich mag vor allem den diskreten Aufbau der Turtle.
Die kann man ja für alles Mögliche gebrauchen.
Ich habe den Thread gleich mal in die Liste der
Algorithmen und Datenstukturen aufgenommen

mfg r.
bokel ist offline   Mit Zitat antworten
Alt 22-03-2003, 17:50   #3 (permalink)
ohnitsch
 
Registriert seit: Oct 2002
Ort: Wien
Beiträge: 42
hier ein menger schwamm, wieder gleich aus java geportet

ActionScript:
  1. MovieClip.prototype.drawRect = function(x, y, x1, y1) {
  2.     this.beginFill(0x000000, 100);
  3.     this.moveTo(x, y);
  4.     this.lineTo(x+x1, y);
  5.     this.lineTo(x+x1, y+y1);
  6.     this.lineTo(x, y+y1);
  7.     this.lineTo(x,y);
  8.     this.endFill();
  9. };
  10. function paint() {
  11.     mengers(_root.createEmptyMovieClip("container", 0), 240, 240, 240);
  12. }
  13. function mengers(ct, c, x, y) {
  14.     if (c>7) {
  15.         mengers(ct, c/3, x-2*c/3, y-2*c/3);
  16.         mengers(ct, c/3, x, y-2*c/3);
  17.         mengers(ct, c/3, x+2*c/3, y-2*c/3);
  18.         mengers(ct, c/3, x-2*c/3, y);
  19.         mengers(ct, c/3, x+2*c/3, y);
  20.         mengers(ct, c/3, x-2*c/3, y+2*c/3);
  21.         mengers(ct, c/3, x, y+2*c/3);
  22.         mengers(ct, c/3, x+2*c/3, y+2*c/3);
  23.     } else {
  24.         ct.drawRect((x+c), (y+c), (2*c), (2*c));
  25.     }
  26. }
  27. paint();
Klesk ist offline   Mit Zitat antworten
Alt 22-03-2003, 18:03   #4 (permalink)
ohnitsch
 
Registriert seit: Oct 2002
Ort: Wien
Beiträge: 42
mal wieder was mit turtle...

ActionScript:
  1. #include "Turtle.mx"
  2. paint = function () {
  3.     t = new Turtle(_root.createEmptyMovieClip("container", 0), 300, 300);
  4.     t.rt(80);
  5.     fbaum(t, 200, 52, 12);
  6. };
  7. function fbaum(t, stamm, winkel, ebene) {
  8.     if (ebene>0) {
  9.         t.fd(stamm);
  10.         t.rt(winkel+15);
  11.         fbaum(t, stamm/1.3, winkel, ebene-1);
  12.         t.rt(-2*winkel-15);
  13.         fbaum(t, stamm/2, winkel, ebene-1);
  14.         t.rt(winkel);
  15.         t.fd(-stamm);
  16.     }
  17. }
  18. paint();
Klesk ist offline   Mit Zitat antworten
Alt 22-03-2003, 19:32   #5 (permalink)
Neuer User
 
Benutzerbild von v0id
 
Registriert seit: Oct 2002
Ort: München
Beiträge: 1.582
Thumbs up

find ich sseeeeeehr schön
v0id ist offline   Mit Zitat antworten
Alt 22-03-2003, 21:34   #6 (permalink)
muh
 
Benutzerbild von Janoscharlipp
 
Registriert seit: Apr 2002
Ort: Freiburg / Stuttgart
Beiträge: 4.338
da hab ich doch gestern auch was dazu gebaut:

ActionScript:
  1. MovieClip.prototype.drawFourangle = function(x1, y1, x2, y2, x3, y3, x4, y4, bThick, bClr, bAlpha, f, fClr, fAlpha){
  2.     this.lineStyle( bThick, bClr, bAlpha);
  3.     if(f) this.beginFill( fClr, fAlpha);
  4.     this.moveTo(x1, y1);
  5.     this.lineTo(x2, y2);
  6.     this.lineTo(x3, y3);
  7.     this.lineTo(x4, y4);
  8.     this.lineTo(x1, y1);
  9.     if(f) this.endFill();
  10. }
  11.  
  12. MovieClip.prototype.drawTriangle = function(x1, y1, x2, y2, x3, y3, bThick, bClr, bAlpha, f, fClr, fAlpha){
  13.     this.lineStyle( bThick, bClr, bAlpha);
  14.     if(f) this.beginFill( fClr, fAlpha);
  15.     this.moveTo(x1, y1);
  16.     this.lineTo(x2, y2);
  17.     this.lineTo(x3, y3);
  18.     this.lineTo(x1, y1);
  19.     if(f) this.endFill();
  20. }
  21.  
  22. _global.pi = Math.PI;
  23. _global.piDiv8 = pi/8;
  24. _global.piDiv2 = pi/2;
  25. _global.tan22 = Math.tan(piDiv8);
  26. _global.i = 0;
  27.  
  28. _root.createEmptyMovieClip("m", 1);
  29. function drawNextTriangle(d, x1, y1, x2, y2){
  30.     var xDif = x2-x1,
  31.         yDif = y1-y2,
  32.         bottomLength = Math.sqrt(xDif*xDif+yDif*yDif),
  33.         bottomGradiant = Math.atan2(yDif, xDif),
  34.         stangLength = tan22*bottomLength/2,
  35.         hypoLength = Math.sqrt(stangLength*stangLength+(BottomLength/2)*(bottomLength/2)),
  36.         peakPositionX = x1+Math.cos(bottomGradiant+piDiv8)*hypoLength,
  37.         peakPositionY = y1-Math.sin(bottomGradiant+piDiv8)*hypoLength,
  38.         c1 = Math.round(d*1.5),
  39.         c2 = 9-d;
  40.        
  41.     m.drawTriangle(x1, y1, peakPositionX, peakPositionY, x2, y2, 1, 0xFFFFFF, 100, true, "0x"+c1+""+c1+"00"+c2+""+c2, 100);
  42.     if(d){
  43.         drawNextFourangle(d-1, x1, y1, peakPositionX, peakPositionY);
  44.         drawNextFourangle(d-1, peakPositionX, peakPositionY, x2, y2);
  45.     }else{
  46.         trace(++i);
  47.     }
  48. }
  49.  
  50. function drawNextFourangle(d, x1, y1, x2, y2){
  51.     var xDif = x2-x1,
  52.         yDif = y1-y2,
  53.         bottomLength = Math.sqrt(xDif*xDif+yDif*yDif),
  54.         bottomGradiant = Math.atan2(yDif, xDif),
  55.         newX = Math.cos(bottomGradiant+piDiv2)*bottomLength,
  56.         newY = Math.sin(bottomGradiant+piDiv2)*bottomLength,
  57.         c1 = Math.round(d*1.5),
  58.         c2 = 9-d;
  59.    
  60.     m.drawFourangle(x1, y1, x1+newX, y1-newY, x2+newX, y2-newY, x2, y2, 1, 0xFFFFFF, 100, true, "0x"+c1+""+c1+"00"+c2+""+c2, 100);
  61.    
  62.     drawNextTriangle(d, x1+newX, y1-newY, x2+newX, y2-newY);
  63. }   
  64.  
  65. m.drawFourangle(350, 250, 450, 250, 450, 350, 350, 350, 1, 0xFFFFFF, 100, true, 0xCC0000, 100);
  66. drawNextTriangle(6, 350, 250, 450, 250);
  67. drawNextTriangle(6, 350, 350, 350, 250);
  68. drawNextTriangle(6, 450, 250, 450, 350);
  69. drawNextTriangle(6, 450, 350, 350, 350);
Janoscharlipp ist offline   Mit Zitat antworten
Alt 22-03-2003, 21:48   #7 (permalink)
ohnitsch
 
Registriert seit: Oct 2002
Ort: Wien
Beiträge: 42
das kenn ich, sag bloß du bist lordmort von piranho
Klesk ist offline   Mit Zitat antworten
Alt 23-03-2003, 10:33   #8 (permalink)
muh
 
Benutzerbild von Janoscharlipp
 
Registriert seit: Apr 2002
Ort: Freiburg / Stuttgart
Beiträge: 4.338
sag bloß

hatten wir das nicht schonmal?
man muss sich doch ein bissel bekannt machen
Janoscharlipp ist offline   Mit Zitat antworten
Alt 24-03-2003, 18:56   #9 (permalink)
muh
 
Benutzerbild von Janoscharlipp
 
Registriert seit: Apr 2002
Ort: Freiburg / Stuttgart
Beiträge: 4.338
hier nochmal was fraktal artiges, nur wird die fraktilität (???) duch random zerstört...

ActionScript:
  1. _root.createEmptyMovieClip("m", 1);
  2. size = 10;
  3. function drawLine(d, x1, y1, x2, y2, t){
  4.     m.lineStyle(d+1, 0x999999, 100);
  5.     m.moveTo(x1, y1);
  6.     m.lineTo(x2, y2);
  7.    
  8.     if(d){
  9.         drawLine(d-1, x2, y2, d*size*Math.cos(Math.random()*Math.PI)+x2, -d*size*Math.sin(Math.random()*Math.PI)+y2, t);
  10.         drawLine(d-1, x2, y2, d*size*Math.cos(Math.random()*Math.PI)+x2, -d*size*Math.sin(Math.random()*Math.PI)+y2, t);
  11.     }
  12. }
  13. drawLine(9, 400, 600, 400, 500, 10);
Janoscharlipp ist offline   Mit Zitat antworten
Alt 29-05-2003, 11:28   #10 (permalink)
helpQLODhelp
 
Benutzerbild von bokel
 
Registriert seit: Feb 2002
Ort: Köln
Beiträge: 8.505
Apropos Turtle:

Hat schon mal jemand eine Engine für L (indenmayer) - Systeme gebaut ? In der ct 11/03 wird beschrieben, wie man damit Pflanzenbilder generieren kann.

mfg r.
bokel ist offline   Mit Zitat antworten
Alt 29-05-2003, 14:10   #11 (permalink)
muh
 
Benutzerbild von Janoscharlipp
 
Registriert seit: Apr 2002
Ort: Freiburg / Stuttgart
Beiträge: 4.338
kann man den Artikel irgendwo lesen?? ich finde ihn nicht
Janoscharlipp ist offline   Mit Zitat antworten
Alt 29-05-2003, 14:38   #12 (permalink)
helpQLODhelp
 
Benutzerbild von bokel
 
Registriert seit: Feb 2002
Ort: Köln
Beiträge: 8.505
Auf Seite 202 in ct 11/03 unter der Überschrift Bildschirmbegrünung

mfg r.
bokel 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 15:27 Uhr.

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


Copyright ©1999 – 2012 Marc Thiele