Saturday 25 November 2017

Dom's Swan Song

Cross posted from Arcus Global's Blog where Nic Williams let me say goodbye. Thanks, Nic!

On the 30th of January 2010 I left my boat (I was living aboard, moored on Stourbridge common in Cambridge, at the time), unlocked and got on my bike and put my headphones on. I cycled along at a silly pace as I was listening to a cool French Punk band at the time. Getting to the Judge Business School took far too little time, and I locked my bike up and went looking for Lars. The next 45 minutes was such a fun experience I ended up emailing him afterwards and saying thanks and apologising for interrupting him – I know that that is seen as good practice in some areas, but not in nursing interviews. As I hinted, I came from a different career, full of people who practice active listening for a living and being able to talk about all the cool things I was interested in, without having to worry that I was being actively listened to, was just cool.

After a call from Denis, to check I knew what I was talking about, I was in and started in the beginning of March 2010 - encouraged to play with all the cool things I was, and still am, fascinated by. We soon won the Guardian Megas and Peter encouraged me to go up with Lars and Denis to accept the prize. One of the best nights I have ever had that was! I got to meet some fantastically bright people at work and not feel like a fraud as I could keep up my end of the conversation more often than not. I was even dragged in front of prospective clients who were so impressed they asked if I could assure them that I’d not disappear off to the Bahamas before the project was done.

We have grown such a lot since then, but I still feel valued, which is why my recent decision to leave Arcus has been so hard.

Arcus helped me more than I can ever hope to express when the worst tragedy rocked my family. Denis was a rock and let me witter on to him in the depths of my despair at ridiculous hours of the day and night – I dread to think what I was saying. That happened in the Summer and every Summer since I have had the urge to wander off. This year I have let the urge have its way, so I am leaving. It feels like leaving home. I have learnt such a lot and grown as a person and developer, but I feel its time to test myself somewhere else.

I no longer live aboard a boat but live in a house that I could not have afforded unless my efforts were rewarded at Arcus. Though being paid has always felt a little odd, as I code for fun rather more than for profit. I know I am not supposed to say that, but there’s nothing quite so much fun as being paid to do what you love. I love the fact that I am allowed, even encouraged, to disappear in my head and figure things out – though the waking up in the early hours with my head full of data structures can be disruptive. However, that is accepted at Arcus, I have popped into the office in the early hours of the morning and left in the early afternoon thanks to getting far more than eight and a half hours in and needing to rest if only to crack the next challenge.

The perks and the close-knit team make this the best place I have ever worked. The people are helpful and generous with their time and – I know I have said this before – frighteningly bright! This in itself is a challenge, but not in a bad way, rather in a way that encourages me to be brighter too.

So I will miss everyone at Arcus, and I hope that you continue to go from strength to strength. It is time for me to test myself though. Who knows, perhaps I will come close to finding a team of people who are as stunning, I do hope so.

Friday 3 November 2017

p5 Pacman.js

I've been playing with p5js on and off for a while in order to generate some resources for use with Code Club and I've made (so far) Frogger, Snake and I've helped with Pong. Now I'm working with Pacman.

The thing about Pacman though, is that his jaws open and close as he's moving along and me and maths have an interesting relationship thanks to a somewhat spotchy formal education. Anyway, p5js has an arc so I was sorted. Sorted until I clocked that by default it uses radians rather than degrees, so much head scratching followed, as well as visits to the Khan Academy. And I got it working.

But p5js knows that people have issues with radians so instead of using radians I set angleMode(DEGREES);, neat eh?

The other thing about Pacman is that he moves and moves along 4 axes so the chomping needs to go in the direction of travel. Again I was stuck with radians until I realised that degrees would work (despite them being an arbitrary measurement). So I just had to rotate the start and stop angles of the arc by 90-degree increments to get this working - except that when Pacman was going right or up he flashed when his mouth was closed, so then I had to replace the arc with a circle if the gap was zero.

This is what I came up with:

if(this.jawWidth === 0){
    ellipse(this.x, this.y, this.r * 2, this.r * 2);
}else{
    let topJaw = this.jawWidth;
    let bottomJaw = -Math.abs(this.jawWidth);
    if(this.speed.every((e, i) => e === [0,-1][i])){
        topJaw += 270;
        bottomJaw += 270;
    }
    if(this.speed.every((e, i) => e === [0,1][i])){
        topJaw += 90;
        bottomJaw += 90;
    }
    if(this.speed.every((e, i) => e === [-1,0][i])){
        topJaw += 180;
        bottomJaw += 180;
    }
    arc(
      this.x, 
      this.y, 
      this.r * 2, 
      this.r * 2, 
      topJaw, 
      bottomJaw, 
      PIE);
}

I was not overly happy with it, but it worked. But what about just rotating Pacman instead? It turns out that that is even easier but does involve pushing and popping to ensure everything works properly - and that took quite a bit of head-scratching as well (It really is no wonder I'm bald). Anyway, here it is:

push();
translate(this.x, this.y);
if(this.speed.every((e, i) => e === [0,-1][i])){
    rotate(270);
}
if(this.speed.every((e, i) => e === [0,1][i])){
    rotate(90);
}
if(this.speed.every((e, i) => e === [-1,0][i])){
    rotate(180);
}
arc(
  0, 
  0, 
  this.r * 2, 
  this.r * 2, 
  this.jawWidth, 
  -Math.abs(this.jawWidth), 
  PIE);  
pop();

It's much more elegant isn't it?