css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              #cc
  max-width 1536px
  margin 0 auto
            
          
!
            
              var w = 1536;
var h = 864;
var canvas;
var epoch = 0;
var level = 0;
const inst = ["",
             "There's only one way, press a key",
             "If it's wrong, try the other way around",
             "RGB",
             "Dark pink, yellow, soft green, navy",
             "Brightness descending",
             "Red to magenta",
             "Make them alternate",
             "Autumn forest: stones, soil, grass, fallen leaves, the last dandelion, needles on trees, the sky, clouds",
             "The invisible amid the visible",
             "First four levels in one",
             "Level nine... vice versa"];
const lvcs = [[],
             ["#fff"],
             ["#f80","#08f"],
             ["#f00","#0f0","#00f"],
             ["#804","#880","#084","#008"],
["#555","#444","#333","#222","#111"],
["#800","#880","#080","#088","#008","#808"],
["#880","#222","#880","#222","#880","#222","#880"],
["#222","#420","#080","#840","#fc0","#040","#8cf","#aaa"],
["#400","#400","#400","#400","#000","#400","#400","#400","#400"],
["#fff","#f80","#08f","#f00","#0f0","#00f","#804","#880","#084","#008"],
["#000","#000","#000","#000","#000","#400","#000","#000","#000","#000","#000"]];
var heis = [];
var cols = [];
var tc;
var xc;
var taken;
var done = null;
const delay = 2000;

function setup() {
  canvas = createCanvas(w,h);
  canvas.parent("cc");
  textFont("Montserrat");
  textAlign(CENTER, CENTER);
  rectMode(CORNER);
  noStroke();
}

function draw() {
  background(0);
  switch (epoch) {
    case 0:
      fill(255);
      textSize(216);
      text("Taken", w/2, h/2);
      textSize(36);
      text("Press any key to continue...", w/2, h*2/3);
      break;
    case 1:
      text("This is a recreation of one of my past games.\nThe original was made using pygame,\nwhich made the implementation slow and painful.\n\nYou are a horizontal line.\nIn this game, white means neutral, colourless.\nUse the right and left arrows to traverse the landscape\nmade of colourful (not white) columns. You can only step up one block at a time.\nPress the up arrow to pick up the colour beneath you.\nThe colour is now taken, as represented by you carrying a square of that colour.\nThen, move to another column and press the down arrow\nto paint the column the taken colour.\nYou turn white again and the original colour of the column\nbelow you is used to fill the white column.\nHowever, it's not just the colour that's being transferred.\nWhen you pick up a column's colour, you pick up one of its blocks as well,\nwhen you put it back down, you increase the height of the column under you.\nOrder the colours according to the instructions at the top of the screen\nand stand on the rightmost column in order to proceed, press R to reset.", w/2, h/2);
      break;
    case 2:
      for (let i in cols) {
        fill(cols[i]);
        rect(i*w/level, h, w/level, -heis[i]*h/12);
      }
      fill(255);
      textSize(28);
      text(inst[level], w/2, h/24);
      rect((xc+.25)*w/level,(11.5-heis[xc])*h/12,w/level/2,1);
      if (taken)  {
        fill(taken);
        rectMode(CENTER);
        rect((xc+.5)*w/level,(11.5-heis[xc])*h/12,h/48,h/48);
        rectMode(CORNER);
      }
      if (done && done+delay < millis()) nextl();
      break;
    case 3:
      textSize(144);
      fill(255);
      text("Congratulations!", w/2 , h/2);
  }
}

function nextl() {
  done = null;
  level++;
  if (level > 11) {
    epoch++;
    return;
  }
  cols = Array(level).fill("#000");
  heis = Array(level).fill(0);
  for (let i in cols) {
    cols[i] = lvcs[level][i];
    heis[i] = Math.min(Math.floor(2+Math.random()*(int(i)+1)), 11);
  }
  cols.sort((a, b) => Math.random()-.5);
  xc = 0;
  taken = null;
}

function keyPressed() {
  switch (epoch) {
    case 1:
      nextl();
    case 0:
      epoch++;
      break;
    case 2:
      if (done) return;
      if (key == 'R') {
        level--;
        nextl();
      }
      switch (keyCode) {
        case RIGHT_ARROW:
          if (xc < level-1 && heis[xc+1] <= heis[xc]+1) xc++;
          break;
        case LEFT_ARROW:
          if (xc && heis[xc-1] <= heis[xc]+1) xc--;
          break;
        case UP_ARROW:
        case DOWN_ARROW:
          if (taken) {
            heis[xc]++;
            cols[tc] = cols[xc];
            cols[xc] = taken;
            taken = null;
          } else {
            heis[xc]--;
            tc = xc;
            taken = cols[xc];
            cols[xc] = "#fff";
          }
      }
      if (xc == level-1) {
        for (let i in cols) {
          if (cols[i] != lvcs[level][i]) return;
        }
        done = millis();
      }
  }
}
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console