aboutsummaryrefslogtreecommitdiff
path: root/Week15 Mandelbrot/src/com/camilstaps/mandelbrot/FractalModel.java
blob: dd091006a4df746dfe7444378ba5d46de58c8786 (plain) (blame)
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
 * The MIT License (MIT)
 * 
 * Copyright (c) 2015 Camil Staps <info@camilstaps.nl>
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
package com.camilstaps.mandelbrot;

import java.util.Observable;

/**
 *
 * @author camilstaps
 */
public class FractalModel extends Observable {
    
    private double start_x, start_y, end_x, end_y;
    
    public FractalModel() {
        start_x = -1;
        end_x = 1;
        start_y = -1;
        end_y = 1;
    }
    
    public int getMandelNumber(MandelbrotFractal.Point p, int repetitions) {
        return MandelbrotFractal.mandelNumber(p, repetitions);
    }
    
    public int getMandelNumber(double x, double y, int repetitions) {
        return MandelbrotFractal.mandelNumber(x, y, repetitions);
    }
    
    public double getStartX() {
        return start_x;
    }
    
    public double getStartY() {
        return start_y;
    }
    
    public double getEndX() {
        return end_x;
    }
    
    public double getEndY() {
        return end_y;
    }
    
    public synchronized void setBorders(double start_x, double end_x, double start_y, double end_y) {
        if (start_x == this.start_x && end_x == this.end_x && start_y == this.start_y && end_y == this.end_y)
            return;
        
        this.start_x = start_x;
        this.end_x = end_x;
        this.start_y = start_y;
        this.end_y = end_y;
        
        setChanged();
        notifyObservers();
    }
    
    public synchronized void setStartX(double x) {
        if (start_x == x)
            return;
        
        start_x = x;
        setChanged();
        notifyObservers();
    }
    
    public synchronized void setStartY(double y) {
        if (start_y == y)
            return;
        
        start_y = y;
        setChanged();
        notifyObservers();
    }
    
    public synchronized void setEndX(double x) {
        if (end_x == x)
            return;
        
        end_x = x;
        setChanged();
        notifyObservers();
    }
    
    public synchronized void setEndY(double y) {
        if (end_y == y)
            return;
        
        end_y = y;
        setChanged();
        notifyObservers();
    }
    
}