Skip to content

Commit

Permalink
Google Java Format
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Dec 18, 2024
1 parent 5c50bf8 commit c9863a9
Show file tree
Hide file tree
Showing 15 changed files with 544 additions and 454 deletions.
6 changes: 3 additions & 3 deletions examples/java/Shader/LightSprite.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.openpatch.scratch.Sprite;

public class LightSprite extends Sprite {
public LightSprite() {
this.addCostume("light", "Shader/light.png");
}
public LightSprite() {
this.addCostume("light", "Shader/light.png");
}
}
56 changes: 28 additions & 28 deletions examples/java/Shader/MySprite.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,36 @@
import org.openpatch.scratch.Sprite;

public class MySprite extends Sprite {
public MySprite() {
this.addCostume("cat", "Shader/cat.png");
var shader = this.addShader("halftone", "Shader/halftone.glsl");
shader = this.addShader("pixelate", "Shader/pixelate.glsl");
shader.set("pixels", 20.0, 10.0);
shader = this.addShader("neon", "Shader/neon.glsl");
shader.set("brt", 0.4);
shader.set("rad", 1);
this.switchShader("halftone");
}
public MySprite() {
this.addCostume("cat", "Shader/cat.png");
var shader = this.addShader("halftone", "Shader/halftone.glsl");
shader = this.addShader("pixelate", "Shader/pixelate.glsl");
shader.set("pixels", 20.0, 10.0);
shader = this.addShader("neon", "Shader/neon.glsl");
shader.set("brt", 0.4);
shader.set("rad", 1);
this.switchShader("halftone");
}

public void whenKeyPressed(int keyCode) {
if (keyCode == KeyCode.VK_N) {
this.nextShader();
}
if (keyCode == KeyCode.VK_M) {
this.resetShader();
}
public void whenKeyPressed(int keyCode) {
if (keyCode == KeyCode.VK_N) {
this.nextShader();
}
if (keyCode == KeyCode.VK_M) {
this.resetShader();
}
}

public void run() {
if ("halftone".equals(this.getCurrentShaderName())) {
var shader = this.getShader("halftone");
shader.set("pixelsPerRow", Operators.round(Operators.absOf(this.getMouseX())));
} else if ("pixelate".equals(this.getCurrentShaderName())) {
var shader = this.getShader("pixelate");
shader.set("pixels", Operators.absOf(this.getX()), Operators.absOf(this.getX()));
}
this.ifOnEdgeBounce();
this.move(2);
this.say("Shaders are cool!");
public void run() {
if ("halftone".equals(this.getCurrentShaderName())) {
var shader = this.getShader("halftone");
shader.set("pixelsPerRow", Operators.round(Operators.absOf(this.getMouseX())));
} else if ("pixelate".equals(this.getCurrentShaderName())) {
var shader = this.getShader("pixelate");
shader.set("pixels", Operators.absOf(this.getX()), Operators.absOf(this.getX()));
}
this.ifOnEdgeBounce();
this.move(2);
this.say("Shaders are cool!");
}
}
95 changes: 48 additions & 47 deletions examples/java/Shader/MyStage.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,59 +5,60 @@
import org.openpatch.scratch.extensions.timer.Timer;

public class MyStage extends Stage {
public MyStage() {
var shader = this.addShader("blobby", "Shader/blobby.glsl");
shader.set("depth", 1.5);
shader.set("rate", 1.5);
shader = this.addShader("glitch", "Shader/glitch.glsl");
shader.set("rate", 0.0001);
shader = this.addShader("light", "Shader/light.glsl");
this.switchShader("light");
public MyStage() {
var shader = this.addShader("blobby", "Shader/blobby.glsl");
shader.set("depth", 1.5);
shader.set("rate", 1.5);
shader = this.addShader("glitch", "Shader/glitch.glsl");
shader.set("rate", 0.0001);
shader = this.addShader("light", "Shader/light.glsl");
this.switchShader("light");

this.add(new MySprite());
this.add(new NormalSprite());
this.add(new MySprite());
this.add(new NormalSprite());

for (int i = 0; i < 8; i++) {
var sprite = new LightSprite();
this.add(sprite);
sprite.goToRandomPosition();
}
for (int i = 0; i < 8; i++) {
var sprite = new LightSprite();
this.add(sprite);
sprite.goToRandomPosition();
}
}

public void whenKeyPressed(int keyCode) {
if (keyCode == KeyCode.VK_A) {
this.nextShader();
}
if (keyCode == KeyCode.VK_S) {
this.resetShader();
}
public void whenKeyPressed(int keyCode) {
if (keyCode == KeyCode.VK_A) {
this.nextShader();
}
if (keyCode == KeyCode.VK_S) {
this.resetShader();
}
}

public void run() {
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.");
var shader = this.getCurrentShader();
if (shader != null) {
shader.set("time", Timer.millis() / 1000.0);
shader.set("resolution", (float) this.getWidth(), (float) this.getHeight());
if ("light".equals(shader.getName())) {
var lights = this.findSpritesOf(LightSprite.class);
var lightPos = new double[lights.size() * 3 + 3];
// light at mouse position
lightPos[0] = this.getMouseX();
lightPos[1] = this.getMouseY();
lightPos[2] = 1;
int i = 3;
for (var light : lights) {
var x = light.getX();
var y = light.getY();
lightPos[i] = x;
lightPos[i + 1] = y;
lightPos[i + 2] = 1;
i += 3;
}
shader.set("lights", lightPos, 3);
}

public void run() {
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.");
var shader = this.getCurrentShader();
if (shader != null) {
shader.set("time", Timer.millis() / 1000.0);
shader.set("resolution", (float) this.getWidth(), (float) this.getHeight());
if ("light".equals(shader.getName())) {
var lights = this.findSpritesOf(LightSprite.class);
var lightPos = new double[lights.size() * 3 + 3];
// light at mouse position
lightPos[0] = this.getMouseX();
lightPos[1] = this.getMouseY();
lightPos[2] = 1;
int i = 3;
for (var light : lights) {
var x = light.getX();
var y = light.getY();
lightPos[i] = x;
lightPos[i + 1] = y;
lightPos[i + 2] = 1;
i += 3;
}
shader.set("lights", lightPos, 3);
}
}
}
}
16 changes: 8 additions & 8 deletions examples/java/Shader/MyWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import org.openpatch.scratch.Window;

public class MyWindow extends Window {
public MyWindow() {
super(800, 400);
this.setStage(new MyStage());
}
public MyWindow() {
super(800, 400);
this.setStage(new MyStage());
}

public static void main(String[] args) {
new MyWindow();
}
}
public static void main(String[] args) {
new MyWindow();
}
}
14 changes: 7 additions & 7 deletions examples/java/Shader/NormalSprite.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import org.openpatch.scratch.Sprite;

public class NormalSprite extends Sprite {
public NormalSprite() {
this.addCostume("cat", "Shader/cat.png");
}
public NormalSprite() {
this.addCostume("cat", "Shader/cat.png");
}

public void run() {
this.ifOnEdgeBounce();
this.move(5);
}
public void run() {
this.ifOnEdgeBounce();
this.move(5);
}
}
13 changes: 8 additions & 5 deletions src/org/openpatch/scratch/Sprite.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Collectors;

import org.openpatch.scratch.extensions.color.Color;
import org.openpatch.scratch.extensions.hitbox.Hitbox;
import org.openpatch.scratch.extensions.math.Random;
Expand All @@ -21,7 +20,6 @@
import org.openpatch.scratch.internal.Image;
import org.openpatch.scratch.internal.Sound;
import org.openpatch.scratch.internal.Stamp;

import processing.core.PGraphics;
import processing.event.KeyEvent;
import processing.event.MouseEvent;
Expand Down Expand Up @@ -186,6 +184,7 @@ public Stage getStage() {
/**
* Adds a new shader to the sprite. If a shader with the received name already exists, this method
* does nothing.
*
* @param name
* @param shaderPath
* @return the shader
Expand All @@ -204,6 +203,7 @@ public Shader addShader(String name, final String shaderPath) {

/**
* Switch to a shader by name.
*
* @param name the name of a shader
*/
public void switchShader(String name) {
Expand All @@ -218,6 +218,7 @@ public void switchShader(String name) {

/**
* Switch to a shader by index.
*
* @param index the index of a shader
*/
public void switchShader(double index) {
Expand All @@ -230,6 +231,7 @@ public void resetShader() {

/**
* Retrieves a shader by name.
*
* @param name the name of a shader
* @return the shader with the specified name, or null if no shader with that name exists
*/
Expand All @@ -242,15 +244,14 @@ public Shader getShader(String name) {
return null;
}

/**
* Sets the next shader as the current shader.
*/
/** Sets the next shader as the current shader. */
public void nextShader() {
this.currentShader = (this.currentShader + 1) % this.shaders.size();
}

/**
* Retrieves the name of the current shader.
*
* @return the name of the current shader, or null if no shaders exist
*/
public String getCurrentShaderName() {
Expand All @@ -261,6 +262,7 @@ public String getCurrentShaderName() {

/**
* Retrieves the index of the current shader.
*
* @return the index of the current shader
*/
public int getCurrentShaderIndex() {
Expand All @@ -269,6 +271,7 @@ public int getCurrentShaderIndex() {

/**
* Retrieves the current shader.
*
* @return the current shader, or null if no shaders exist
*/
public Shader getCurrentShader() {
Expand Down
Loading

0 comments on commit c9863a9

Please sign in to comment.