equal
deleted
inserted
replaced
7 import javax.swing.JPanel |
7 import javax.swing.JPanel |
8 import javax.swing.WindowConstants |
8 import javax.swing.WindowConstants |
9 |
9 |
10 // complex numbers |
10 // complex numbers |
11 case class Complex(val a: Double, val b: Double) { |
11 case class Complex(val a: Double, val b: Double) { |
12 // represents the complex number a + b*i |
12 // represents the complex number a + b * i |
13 def +(that: Complex) = Complex(this.a + that.a, this.b + that.b) |
13 def +(that: Complex) = Complex(this.a + that.a, this.b + that.b) |
14 def -(that: Complex) = Complex(this.a - that.a, this.b - that.b) |
14 def -(that: Complex) = Complex(this.a - that.a, this.b - that.b) |
15 def *(that: Complex) = Complex(this.a * that.a - this.b * that.b, |
15 def *(that: Complex) = Complex(this.a * that.a - this.b * that.b, |
16 this.a * that.b + that.a * this.b) |
16 this.a * that.b + that.a * this.b) |
17 def *(that: Double) = Complex(this.a * that, this.b * that) |
17 def *(that: Double) = Complex(this.a * that, this.b * that) |
84 if (it < level && z.abs < 2) iters(z * z + c, it + 1) else |
84 if (it < level && z.abs < 2) iters(z * z + c, it + 1) else |
85 if (it == level) black else colours(it % 16) |
85 if (it == level) black else colours(it % 16) |
86 } |
86 } |
87 |
87 |
88 pixel(x0, y0, iters(Complex(0, 0), 0)) |
88 pixel(x0, y0, iters(Complex(0, 0), 0)) |
89 } |
89 } |
90 viewer.updateUI() |
90 viewer.updateUI() |
91 } |
91 } |
92 } |
92 } |
93 |
93 |
94 // Examples |
94 // Examples |
95 //========== |
95 //========== |
96 |
96 |