File: lambda.C

package info (click to toggle)
kdegraphics 2%3A980312-3
  • links: PTS
  • area: contrib
  • in suites: hamm
  • size: 6,168 kB
  • ctags: 5,778
  • sloc: ansic: 26,607; cpp: 21,205; sh: 5,224; makefile: 1,651; perl: 108
file content (97 lines) | stat: -rw-r--r-- 2,240 bytes parent folder | download | duplicates (2)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97

    /*

    lambda.C  version 0.1.1

    Copyright (C) 1997 Uwe Thiem   
                       uwe@uwix.alt.na

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

    */


#include <stdio.h>

#include "lambda.h"


#define DEFAULT_X  0.0
#define DEFAULT_Y  0.0
#define DEFAULT_WIDTH 4.0
#define DEFAULT_BAILOUT 4.0


Lambda::Lambda()
  {
  }


void Lambda::init( double center_x, double center_y, 
                  double dx, double dy,
                  int x_max, int y_max,
                  int iter_max, double bail_out,
                  double param_x, double param_y )
  {
  Fract::init( center_x, center_y, dx, dy,
               x_max, y_max, iter_max, bail_out );
  lambda_x = param_x;
  lambda_y = param_y;
  }


int Lambda::calcPoint( int x, int y )
  {
  double r = x_values[x], i = y_values[y]; 
  double r_out = r, i_out = i; 
  double tmp, r2 = r * r, i2 = i * i;
  register int iter = 0;

  while ( ( r2 + i2 < bail ) && ( iter < max_iter ) )
    {
    tmp = 2.0 * r_out * i_out + julia_x;
// This is sort of sneaky because we actually compare the values of the
// last iteration to bailout. But the results are very close to those of
// the correct way and it's significantly faster.
    r_out = ( r2 = r_out * r_out ) - ( i2 = i_out * i_out ) + julia_y;
    i_out = tmp;
    iter++;
    }
  return iter;
  }


double Lambda::defaultCenterX()
  {
  return DEFAULT_X;
  }


double Lambda::defaultCenterY()
  {
  return DEFAULT_Y;
  }


double Lambda::defaultWidth()
  {
  return DEFAULT_WIDTH;
  }


double Lambda::defaultBailout()
  {
  return DEFAULT_BAILOUT;
  }