find(final Class extends Drawable> c) {
* @param name a unique name
* @param imagePath a image path
*/
- public void addBackdrop(final String name, final String imagePath) {
- for (final Image backdrop : this.backdrops) {
+ public void addBackdrop(String name, final String imagePath) {
+ for (Image backdrop : this.backdrops) {
if (backdrop.getName().equals(name)) {
return;
}
}
- final Image backdrop = new Image(name, imagePath);
+ Image backdrop = new Image(name, imagePath);
this.backdrops.add(backdrop);
backdrop.addedToStage(this);
}
@@ -193,9 +193,9 @@ public void addBackdrop(final String name, final String imagePath) {
*
* @param name of the backdrop
*/
- public void removeBackdrop(final String name) {
+ public void removeBackdrop(String name) {
for (int i = 0; i < this.backdrops.size(); i++) {
- final Image backdrop = this.backdrops.get(i);
+ Image backdrop = this.backdrops.get(i);
if (backdrop.getName().equals(name)) {
this.backdrops.remove(i);
return;
@@ -208,9 +208,9 @@ public void removeBackdrop(final String name) {
*
* @param name the name of a backdrop
*/
- public void switchBackdrop(final String name) {
+ public void switchBackdrop(String name) {
for (int i = 0; i < this.backdrops.size(); i++) {
- final Image backdrop = this.backdrops.get(i);
+ Image backdrop = this.backdrops.get(i);
if (backdrop.getName().equals(name)) {
this.currentBackdrop = i;
this.emitBackdropSwitch();
@@ -220,19 +220,19 @@ public void switchBackdrop(final String name) {
}
private void emitBackdropSwitch() {
- final Image backdrop = this.backdrops.get(this.currentBackdrop);
- final String name = backdrop.getName();
+ Image backdrop = this.backdrops.get(this.currentBackdrop);
+ String name = backdrop.getName();
this.drawables.stream()
.forEach(
d -> {
- if (d instanceof Sprite) {
- ((Sprite) d).whenBackdropSwitches(name);
- }
+ if (d instanceof Sprite) {
+ ((Sprite) d).whenBackdropSwitches(name);
+ }
});
this.whenBackdropSwitches(name);
}
- public void whenBackdropSwitches(final String name) {
+ public void whenBackdropSwitches(String name) {
}
/** Switch to the next backdrop. */
@@ -249,7 +249,7 @@ public void previousBackdrop() {
/** Switch to a random backdrop. */
public void randomBackdrop() {
- final int size = this.backdrops.size();
+ int size = this.backdrops.size();
this.currentBackdrop = this.pickRandom(0, size - 1) % size;
this.emitBackdropSwitch();
}
@@ -276,7 +276,7 @@ public int getCurrentBackdropIndex() {
public void eraseAll() {
try {
this.penBuffer = Applet.getInstance().createGraphics(this.getWidth(), this.getHeight());
- } catch (final Exception e) {
+ } catch (Exception e) {
}
}
@@ -287,14 +287,14 @@ public void eraseAll() {
* @param name a unique name
* @param soundPath a sound path
*/
- public void addSound(final String name, final String soundPath) {
- for (final Sound sound : this.sounds) {
+ public void addSound(String name, final String soundPath) {
+ for (Sound sound : this.sounds) {
if (sound.getName().equals(name)) {
return;
}
}
- final Sound sound = new Sound(name, soundPath);
+ Sound sound = new Sound(name, soundPath);
this.sounds.add(sound);
}
@@ -303,9 +303,9 @@ public void addSound(final String name, final String soundPath) {
*
* @param name the sound name
*/
- public void removeSound(final String name) {
+ public void removeSound(String name) {
for (int i = 0; i < this.sounds.size(); i++) {
- final Sound sound = this.sounds.get(i);
+ Sound sound = this.sounds.get(i);
if (sound.getName().equals(name)) {
this.sounds.remove(i);
return;
@@ -318,8 +318,8 @@ public void removeSound(final String name) {
*
* @param name the sound name
*/
- public void playSound(final String name) {
- for (final Sound sound : this.sounds) {
+ public void playSound(String name) {
+ for (Sound sound : this.sounds) {
if (sound.getName().equals(name) && !sound.isPlaying()) {
sound.play();
}
@@ -328,7 +328,7 @@ public void playSound(final String name) {
/** Stops the playing of all sounds of the stage. */
public void stopAllSounds() {
- for (final Sound sound : this.sounds) {
+ for (Sound sound : this.sounds) {
sound.stop();
}
}
@@ -338,8 +338,8 @@ public void stopAllSounds() {
*
* @param name Name of the sound
*/
- public void stopSound(final String name) {
- for (final Sound sound : this.sounds) {
+ public void stopSound(String name) {
+ for (Sound sound : this.sounds) {
if (sound.getName().equals(name)) {
sound.stop();
break;
@@ -352,8 +352,8 @@ public void stopSound(final String name) {
*
* @return playing
*/
- public boolean isSoundPlaying(final String name) {
- for (final Sound sound : this.sounds) {
+ public boolean isSoundPlaying(String name) {
+ for (Sound sound : this.sounds) {
if (sound.getName().equals(name)) {
return sound.isPlaying();
}
@@ -376,7 +376,7 @@ public PGraphics getPenBuffer() {
*
* @param h a hue value [0...255]
*/
- public void setColor(final float h) {
+ public void setColor(float h) {
this.color.setHSB(h);
}
@@ -387,11 +387,11 @@ public void setColor(final float h) {
* @param g a green value [0...255]
* @param b a blue value [0...255]
*/
- public void setColor(final float r, final float g, final float b) {
+ public void setColor(float r, final float g, final float b) {
this.color.setRGB(r, g, b);
}
- public void setColor(final Color c) {
+ public void setColor(Color c) {
this.color = c;
}
@@ -400,11 +400,11 @@ public void setColor(final Color c) {
*
* @param h a step value
*/
- public void changeColor(final float h) {
+ public void changeColor(float h) {
this.color.changeColor(h);
}
- public void changeColor(final double h) {
+ public void changeColor(double h) {
this.changeColor((float) h);
}
@@ -413,7 +413,7 @@ public void changeColor(final double h) {
*
* @see Image#setTint(float, float, float)
*/
- public void setTint(final int r, final int g, final int b) {
+ public void setTint(int r, final int g, final int b) {
if (this.backdrops.size() == 0)
return;
this.backdrops.get(this.currentBackdrop).setTint(r, g, b);
@@ -424,7 +424,7 @@ public void setTint(final int r, final int g, final int b) {
*
* @see Image#setTint(float)
*/
- public void setTint(final float h) {
+ public void setTint(float h) {
if (this.backdrops.size() == 0)
return;
this.backdrops.get(this.currentBackdrop).setTint(h);
@@ -435,7 +435,7 @@ public void setTint(final float h) {
*
* @see Image#changeTint(float)
*/
- public void changeTint(final float step) {
+ public void changeTint(float step) {
if (this.backdrops.size() == 0)
return;
@@ -447,11 +447,11 @@ public void changeTint(final float step) {
*
* @see Image#setTransparency(float)
*/
- public void setTransparency(final float transparency) {
+ public void setTransparency(float transparency) {
this.backdrops.get(this.currentBackdrop).setTransparency(transparency);
}
- public void setTransparency(final double transparency) {
+ public void setTransparency(double transparency) {
this.setTransparency((float) transparency);
}
@@ -460,7 +460,7 @@ public void setTransparency(final double transparency) {
*
* @see Image#changeTransparency(float)
*/
- public void changeTransparency(final float step) {
+ public void changeTransparency(float step) {
if (this.backdrops.size() == 0)
return;
@@ -502,7 +502,7 @@ public Timer getTimer() {
* @param name a name
* @return the timer
*/
- public Timer getTimer(final String name) {
+ public Timer getTimer(String name) {
return this.timer.get(name);
}
@@ -511,7 +511,7 @@ public Timer getTimer(final String name) {
*
* @param name the name of the timer
*/
- public void addTimer(final String name) {
+ public void addTimer(String name) {
if ("default".equals(name))
return;
@@ -523,14 +523,14 @@ public void addTimer(final String name) {
*
* @param name the name of the timer
*/
- public void removeTimer(final String name) {
+ public void removeTimer(String name) {
if ("default".equals(name))
return;
this.timer.remove(name);
}
- public void mouseEvent(final MouseEvent e) {
+ public void mouseEvent(MouseEvent e) {
this.mouseX = e.getX();
this.mouseY = e.getY();
this.mouseDown = false;
@@ -577,10 +577,10 @@ public boolean isMouseDown() {
return this.mouseDown;
}
- public void whenKeyPressed(final int keyCode) {
+ public void whenKeyPressed(int keyCode) {
}
- public void keyEvent(final KeyEvent e) {
+ public void keyEvent(KeyEvent e) {
switch (e.getAction()) {
case KeyEvent.PRESS:
this.whenKeyPressed(e.getKeyCode());
@@ -598,8 +598,8 @@ public void keyEvent(final KeyEvent e) {
* @param keyCode a key code
* @return key pressed
*/
- public boolean isKeyPressed(final int keyCode) {
- final Boolean isPressed = this.keyCodePressed.get(keyCode);
+ public boolean isKeyPressed(int keyCode) {
+ Boolean isPressed = this.keyCodePressed.get(keyCode);
if (isPressed == null) {
return false;
}
@@ -612,7 +612,7 @@ public boolean isKeyPressed(final int keyCode) {
* @return current year
*/
public int getCurrentYear() {
- final LocalDateTime now = LocalDateTime.now();
+ LocalDateTime now = LocalDateTime.now();
return now.getYear();
}
@@ -622,7 +622,7 @@ public int getCurrentYear() {
* @return current month
*/
public int getCurrentMonth() {
- final LocalDateTime now = LocalDateTime.now();
+ LocalDateTime now = LocalDateTime.now();
return now.getMonthValue();
}
@@ -632,7 +632,7 @@ public int getCurrentMonth() {
* @return current day of the week
*/
public int getCurrentDayOfWeek() {
- final LocalDateTime now = LocalDateTime.now();
+ LocalDateTime now = LocalDateTime.now();
return now.getDayOfWeek().getValue();
}
@@ -642,7 +642,7 @@ public int getCurrentDayOfWeek() {
* @return current day of the month
*/
public int getCurrentDay() {
- final LocalDateTime now = LocalDateTime.now();
+ LocalDateTime now = LocalDateTime.now();
return now.getDayOfMonth();
}
@@ -652,7 +652,7 @@ public int getCurrentDay() {
* @return current hour
*/
public int getCurrentHour() {
- final LocalDateTime now = LocalDateTime.now();
+ LocalDateTime now = LocalDateTime.now();
return now.getHour();
}
@@ -662,7 +662,7 @@ public int getCurrentHour() {
* @return current minute
*/
public int getCurrentMinute() {
- final LocalDateTime now = LocalDateTime.now();
+ LocalDateTime now = LocalDateTime.now();
return now.getMinute();
}
@@ -672,7 +672,7 @@ public int getCurrentMinute() {
* @return current second
*/
public int getCurrentSecond() {
- final LocalDateTime now = LocalDateTime.now();
+ LocalDateTime now = LocalDateTime.now();
return now.getSecond();
}
@@ -682,7 +682,7 @@ public int getCurrentSecond() {
* @return current millisecond
*/
public int getCurrentMillisecond() {
- final LocalDateTime now = LocalDateTime.now();
+ LocalDateTime now = LocalDateTime.now();
return (int) Math.round(now.getNano() / 1000000.0);
}
@@ -692,30 +692,44 @@ public int getCurrentMillisecond() {
* @return days since 2010/01/01
*/
public int getDaysSince2000() {
- final LocalDate now = LocalDate.now();
- final LocalDate then = LocalDate.of(2000, Month.JANUARY, 1);
- final long c = ChronoUnit.DAYS.between(then, now);
+ LocalDate now = LocalDate.now();
+ LocalDate then = LocalDate.of(2000, Month.JANUARY, 1);
+ long c = ChronoUnit.DAYS.between(then, now);
return (int) c;
}
- public int pickRandom(final int from, final int to) {
+ public int pickRandom(int from, final int to) {
if (to < from) {
return to + (int) (Math.random() * (from - to));
}
return from + (int) (Math.random() * (to - from));
}
- public void display(final String text) {
+ public void display(String text) {
this.display.showText(text);
}
- public void display(final String text, final int millis) {
+ public void display(String text, final int millis) {
this.display.showText(text, millis);
}
+ public void broadcast(String message) {
+ this.drawables.stream()
+ .forEach(
+ d -> {
+ if (d instanceof Sprite) {
+ ((Sprite) d).whenIReceive(message);
+ }
+ });
+ }
+
+ public void whenIReceive(String message) {
+
+ }
+
/** Draws the current backdrop or if none a solid color */
public void pre() {
- final Applet applet = Applet.getInstance();
+ Applet applet = Applet.getInstance();
if (applet == null)
return;
// redraw background to clear screen
@@ -730,7 +744,7 @@ public void pre() {
} else {
try {
this.penBuffer.loadPixels();
- } catch (final Exception e) {
+ } catch (Exception e) {
}
}
}
@@ -740,10 +754,10 @@ public void pre() {
*
* @param millis Milliseconds
*/
- public void wait(final int millis) {
+ public void wait(int millis) {
try {
Thread.sleep(millis);
- } catch (final InterruptedException e) {
+ } catch (InterruptedException e) {
}
}
@@ -751,10 +765,10 @@ public void run() {
}
public void draw() {
- final Applet applet = Applet.getInstance();
+ Applet applet = Applet.getInstance();
if (applet == null)
return;
- for (final Drawable d : this.drawables) {
+ for (Drawable d : this.drawables) {
d.draw();
}
if (this.display != null) {
@@ -774,9 +788,9 @@ public void draw() {
}
public static float[] rotateXY(float x, float y, final float originX, final float originY, final float degrees) {
- final float[] rotatedXY = new float[2];
+ float[] rotatedXY = new float[2];
- final double radians = degrees * Math.PI / 180.0;
+ double radians = degrees * Math.PI / 180.0;
x = x - originX;
y = y - originY;
rotatedXY[0] = (float) (x * Math.cos(radians) - y * Math.sin(radians)) + originX;
diff --git a/src/org/openpatch/scratch/Window.java b/src/org/openpatch/scratch/Window.java
index e01e059e..b0a94a65 100644
--- a/src/org/openpatch/scratch/Window.java
+++ b/src/org/openpatch/scratch/Window.java
@@ -11,15 +11,15 @@ public Window() {
this(480, 360);
}
- public Window(final String assets) {
+ public Window(String assets) {
this(480, 360, assets);
}
- public Window(final int width, final int height) {
+ public Window(int width, final int height) {
this(width, height, null);
}
- public Window(final int width, final int height, final String assets) {
+ public Window(int width, final int height, final String assets) {
super();
if (Window.instance != null) {
throw new Error("You can only have one Window.");
@@ -37,7 +37,7 @@ public boolean isDebug() {
return Applet.getInstance().isDebug();
}
- public void setDebug(final boolean debug) {
+ public void setDebug(boolean debug) {
Applet.getInstance().setDebug(debug);
}
@@ -49,19 +49,19 @@ public int getHeight() {
return Applet.getInstance().getHeight();
}
- public void addStage(final String name, final Stage stage) {
+ public void addStage(String name, final Stage stage) {
Applet.getInstance().addStage(name, stage);
}
- public Stage getStage(final String name) {
+ public Stage getStage(String name) {
return Applet.getInstance().getStage(name);
}
- public void removeStage(final String name) {
+ public void removeStage(String name) {
Applet.getInstance().removeStage(name);
}
- public void switchStage(final String name) {
+ public void switchStage(String name) {
Applet.getInstance().switchStage(name);
}
diff --git a/src/org/openpatch/scratch/internal/AnimatedGifEncoder.java b/src/org/openpatch/scratch/internal/AnimatedGifEncoder.java
index ec7f1c34..76bf0844 100644
--- a/src/org/openpatch/scratch/internal/AnimatedGifEncoder.java
+++ b/src/org/openpatch/scratch/internal/AnimatedGifEncoder.java
@@ -5,7 +5,8 @@
import java.io.*;
/**
- * Class AnimatedGifEncoder - Encodes a GIF file consisting of one or more frames.
+ * Class AnimatedGifEncoder - Encodes a GIF file consisting of one or more
+ * frames.
*
*
* Example:
@@ -17,8 +18,10 @@
* e.finish();
*
*
- * No copyright asserted on the source code of this class. May be used for any purpose, however,
- * refer to the Unisys LZW patent for restrictions on use of the associated LZWEncoder class. Please
+ * No copyright asserted on the source code of this class. May be used for any
+ * purpose, however,
+ * refer to the Unisys LZW patent for restrictions on use of the associated
+ * LZWEncoder class. Please
* forward any corrections to kweiner@fmsware.com.
*
* @author Kevin Weiner, FM Software
@@ -67,7 +70,8 @@ public class AnimatedGifEncoder {
protected int sample = 10; // default sample interval for quantizer
/**
- * Sets the delay time between each frame, or changes it for subsequent frames (applies to last
+ * Sets the delay time between each frame, or changes it for subsequent frames
+ * (applies to last
* frame added).
*
* @param ms int delay time in milliseconds
@@ -81,7 +85,8 @@ public OutputStream getOut() {
}
/**
- * Sets the GIF frame disposal code for the last added frame and any subsequent frames. Default is
+ * Sets the GIF frame disposal code for the last added frame and any subsequent
+ * frames. Default is
* 0 if no transparent color has been set, otherwise 2.
*
* @param code int disposal code.
@@ -93,7 +98,8 @@ public void setDispose(int code) {
}
/**
- * Sets the number of times the set of GIF frames should be played. Default is 1; 0 means play
+ * Sets the number of times the set of GIF frames should be played. Default is
+ * 1; 0 means play
* indefinitely. Must be invoked before the first image is added.
*
* @param iter int number of iterations.
@@ -106,9 +112,12 @@ public void setRepeat(int iter) {
}
/**
- * Sets the transparent color for the last added frame and any subsequent frames. Since all colors
- * are subject to modification in the quantization process, the color in the final palette for
- * each frame closest to the given color becomes the transparent color for that frame. May be set
+ * Sets the transparent color for the last added frame and any subsequent
+ * frames. Since all colors
+ * are subject to modification in the quantization process, the color in the
+ * final palette for
+ * each frame closest to the given color becomes the transparent color for that
+ * frame. May be set
* to null to indicate no transparent color.
*
* @param c Color to be treated as transparent on display.
@@ -130,9 +139,12 @@ public boolean addFrame(int[] pixels, int width, int height) {
}
/**
- * Adds next GIF frame. The frame is not written immediately, but is actually deferred until the
- * next frame is received so that timing data can be inserted. Invoking finish()
- * flushes all frames. If setSize
was not invoked, the size of the first image is
+ * Adds next GIF frame. The frame is not written immediately, but is actually
+ * deferred until the
+ * next frame is received so that timing data can be inserted. Invoking
+ * finish()
+ * flushes all frames. If setSize
was not invoked, the size of the
+ * first image is
* used for all subsequent frames.
*
* @param im BufferedImage containing frame to write.
@@ -174,11 +186,13 @@ public boolean addFrame(BufferedImage im) {
}
/**
- * Flushes any pending data and closes output file. If writing to an OutputStream, the stream is
+ * Flushes any pending data and closes output file. If writing to an
+ * OutputStream, the stream is
* not closed.
*/
public boolean finish() {
- if (!started) return false;
+ if (!started)
+ return false;
boolean ok = true;
started = false;
try {
@@ -205,7 +219,8 @@ public boolean finish() {
}
/**
- * Sets frame rate in frames per second. Equivalent to setDelay(1000/fps)
.
+ * Sets frame rate in frames per second. Equivalent to
+ * setDelay(1000/fps)
.
*
* @param fps float frame rate (frames per second)
*/
@@ -216,43 +231,53 @@ public void setFrameRate(float fps) {
}
/**
- * Sets quality of color quantization (conversion of images to the maximum 256 colors allowed by
- * the GIF specification). Lower values (minimum = 1) produce better colors, but slow processing
- * significantly. 10 is the default, and produces good color mapping at reasonable speeds. Values
+ * Sets quality of color quantization (conversion of images to the maximum 256
+ * colors allowed by
+ * the GIF specification). Lower values (minimum = 1) produce better colors, but
+ * slow processing
+ * significantly. 10 is the default, and produces good color mapping at
+ * reasonable speeds. Values
* greater than 20 do not yield significant improvements in speed.
*
* @param quality int greater than 0.
* @return
*/
public void setQuality(int quality) {
- if (quality < 1) quality = 1;
+ if (quality < 1)
+ quality = 1;
sample = quality;
}
/**
- * Sets the GIF frame size. The default size is the size of the first frame added if this method
+ * Sets the GIF frame size. The default size is the size of the first frame
+ * added if this method
* is not invoked.
*
* @param w int frame width.
* @param h int frame width.
*/
public void setSize(int w, int h) {
- if (started && !firstFrame) return;
+ if (started && !firstFrame)
+ return;
width = w;
height = h;
- if (width < 1) width = 320;
- if (height < 1) height = 240;
+ if (width < 1)
+ width = 320;
+ if (height < 1)
+ height = 240;
sizeSet = true;
}
/**
- * Initiates GIF file creation on the given stream. The stream is not closed automatically.
+ * Initiates GIF file creation on the given stream. The stream is not closed
+ * automatically.
*
* @param os OutputStream on which GIF images are written.
* @return false if initial write failed.
*/
public boolean start(OutputStream os) {
- if (os == null) return false;
+ if (os == null)
+ return false;
boolean ok = true;
closeStream = false;
out = os;
@@ -315,14 +340,15 @@ protected void analyzePixels() {
/** Returns index of palette color closest to c */
protected int findClosest(Color c) {
- if (colorTab == null) return -1;
+ if (colorTab == null)
+ return -1;
int r = (int) c.getRed();
int g = (int) c.getGreen();
int b = (int) c.getBlue();
int minpos = 0;
int dmin = 256 * 256 * 256;
int len = colorTab.length;
- for (int i = 0; i < len; ) {
+ for (int i = 0; i < len;) {
int dr = r - (colorTab[i++] & 0xff);
int dg = g - (colorTab[i++] & 0xff);
int db = b - (colorTab[i] & 0xff);
@@ -620,7 +646,8 @@ public NeuQuant(byte[] thepic, int len, int sample) {
public byte[] colorMap() {
byte[] map = new byte[3 * netsize];
int[] index = new int[netsize];
- for (int i = 0; i < netsize; i++) index[network[i][3]] = i;
+ for (int i = 0; i < netsize; i++)
+ index[network[i][3]] = i;
int k = 0;
for (int i = 0; i < netsize; i++) {
int j = index[i];
@@ -678,13 +705,15 @@ public void inxbuild() {
/* smallval entry is now in position i */
if (smallval != previouscol) {
netindex[previouscol] = (startpos + i) >> 1;
- for (j = previouscol + 1; j < smallval; j++) netindex[j] = i;
+ for (j = previouscol + 1; j < smallval; j++)
+ netindex[j] = i;
previouscol = smallval;
startpos = i;
}
}
netindex[previouscol] = (startpos + maxnetpos) >> 1;
- for (j = previouscol + 1; j < 256; j++) netindex[j] = maxnetpos; /* really 256 */
+ for (j = previouscol + 1; j < 256; j++)
+ netindex[j] = maxnetpos; /* really 256 */
}
/*
@@ -697,7 +726,8 @@ public void learn() {
byte[] p;
int pix, lim;
- if (lengthcount < minpicturebytes) samplefac = 1;
+ if (lengthcount < minpicturebytes)
+ samplefac = 1;
alphadec = 30 + ((samplefac - 1) / 3);
p = thepicture;
pix = 0;
@@ -708,18 +738,25 @@ public void learn() {
radius = initradius;
rad = radius >> radiusbiasshift;
- if (rad <= 1) rad = 0;
- for (i = 0; i < rad; i++) radpower[i] = alpha * (((rad * rad - i * i) * radbias) / (rad * rad));
+ if (rad <= 1)
+ rad = 0;
+ for (i = 0; i < rad; i++)
+ radpower[i] = alpha * (((rad * rad - i * i) * radbias) / (rad * rad));
// fprintf(stderr,"beginning 1D learning: initial radius=%d\n", rad);
- if (lengthcount < minpicturebytes) step = 3;
- else if ((lengthcount % prime1) != 0) step = 3 * prime1;
+ if (lengthcount < minpicturebytes)
+ step = 3;
+ else if ((lengthcount % prime1) != 0)
+ step = 3 * prime1;
else {
- if ((lengthcount % prime2) != 0) step = 3 * prime2;
+ if ((lengthcount % prime2) != 0)
+ step = 3 * prime2;
else {
- if ((lengthcount % prime3) != 0) step = 3 * prime3;
- else step = 3 * prime4;
+ if ((lengthcount % prime3) != 0)
+ step = 3 * prime3;
+ else
+ step = 3 * prime4;
}
}
@@ -731,18 +768,22 @@ public void learn() {
j = contest(b, g, r);
altersingle(alpha, j, b, g, r);
- if (rad != 0) alterneigh(rad, j, b, g, r); /* alter neighbours */
+ if (rad != 0)
+ alterneigh(rad, j, b, g, r); /* alter neighbours */
pix += step;
- if (pix >= lim) pix -= lengthcount;
+ if (pix >= lim)
+ pix -= lengthcount;
i++;
- if (delta == 0) delta = 1;
+ if (delta == 0)
+ delta = 1;
if (i % delta == 0) {
alpha -= alpha / alphadec;
radius -= radius / radiusdec;
rad = radius >> radiusbiasshift;
- if (rad <= 1) rad = 0;
+ if (rad <= 1)
+ rad = 0;
for (j = 0; j < rad; j++)
radpower[j] = alpha * (((rad * rad - j * j) * radbias) / (rad * rad));
}
@@ -771,16 +812,20 @@ public int map(int b, int g, int r) {
if (i < netsize) {
p = network[i];
dist = p[1] - g; /* inx key */
- if (dist >= bestd) i = netsize; /* stop iter */
+ if (dist >= bestd)
+ i = netsize; /* stop iter */
else {
i++;
- if (dist < 0) dist = -dist;
+ if (dist < 0)
+ dist = -dist;
a = p[0] - b;
- if (a < 0) a = -a;
+ if (a < 0)
+ a = -a;
dist += a;
if (dist < bestd) {
a = p[2] - r;
- if (a < 0) a = -a;
+ if (a < 0)
+ a = -a;
dist += a;
if (dist < bestd) {
bestd = dist;
@@ -792,16 +837,20 @@ public int map(int b, int g, int r) {
if (j >= 0) {
p = network[j];
dist = g - p[1]; /* inx key - reverse dif */
- if (dist >= bestd) j = -1; /* stop iter */
+ if (dist >= bestd)
+ j = -1; /* stop iter */
else {
j--;
- if (dist < 0) dist = -dist;
+ if (dist < 0)
+ dist = -dist;
a = p[0] - b;
- if (a < 0) a = -a;
+ if (a < 0)
+ a = -a;
dist += a;
if (dist < bestd) {
a = p[2] - r;
- if (a < 0) a = -a;
+ if (a < 0)
+ a = -a;
dist += a;
if (dist < bestd) {
bestd = dist;
@@ -851,9 +900,11 @@ protected void alterneigh(int rad, int i, int b, int g, int r) {
int[] p;
lo = i - rad;
- if (lo < -1) lo = -1;
+ if (lo < -1)
+ lo = -1;
hi = i + rad;
- if (hi > netsize) hi = netsize;
+ if (hi > netsize)
+ hi = netsize;
j = i + 1;
k = i - 1;
@@ -916,12 +967,15 @@ protected int contest(int b, int g, int r) {
for (i = 0; i < netsize; i++) {
n = network[i];
dist = n[0] - b;
- if (dist < 0) dist = -dist;
+ if (dist < 0)
+ dist = -dist;
a = n[1] - g;
- if (a < 0) a = -a;
+ if (a < 0)
+ a = -a;
dist += a;
a = n[2] - r;
- if (a < 0) a = -a;
+ if (a < 0)
+ a = -a;
dist += a;
if (dist < bestd) {
bestd = dist;
@@ -1040,8 +1094,8 @@ class LZWEncoder {
int cur_bits = 0;
int masks[] = {
- 0x0000, 0x0001, 0x0003, 0x0007, 0x000F, 0x001F, 0x003F, 0x007F, 0x00FF, 0x01FF, 0x03FF, 0x07FF,
- 0x0FFF, 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF
+ 0x0000, 0x0001, 0x0003, 0x0007, 0x000F, 0x001F, 0x003F, 0x007F, 0x00FF, 0x01FF, 0x03FF, 0x07FF,
+ 0x0FFF, 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF
};
// Number of characters so far in this 'packet'
@@ -1062,7 +1116,8 @@ class LZWEncoder {
// characters, flush the packet to disk.
void char_out(byte c, OutputStream outs) throws IOException {
accum[a_count++] = c;
- if (a_count >= 254) flush_char(outs);
+ if (a_count >= 254)
+ flush_char(outs);
}
// Clear out the hash table
@@ -1078,7 +1133,8 @@ void cl_block(OutputStream outs) throws IOException {
// reset code table
void cl_hash(int hsize) {
- for (int i = 0; i < hsize; ++i) htab[i] = -1;
+ for (int i = 0; i < hsize; ++i)
+ htab[i] = -1;
}
void compress(int init_bits, OutputStream outs) throws IOException {
@@ -1107,7 +1163,8 @@ void compress(int init_bits, OutputStream outs) throws IOException {
ent = nextPixel();
hshift = 0;
- for (fcode = hsize; fcode < 65536; fcode *= 2) ++hshift;
+ for (fcode = hsize; fcode < 65536; fcode *= 2)
+ ++hshift;
hshift = 8 - hshift; // set hash code range bound
hsize_reg = hsize;
@@ -1115,8 +1172,7 @@ void compress(int init_bits, OutputStream outs) throws IOException {
output(ClearCode, outs);
- outer_loop:
- while ((c = nextPixel()) != EOF) {
+ outer_loop: while ((c = nextPixel()) != EOF) {
fcode = (c << maxbits) + ent;
i = (c << hshift) ^ ent; // xor hashing
@@ -1126,9 +1182,11 @@ void compress(int init_bits, OutputStream outs) throws IOException {
} else if (htab[i] >= 0) // non-empty slot
{
disp = hsize_reg - i; // secondary hash (after G. Knott)
- if (i == 0) disp = 1;
+ if (i == 0)
+ disp = 1;
do {
- if ((i -= disp) < 0) i += hsize_reg;
+ if ((i -= disp) < 0)
+ i += hsize_reg;
if (htab[i] == fcode) {
ent = codetab[i];
@@ -1141,7 +1199,8 @@ void compress(int init_bits, OutputStream outs) throws IOException {
if (free_ent < maxmaxcode) {
codetab[i] = free_ent++; // code -> hashtable
htab[i] = fcode;
- } else cl_block(outs);
+ } else
+ cl_block(outs);
}
// Put out the final code.
output(ent, outs);
@@ -1169,7 +1228,7 @@ void flush_char(OutputStream outs) throws IOException {
}
}
- final int MAXCODE(int n_bits) {
+ int MAXCODE(int n_bits) {
return (1 << n_bits) - 1;
}
@@ -1177,7 +1236,8 @@ final int MAXCODE(int n_bits) {
// Return the next pixel from the image
// ----------------------------------------------------------------------------
private int nextPixel() {
- if (remaining == 0) return EOF;
+ if (remaining == 0)
+ return EOF;
--remaining;
@@ -1189,8 +1249,10 @@ private int nextPixel() {
void output(int code, OutputStream outs) throws IOException {
cur_accum &= masks[cur_bits];
- if (cur_bits > 0) cur_accum |= (code << cur_bits);
- else cur_accum = code;
+ if (cur_bits > 0)
+ cur_accum |= (code << cur_bits);
+ else
+ cur_accum = code;
cur_bits += n_bits;
@@ -1208,8 +1270,10 @@ void output(int code, OutputStream outs) throws IOException {
clear_flg = false;
} else {
++n_bits;
- if (n_bits == maxbits) maxcode = maxmaxcode;
- else maxcode = MAXCODE(n_bits);
+ if (n_bits == maxbits)
+ maxcode = maxmaxcode;
+ else
+ maxcode = MAXCODE(n_bits);
}
}
diff --git a/src/org/openpatch/scratch/internal/Applet.java b/src/org/openpatch/scratch/internal/Applet.java
index 4321e515..18a7bffe 100644
--- a/src/org/openpatch/scratch/internal/Applet.java
+++ b/src/org/openpatch/scratch/internal/Applet.java
@@ -37,13 +37,13 @@ private class StageBox {
public Stage stage;
public String name;
- public StageBox(final String name, final Stage stage) {
+ public StageBox(String name, final Stage stage) {
this.name = name;
this.stage = stage;
}
}
- public Applet(final int width, final int height, final String assets) {
+ public Applet(int width, final int height, final String assets) {
this.INITIAL_HEIGHT = height;
this.INITIAL_WIDTH = width;
this.assets = assets;
@@ -62,7 +62,7 @@ public static Applet getInstance() {
return instance;
}
- public void setDebug(final boolean debug) {
+ public void setDebug(boolean debug) {
this.debug = debug;
}
@@ -78,8 +78,8 @@ public int getHeight() {
return this.height;
}
- public void addStage(final String name, final Stage stage) {
- for (final StageBox s : this.stages) {
+ public void addStage(String name, final Stage stage) {
+ for (StageBox s : this.stages) {
if (s.name.equals(name)) {
return;
}
@@ -92,8 +92,8 @@ public void addStage(final String name, final Stage stage) {
}
}
- public Stage getStage(final String name) {
- for (final StageBox s : this.stages) {
+ public Stage getStage(String name) {
+ for (StageBox s : this.stages) {
if (s.name.equals(name)) {
return s.stage;
}
@@ -101,13 +101,13 @@ public Stage getStage(final String name) {
return null;
}
- public void removeStage(final String name) {
+ public void removeStage(String name) {
this.stages.removeIf(sb -> sb.name.equals(name));
}
- public void switchStage(final String name) {
+ public void switchStage(String name) {
for (int i = 0; i < this.stages.size(); i++) {
- final StageBox stageBox = this.stages.get(i);
+ StageBox stageBox = this.stages.get(i);
if (stageBox.name.equals(name)) {
this.currentStage = i;
return;
@@ -156,13 +156,13 @@ public void setup() {
this.imageMode(PConstants.CENTER);
this.rectMode(PConstants.CENTER);
this.loading = this.loadImage("loading.png");
- final var loadingScaleX = this.INITIAL_WIDTH / 480.0;
- final var loadingScaleY = this.INITIAL_HEIGHT / (360.0 + 150); // normal height + padding for loading text
- final var scale = Math.min(1, Math.min(loadingScaleX, loadingScaleY));
- this.loading.resize((int) (this.loading.width * scale), (int)(this.loading.height * scale));
+ var loadingScaleX = this.INITIAL_WIDTH / 480.0;
+ var loadingScaleY = this.INITIAL_HEIGHT / (360.0 + 150); // normal height + padding for loading text
+ var scale = Math.min(1, Math.min(loadingScaleX, loadingScaleY));
+ this.loading.resize((int) (this.loading.width * scale), (int) (this.loading.height * scale));
}
- private void setLoadingText(final String type, final String path) {
+ private void setLoadingText(String type, final String path) {
this.loadingText = "Loading " + type + ": ";
if (path.length() > 40) {
this.loadingText += "..." + path.substring(path.length() - 40);
@@ -176,22 +176,22 @@ public void loadAssets() {
if (this.assets != null) {
try {
this.loadingText = "Finding files...";
- final var p =Path.of(ClassLoader.getSystemResource(this.assets).toURI());
- final var imageFiles = Files.find(
+ var p = Path.of(ClassLoader.getSystemResource(this.assets).toURI());
+ var imageFiles = Files.find(
p,
Integer.MAX_VALUE,
(filePath, fileAttr) -> fileAttr.isRegularFile())
.map(f -> f.toString())
.filter(f -> f.endsWith(".png") || f.endsWith(".jpg") || f.endsWith(".jpeg"))
.collect(Collectors.toList());
- final var soundFiles = Files.find(
+ var soundFiles = Files.find(
p,
Integer.MAX_VALUE,
(filePath, fileAttr) -> fileAttr.isRegularFile())
.map(f -> f.toString())
.filter(f -> f.endsWith(".mp3") || f.endsWith(".wav"))
.collect(Collectors.toList());
- final var fontFiles = Files.find(
+ var fontFiles = Files.find(
p,
Integer.MAX_VALUE,
(filePath, fileAttr) -> fileAttr.isRegularFile())
@@ -201,22 +201,22 @@ public void loadAssets() {
this.numberAssets += imageFiles.size();
this.numberAssets += soundFiles.size();
this.numberAssets += fontFiles.size();
- for (final var file : imageFiles) {
+ for (var file : imageFiles) {
this.setLoadingText("Image", file);
Image.loadImage(file);
this.loadedAssets += 1;
}
- for (final var file : fontFiles) {
+ for (var file : fontFiles) {
this.setLoadingText("Font", file);
Font.loadFont(file);
this.loadedAssets += 1;
}
- for (final var file : soundFiles) {
+ for (var file : soundFiles) {
this.setLoadingText("Sound", file);
new SoundFile(this, file, true);
this.loadedAssets += 1;
}
- } catch (final IOException | URISyntaxException e) {
+ } catch (IOException | URISyntaxException e) {
}
}
}
@@ -228,23 +228,23 @@ private float loadingStatus() {
public void pre() {
if (this.loadingStatus() == 1 && this.stages.size() > 0) {
try {
- final StageBox box = this.stages.get(this.currentStage);
+ StageBox box = this.stages.get(this.currentStage);
box.stage.pre();
- } catch (final ArrayIndexOutOfBoundsException e) {
+ } catch (ArrayIndexOutOfBoundsException e) {
}
}
}
- public void mouseEvent(final MouseEvent e) {
+ public void mouseEvent(MouseEvent e) {
if (this.loadingStatus() == 1 && this.stages.size() > 0) {
- final StageBox box = this.stages.get(this.currentStage);
+ StageBox box = this.stages.get(this.currentStage);
box.stage.mouseEvent(e);
}
}
- public void keyEvent(final KeyEvent e) {
+ public void keyEvent(KeyEvent e) {
if (this.loadingStatus() == 1 && this.stages.size() > 0) {
- final StageBox box = this.stages.get(this.currentStage);
+ StageBox box = this.stages.get(this.currentStage);
box.stage.keyEvent(e);
}
if (e.getKeyCode() == KeyCode.VK_F11) {
@@ -253,7 +253,7 @@ public void keyEvent(final KeyEvent e) {
}
public void draw() {
- final int sizeStages = this.stages.size();
+ int sizeStages = this.stages.size();
if (this.loadingStatus() < 1) {
this.background(0x222222);
this.image(this.loading, this.width / 2, this.height / 2);
@@ -262,10 +262,10 @@ public void draw() {
this.textSize(20);
this.textSize(14);
this.text(this.loadingText, this.width / 2, this.height / 2 +
- this.loading.height / 2 + 20);
+ this.loading.height / 2 + 20);
this.textSize(20);
this.text(round(this.loadingStatus() * 100) + "%", this.width / 2, this.height / 2 +
- this.loading.height / 2 + 40);
+ this.loading.height / 2 + 40);
this.textSize(14);
} else if (sizeStages > 0) {
if (this.currentStage > sizeStages - 1) {
@@ -274,9 +274,9 @@ public void draw() {
this.currentStage = 0;
}
try {
- final StageBox box = this.stages.get(this.currentStage);
+ StageBox box = this.stages.get(this.currentStage);
box.stage.draw();
- } catch (final ArrayIndexOutOfBoundsException e) {
+ } catch (ArrayIndexOutOfBoundsException e) {
}
}
}