Commits

Anonymous committed 1c0eba8

Using subpixel blit for Noise demo now

  • Participants
  • Parent commits 128ba11

Comments (0)

Files changed (1)

File src/main/java/net/fishbulb/jcod/demo/Noise.java

 
 import com.badlogic.gdx.Input;
 import com.badlogic.gdx.graphics.Color;
-import com.google.common.collect.Iterators;
+import com.badlogic.gdx.graphics.Pixmap;
 import net.fishbulb.jcod.Console;
-import net.fishbulb.jcod.util.BlendMode;
+import net.fishbulb.jcod.util.ImageUtils;
 import toxi.math.noise.PerlinNoise;
 
-import java.util.Iterator;
-
-import static java.lang.Math.*;
-import static net.fishbulb.jcod.util.BlendMode.*;
-import static net.fishbulb.jcod.util.PlotAlgorithms.PlotFunction;
-import static net.fishbulb.jcod.util.PlotAlgorithms.bresenham;
+import static java.lang.Math.max;
+import static java.lang.Math.min;
+import static net.fishbulb.jcod.util.BlendMode.None;
+import static net.fishbulb.jcod.util.BlendMode.Set;
 
 public class Noise extends DemoApplet {
 
 
     private PerlinNoise noise;
 
+    private Pixmap img;
+
     public Noise(Console parent) {
         super(parent);
         console.setDefaultForeground(Color.WHITE);
         console.setBlendFunction(Set);
         noise = new PerlinNoise();
+        img = new Pixmap(console.getWidth() * 2, console.getHeight() * 2, Pixmap.Format.RGBA8888);
     }
 
     @Override public void update() {
         if ((now - lastUpdate) < updateMillis) return;
         lastUpdate = now;
         console.setBlendFunction(Set);
-        for (int y = 0; y < height; y++) {
-            for (int x = 0; x < width; x++) {
-                float xx = (float) x*zoom / width + dx;
-                float yy = (float) y*zoom / height + dy;
+        for (int y = 0; y < img.getHeight(); y++) {
+            for (int x = 0; x < img.getWidth(); x++) {
+                float xx = (float) x * zoom / width + dx;
+                float yy = (float) y * zoom / height + dy;
                 float val = noise.noise(xx, yy);
                 currentColor.set(noiseColor);
                 currentColor.mul(val);
-                console.setCharBackground(x,y,currentColor);
+                img.drawPixel(x, y, Color.rgba8888(currentColor));
             }
         }
+        ImageUtils.imageBlit2x(img, console, 0, 0, 0, 0, img.getWidth(), img.getHeight());
         console.setBlendFunction(None);
         console.setDefaultForeground(Color.WHITE);
         console.print(0, 0, String.format("zoom: %.1f    ", zoom));