-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCollageApplication.java
66 lines (50 loc) · 2.25 KB
/
CollageApplication.java
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
package collage;
// ______ __ __ __ __
///\ ___\ /\ \/\ \ /\_\_\_\
//\ \ \____\ \ \_\ \\/_/\_\/_
// \ \_____\\ \_____\ /\_\/\_\
// \/_____/ \/_____/ \/_/\/_/
import javafx.application.*;
import javafx.scene.*;
import javafx.scene.image.*;
import javafx.scene.layout.*;
import javafx.scene.paint.*;
import javafx.stage.*;
public class CollageApplication extends Application {
@Override
public void start(Stage stage) {
Image sourceImage = new Image("file:monalisa.png");
PixelReader imageReader = sourceImage.getPixelReader();
int width = (int) sourceImage.getWidth();
int height = (int) sourceImage.getHeight();
WritableImage targetImage = new WritableImage(width, height);
PixelWriter imageWriter = targetImage.getPixelWriter();
for (int y = 0; y < height; y += 2) { //solo funciona si haces y += 2
for (int x = 0; x < width; x += 2) { //no funciona si haces x++
Color color = imageReader.getColor(x, y);
double red = 1.0 - color.getRed();
double green = 1.0 - color.getGreen();
double blue = 1.0 - color.getBlue();
double opacity = color.getOpacity();
Color newColor = new Color(red, green, blue, opacity);
imageWriter.setColor(x / 2, y / 2, newColor); //(0, 0)
imageWriter.setColor(width / 2 + x / 2, y / 2, newColor); //(width/2, 0)
imageWriter.setColor(x / 2, height / 2 + y / 2, newColor); //(0, height/2)
imageWriter.setColor(width / 2 + x / 2, height / 2 + y / 2, newColor); //(width/2, height/2)
}
}
ImageView imageView = new ImageView(targetImage);
Pane pane = new Pane();
pane.getChildren().add(imageView);
stage.setScene(new Scene(pane));
stage.show();
}
public static void main(String[] args) {
launch(CollageApplication.class);
}
}
//keep taking care of your goals,
//mental health, self care, recognize
//cognitive distortions and rebel against them!!
//one step at a time, don't be afraid to
//ask 4 help or to fail at times.