Skip to content

Commit c9863a9

Browse files
author
github-actions
committed
Google Java Format
1 parent 5c50bf8 commit c9863a9

File tree

15 files changed

+544
-454
lines changed

15 files changed

+544
-454
lines changed

examples/java/Shader/LightSprite.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import org.openpatch.scratch.Sprite;
44

55
public class LightSprite extends Sprite {
6-
public LightSprite() {
7-
this.addCostume("light", "Shader/light.png");
8-
}
6+
public LightSprite() {
7+
this.addCostume("light", "Shader/light.png");
8+
}
99
}

examples/java/Shader/MySprite.java

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,36 @@
55
import org.openpatch.scratch.Sprite;
66

77
public class MySprite extends Sprite {
8-
public MySprite() {
9-
this.addCostume("cat", "Shader/cat.png");
10-
var shader = this.addShader("halftone", "Shader/halftone.glsl");
11-
shader = this.addShader("pixelate", "Shader/pixelate.glsl");
12-
shader.set("pixels", 20.0, 10.0);
13-
shader = this.addShader("neon", "Shader/neon.glsl");
14-
shader.set("brt", 0.4);
15-
shader.set("rad", 1);
16-
this.switchShader("halftone");
17-
}
8+
public MySprite() {
9+
this.addCostume("cat", "Shader/cat.png");
10+
var shader = this.addShader("halftone", "Shader/halftone.glsl");
11+
shader = this.addShader("pixelate", "Shader/pixelate.glsl");
12+
shader.set("pixels", 20.0, 10.0);
13+
shader = this.addShader("neon", "Shader/neon.glsl");
14+
shader.set("brt", 0.4);
15+
shader.set("rad", 1);
16+
this.switchShader("halftone");
17+
}
1818

19-
public void whenKeyPressed(int keyCode) {
20-
if (keyCode == KeyCode.VK_N) {
21-
this.nextShader();
22-
}
23-
if (keyCode == KeyCode.VK_M) {
24-
this.resetShader();
25-
}
19+
public void whenKeyPressed(int keyCode) {
20+
if (keyCode == KeyCode.VK_N) {
21+
this.nextShader();
22+
}
23+
if (keyCode == KeyCode.VK_M) {
24+
this.resetShader();
2625
}
26+
}
2727

28-
public void run() {
29-
if ("halftone".equals(this.getCurrentShaderName())) {
30-
var shader = this.getShader("halftone");
31-
shader.set("pixelsPerRow", Operators.round(Operators.absOf(this.getMouseX())));
32-
} else if ("pixelate".equals(this.getCurrentShaderName())) {
33-
var shader = this.getShader("pixelate");
34-
shader.set("pixels", Operators.absOf(this.getX()), Operators.absOf(this.getX()));
35-
}
36-
this.ifOnEdgeBounce();
37-
this.move(2);
38-
this.say("Shaders are cool!");
28+
public void run() {
29+
if ("halftone".equals(this.getCurrentShaderName())) {
30+
var shader = this.getShader("halftone");
31+
shader.set("pixelsPerRow", Operators.round(Operators.absOf(this.getMouseX())));
32+
} else if ("pixelate".equals(this.getCurrentShaderName())) {
33+
var shader = this.getShader("pixelate");
34+
shader.set("pixels", Operators.absOf(this.getX()), Operators.absOf(this.getX()));
3935
}
36+
this.ifOnEdgeBounce();
37+
this.move(2);
38+
this.say("Shaders are cool!");
39+
}
4040
}

examples/java/Shader/MyStage.java

Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,59 +5,60 @@
55
import org.openpatch.scratch.extensions.timer.Timer;
66

77
public class MyStage extends Stage {
8-
public MyStage() {
9-
var shader = this.addShader("blobby", "Shader/blobby.glsl");
10-
shader.set("depth", 1.5);
11-
shader.set("rate", 1.5);
12-
shader = this.addShader("glitch", "Shader/glitch.glsl");
13-
shader.set("rate", 0.0001);
14-
shader = this.addShader("light", "Shader/light.glsl");
15-
this.switchShader("light");
8+
public MyStage() {
9+
var shader = this.addShader("blobby", "Shader/blobby.glsl");
10+
shader.set("depth", 1.5);
11+
shader.set("rate", 1.5);
12+
shader = this.addShader("glitch", "Shader/glitch.glsl");
13+
shader.set("rate", 0.0001);
14+
shader = this.addShader("light", "Shader/light.glsl");
15+
this.switchShader("light");
1616

17-
this.add(new MySprite());
18-
this.add(new NormalSprite());
17+
this.add(new MySprite());
18+
this.add(new NormalSprite());
1919

20-
for (int i = 0; i < 8; i++) {
21-
var sprite = new LightSprite();
22-
this.add(sprite);
23-
sprite.goToRandomPosition();
24-
}
20+
for (int i = 0; i < 8; i++) {
21+
var sprite = new LightSprite();
22+
this.add(sprite);
23+
sprite.goToRandomPosition();
2524
}
25+
}
2626

27-
public void whenKeyPressed(int keyCode) {
28-
if (keyCode == KeyCode.VK_A) {
29-
this.nextShader();
30-
}
31-
if (keyCode == KeyCode.VK_S) {
32-
this.resetShader();
33-
}
27+
public void whenKeyPressed(int keyCode) {
28+
if (keyCode == KeyCode.VK_A) {
29+
this.nextShader();
3430
}
31+
if (keyCode == KeyCode.VK_S) {
32+
this.resetShader();
33+
}
34+
}
3535

36-
public void run() {
37-
this.display("Press A for the next stage shader. Press S to remove the stage shader. Press N for the next sprite shader. Press M to remove the sprite shader.");
38-
var shader = this.getCurrentShader();
39-
if (shader != null) {
40-
shader.set("time", Timer.millis() / 1000.0);
41-
shader.set("resolution", (float) this.getWidth(), (float) this.getHeight());
42-
if ("light".equals(shader.getName())) {
43-
var lights = this.findSpritesOf(LightSprite.class);
44-
var lightPos = new double[lights.size() * 3 + 3];
45-
// light at mouse position
46-
lightPos[0] = this.getMouseX();
47-
lightPos[1] = this.getMouseY();
48-
lightPos[2] = 1;
49-
int i = 3;
50-
for (var light : lights) {
51-
var x = light.getX();
52-
var y = light.getY();
53-
lightPos[i] = x;
54-
lightPos[i + 1] = y;
55-
lightPos[i + 2] = 1;
56-
i += 3;
57-
}
58-
shader.set("lights", lightPos, 3);
59-
}
60-
36+
public void run() {
37+
this.display(
38+
"Press A for the next stage shader. Press S to remove the stage shader. Press N for the"
39+
+ " next sprite shader. Press M to remove the sprite shader.");
40+
var shader = this.getCurrentShader();
41+
if (shader != null) {
42+
shader.set("time", Timer.millis() / 1000.0);
43+
shader.set("resolution", (float) this.getWidth(), (float) this.getHeight());
44+
if ("light".equals(shader.getName())) {
45+
var lights = this.findSpritesOf(LightSprite.class);
46+
var lightPos = new double[lights.size() * 3 + 3];
47+
// light at mouse position
48+
lightPos[0] = this.getMouseX();
49+
lightPos[1] = this.getMouseY();
50+
lightPos[2] = 1;
51+
int i = 3;
52+
for (var light : lights) {
53+
var x = light.getX();
54+
var y = light.getY();
55+
lightPos[i] = x;
56+
lightPos[i + 1] = y;
57+
lightPos[i + 2] = 1;
58+
i += 3;
6159
}
60+
shader.set("lights", lightPos, 3);
61+
}
6262
}
63+
}
6364
}

examples/java/Shader/MyWindow.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
import org.openpatch.scratch.Window;
44

55
public class MyWindow extends Window {
6-
public MyWindow() {
7-
super(800, 400);
8-
this.setStage(new MyStage());
9-
}
6+
public MyWindow() {
7+
super(800, 400);
8+
this.setStage(new MyStage());
9+
}
1010

11-
public static void main(String[] args) {
12-
new MyWindow();
13-
}
14-
}
11+
public static void main(String[] args) {
12+
new MyWindow();
13+
}
14+
}

examples/java/Shader/NormalSprite.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
import org.openpatch.scratch.Sprite;
44

55
public class NormalSprite extends Sprite {
6-
public NormalSprite() {
7-
this.addCostume("cat", "Shader/cat.png");
8-
}
6+
public NormalSprite() {
7+
this.addCostume("cat", "Shader/cat.png");
8+
}
99

10-
public void run() {
11-
this.ifOnEdgeBounce();
12-
this.move(5);
13-
}
10+
public void run() {
11+
this.ifOnEdgeBounce();
12+
this.move(5);
13+
}
1414
}

src/org/openpatch/scratch/Sprite.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import java.util.concurrent.ConcurrentHashMap;
77
import java.util.concurrent.CopyOnWriteArrayList;
88
import java.util.stream.Collectors;
9-
109
import org.openpatch.scratch.extensions.color.Color;
1110
import org.openpatch.scratch.extensions.hitbox.Hitbox;
1211
import org.openpatch.scratch.extensions.math.Random;
@@ -21,7 +20,6 @@
2120
import org.openpatch.scratch.internal.Image;
2221
import org.openpatch.scratch.internal.Sound;
2322
import org.openpatch.scratch.internal.Stamp;
24-
2523
import processing.core.PGraphics;
2624
import processing.event.KeyEvent;
2725
import processing.event.MouseEvent;
@@ -186,6 +184,7 @@ public Stage getStage() {
186184
/**
187185
* Adds a new shader to the sprite. If a shader with the received name already exists, this method
188186
* does nothing.
187+
*
189188
* @param name
190189
* @param shaderPath
191190
* @return the shader
@@ -204,6 +203,7 @@ public Shader addShader(String name, final String shaderPath) {
204203

205204
/**
206205
* Switch to a shader by name.
206+
*
207207
* @param name the name of a shader
208208
*/
209209
public void switchShader(String name) {
@@ -218,6 +218,7 @@ public void switchShader(String name) {
218218

219219
/**
220220
* Switch to a shader by index.
221+
*
221222
* @param index the index of a shader
222223
*/
223224
public void switchShader(double index) {
@@ -230,6 +231,7 @@ public void resetShader() {
230231

231232
/**
232233
* Retrieves a shader by name.
234+
*
233235
* @param name the name of a shader
234236
* @return the shader with the specified name, or null if no shader with that name exists
235237
*/
@@ -242,15 +244,14 @@ public Shader getShader(String name) {
242244
return null;
243245
}
244246

245-
/**
246-
* Sets the next shader as the current shader.
247-
*/
247+
/** Sets the next shader as the current shader. */
248248
public void nextShader() {
249249
this.currentShader = (this.currentShader + 1) % this.shaders.size();
250250
}
251251

252252
/**
253253
* Retrieves the name of the current shader.
254+
*
254255
* @return the name of the current shader, or null if no shaders exist
255256
*/
256257
public String getCurrentShaderName() {
@@ -261,6 +262,7 @@ public String getCurrentShaderName() {
261262

262263
/**
263264
* Retrieves the index of the current shader.
265+
*
264266
* @return the index of the current shader
265267
*/
266268
public int getCurrentShaderIndex() {
@@ -269,6 +271,7 @@ public int getCurrentShaderIndex() {
269271

270272
/**
271273
* Retrieves the current shader.
274+
*
272275
* @return the current shader, or null if no shaders exist
273276
*/
274277
public Shader getCurrentShader() {

0 commit comments

Comments
 (0)