Pen Settings

HTML

CSS

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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                #cc
              
            
!

CSS

              
                #cc
  max-width 1536px
  margin 0 auto
              
            
!

JS

              
                var w = 1536;
var h = 864;
var canvas;
var epoch = 0;
var curse = "";
var curses = ["f***", "c***", "d***", "s***", "h***", "b***", "r***"];
var purses = [[0, 0], [0, 0]];
var gend;
var genp = 4000;
var cols = [];
var score = 0;

function setup() {
  canvas = createCanvas(w,h);
  canvas.parent("cc");
  textFont("Montserrat");
  cols = [color(128, 64, 32), color(32, 64, 128), color(32, 128, 32), color(64, 64, 64)];
  shuf(curses);
  console.log(purses[0]);
}

function draw() {
  background(255);
  switch (epoch) {
    case 0:
      textAlign(CENTER, CENTER);
      textSize(216);
      text("CURSES", w/2, h/4);
      text("PURSES", w/2, h*3/4);
      textSize(144);
      text("versus", w/2, h/2);
      break;
    case 1:
      textAlign(CENTER, CENTER);
      textSize(48);
      rectMode(CENTER);
      text("You have decided to go on a little pickpocketing adventure. And, man, is it tedious! You can't resist some cursing. After all, it looks like it's even useful. You have seven curse words available: f***, c***, d***, h***, b***, r*** and s***. Each of these corresponds to either one of the three shapes or one of the four colours of the purses in the game. After pressing any key to continue, you can type in a curse to pick appropriate purses. The mapping of curses to purse traits is randomized every game. You lose when there are too many purses to keep track of.", w/2, h/2, w, h);
      break;
    case 2:
      textAlign(CENTER, CENTER);
      textSize(72);
      text(curse, w/2, h/4);
      //console.log("drawing epoch 2");
      if (millis() > gend+genp) {
        if (purses.length > 12) {
          epoch = 3;
        } else {
          pgen();
          gend += genp;
        }
      }
      for (let p in purses) {
        //console.log("drawing purse "+p+purses[p][0]+purses[p][1]+w*(p+1)/(purses.length+1));
        push();
        translate(w*(int(p)+1)/(purses.length+1), h/2);
        rectMode(CENTER);
        ellipseMode(CENTER);
        noStroke();
        fill(cols[purses[p][0]]);
        switch(purses[p][1]) {
          case 4:
            ellipse(0, 0, 120, 120);
            break;
          case 5:
            rect(0, 0, 100, 100, 20);
            break;
          case 6:
            rect(0, 0, 120, 80, 20);
            break;
        }
        pop();
      }
      text(score, w/2, h*3/4);
      break;
    case 3:
      textAlign(CENTER, CENTER);
      textSize(144);
      text("Game Over", w/2, h/2);
      text(score, w/2, h*3/4);
  }
}

function keyTyped() {
  console.log(epoch, key, curse);
  switch (epoch) {
    case 0:
      epoch = 1;
      break;
    case 1:
      epoch = 2;
      pgen();
      purses.shift();
      purses.shift();
      gend = millis();
      break;
    case 2:
      curse += key;
      if (curse.length > 3) {
        if (curses.includes(curse)) {
          console.log(curse);
          let i = curses.indexOf(curse);
          for (let p in purses) {
            if (purses[p].includes(i)) {
              purses.splice(p, 1);
              p -= 1;
              score += 1;
            }
          }
        }
        curse = "";
      }
  }
}

function pgen() {
  let npurse = [Math.floor(Math.random()*4), Math.floor(Math.random()*3+4)]
  console.log("new purse: ", npurse);
  purses.push(npurse);
  genp *= 0.9;
  console.log("purses now: ", purses);
}

function shuf(a) {
    for (let i = a.length - 1; i > 0; i--) {
        const j = Math.floor(Math.random() * (i + 1));
        [a[i], a[j]] = [a[j], a[i]];
    }
    return a;
}
              
            
!
999px

Console