Skip to content

Commit 6228d83

Browse files
committed
Part-14
1 parent f6d1f3e commit 6228d83

File tree

15 files changed

+951
-0
lines changed

15 files changed

+951
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export SERVER="true"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
force_new_sandbox: true
651 KB
Loading
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<actions>
3+
<action>
4+
<actionName>CUSTOM-custom maven command</actionName>
5+
<displayName>custom maven command</displayName>
6+
<goals>
7+
<goal>mvn</goal>
8+
<goal>-version</goal>
9+
</goals>
10+
</action>
11+
<action>
12+
<actionName>run</actionName>
13+
<packagings>
14+
<packaging>jar</packaging>
15+
</packagings>
16+
<goals>
17+
<goal>process-classes</goal>
18+
<goal>fi.helsinki.cs.tmc:runner-maven-plugin:1.0.1:run-javafx</goal>
19+
20+
</goals>
21+
<properties>
22+
<exec.args>-classpath %classpath ${packageClassName}</exec.args>
23+
<exec.executable>java</exec.executable>
24+
</properties>
25+
</action>
26+
</actions>
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
5+
http://maven.apache.org/xsd/maven-4.0.0.xsd">
6+
<modelVersion>4.0.0</modelVersion>
7+
<groupId>tkt</groupId>
8+
<artifactId>Part14_07.Collage</artifactId>
9+
<name>Part14_07.Collage</name>
10+
<version>1.0-SNAPSHOT</version>
11+
<packaging>jar</packaging>
12+
13+
<properties>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
</properties>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>junit</groupId>
20+
<artifactId>junit</artifactId>
21+
<version>4.12</version>
22+
<scope>test</scope>
23+
</dependency>
24+
<dependency>
25+
<groupId>fi.helsinki.cs.tmc</groupId>
26+
<artifactId>edu-test-utils</artifactId>
27+
<version>0.4.2</version>
28+
<scope>test</scope>
29+
</dependency>
30+
31+
<dependency>
32+
<groupId>org.testfx</groupId>
33+
<artifactId>testfx-junit</artifactId>
34+
<version>4.0.15-alpha</version>
35+
<scope>test</scope>
36+
</dependency>
37+
<dependency>
38+
<groupId>org.testfx</groupId>
39+
<artifactId>testfx-core</artifactId>
40+
<version>4.0.15-alpha</version>
41+
<scope>test</scope>
42+
</dependency>
43+
<dependency>
44+
<groupId>org.testfx</groupId>
45+
<artifactId>openjfx-monocle</artifactId>
46+
<version>8u76-b04</version>
47+
<scope>test</scope>
48+
</dependency>
49+
</dependencies>
50+
51+
<build>
52+
<plugins>
53+
<plugin>
54+
<groupId>org.apache.maven.plugins</groupId>
55+
<artifactId>maven-compiler-plugin</artifactId>
56+
<version>3.8.0</version>
57+
</plugin>
58+
<plugin>
59+
<groupId>org.codehaus.mojo</groupId>
60+
<artifactId>exec-maven-plugin</artifactId>
61+
<version>1.6.0</version>
62+
</plugin>
63+
<plugin>
64+
<groupId>org.apache.maven.plugins</groupId>
65+
<artifactId>maven-surefire-plugin</artifactId>
66+
<version>2.22.1</version>
67+
<configuration>
68+
<argLine>-Djdk.net.URLClassPath.disableClassPathURLCheck=true</argLine>
69+
</configuration>
70+
</plugin>
71+
<plugin>
72+
<groupId>fi.helsinki.cs.tmc</groupId>
73+
<artifactId>runner-maven-plugin</artifactId>
74+
<version>1.0.1</version>
75+
</plugin>
76+
</plugins>
77+
</build>
78+
79+
<profiles>
80+
<profile>
81+
<id>java8</id>
82+
<activation>
83+
<jdk>1.8</jdk>
84+
</activation>
85+
86+
<properties>
87+
<maven.compiler.source>1.8</maven.compiler.source>
88+
<maven.compiler.target>1.8</maven.compiler.target>
89+
</properties>
90+
91+
<dependencies>
92+
<dependency>
93+
<groupId>org.testfx</groupId>
94+
<artifactId>openjfx-monocle</artifactId>
95+
<version>8u76-b04</version>
96+
<scope>test</scope>
97+
</dependency>
98+
</dependencies>
99+
</profile>
100+
<profile>
101+
<id>java11</id>
102+
<activation>
103+
<jdk>11</jdk>
104+
</activation>
105+
<properties>
106+
<maven.compiler.source>11</maven.compiler.source>
107+
<maven.compiler.target>11</maven.compiler.target>
108+
</properties>
109+
<dependencies>
110+
<dependency>
111+
<groupId>org.openjfx</groupId>
112+
<artifactId>javafx-base</artifactId>
113+
<version>11.0.2</version>
114+
</dependency>
115+
<dependency>
116+
<groupId>org.openjfx</groupId>
117+
<artifactId>javafx-controls</artifactId>
118+
<version>11.0.2</version>
119+
</dependency>
120+
<dependency>
121+
<groupId>org.testfx</groupId>
122+
<artifactId>openjfx-monocle</artifactId>
123+
<version>jdk-11+26</version>
124+
<scope>test</scope>
125+
</dependency>
126+
</dependencies>
127+
<build>
128+
<plugins>
129+
<plugin>
130+
<groupId>org.openjfx</groupId>
131+
<artifactId>javafx-maven-plugin</artifactId>
132+
<version>0.0.2</version>
133+
<configuration>
134+
<mainClass>collage.CollageApplication</mainClass>
135+
</configuration>
136+
</plugin>
137+
</plugins>
138+
</build>
139+
</profile>
140+
</profiles>
141+
142+
<repositories>
143+
<repository>
144+
<id>tmc</id>
145+
<name>TMC repo</name>
146+
<url>https://maven.mooc.fi/releases</url>
147+
<releases>
148+
<enabled>true</enabled>
149+
</releases>
150+
<snapshots>
151+
<enabled>true</enabled>
152+
</snapshots>
153+
</repository>
154+
<repository>
155+
<id>tmc-snapshots</id>
156+
<name>TMC repo</name>
157+
<url>https://maven.mooc.fi/snapshots</url>
158+
<releases>
159+
<enabled>true</enabled>
160+
</releases>
161+
<snapshots>
162+
<enabled>true</enabled>
163+
</snapshots>
164+
</repository>
165+
</repositories>
166+
167+
<pluginRepositories>
168+
<pluginRepository>
169+
<id>tmc</id>
170+
<name>TMC repo</name>
171+
<url>https://maven.mooc.fi/releases</url>
172+
<releases>
173+
<enabled>true</enabled>
174+
</releases>
175+
<snapshots>
176+
<enabled>true</enabled>
177+
</snapshots>
178+
</pluginRepository>
179+
<pluginRepository>
180+
<id>tmc-snapshots</id>
181+
<name>TMC repo</name>
182+
<url>https://maven.mooc.fi/snapshots</url>
183+
<releases>
184+
<enabled>true</enabled>
185+
</releases>
186+
<snapshots>
187+
<enabled>true</enabled>
188+
</snapshots>
189+
</pluginRepository>
190+
</pluginRepositories>
191+
</project>
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
package collage;
2+
3+
import javafx.application.Application;
4+
import static javafx.application.Application.launch;
5+
import javafx.scene.Scene;
6+
import javafx.scene.image.Image;
7+
import javafx.scene.image.ImageView;
8+
import javafx.scene.image.PixelReader;
9+
import javafx.scene.image.PixelWriter;
10+
import javafx.scene.image.WritableImage;
11+
import javafx.scene.layout.Pane;
12+
import javafx.scene.paint.Color;
13+
import javafx.stage.Stage;
14+
15+
public class CollageApplication extends Application {
16+
17+
@Override
18+
public void start(Stage stage) {
19+
20+
// the example opens the image, creates a new image, and copies the opened image
21+
// into the new one, pixel by pixel
22+
Image sourceImage = new Image("file:monalisa.png");
23+
24+
PixelReader imageReader = sourceImage.getPixelReader();
25+
26+
int width = (int) sourceImage.getWidth();
27+
int height = (int) sourceImage.getHeight();
28+
29+
WritableImage targetImage = new WritableImage(width, height);
30+
PixelWriter imageWriter = targetImage.getPixelWriter();
31+
32+
int yCoordinate = 0;
33+
while (yCoordinate < height) {
34+
int xCoordinate = 0;
35+
while (xCoordinate < width) {
36+
37+
Color color = imageReader.getColor(xCoordinate, yCoordinate);
38+
double red = color.getRed();
39+
double green = color.getGreen();
40+
double blue = color.getBlue();
41+
double opacity = color.getOpacity();
42+
43+
Color newColor = new Color(red, green, blue, opacity);
44+
45+
imageWriter.setColor(xCoordinate, yCoordinate, newColor);
46+
47+
xCoordinate++;
48+
}
49+
50+
yCoordinate++;
51+
}
52+
53+
// create a smaller copy of the image in the top left corner
54+
for (int x = 0; x < width / 2; x++) {
55+
for (int y = 0; y < height / 2; y++) {
56+
Color color = imageReader.getColor(x * 2, y * 2);
57+
imageWriter.setColor(x, y, color);
58+
}
59+
}
60+
61+
// copy that image to the other corners
62+
imageReader = targetImage.getPixelReader();
63+
for (int x = 0; x < width / 2; x++) {
64+
for (int y = 0; y < height / 2; y++) {
65+
Color color = imageReader.getColor(x, y);
66+
67+
imageWriter.setColor(x + width / 2, y, color);
68+
imageWriter.setColor(x, y + height / 2, color);
69+
imageWriter.setColor(x + width / 2, y + height / 2, color);
70+
}
71+
}
72+
73+
// create the negative
74+
for (int x = 0; x < width; x++) {
75+
for (int y = 0; y < height; y++) {
76+
Color color = imageReader.getColor(x, y);
77+
78+
double r = 1 - color.getRed();
79+
double g = 1 - color.getGreen();
80+
double b = 1 - color.getBlue();
81+
82+
Color negative = new Color(r, g, b, color.getOpacity());
83+
84+
imageWriter.setColor(x, y, negative);
85+
}
86+
}
87+
88+
ImageView image = new ImageView(targetImage);
89+
90+
Pane pane = new Pane();
91+
pane.getChildren().add(image);
92+
93+
stage.setScene(new Scene(pane));
94+
stage.show();
95+
}
96+
97+
public static void main(String[] args) {
98+
launch(CollageApplication.class);
99+
}
100+
101+
}
102+

0 commit comments

Comments
 (0)