From 648d2dd2d668261ecc90f05d35ae20c781b21712 Mon Sep 17 00:00:00 2001 From: pommicket Date: Sun, 8 Jan 2017 10:49:29 -0500 Subject: Bug fixes The output bitmap sometimes had negative numbers, which caused problems. (Because % is the remainder, not the modulus). --- .../org/neocities/autoart/autoart/AutoArt.java | 30 +++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'src') 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; } -- cgit v1.2.3