Mouse Walker II
Goals:
- Create new function
moveTowards
and give coordinates (for this it’ll be the mouse)- The closer to the target the more likely to move towards it
- There should be a zone close to the target where moving towards isn’t likely anymore (avoiding collisons, maybe)
- Create new function
moveRandomly
- Only move in available directions (at the wall don’t consider moving in a way that’s not allowed)
Mostly this worked out. I found out that I can’t use ...
(the spread operator) in JS without saving to a variable so return {...state}
isn’t working. So there’s lots of futzing in the global state. There’s more to play with- in this sketch there’s the bones of an energy system, an being in explore/seek/sleep states. Those will have to wait a little.
Mouse around!
Move the mouse move the candy! Friend is trying their best to get to the candy
Plain text
It’s a good morning for laying around and watching some conference talks a couple I enjoyed this morning:
- Plain Text • Dylan Beattie • GOTO 2023 - text encoding is complicated! ASCII was meant to solve a very limited problem in a very clever way (capital and lower case letters can switched by flipping one bit) but it didn’t scale beyond it’s US-based origins. Dylan explores some of the ways text encoding goes awry
- [https://www.youtube.com/watch?v=WgV6M1LyfNY](The Unreasonable Effectiveness Of Plain Text) - Tristram Oaten makes the case for plain text and simple systems for managing all of your project/documentation/planning needs. It introduced me to the idea of a “Ulysses Pact” which is the idea that you make a good decision for your future self (like leaving a credit card at home when going somewhere you don’t want to spend money, or, originally, tying yourself to the mast of a boat so you can’t respond to a sirens song).
Friend Sketch
The idea for this sketch was to steal ideas from Apple Maps’ locator dot (unrelated thread but it shows off the design pretty well).
Use your keyboard!
You can move Friend around with your arrow keys
I feel like everytime I do a sketch I end up learning a ton, even if I wasn’t really setting out to learn those things!
- The
loadImage
function must be called in thesetup
function. I think if I have a lot of assets I’ll end up bundling them all up into an asset catalog and loading them here. Because assets needed to be loaded here it means have they have to be passed around to wherever needs them. - Keyboard handling happens by adding a function called
keyPressed
and then p5 magically knows how to call it. The diference between a library and a framework is “you call a library, a framework calls you”. P5 is sooo close to being a library but then having functions likedraw
andkeyPressed
just magically get called makes it not quite there. - I am suspicious of object-oriented programming because it’s hard to understand how all of the data in the object interacts. But… without typescript and since I don’t really need to test/serialize/explain these sketches it’s turning out to be the nicest way.
- If I was going to shape the p5 environment to work for me it would be based on typescript and have a setup function that kicked off everything. Maybe something like:
p5.start({
draw: myDrawingFn,
update: updateTheWorld,
keyPressed: handleKeyInput
})
I listened to Music for 18 Hairdressers: Braids & Fractals while working on this.
Eight Walker
The goal of this sketch was to implement a walker that can move in all eight directions (the cardinal ones and the diagonals).
I notice right away that it feels more alive. This is more how ti looks when a bug is exploring the world. It kind of reminds me of a butterfly.
Levy Walker
This walker uses levy flight to occasionally move on from the place that it’s searching. A couple of things:
- When it’s time to move on Friend chooses a direction and starts walking that
- I notice Friend gets stuck in the corners a lot (and especially the upper left. I wonder if I have an issue somewhere that’s causing that)
- I added a historian who records all the places that friend (or any object that emits x,y coords has been). I’m showing the number of unique spots that the historian knows the moving object has visited
Euler 008
I got through 008 but I’m not super happy with my solution:
const bigNumber = "<snip>"
function product(digit: number, product: number = 1): number {
return digit * product
}
function productOfDigits(digits: string[]) {
return digits.map(i => parseInt(i)).reduce(product);
}
function largestProductOfAdjacentDigits(num: string, numDigits: number): number {
const digits = num.split("")
let largestNum = 0;
for (let i = 0; i < digits.length; i += 1) {
const subDigits = digits.slice(i, i + numDigits);
const product = productOfDigits(subDigits)
if (product > largestNum) {
largestNum = product
}
}
return largestNum
}
function main() {
console.log(largestProductOfAdjacentDigits(bigNumber, 13))
}
main();
The solution feels blahhh compared to the previous days where the solution just kind of fell out of the code. I think I want the for loop to be a map, then the find-the-biggest part to be a reduce. Maybe I’ll come back another time and fight for that. I have a feeling it will be slower, though. I think this trades readability for speed.
End of day
Today was a mostly creative-code day! I worked from home and then from the Brooklyn Public Library’s main branch. I was nestled in the room in the second floor with non-fiction. When I needed a break I was delighted at how many vegan cookbooks there are in the library. I wish my apartment was better setup for cooking!
This morning I watched two talks I recommend:
- Plain Text • Dylan Beattie • GOTO 2023
- [https://www.youtube.com/watch?v=WgV6M1LyfNY](The Unreasonable Effectiveness Of Plain Text)
Worked on Today
Notebook page for the day: https://notes.nicole.computer/daily/2024-11-09 (it has all of the sketches and everything I worked on and is probably the prettiest way to see what’s up)
- I wrote a random walker that will follow the mouse around. It’s still exploring but it has a good chance to chase the mouse: https://creative.nicole.computer/2024-11-09-mouse-walker-ii/
- Here’s exploring the UI for showing a random walker (my walker is named after a stuffed animal that lives in my home, Friend): https://creative.nicole.computer/2024-11-09-friendlocator/
- Exploring a walker than can move in all eight directions (cardinals and diagonals: https://creative.nicole.computer/2024-11-09-eight-walker/)
- And finally one that implements Levy flight (sometimes it decides to “move on” from a location): https://creative.nicole.computer/2024-11-09-levy-walker/
- And also for the day, Euler problem 8: https://github.com/nicolecomputer/euler/blob/main/008/main.ts
Tomorrow
I might watch movies in bed? Or maybe I’ll come to the hub and see about video games? I still have some things I want to explore before Monday’s Nature of Code gathering:
- I have a sketch I want to do for Gaussian Noise - I’m thinking about generating robots who’s height is a Gaussian distribution
- I need to spend some time with Perlin noise- I don’t fully understand it yet
I think we’re reading Chapters 0-3 for the first meeting. Everything I’ve done has been chapter 0 so maybe I to skim through the other chapters? I don’t regret going deep and really understanding but it does mean I am slower to get through the material.