Commits

Anonymous committed 1fb4fef

new demo app

  • Participants
  • Parent commits ae4eb44

Comments (0)

Files changed (1)

src/main/java/net/fishbulb/jcod/demo/Demo.java

 import com.badlogic.gdx.graphics.GL10;
 import com.badlogic.gdx.graphics.Texture;
 import com.badlogic.gdx.scenes.scene2d.Stage;
-import com.badlogic.gdx.scenes.scene2d.actions.Actions;
 import net.fishbulb.jcod.Console;
-import net.fishbulb.jcod.display.Tile;
 import net.fishbulb.jcod.display.TileDisplay;
 import net.fishbulb.jcod.display.Tileset;
 
+import java.util.Random;
+
+import static net.fishbulb.jcod.util.ColorUtils.lerp;
+
 public class Demo extends InputAdapter implements ApplicationListener {
     Stage stage;
 
+    int SAMPLE_SCREEN_WIDTH = 120;
+    int SAMPLE_SCREEN_HEIGHT = 90;
+
+    int TOPLEFT = 0;
+    int TOPRIGHT = 1;
+    int BOTTOMLEFT = 2;
+    int BOTTOMRIGHT = 3;
+
+    int[] dirr = {1, -1, 1, 1};
+    int[] dirg = {1, -1, -1, 1};
+    int[] dirb = {1, 1, 1, -1};
+
+    Color[] cols = new Color[]{
+            new Color(0.19f, 0.15f, 0.58f, 1),
+            new Color(0.94f, 0.33f, 0.01f, 1),
+            new Color(0.19f, 0.13f, 0.94f, 1),
+            new Color(0.03f, 0.78f, 0.50f, 1)
+    }; // random corner colors
+
+    Random rng = new Random();
+    private Console console;
+
+    private void renderConsole() {
+        // tweak colors
+        for (int c = 0; c < 4; c++) {
+            // move each corner color
+            int component = rng.nextInt(3);
+            switch (component) {
+                case 0:
+                    cols[c].r += 0.01f * dirr[c];
+                    if (cols[c].r >= 1) dirr[c] = -1;
+                    else if (cols[c].r <= 0) dirr[c] = 1;
+                    break;
+                case 1:
+                    cols[c].g += 0.01f * dirg[c];
+                    if (cols[c].g >= 1) dirg[c] = -1;
+                    else if (cols[c].g <= 0) dirg[c] = 1;
+                    break;
+                case 2:
+                    cols[c].b += 0.01f * dirb[c];
+                    if (cols[c].b >= 1) dirb[c] = -1;
+                    else if (cols[c].b <= 0) dirb[c] = 1;
+                    break;
+            }
+        }
+
+        Color top = new Color();
+        Color bottom = new Color();
+        Color cur = new Color();
+
+        for (int x = 0; x < SAMPLE_SCREEN_WIDTH; x++) {
+            float xcoef = (float) (x) / (SAMPLE_SCREEN_WIDTH - 1);
+            // get the current column top and bottom colors
+            lerp(cols[TOPLEFT], cols[TOPRIGHT], xcoef, top);
+            lerp(cols[BOTTOMLEFT], cols[BOTTOMRIGHT], xcoef, bottom);
+            for (int y = 0; y < SAMPLE_SCREEN_HEIGHT; y++) {
+                float ycoef = (float) (y) / (SAMPLE_SCREEN_HEIGHT - 1);
+                // get the current cell color
+                lerp(top, bottom, ycoef, cur);
+                console.setCharBackground(x, y, cur);
+            }
+        }
+        console.flush();
+    }
+
     @Override
     public void create() {
         stage = new Stage();
         Texture tiles = new Texture(Gdx.files.internal("tiles/terminal_trans.png"));
         Tileset tileset = new Tileset(tiles, 8, 8, Tileset.Layout.InColumns);
 
-        TileDisplay display = new TileDisplay(10, 10, 16, 16);
-        Console console = new Console(tileset, 10, 10, display);
+        TileDisplay display = new TileDisplay(SAMPLE_SCREEN_WIDTH, SAMPLE_SCREEN_HEIGHT, 8, 8);
+        console = new Console(tileset, SAMPLE_SCREEN_WIDTH, SAMPLE_SCREEN_HEIGHT, display);
 
         stage.addActor(console.getDisplay());
 
-        Tile floor = tileset.get(15, 10);
-        Tile wall = tileset.get(11, 1);
-        Tile arrow = tileset.get(1, 0);
-        Tile bangBang = tileset.get(1, 3);
-
-        tileset.mapChar('.', floor);
-        tileset.mapChar('#', wall);
-        tileset.mapChar('>', arrow);
-        tileset.mapChar('\u203c', bangBang);    // ‼ DOUBLE EXCLAMATION MARK
-
-
-        console.setChar(1, 1, (char) 23);
-        console.setCharBackground(1,1,Color.YELLOW);
-        console.setCharForeground(1,1,Color.MAGENTA);
-        console.setChar(3, 3, '#');
-        console.flush();
-
-
-        display.addAction(Actions.alpha(0,5));
 
     }
 
+
     @Override
     public void resize(int width, int height) {
     }
 
     @Override
     public void render() {
+        renderConsole();
         Gdx.gl.glClearColor(0, 0, 0, 0);
         Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
         stage.act(Math.min(Gdx.graphics.getDeltaTime(), 1 / 30f));