Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Hex-A-Tron
- *
- * by tchnmncr @ eldri.tech
- *
- * See http://eldri.tech/portfolio/vehicles/#Hex-A-Tron
- * for more info.
- *
- */
- PImage bg, fg; // background and foreground images
- PShape grid; // svg grid of 16 triangles
- PShape[] sectors = new PShape[16]; // array of triangles from grid
- int prevSect1 = 0; // # of first previous sector
- int prevSect2 = 0; // # of second previous sector
- String[] lines; // lines of string data from text file
- int hIndex = 0; // horizontal (x) index
- int vIndex = 0; // vertical (y) index
- void setup() {
- size(1920, 1080); // set screen size to 1080p
- // load png and svg images
- bg = loadImage("bg.png");
- fg = loadImage("fg.png");
- grid = loadShape("grid.svg");
- // fill PShape[] array with shapes from svg file
- for (int i = 0; i < sectors.length; i++) {
- sectors[i] = grid.getChild(str(i));
- }
- // get lines of string data from text file
- lines = loadStrings("spell.txt");
- }
- void draw() {
- // draw background layer
- background(bg);
- // reset previous sectors' colors
- sectors[prevSect1].setFill(#660000);
- sectors[prevSect2].setFill(#660000);
- // get the next character in the file
- char newChar = lines[vIndex].charAt(hIndex);
- // if that character is not '*' then
- // change colors for sectors corresponding to character's hex value
- if (newChar != '*') {
- String hexVal = hex(newChar);
- int newSect1 = unhex(str(hexVal.charAt(2)));
- int newSect2 = unhex(str(hexVal.charAt(3)));
- // debug
- // println(newChar + " " + hexVal + " " + newSect1 + " " + newSect2);
- // println("hIndex: " + hIndex + " vIndex: " + vIndex);
- // set new sectors' colors
- sectors[newSect1].setFill(#aa0000);
- sectors[newSect2].setFill(#ff0000);
- // record sector values to reset in the next iteration
- prevSect1 = newSect1;
- prevSect2 = newSect2;
- }
- // draw the sectors
- shape(grid);
- // advance horizontal and vertical indices
- hIndex++;
- if (hIndex == lines[vIndex].length()) {
- hIndex = 0;
- vIndex++;
- if (vIndex == lines.length) {
- vIndex = 0;
- }
- }
- // draw foreground layer
- image(fg, 0, 0);
- // delay one second
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement