diff --git a/examples/java/Shader/LightSprite.java b/examples/java/Shader/LightSprite.java index b09d884..3631898 100644 --- a/examples/java/Shader/LightSprite.java +++ b/examples/java/Shader/LightSprite.java @@ -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"); + } } diff --git a/examples/java/Shader/MySprite.java b/examples/java/Shader/MySprite.java index 5970018..1fbb9ab 100644 --- a/examples/java/Shader/MySprite.java +++ b/examples/java/Shader/MySprite.java @@ -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!"); + } } diff --git a/examples/java/Shader/MyStage.java b/examples/java/Shader/MyStage.java index 9f63125..1a4e2d0 100644 --- a/examples/java/Shader/MyStage.java +++ b/examples/java/Shader/MyStage.java @@ -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); + } } + } } diff --git a/examples/java/Shader/MyWindow.java b/examples/java/Shader/MyWindow.java index 20ac533..ec45b79 100644 --- a/examples/java/Shader/MyWindow.java +++ b/examples/java/Shader/MyWindow.java @@ -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(); - } -} \ No newline at end of file + public static void main(String[] args) { + new MyWindow(); + } +} diff --git a/examples/java/Shader/NormalSprite.java b/examples/java/Shader/NormalSprite.java index fc3e561..e8f4001 100644 --- a/examples/java/Shader/NormalSprite.java +++ b/examples/java/Shader/NormalSprite.java @@ -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); + } } diff --git a/src/org/openpatch/scratch/Sprite.java b/src/org/openpatch/scratch/Sprite.java index 3ae32cb..f925895 100644 --- a/src/org/openpatch/scratch/Sprite.java +++ b/src/org/openpatch/scratch/Sprite.java @@ -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; @@ -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; @@ -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 @@ -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) { @@ -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) { @@ -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 */ @@ -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() { @@ -261,6 +262,7 @@ public String getCurrentShaderName() { /** * Retrieves the index of the current shader. + * * @return the index of the current shader */ public int getCurrentShaderIndex() { @@ -269,6 +271,7 @@ public int getCurrentShaderIndex() { /** * Retrieves the current shader. + * * @return the current shader, or null if no shaders exist */ public Shader getCurrentShader() { diff --git a/src/org/openpatch/scratch/Stage.java b/src/org/openpatch/scratch/Stage.java index a840b8d..e9b2c0f 100644 --- a/src/org/openpatch/scratch/Stage.java +++ b/src/org/openpatch/scratch/Stage.java @@ -33,10 +33,8 @@ import processing.event.MouseEvent; /** - * The Stage class represents a stage where various elements such as sprites, - * texts, pens, and - * backdrops can be added and manipulated. It provides methods to manage these - * elements, handle + * The Stage class represents a stage where various elements such as sprites, texts, pens, and + * backdrops can be added and manipulated. It provides methods to manage these elements, handle * events, and control the stage's appearance and behavior. */ public class Stage { @@ -88,8 +86,7 @@ public class Stage { private Camera camera; /** - * Constructs a new Stage with default dimensions. The default width is 480 - * pixels and the default + * Constructs a new Stage with default dimensions. The default width is 480 pixels and the default * height is 360 pixels. */ public Stage() { @@ -99,7 +96,7 @@ public Stage() { /** * Constructs a new Stage with the specified width and height. * - * @param width the width of the stage + * @param width the width of the stage * @param height the height of the stage */ public Stage(int width, final int height) { @@ -109,7 +106,7 @@ public Stage(int width, final int height) { /** * Constructs a new Stage with the specified width, height, and assets path. * - * @param width the width of the stage + * @param width the width of the stage * @param height the height of the stage * @param assets the path to the assets directory */ @@ -120,8 +117,7 @@ public Stage(int width, int height, String assets) { /** * Constructs a new Stage. * - * @param fullScreen a boolean indicating whether the stage should be in full - * screen mode. + * @param fullScreen a boolean indicating whether the stage should be in full screen mode. */ public Stage(boolean fullScreen) { this(480, 360, fullScreen, null); @@ -130,9 +126,8 @@ public Stage(boolean fullScreen) { /** * Constructs a new Stage with the specified fullscreen mode and assets path. * - * @param fullScreen a boolean indicating whether the stage should be in - * fullscreen mode - * @param assets the path to the assets directory + * @param fullScreen a boolean indicating whether the stage should be in fullscreen mode + * @param assets the path to the assets directory */ public Stage(boolean fullScreen, String assets) { this(480, 360, fullScreen, assets); @@ -141,10 +136,10 @@ public Stage(boolean fullScreen, String assets) { /** * Constructs a new Stage with the specified parameters. * - * @param width the width of the stage - * @param height the height of the stage + * @param width the width of the stage + * @param height the height of the stage * @param fullScreen whether the stage should be in full screen mode - * @param assets the path to the assets directory + * @param assets the path to the assets directory */ public Stage(int width, final int height, boolean fullScreen, String assets) { this.cursor = null; @@ -168,9 +163,12 @@ public Stage(int width, final int height, boolean fullScreen, String assets) { } Applet applet = Applet.getInstance(); this.mainBuffer = applet.createGraphics(applet.width, applet.height, applet.sketchRenderer()); - this.backdropBuffer = applet.createGraphics(applet.width, applet.height, applet.sketchRenderer()); - this.backgroundBuffer = applet.createGraphics(applet.width, applet.height, applet.sketchRenderer()); - this.foregroundBuffer = applet.createGraphics(applet.width, applet.height, applet.sketchRenderer()); + this.backdropBuffer = + applet.createGraphics(applet.width, applet.height, applet.sketchRenderer()); + this.backgroundBuffer = + applet.createGraphics(applet.width, applet.height, applet.sketchRenderer()); + this.foregroundBuffer = + applet.createGraphics(applet.width, applet.height, applet.sketchRenderer()); this.uiBuffer = applet.createGraphics(applet.width, applet.height, applet.sketchRenderer()); this.debugBuffer = applet.createGraphics(applet.width, applet.height, applet.sketchRenderer()); /** @@ -183,7 +181,8 @@ public Stage(int width, final int height, boolean fullScreen, String assets) { this.uiBuffer.smooth(4); this.debugBuffer.smooth(4); this.timer.put("default", new Timer()); - this.display = new Text(null, -applet.width / 2, -applet.height / 2, applet.width, TextStyle.BOX); + this.display = + new Text(null, -applet.width / 2, -applet.height / 2, applet.width, TextStyle.BOX); this.display.addedToStage(this); var p = new Polygon(); @@ -218,9 +217,8 @@ public Stage(int width, final int height, boolean fullScreen, String assets) { /** * Enables or disables the debug mode for the application. * - * @param debug a boolean value where {@code true} enables debug mode and - * {@code false} disables - * it. + * @param debug a boolean value where {@code true} enables debug mode and {@code false} disables + * it. */ public void setDebug(boolean debug) { Applet.getInstance().setDebug(debug); @@ -268,6 +266,7 @@ public void add(Pen pen) { /** * 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 @@ -286,6 +285,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) { @@ -300,6 +300,7 @@ public void switchShader(String name) { /** * Switch to a shader by index. + * * @param index the index of a shader */ public void switchShader(double index) { @@ -312,6 +313,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 */ @@ -324,15 +326,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() { @@ -343,6 +344,7 @@ public String getCurrentShaderName() { /** * Retrieves the index of the current shader. + * * @return the index of the current shader */ public int getCurrentShaderIndex() { @@ -351,6 +353,7 @@ public int getCurrentShaderIndex() { /** * Retrieves the current shader. + * * @return the current shader, or null if no shaders exist */ public Shader getCurrentShader() { @@ -360,44 +363,35 @@ public Shader getCurrentShader() { } /** - * Moves the specified sprite backwards by a given number of layers in the - * sprite list. If the - * resulting position is less than zero, the sprite is moved to the first - * position. If the - * resulting position is greater than the last index, the sprite is moved to the - * last position. + * Moves the specified sprite backwards by a given number of layers in the sprite list. If the + * resulting position is less than zero, the sprite is moved to the first position. If the + * resulting position is greater than the last index, the sprite is moved to the last position. * * @param sprite the sprite to be moved backwards in the layer order * @param number the number of layers to move the sprite backwards */ public void goLayersBackwards(Sprite sprite, int number) { int index = this.sprites.indexOf(sprite); - if (index == -1) - return; + if (index == -1) return; int newIndex = index - number; - if (newIndex < 0) - newIndex = 0; + if (newIndex < 0) newIndex = 0; newIndex = Math.min(newIndex, this.sprites.size() - 1); this.sprites.remove(index); this.sprites.add(newIndex, sprite); } /** - * Moves the specified sprite forward by a given number of layers in the sprite - * list. If the - * resulting position is out of bounds, it will be adjusted to the nearest valid - * position. + * Moves the specified sprite forward by a given number of layers in the sprite list. If the + * resulting position is out of bounds, it will be adjusted to the nearest valid position. * * @param sprite the sprite to be moved forward in the layer order * @param number the number of layers to move the sprite forward */ public void goLayersForwards(Sprite sprite, int number) { int index = this.sprites.indexOf(sprite); - if (index == -1) - return; + if (index == -1) return; int newIndex = index + number; - if (newIndex < 0) - newIndex = 0; + if (newIndex < 0) newIndex = 0; newIndex = Math.min(newIndex, this.sprites.size() - 1); this.sprites.remove(index); this.sprites.add(newIndex, sprite); @@ -424,8 +418,7 @@ public void goToBackLayer(Sprite sprite) { } /** - * Moves the specified sprite to the UI layer by removing it from the current - * list of sprites. + * Moves the specified sprite to the UI layer by removing it from the current list of sprites. * * @param sprite the sprite to be moved to the UI layer */ @@ -628,12 +621,11 @@ public long countPensOf(Class c) { } /** - * Add a backdrop to the stage. If a backdrop with the received name already - * exists do nothing. + * Add a backdrop to the stage. If a backdrop with the received name already exists do nothing. * - * @param name a unique name + * @param name a unique name * @param imagePath a image path - * @param stretch stretch image to window size + * @param stretch stretch image to window size */ public void addBackdrop(String name, final String imagePath, boolean stretch) { for (Image backdrop : this.backdrops) { @@ -649,10 +641,9 @@ public void addBackdrop(String name, final String imagePath, boolean stretch) { } /** - * Add a backdrop to the stage. If a backdrop with the received name already - * exists do nothing. + * Add a backdrop to the stage. If a backdrop with the received name already exists do nothing. * - * @param name a unique name + * @param name a unique name * @param imagePath a image path */ public void addBackdrop(String name, final String imagePath) { @@ -698,14 +689,12 @@ private void emitBackdropSwitch() { } /** - * This method is called when the backdrop switches to the specified name. - * Override this method to + * This method is called when the backdrop switches to the specified name. Override this method to * add custom behavior. * * @param name the name of the backdrop to switch to */ - public void whenBackdropSwitches(String name) { - } + public void whenBackdropSwitches(String name) {} /** Switch to the next backdrop. */ public void nextBackdrop() { @@ -762,18 +751,16 @@ public void eraseForeground() { } /** - * This method marks the UI buffer to be erased, which will be processed in the - * next update cycle. + * This method marks the UI buffer to be erased, which will be processed in the next update cycle. */ public void eraseUI() { this.eraseUIBuffer = true; } /** - * Add a sound to the stage. If a sound with the received name already exists do - * nothing. + * Add a sound to the stage. If a sound with the received name already exists do nothing. * - * @param name a unique name + * @param name a unique name * @param soundPath a sound path */ public void addSound(String name, final String soundPath) { @@ -935,8 +922,7 @@ public void changeColor(double h) { * @param b a blue value [0...255] */ public void setTint(double r, double g, double b) { - if (this.backdrops.size() == 0) - return; + if (this.backdrops.size() == 0) return; this.backdrops.get(this.currentBackdrop).setTint(r, g, b); } @@ -946,8 +932,7 @@ public void setTint(double r, double g, double b) { * @see Image#setTint(double) */ public void setTint(double h) { - if (this.backdrops.size() == 0) - return; + if (this.backdrops.size() == 0) return; this.backdrops.get(this.currentBackdrop).setTint(h); } @@ -958,8 +943,7 @@ public void setTint(double h) { * @param step a step value */ public void changeTint(double step) { - if (this.backdrops.size() == 0) - return; + if (this.backdrops.size() == 0) return; this.backdrops.get(this.currentBackdrop).changeTint(step); } @@ -981,15 +965,13 @@ public void setTransparency(double transparency) { * @param step a step value */ public void changeTransparency(double step) { - if (this.backdrops.size() == 0) - return; + if (this.backdrops.size() == 0) return; this.backdrops.get(this.currentBackdrop).changeTransparency(step); } /** - * Return the width of the current costume or the pen size, when no costume is - * available. + * Return the width of the current costume or the pen size, when no costume is available. * * @return the width of the sprite */ @@ -998,8 +980,7 @@ public int getWidth() { } /** - * Return the height of the current costume or the pen size, when no costume is - * available. + * Return the height of the current costume or the pen size, when no costume is available. * * @return the height of the sprite */ @@ -1032,8 +1013,7 @@ public Timer getTimer(String name) { * @param name the name of the timer */ public void addTimer(String name) { - if ("default".equals(name)) - return; + if ("default".equals(name)) return; this.timer.put(name, new Timer()); } @@ -1044,8 +1024,7 @@ public void addTimer(String name) { * @param name the name of the timer */ public void removeTimer(String name) { - if ("default".equals(name)) - return; + if ("default".equals(name)) return; this.timer.remove(name); } @@ -1086,27 +1065,21 @@ public void mouseEvent(MouseEvent e) { } /** - * This method is called when a mouse click event occurs. Overwrite this method - * to add custom + * This method is called when a mouse click event occurs. Overwrite this method to add custom * behavior. * * @param mouseEvent The mouse event that triggered this method. */ - public void whenMouseClicked(MouseCode mouseEvent) { - } + public void whenMouseClicked(MouseCode mouseEvent) {} /** - * This method is called when the mouse wheel is moved. Overwrite this method to - * add custom + * This method is called when the mouse wheel is moved. Overwrite this method to add custom * behavior. * - * @param steps the number of steps the mouse wheel has moved. Positive values - * indicate movement - * away from the user, while negative values indicate movement - * towards the user. + * @param steps the number of steps the mouse wheel has moved. Positive values indicate movement + * away from the user, while negative values indicate movement towards the user. */ - public void whenMouseWheelMoved(int steps) { - } + public void whenMouseWheelMoved(int steps) {} /** * Returns the current x-position of the mouse cursor @@ -1140,22 +1113,18 @@ public boolean isMouseDown() { } /** - * This method is called when a key is pressed. Override this method to add - * custom behavior. + * This method is called when a key is pressed. Override this method to add custom behavior. * * @param keyCode the code of the key that was pressed */ - public void whenKeyPressed(int keyCode) { - } + public void whenKeyPressed(int keyCode) {} /** - * This method is called when a key is released. Override this method to add - * custom behavior. + * This method is called when a key is released. Override this method to add custom behavior. * * @param keyCode the code of the key that was released */ - public void whenKeyReleased(int keyCode) { - } + public void whenKeyReleased(int keyCode) {} public void keyEvent(KeyEvent e) { switch (e.getAction()) { @@ -1290,7 +1259,7 @@ public int getDaysSince2000() { * Returns a random integer between the specified range (inclusive). * * @param from the lower bound of the range (inclusive) - * @param to the upper bound of the range (inclusive) + * @param to the upper bound of the range (inclusive) * @return a random integer between {@code from} and {@code to} (inclusive) */ public int pickRandom(int from, final int to) { @@ -1312,17 +1281,15 @@ public void display(String text) { /** * Displays the given text on the screen for a specified duration. * - * @param text The text to be displayed. - * @param millis The duration in milliseconds for which the text will be - * displayed. + * @param text The text to be displayed. + * @param millis The duration in milliseconds for which the text will be displayed. */ public void display(String text, final int millis) { this.display.showText(text, millis); } /** - * Broadcasts a message to all sprites in the stage. Each sprite will execute - * its `whenIReceive` + * Broadcasts a message to all sprites in the stage. Each sprite will execute its `whenIReceive` * method with the given message. * * @param message The message to broadcast to all sprites. @@ -1332,8 +1299,7 @@ public void broadcast(String message) { } /** - * Broadcasts a message to all sprites in the stage. Each sprite will execute - * its `whenIReceive` + * Broadcasts a message to all sprites in the stage. Each sprite will execute its `whenIReceive` * method with the given message. * * @param message The message to broadcast to all sprites. @@ -1343,22 +1309,19 @@ public void broadcast(Object message) { } /** - * This method is called when a specific message is received. Override this - * method to add custom + * This method is called when a specific message is received. Override this method to add custom * behavior. * * @param message The message that triggers this method. */ - public void whenIReceive(String message) { - } + public void whenIReceive(String message) {} /** * This method is called when a message is received. * * @param message The message object that is received. */ - public void whenIReceive(Object message) { - } + public void whenIReceive(Object message) {} /** * Sets the cursor image for the stage. @@ -1375,8 +1338,8 @@ public void setCursor(String path) { * Sets the cursor image and its active spot coordinates. * * @param path the file path to the cursor image - * @param x the x-coordinate of the cursor's active spot - * @param y the y-coordinate of the cursor's active spot + * @param x the x-coordinate of the cursor's active spot + * @param y the y-coordinate of the cursor's active spot */ public void setCursor(String path, int x, int y) { this.cursor = path; @@ -1406,17 +1369,14 @@ public void wait(int millis) { } /** - * Executes the main logic of the stage. This method should be overridden by - * subclasses to define + * Executes the main logic of the stage. This method should be overridden by subclasses to define * the specific behavior of the stage. */ - public void run() { - } + public void run() {} public void pre() { Applet applet = Applet.getInstance(); - if (applet == null) - return; + if (applet == null) return; var globalMouseX = applet.mouseX - this.getWidth() / 2; var globalMouseY = -(applet.mouseY - this.getHeight() / 2); this.mouseX = this.getCamera().toLocalX(globalMouseX); @@ -1433,8 +1393,7 @@ public void exit() { public void draw() { Applet applet = Applet.getInstance(); - if (applet == null) - return; + if (applet == null) return; var shader = this.getCurrentShader(); if (shader != null) { @@ -1540,7 +1499,9 @@ public void draw() { this.sprites.stream().filter(s -> s.isUI()).forEach(s -> s.draw(applet.getGraphics())); this.texts.stream().filter(t -> t.isUI()).forEach(t -> t.draw(applet.getGraphics())); - this.sprites.stream().filter(s -> s.isUI()).forEach(s -> s.getText().draw(applet.getGraphics())); + this.sprites.stream() + .filter(s -> s.isUI()) + .forEach(s -> s.getText().draw(applet.getGraphics())); applet.pop(); // draw ui diff --git a/src/org/openpatch/scratch/extensions/color/Color.java b/src/org/openpatch/scratch/extensions/color/Color.java index 2abb1ba..5715161 100644 --- a/src/org/openpatch/scratch/extensions/color/Color.java +++ b/src/org/openpatch/scratch/extensions/color/Color.java @@ -22,9 +22,9 @@ public Color(String hexCode) { if (hexCode.startsWith("#")) { hexCode = hexCode.substring(1); } - this.r = Integer.valueOf(hexCode.substring(0, 2), 16); - this.g = Integer.valueOf(hexCode.substring(2, 4), 16); - this.b = Integer.valueOf(hexCode.substring(4, 6), 16); + this.r = Integer.valueOf(hexCode.substring(0, 2), 16); + this.g = Integer.valueOf(hexCode.substring(2, 4), 16); + this.b = Integer.valueOf(hexCode.substring(4, 6), 16); } /** diff --git a/src/org/openpatch/scratch/extensions/color/HtmlColor.java b/src/org/openpatch/scratch/extensions/color/HtmlColor.java index eae0689..0ccc7fe 100644 --- a/src/org/openpatch/scratch/extensions/color/HtmlColor.java +++ b/src/org/openpatch/scratch/extensions/color/HtmlColor.java @@ -3,176 +3,298 @@ import java.util.Random; public class HtmlColor { - public static Color ALICE_BLUE = new Color("#F0F8FF"); - public static Color ANTIQUE_WHITE = new Color("#FAEBD7"); - public static Color AQUA = new Color("#00FFFF"); - public static Color AQUAMARINE = new Color("#7FFFD4"); - public static Color AZURE = new Color("#F0FFFF"); - public static Color BEIGE = new Color("#F5F5DC"); - public static Color BISQUE = new Color("#FFE4C4"); - public static Color BLACK = new Color("#000000"); - public static Color BLANCHED_ALMOND = new Color("#FFEBCD"); - public static Color BLUE = new Color("#0000FF"); - public static Color BLUE_VIOLET = new Color("#8A2BE2"); - public static Color BROWN = new Color("#A52A2A"); - public static Color BURLYWOOD = new Color("#DEB887"); - public static Color CADET_BLUE = new Color("#5F9EA0"); - public static Color CHARTREUSE = new Color("#7FFF00"); - public static Color CHOCOLATE = new Color("#D2691E"); - public static Color CORAL = new Color("#FF7F50"); - public static Color CORNFLOWER_BLUE = new Color("#6495ED"); - public static Color CORNSILK = new Color("#FFF8DC"); - public static Color CRIMSON = new Color("#DC143C"); - public static Color CYAN = new Color("#00FFFF"); - public static Color DARK_BLUE = new Color("#00008B"); - public static Color DARK_CYAN = new Color("#008B8B"); - public static Color DARK_GOLDENROD = new Color("#B8860B"); - public static Color DARK_GRAY = new Color("#A9A9A9"); - public static Color DARK_GREEN = new Color("#006400"); - public static Color DARK_KHAKI = new Color("#BDB76B"); - public static Color DARK_MAGENTA = new Color("#8B008B"); - public static Color DARK_OLIVE_GREEN = new Color("#556B2F"); - public static Color DARK_ORANGE = new Color("#FF8C00"); - public static Color DARK_ORCHID = new Color("#9932CC"); - public static Color DARK_RED = new Color("#8B0000"); - public static Color DARK_SALMON = new Color("#E9967A"); - public static Color DARK_SEA_GREEN = new Color("#8FBC8F"); - public static Color DARK_SLATE_BLUE = new Color("#483D8B"); - public static Color DARK_SLATE_GRAY = new Color("#2F4F4F"); - public static Color DARK_TURQUOISE = new Color("#00CED1"); - public static Color DARK_VIOLET = new Color("#9400D3"); - public static Color DEEP_PINK = new Color("#FF1493"); - public static Color DEEP_SKY_BLUE = new Color("#00BFFF"); - public static Color DIM_GRAY = new Color("#696969"); - public static Color DODGER_BLUE = new Color("#1E90FF"); - public static Color FIREBRICK = new Color("#B22222"); - public static Color FLORAL_WHITE = new Color("#FFFAF0"); - public static Color FOREST_GREEN = new Color("#228B22"); - public static Color FUCHSIA = new Color("#FF00FF"); - public static Color GAINSBORO = new Color("#DCDCDC"); - public static Color GHOST_WHITE = new Color("#F8F8FF"); - public static Color GOLD = new Color("#FFD700"); - public static Color GOLDENROD = new Color("#DAA520"); - public static Color GRAY = new Color("#808080"); - public static Color GREEN = new Color("#008000"); - public static Color GREEN_YELLOW = new Color("#ADFF2F"); - public static Color HONEYDEW = new Color("#F0FFF0"); - public static Color HOT_PINK = new Color("#FF69B4"); - public static Color INDIAN_RED = new Color("#CD5C5C"); - public static Color INDIGO = new Color("#4B0082"); - public static Color IVORY = new Color("#FFFFF0"); - public static Color KHAKI = new Color("#F0E68C"); - public static Color LAVENDER = new Color("#E6E6FA"); - public static Color LAVENDER_BLUSH = new Color("#FFF0F5"); - public static Color LAWN_GREEN = new Color("#7CFC00"); - public static Color LEMON_CHIFFON = new Color("#FFFACD"); - public static Color LIGHT_BLUE = new Color("#ADD8E6"); - public static Color LIGHT_CORAL = new Color("#F08080"); - public static Color LIGHT_CYAN = new Color("#E0FFFF"); - public static Color LIGHT_GOLDENROD_YELLOW = new Color("#FAFAD2"); - public static Color LIGHT_GRAY = new Color("#D3D3D3"); - public static Color LIGHT_GREEN = new Color("#90EE90"); - public static Color LIGHT_PINK = new Color("#FFB6C1"); - public static Color LIGHT_SALMON = new Color("#FFA07A"); - public static Color LIGHT_SEA_GREEN = new Color("#20B2AA"); - public static Color LIGHT_SKY_BLUE = new Color("#87CEFA"); - public static Color LIGHT_SLATE_GRAY = new Color("#778899"); - public static Color LIGHT_STEEL_BLUE = new Color("#B0C4DE"); - public static Color LIGHT_YELLOW = new Color("#FFFFE0"); - public static Color LIME = new Color("#00FF00"); - public static Color LIME_GREEN = new Color("#32CD32"); - public static Color LINEN = new Color("#FAF0E6"); - public static Color MAGENTA = new Color("#FF00FF"); - public static Color MAROON = new Color("#800000"); - public static Color MEDIUM_AQUAMARINE = new Color("#66CDAA"); - public static Color MEDIUM_BLUE = new Color("#0000CD"); - public static Color MEDIUM_ORCHID = new Color("#BA55D3"); - public static Color MEDIUM_PURPLE = new Color("#9370DB"); - public static Color MEDIUM_SEA_GREEN = new Color("#3CB371"); - public static Color MEDIUM_SLATE_BLUE = new Color("#7B68EE"); - public static Color MEDIUM_SPRING_GREEN = new Color("#00FA9A"); - public static Color MEDIUM_TURQUOISE = new Color("#48D1CC"); - public static Color MEDIUM_VIOLET_RED = new Color("#C71585"); - public static Color MIDNIGHT_BLUE = new Color("#191970"); - public static Color MINT_CREAM = new Color("#F5FFFA"); - public static Color MISTY_ROSE = new Color("#FFE4E1"); - public static Color MOCCASIN = new Color("#FFE4B5"); - public static Color NAVAJO_WHITE = new Color("#FFDEAD"); - public static Color NAVY = new Color("#000080"); - public static Color OLD_LACE = new Color("#FDF5E6"); - public static Color OLIVE = new Color("#808000"); - public static Color OLIVE_DRAB = new Color("#6B8E23"); - public static Color ORANGE = new Color("#FFA500"); - public static Color ORANGE_RED = new Color("#FF4500"); - public static Color ORCHID = new Color("#DA70D6"); - public static Color PALE_GOLDENROD = new Color("#EEE8AA"); - public static Color PALE_GREEN = new Color("#98FB98"); - public static Color PALE_TURQUOISE = new Color("#AFEEEE"); - public static Color PALE_VIOLET_RED = new Color("#DB7093"); - public static Color PAPAYA_WHIP = new Color("#FFEFD5"); - public static Color PEACH_PUFF = new Color("#FFDAB9"); - public static Color PERU = new Color("#CD853F"); - public static Color PINK = new Color("#FFC0CB"); - public static Color PLUM = new Color("#DDA0DD"); - public static Color POWDER_BLUE = new Color("#B0E0E6"); - public static Color PURPLE = new Color("#800080"); - public static Color RED = new Color("#FF0000"); - public static Color ROSY_BROWN = new Color("#BC8F8F"); - public static Color ROYAL_BLUE = new Color("#4169E1"); - public static Color SADDLE_BROWN = new Color("#8B4513"); - public static Color SALMON = new Color("#FA8072"); - public static Color SANDY_BROWN = new Color("#F4A460"); - public static Color SEA_GREEN = new Color("#2E8B57"); - public static Color SEASHELL = new Color("#FFF5EE"); - public static Color SIENNA = new Color("#A0522D"); - public static Color SILVER = new Color("#C0C0C0"); - public static Color SKY_BLUE = new Color("#87CEEB"); - public static Color SLATE_BLUE = new Color("#6A5ACD"); - public static Color SLATE_GRAY = new Color("#708090"); - public static Color SNOW = new Color("#FFFAFA"); - public static Color SPRING_GREEN = new Color("#00FF7F"); - public static Color STEEL_BLUE = new Color("#4682B4"); - public static Color TAN = new Color("#D2B48C"); - public static Color TEAL = new Color("#008080"); - public static Color THISTLE = new Color("#D8BFD8"); - public static Color TOMATO = new Color("#FF6347"); - public static Color TURQUOISE = new Color("#40E0D0"); - public static Color VIOLET = new Color("#EE82EE"); - public static Color WHEAT = new Color("#F5DEB3"); - public static Color WHITE = new Color("#FFFFFF"); - public static Color WHITE_SMOKE = new Color("#F5F5F5"); - public static Color YELLOW = new Color("#FFFF00"); - public static Color YELLOW_GREEN = new Color("#9ACD32"); + public static Color ALICE_BLUE = new Color("#F0F8FF"); + public static Color ANTIQUE_WHITE = new Color("#FAEBD7"); + public static Color AQUA = new Color("#00FFFF"); + public static Color AQUAMARINE = new Color("#7FFFD4"); + public static Color AZURE = new Color("#F0FFFF"); + public static Color BEIGE = new Color("#F5F5DC"); + public static Color BISQUE = new Color("#FFE4C4"); + public static Color BLACK = new Color("#000000"); + public static Color BLANCHED_ALMOND = new Color("#FFEBCD"); + public static Color BLUE = new Color("#0000FF"); + public static Color BLUE_VIOLET = new Color("#8A2BE2"); + public static Color BROWN = new Color("#A52A2A"); + public static Color BURLYWOOD = new Color("#DEB887"); + public static Color CADET_BLUE = new Color("#5F9EA0"); + public static Color CHARTREUSE = new Color("#7FFF00"); + public static Color CHOCOLATE = new Color("#D2691E"); + public static Color CORAL = new Color("#FF7F50"); + public static Color CORNFLOWER_BLUE = new Color("#6495ED"); + public static Color CORNSILK = new Color("#FFF8DC"); + public static Color CRIMSON = new Color("#DC143C"); + public static Color CYAN = new Color("#00FFFF"); + public static Color DARK_BLUE = new Color("#00008B"); + public static Color DARK_CYAN = new Color("#008B8B"); + public static Color DARK_GOLDENROD = new Color("#B8860B"); + public static Color DARK_GRAY = new Color("#A9A9A9"); + public static Color DARK_GREEN = new Color("#006400"); + public static Color DARK_KHAKI = new Color("#BDB76B"); + public static Color DARK_MAGENTA = new Color("#8B008B"); + public static Color DARK_OLIVE_GREEN = new Color("#556B2F"); + public static Color DARK_ORANGE = new Color("#FF8C00"); + public static Color DARK_ORCHID = new Color("#9932CC"); + public static Color DARK_RED = new Color("#8B0000"); + public static Color DARK_SALMON = new Color("#E9967A"); + public static Color DARK_SEA_GREEN = new Color("#8FBC8F"); + public static Color DARK_SLATE_BLUE = new Color("#483D8B"); + public static Color DARK_SLATE_GRAY = new Color("#2F4F4F"); + public static Color DARK_TURQUOISE = new Color("#00CED1"); + public static Color DARK_VIOLET = new Color("#9400D3"); + public static Color DEEP_PINK = new Color("#FF1493"); + public static Color DEEP_SKY_BLUE = new Color("#00BFFF"); + public static Color DIM_GRAY = new Color("#696969"); + public static Color DODGER_BLUE = new Color("#1E90FF"); + public static Color FIREBRICK = new Color("#B22222"); + public static Color FLORAL_WHITE = new Color("#FFFAF0"); + public static Color FOREST_GREEN = new Color("#228B22"); + public static Color FUCHSIA = new Color("#FF00FF"); + public static Color GAINSBORO = new Color("#DCDCDC"); + public static Color GHOST_WHITE = new Color("#F8F8FF"); + public static Color GOLD = new Color("#FFD700"); + public static Color GOLDENROD = new Color("#DAA520"); + public static Color GRAY = new Color("#808080"); + public static Color GREEN = new Color("#008000"); + public static Color GREEN_YELLOW = new Color("#ADFF2F"); + public static Color HONEYDEW = new Color("#F0FFF0"); + public static Color HOT_PINK = new Color("#FF69B4"); + public static Color INDIAN_RED = new Color("#CD5C5C"); + public static Color INDIGO = new Color("#4B0082"); + public static Color IVORY = new Color("#FFFFF0"); + public static Color KHAKI = new Color("#F0E68C"); + public static Color LAVENDER = new Color("#E6E6FA"); + public static Color LAVENDER_BLUSH = new Color("#FFF0F5"); + public static Color LAWN_GREEN = new Color("#7CFC00"); + public static Color LEMON_CHIFFON = new Color("#FFFACD"); + public static Color LIGHT_BLUE = new Color("#ADD8E6"); + public static Color LIGHT_CORAL = new Color("#F08080"); + public static Color LIGHT_CYAN = new Color("#E0FFFF"); + public static Color LIGHT_GOLDENROD_YELLOW = new Color("#FAFAD2"); + public static Color LIGHT_GRAY = new Color("#D3D3D3"); + public static Color LIGHT_GREEN = new Color("#90EE90"); + public static Color LIGHT_PINK = new Color("#FFB6C1"); + public static Color LIGHT_SALMON = new Color("#FFA07A"); + public static Color LIGHT_SEA_GREEN = new Color("#20B2AA"); + public static Color LIGHT_SKY_BLUE = new Color("#87CEFA"); + public static Color LIGHT_SLATE_GRAY = new Color("#778899"); + public static Color LIGHT_STEEL_BLUE = new Color("#B0C4DE"); + public static Color LIGHT_YELLOW = new Color("#FFFFE0"); + public static Color LIME = new Color("#00FF00"); + public static Color LIME_GREEN = new Color("#32CD32"); + public static Color LINEN = new Color("#FAF0E6"); + public static Color MAGENTA = new Color("#FF00FF"); + public static Color MAROON = new Color("#800000"); + public static Color MEDIUM_AQUAMARINE = new Color("#66CDAA"); + public static Color MEDIUM_BLUE = new Color("#0000CD"); + public static Color MEDIUM_ORCHID = new Color("#BA55D3"); + public static Color MEDIUM_PURPLE = new Color("#9370DB"); + public static Color MEDIUM_SEA_GREEN = new Color("#3CB371"); + public static Color MEDIUM_SLATE_BLUE = new Color("#7B68EE"); + public static Color MEDIUM_SPRING_GREEN = new Color("#00FA9A"); + public static Color MEDIUM_TURQUOISE = new Color("#48D1CC"); + public static Color MEDIUM_VIOLET_RED = new Color("#C71585"); + public static Color MIDNIGHT_BLUE = new Color("#191970"); + public static Color MINT_CREAM = new Color("#F5FFFA"); + public static Color MISTY_ROSE = new Color("#FFE4E1"); + public static Color MOCCASIN = new Color("#FFE4B5"); + public static Color NAVAJO_WHITE = new Color("#FFDEAD"); + public static Color NAVY = new Color("#000080"); + public static Color OLD_LACE = new Color("#FDF5E6"); + public static Color OLIVE = new Color("#808000"); + public static Color OLIVE_DRAB = new Color("#6B8E23"); + public static Color ORANGE = new Color("#FFA500"); + public static Color ORANGE_RED = new Color("#FF4500"); + public static Color ORCHID = new Color("#DA70D6"); + public static Color PALE_GOLDENROD = new Color("#EEE8AA"); + public static Color PALE_GREEN = new Color("#98FB98"); + public static Color PALE_TURQUOISE = new Color("#AFEEEE"); + public static Color PALE_VIOLET_RED = new Color("#DB7093"); + public static Color PAPAYA_WHIP = new Color("#FFEFD5"); + public static Color PEACH_PUFF = new Color("#FFDAB9"); + public static Color PERU = new Color("#CD853F"); + public static Color PINK = new Color("#FFC0CB"); + public static Color PLUM = new Color("#DDA0DD"); + public static Color POWDER_BLUE = new Color("#B0E0E6"); + public static Color PURPLE = new Color("#800080"); + public static Color RED = new Color("#FF0000"); + public static Color ROSY_BROWN = new Color("#BC8F8F"); + public static Color ROYAL_BLUE = new Color("#4169E1"); + public static Color SADDLE_BROWN = new Color("#8B4513"); + public static Color SALMON = new Color("#FA8072"); + public static Color SANDY_BROWN = new Color("#F4A460"); + public static Color SEA_GREEN = new Color("#2E8B57"); + public static Color SEASHELL = new Color("#FFF5EE"); + public static Color SIENNA = new Color("#A0522D"); + public static Color SILVER = new Color("#C0C0C0"); + public static Color SKY_BLUE = new Color("#87CEEB"); + public static Color SLATE_BLUE = new Color("#6A5ACD"); + public static Color SLATE_GRAY = new Color("#708090"); + public static Color SNOW = new Color("#FFFAFA"); + public static Color SPRING_GREEN = new Color("#00FF7F"); + public static Color STEEL_BLUE = new Color("#4682B4"); + public static Color TAN = new Color("#D2B48C"); + public static Color TEAL = new Color("#008080"); + public static Color THISTLE = new Color("#D8BFD8"); + public static Color TOMATO = new Color("#FF6347"); + public static Color TURQUOISE = new Color("#40E0D0"); + public static Color VIOLET = new Color("#EE82EE"); + public static Color WHEAT = new Color("#F5DEB3"); + public static Color WHITE = new Color("#FFFFFF"); + public static Color WHITE_SMOKE = new Color("#F5F5F5"); + public static Color YELLOW = new Color("#FFFF00"); + public static Color YELLOW_GREEN = new Color("#9ACD32"); - private static final Random RANDOM = new Random(); - private static final Color[] COLORS = new Color[] { - ALICE_BLUE, ANTIQUE_WHITE, AQUA, AQUAMARINE, AZURE, BEIGE, BISQUE, BLACK, - BLANCHED_ALMOND, BLUE, BLUE_VIOLET, BROWN, BURLYWOOD, CADET_BLUE, CHARTREUSE, - CHOCOLATE, CORAL, CORNFLOWER_BLUE, CORNSILK, CRIMSON, CYAN, DARK_BLUE, - DARK_CYAN, DARK_GOLDENROD, DARK_GRAY, DARK_GREEN, DARK_KHAKI, DARK_MAGENTA, - DARK_OLIVE_GREEN, DARK_ORANGE, DARK_ORCHID, DARK_RED, DARK_SALMON, DARK_SEA_GREEN, - DARK_SLATE_BLUE, DARK_SLATE_GRAY, DARK_TURQUOISE, DARK_VIOLET, DEEP_PINK, - DEEP_SKY_BLUE, DIM_GRAY, DODGER_BLUE, FIREBRICK, FLORAL_WHITE, FOREST_GREEN, - FUCHSIA, GAINSBORO, GHOST_WHITE, GOLD, GOLDENROD, GRAY, GREEN, GREEN_YELLOW, - HONEYDEW, HOT_PINK, INDIAN_RED, INDIGO, IVORY, KHAKI, LAVENDER, LAVENDER_BLUSH, - LAWN_GREEN, LEMON_CHIFFON, LIGHT_BLUE, LIGHT_CORAL, LIGHT_CYAN, LIGHT_GOLDENROD_YELLOW, - LIGHT_GRAY, LIGHT_GREEN, LIGHT_PINK, LIGHT_SALMON, LIGHT_SEA_GREEN, LIGHT_SKY_BLUE, - LIGHT_SLATE_GRAY, LIGHT_STEEL_BLUE, LIGHT_YELLOW, LIME, LIME_GREEN, LINEN, MAGENTA, - MAROON, MEDIUM_AQUAMARINE, MEDIUM_BLUE, MEDIUM_ORCHID, MEDIUM_PURPLE, MEDIUM_SEA_GREEN, - MEDIUM_SLATE_BLUE, MEDIUM_SPRING_GREEN, MEDIUM_TURQUOISE, MEDIUM_VIOLET_RED, MIDNIGHT_BLUE, - MINT_CREAM, MISTY_ROSE, MOCCASIN, NAVAJO_WHITE, NAVY, OLD_LACE, OLIVE, OLIVE_DRAB, - ORANGE, ORANGE_RED, ORCHID, PALE_GOLDENROD, PALE_GREEN, PALE_TURQUOISE, PALE_VIOLET_RED, - PAPAYA_WHIP, PEACH_PUFF, PERU, PINK, PLUM, POWDER_BLUE, PURPLE, RED, ROSY_BROWN, - ROYAL_BLUE, SADDLE_BROWN, SALMON, SANDY_BROWN, SEA_GREEN, SEASHELL, SIENNA, SILVER, - SKY_BLUE, SLATE_BLUE, SLATE_GRAY, SNOW, SPRING_GREEN, STEEL_BLUE, TAN, TEAL, - THISTLE, TOMATO, TURQUOISE, VIOLET, WHEAT, WHITE, WHITE_SMOKE, YELLOW, YELLOW_GREEN - }; + private static final Random RANDOM = new Random(); + private static final Color[] COLORS = + new Color[] { + ALICE_BLUE, + ANTIQUE_WHITE, + AQUA, + AQUAMARINE, + AZURE, + BEIGE, + BISQUE, + BLACK, + BLANCHED_ALMOND, + BLUE, + BLUE_VIOLET, + BROWN, + BURLYWOOD, + CADET_BLUE, + CHARTREUSE, + CHOCOLATE, + CORAL, + CORNFLOWER_BLUE, + CORNSILK, + CRIMSON, + CYAN, + DARK_BLUE, + DARK_CYAN, + DARK_GOLDENROD, + DARK_GRAY, + DARK_GREEN, + DARK_KHAKI, + DARK_MAGENTA, + DARK_OLIVE_GREEN, + DARK_ORANGE, + DARK_ORCHID, + DARK_RED, + DARK_SALMON, + DARK_SEA_GREEN, + DARK_SLATE_BLUE, + DARK_SLATE_GRAY, + DARK_TURQUOISE, + DARK_VIOLET, + DEEP_PINK, + DEEP_SKY_BLUE, + DIM_GRAY, + DODGER_BLUE, + FIREBRICK, + FLORAL_WHITE, + FOREST_GREEN, + FUCHSIA, + GAINSBORO, + GHOST_WHITE, + GOLD, + GOLDENROD, + GRAY, + GREEN, + GREEN_YELLOW, + HONEYDEW, + HOT_PINK, + INDIAN_RED, + INDIGO, + IVORY, + KHAKI, + LAVENDER, + LAVENDER_BLUSH, + LAWN_GREEN, + LEMON_CHIFFON, + LIGHT_BLUE, + LIGHT_CORAL, + LIGHT_CYAN, + LIGHT_GOLDENROD_YELLOW, + LIGHT_GRAY, + LIGHT_GREEN, + LIGHT_PINK, + LIGHT_SALMON, + LIGHT_SEA_GREEN, + LIGHT_SKY_BLUE, + LIGHT_SLATE_GRAY, + LIGHT_STEEL_BLUE, + LIGHT_YELLOW, + LIME, + LIME_GREEN, + LINEN, + MAGENTA, + MAROON, + MEDIUM_AQUAMARINE, + MEDIUM_BLUE, + MEDIUM_ORCHID, + MEDIUM_PURPLE, + MEDIUM_SEA_GREEN, + MEDIUM_SLATE_BLUE, + MEDIUM_SPRING_GREEN, + MEDIUM_TURQUOISE, + MEDIUM_VIOLET_RED, + MIDNIGHT_BLUE, + MINT_CREAM, + MISTY_ROSE, + MOCCASIN, + NAVAJO_WHITE, + NAVY, + OLD_LACE, + OLIVE, + OLIVE_DRAB, + ORANGE, + ORANGE_RED, + ORCHID, + PALE_GOLDENROD, + PALE_GREEN, + PALE_TURQUOISE, + PALE_VIOLET_RED, + PAPAYA_WHIP, + PEACH_PUFF, + PERU, + PINK, + PLUM, + POWDER_BLUE, + PURPLE, + RED, + ROSY_BROWN, + ROYAL_BLUE, + SADDLE_BROWN, + SALMON, + SANDY_BROWN, + SEA_GREEN, + SEASHELL, + SIENNA, + SILVER, + SKY_BLUE, + SLATE_BLUE, + SLATE_GRAY, + SNOW, + SPRING_GREEN, + STEEL_BLUE, + TAN, + TEAL, + THISTLE, + TOMATO, + TURQUOISE, + VIOLET, + WHEAT, + WHITE, + WHITE_SMOKE, + YELLOW, + YELLOW_GREEN + }; - /** - * Returns a random HTML color. - * @return a random Color from the predefined HTML colors - */ - public static Color getRandom() { - return COLORS[RANDOM.nextInt(COLORS.length)]; - } + /** + * Returns a random HTML color. + * + * @return a random Color from the predefined HTML colors + */ + public static Color getRandom() { + return COLORS[RANDOM.nextInt(COLORS.length)]; + } } diff --git a/src/org/openpatch/scratch/extensions/pen/Pen.java b/src/org/openpatch/scratch/extensions/pen/Pen.java index 4f3b0ac..cdac77b 100644 --- a/src/org/openpatch/scratch/extensions/pen/Pen.java +++ b/src/org/openpatch/scratch/extensions/pen/Pen.java @@ -4,13 +4,11 @@ import java.util.Iterator; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; - import org.openpatch.scratch.Sprite; import org.openpatch.scratch.Stage; import org.openpatch.scratch.extensions.color.Color; import org.openpatch.scratch.extensions.math.Random; import org.openpatch.scratch.extensions.math.Vector2; - import processing.core.PGraphics; /** diff --git a/src/org/openpatch/scratch/extensions/shader/Shader.java b/src/org/openpatch/scratch/extensions/shader/Shader.java index 38fbbb3..d143729 100644 --- a/src/org/openpatch/scratch/extensions/shader/Shader.java +++ b/src/org/openpatch/scratch/extensions/shader/Shader.java @@ -3,7 +3,6 @@ import org.openpatch.scratch.extensions.color.Color; import org.openpatch.scratch.extensions.math.Vector2; import org.openpatch.scratch.internal.Applet; - import processing.opengl.PShader; public class Shader { @@ -34,7 +33,7 @@ public Shader(Shader shader) { /** * Load shader - * + * * @param path path to the shader file * @return shader */ diff --git a/src/org/openpatch/scratch/internal/AnimatedGifEncoder.java b/src/org/openpatch/scratch/internal/AnimatedGifEncoder.java index 962ef5d..9bb7cf5 100644 --- a/src/org/openpatch/scratch/internal/AnimatedGifEncoder.java +++ b/src/org/openpatch/scratch/internal/AnimatedGifEncoder.java @@ -3,7 +3,6 @@ import java.awt.*; import java.awt.image.*; import java.io.*; - import org.openpatch.scratch.extensions.color.Color; /** diff --git a/src/org/openpatch/scratch/internal/Image.java b/src/org/openpatch/scratch/internal/Image.java index 83b9214..14f697a 100644 --- a/src/org/openpatch/scratch/internal/Image.java +++ b/src/org/openpatch/scratch/internal/Image.java @@ -2,12 +2,10 @@ import java.util.AbstractMap; import java.util.concurrent.ConcurrentHashMap; - import org.openpatch.scratch.RotationStyle; import org.openpatch.scratch.Window; import org.openpatch.scratch.extensions.color.Color; import org.openpatch.scratch.extensions.shader.Shader; - import processing.core.PApplet; import processing.core.PConstants; import processing.core.PGraphics; @@ -32,7 +30,7 @@ public class Image { /** * Construct a ScratchImage object by a name and a path to an image. * - * @param name a a name + * @param name a a name * @param imagePath a path to an image */ public Image(String name, String imagePath) { @@ -46,12 +44,12 @@ public Image(String name, String imagePath) { /** * Construct a ScratchImage object by a name and a path to a sprite sheet. * - * @param name a name + * @param name a name * @param spriteSheetPath a path to a sprite sheet - * @param x the x coordinate of the tile - * @param y the y coordinate of the tile - * @param width the width of the tile - * @param height the height of the tile + * @param x the x coordinate of the tile + * @param y the y coordinate of the tile + * @param width the width of the tile + * @param height the height of the tile */ public Image(String name, String spriteSheetPath, int x, int y, int width, int height) { this.name = name; @@ -96,10 +94,10 @@ public static PImage loadImage(String path) { /** * Loads an image from a given path and returns a tile of the image. * - * @param path the path to the image - * @param x the x coordinate of the tile - * @param y the y coordinate of the tile - * @param width the width of the tile + * @param path the path to the image + * @param x the x coordinate of the tile + * @param y the y coordinate of the tile + * @param width the width of the tile * @param height the height of the tile * @return a tile of the image */ @@ -247,13 +245,11 @@ public void setSize(double percentage) { } /** - * Sets the size of the image to the specified width and height. If a resized - * version with the - * requested dimensions already exists in cache, it will use that version. - * Otherwise, it creates a + * Sets the size of the image to the specified width and height. If a resized version with the + * requested dimensions already exists in cache, it will use that version. Otherwise, it creates a * new resized copy from the original image and caches it for future use. * - * @param width The desired width of the image in pixels + * @param width The desired width of the image in pixels * @param height The desired height of the image in pixels */ public void setSize(int width, int height) { @@ -273,14 +269,21 @@ public void setSize(int width, int height) { * Draw the scaled image at a given position. * * @param buffer a buffer - * @param size a percentage value + * @param size a percentage value * @param degrees direction - * @param x a x coordinate - * @param y a y coordinate - * @param style a rotation style + * @param x a x coordinate + * @param y a y coordinate + * @param style a rotation style * @param shader a shader */ - public void draw(PGraphics buffer, double size, double degrees, double x, double y, RotationStyle style, Shader shader) { + public void draw( + PGraphics buffer, + double size, + double degrees, + double x, + double y, + RotationStyle style, + Shader shader) { buffer.push(); buffer.imageMode(PConstants.CENTER); buffer.translate((float) x, (float) -y); @@ -317,11 +320,11 @@ public void draw(PGraphics buffer, double size, double degrees, double x, double /** * Draw the scaled image at a given position. * - * @param size a percentage value + * @param size a percentage value * @param degrees direction - * @param x a x coordinate - * @param y a y coordinate - * @param style a rotation style + * @param x a x coordinate + * @param y a y coordinate + * @param style a rotation style */ public void drawDebug( PGraphics buffer, double size, double degrees, double x, double y, RotationStyle style) { @@ -338,10 +341,10 @@ public void drawDebug( * Draw the scaled image at a given position. * * @param buffer a buffer - * @param size a percentage value + * @param size a percentage value * @param degrees direction - * @param x a x coordinate - * @param y a y coordinate + * @param x a x coordinate + * @param y a y coordinate * @param shader a shader */ public void draw(PGraphics buffer, float size, float degrees, float x, float y, Shader shader) { @@ -361,9 +364,8 @@ public void draw() { } /** - * Draw the image as a background. The image is automatically scaled to fit the - * window size. - * + * Draw the image as a background. The image is automatically scaled to fit the window size. + * * @param buffer a buffer */ public void drawAsBackground(PGraphics buffer) { diff --git a/src/org/openpatch/scratch/internal/package-info.java b/src/org/openpatch/scratch/internal/package-info.java index 2d7fd5f..efa2b29 100644 --- a/src/org/openpatch/scratch/internal/package-info.java +++ b/src/org/openpatch/scratch/internal/package-info.java @@ -1,6 +1,6 @@ /** * This package contains the internal classes of the Scratch plugin. - * - * The classes in this package are not meant to be used by the users of the library. + * + *

The classes in this package are not meant to be used by the users of the library. */ package org.openpatch.scratch.internal; diff --git a/src/org/openpatch/scratch/package-info.java b/src/org/openpatch/scratch/package-info.java index 9017ab6..b061ab5 100644 --- a/src/org/openpatch/scratch/package-info.java +++ b/src/org/openpatch/scratch/package-info.java @@ -1,52 +1,57 @@ /** - * The org.openpatch.scratch package contains classes that provide an API for creating Scratch-like projects in Java. - * - * The documentation with many examples can be found at https://scratch4j.openpatch.org. - * - * To create a scratch4j project, you will need to create a class that extends the {@link org.openpatch.scratch.Window} class. - * - * The {@link org.openpatch.scratch.Window} class is the main class that represents the window of the project. - * + * The org.openpatch.scratch package contains classes that provide an API for creating Scratch-like + * projects in Java. + * + *

The documentation with many examples can be found at https://scratch4j.openpatch.org. + * + *

To create a scratch4j project, you will need to create a class that extends the {@link + * org.openpatch.scratch.Window} class. + * + *

The {@link org.openpatch.scratch.Window} class is the main class that represents the window of + * the project. + * *

  * import org.openpatch.scratch.Window;
- * 
+ *
  * public class Game extends Window {
  *      public Game() {
  *          super(800, 600);
  *          this.setStage(new MyStage());
  *      }
- * } 
+ * }
  * 
- * + * * The {@link org.openpatch.scratch.Stage} class represents the stage of the project. - * + * *
  * import org.openpatch.scratch.Stage;
- * 
+ *
  * class MyStage extends Stage {
  *      public MyStage() {
  *          this.add(new MySprite());
- *      }     
+ *      }
  * }
  * 
- * + * * The {@link org.openpatch.scratch.Sprite} class represents a sprite in the project. - * + * *
  * import org.openpatch.scratch.Sprite;
- * 
+ *
  * class MySprite extends Sprite {
  *      public MySprite() {
  *          this.setCostume("cat_sitting", "cat.png");
  *      }
- * 
+ *
  *      public void run() {
  *          this.ifOnEdgeBounce();
  *          this.move(10);
  *      }
  * }
  * 
- * - * This will create a window with a stage containing a sprite that moves 10 pixels every frame and bounces off the edges of the window. + * + * This will create a window with a stage containing a sprite that moves 10 pixels every frame and + * bounces off the edges of the window. */ -package org.openpatch.scratch; \ No newline at end of file +package org.openpatch.scratch;