summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorpommicket <leonardomtenenbaum@gmail.com>2017-01-08 10:49:29 -0500
committerpommicket <leonardomtenenbaum@gmail.com>2017-01-08 10:49:29 -0500
commit648d2dd2d668261ecc90f05d35ae20c781b21712 (patch)
tree83fa7c6d7d9a2bf7c803c7ac676a0a7cf26eed53 /src
parentfc8b7f555ff9202220eee46b181c6fef2ac4c166 (diff)
Bug fixesHEADmaster
The output bitmap sometimes had negative numbers, which caused problems. (Because % is the remainder, not the modulus).
Diffstat (limited to 'src')
-rw-r--r--src/java/org/neocities/autoart/autoart/AutoArt.java30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/java/org/neocities/autoart/autoart/AutoArt.java b/src/java/org/neocities/autoart/autoart/AutoArt.java
index 9de5e28..ab24c0a 100644
--- a/src/java/org/neocities/autoart/autoart/AutoArt.java
+++ b/src/java/org/neocities/autoart/autoart/AutoArt.java
@@ -20,6 +20,34 @@ import java.util.Stack;
public class AutoArt extends AppCompatActivity
{
+
+ int sgn(double x)
+ {
+ if (x > 0)
+ return 1;
+ return -1;
+ }
+
+ double mod(double a, double b)
+ {
+ if (b <= 0)
+ throw new RuntimeException("Mod <=0! Mod < 0 not implemented yet!");
+
+ if (sgn(a) == sgn(b))
+ {
+ return a % b;
+ }
+ else
+ {
+ while (a < 0)
+ {
+ a += b;
+ }
+ return a;
+ }
+ }
+
+
final int FUNCTION_LENGTH = 20;
double[][] matrix_add(double[][] a, double[][] b)
{
@@ -109,7 +137,7 @@ public class AutoArt extends AppCompatActivity
for (int i = 0; i < m.length; i++)
{
for (int j = 0; j < m[i].length; j++)
- cpy[i][j] = m[i][j] % 256;
+ cpy[i][j] = mod(m[i][j], 256);
}
return cpy;
}