Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Complex {
- constructor(x, y) {
- this.x = x;
- this.y = y;
- }
- /** Return the multiplication of this and another complex num */
- mul(other) {
- return new Complex(other.x * this.x - other.y * this.y,
- other.x * this.y + other.y * this.x);
- }
- add(other) {
- return new Complex(other.x + this.x, other.y + this.y);
- }
- len_2() {
- return this.x * this.x + this.y * this.y;
- }
- }
- function mandel(c) {
- let iter = function(z) {
- return (z.mul(z)).add(c);
- };
- let z = new Complex(0, 0);
- for (let ii = 0; ii < 100000; ++ii) {
- z = iter(z);
- if (z.len_2() > 4) {
- return ii;
- }
- }
- return -1;
- }
- let start = (new Date()).getTime();
- let values = [];
- for (let ii = 0; ii < 100; ++ii) {
- values.push([]);
- for (let jj = 0; jj < 100; ++jj) {
- let c = new Complex(ii / 20, jj / 20);
- values[values.length - 1].push(mandel(c));
- }
- }
- let end = (new Date()).getTime();
- console.log("Result: " + values);
- console.log("Time taken (millis): " + (end - start));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement