Mathematicals and AS3 = Biomorphs

A biomorph is a shape resembling that of a living organism (such as bacteria), though not necessarily of biotic origin. It is created with Mathematicals functions, such as fractal.
Based on the work of C. Pickover, I have made a computer program with AS3 that you can try below. I used the as3mathlib because of Complex Numbers.

Biomorphs – the computing time could be long, wait a moment.

Here is a part of the code. All comments are welcome 🙂

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
private function calculate():void {
 
  var r:Number = 0;
  var n:uint;
 
  for (var abs:Number = -3; abs < 3; abs += 0.01) {
 
    for (var ord:Number = -2.5; ord < 2.5; ord += 0.01) {
 
    n = 0;
    r = 0;
 
    z  = new Complex(abs, ord);
 
      while ((n < 11) && (r < 10)) {
 
      z = f(z, A, B, C, D, E, F, G);
      r = Complex.modulo(z);
 
      if ((n == 10) || (r > 10)) {
 
        putPixels(Complex.abs(z), abs, ord);
      }
      n++;
      }
    }
  }
  showBitmap();
}
 
private function f(z:Complex, A:Complex, B:Complex, C:Complex, D:Complex, E:Complex, F:Complex, G:Complex):Complex {
 
  var i:Complex = new Complex(0, 1);
 
  var inter1:Complex = Complex.adds(Complex.power(z, A), B);
  var inter2:Complex = Complex.adds(Complex.mult(C, i), Complex.mult(D, Complex.cos(z)));
  var inter3:Complex = Complex.adds(Complex.mult(E, Complex.sin(z)), Complex.mult(F, Complex.exp(z)));
  var inter4:Complex = Complex.mult(G, Complex.exp(z));
 
  return Complex.adds(Complex.adds(inter1, inter2), Complex.adds(inter3, inter4));
}
 
private function putPixels(h:Complex, abs:Number, ord:Number):void {
 
  abs = Math.round((abs + 3) * 100);
  ord = Math.round((ord + 2.5) * 100);
 
  var biomorphe:Number = Complex.norm(h) / 2;
 
  if (biomorphe > 1500000) {
    monBitmap.setPixel(abs, ord, 0xFFFFFF);
  } else if (biomorphe > 15000) {
  monBitmap.setPixel(abs, ord, 0x0099CC);
  } else if (biomorphe > 150) {
  monBitmap.setPixel(abs, ord, 0x993333);
  } else {
  monBitmap.setPixel(abs, ord, 0xFFFF00);
  }
}

1 thought on “Mathematicals and AS3 = Biomorphs

Leave a Reply

Your email address will not be published. Required fields are marked *