daily pastebin goal
79%
SHARE
TWEET

Hex-A-Tron.pde

tchnmncr Sep 19th, 2017 (edited) 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Hex-A-Tron
  3.  *
  4.  * by tchnmncr @ eldri.tech
  5.  *
  6.  * See http://eldri.tech/portfolio/vehicles/#Hex-A-Tron
  7.  * for more info.
  8.  *
  9.  */
  10.  
  11. PImage bg, fg; // background and foreground images
  12. PShape grid; // svg grid of 16 triangles
  13. PShape[] sectors = new PShape[16]; // array of triangles from grid
  14. int prevSect1 = 0; // # of first previous sector
  15. int prevSect2 = 0; // # of second previous sector
  16. String[] lines; // lines of string data from text file
  17. int hIndex = 0; // horizontal (x) index
  18. int vIndex = 0; // vertical (y) index
  19.  
  20. void setup() {
  21.   size(1920, 1080); // set screen size to 1080p
  22.  
  23.   // load png and svg images
  24.   bg = loadImage("bg.png");
  25.   fg = loadImage("fg.png");
  26.   grid = loadShape("grid.svg");
  27.  
  28.   // fill PShape[] array with shapes from svg file
  29.   for (int i = 0; i < sectors.length; i++) {
  30.     sectors[i] = grid.getChild(str(i));
  31.   }
  32.  
  33.   // get lines of string data from text file
  34.   lines = loadStrings("spell.txt");
  35. }
  36.  
  37. void draw() {
  38.  
  39.   // draw background layer
  40.   background(bg);
  41.  
  42.   // reset previous sectors' colors
  43.   sectors[prevSect1].setFill(#660000);
  44.   sectors[prevSect2].setFill(#660000);
  45.  
  46.   // get the next character in the file
  47.   char newChar = lines[vIndex].charAt(hIndex);
  48.  
  49.   // if that character is not '*' then
  50.   // change colors for sectors corresponding to character's hex value
  51.   if (newChar != '*') {
  52.    
  53.     String hexVal = hex(newChar);
  54.    
  55.     int newSect1 = unhex(str(hexVal.charAt(2)));
  56.     int newSect2 = unhex(str(hexVal.charAt(3)));
  57.    
  58.     // debug
  59.     // println(newChar + " " + hexVal + " " + newSect1 + " " + newSect2);
  60.     // println("hIndex: " + hIndex + "  vIndex: " + vIndex);
  61.    
  62.     // set new sectors' colors
  63.     sectors[newSect1].setFill(#aa0000);
  64.     sectors[newSect2].setFill(#ff0000);
  65.    
  66.     // record sector values to reset in the next iteration
  67.     prevSect1 = newSect1;
  68.     prevSect2 = newSect2;
  69.   }
  70.  
  71.   // draw the sectors
  72.   shape(grid);
  73.  
  74.   // advance horizontal and vertical indices  
  75.   hIndex++;
  76.   if (hIndex == lines[vIndex].length()) {
  77.     hIndex = 0;
  78.     vIndex++;
  79.     if (vIndex == lines.length) {
  80.       vIndex = 0;
  81.     }
  82.   }
  83.  
  84.   // draw foreground layer
  85.   image(fg, 0, 0);
  86.  
  87.   // delay one second
  88.   delay(1000);
  89. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top