Skip to content

Instantly share code, notes, and snippets.

@onsclom
onsclom / maze.c
Created August 5, 2023 04:27
Maze Generator
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
typedef struct
{
int x, y;
} Vector2d;
#define WALL "#"
for (let i = 1; i <= 100; i++) {
let text = ""
if (i % 3 === 0) text += "Crackle"
if (i % 5 === 0) text += "Pop"
console.log(text || i)
}
@onsclom
onsclom / index.html
Last active April 29, 2023 02:10
bouncing dvd logo
<svg
xmlns="http://www.w3.org/2000/svg"
height="6rem"
viewBox="0 0 210 107"
style="position: fixed"
>
<path
d="M118.895,20.346c0,0-13.743,16.922-13.04,18.001c0.975-1.079-4.934-18.186-4.934-18.186s-1.233-3.597-5.102-15.387H81.81H47.812H22.175l-2.56,11.068h19.299h4.579c12.415,0,19.995,5.132,17.878,14.225c-2.287,9.901-13.123,14.128-24.665,14.128H32.39l5.552-24.208H18.647l-8.192,35.368h27.398c20.612,0,40.166-11.067,43.692-25.288c0.617-2.614,0.53-9.185-1.054-13.053c0-0.093-0.091-0.271-0.178-0.537c-0.087-0.093-0.178-0.722,0.178-0.814c0.172-0.092,0.525,0.271,0.525,0.358c0,0,0.179,0.456,0.351,0.813l17.44,50.315l44.404-51.216l18.761-0.092h4.579c12.424,0,20.09,5.132,17.969,14.225c-2.29,9.901-13.205,14.128-24.75,14.128h-4.405L161,19.987h-19.287l-8.198,35.368h27.398c20.611,0,40.343-11.067,43.604-25.288c3.347-14.225-11.101-25.293-31.89-25.293h-18.143h-22.727C120.923,17.823,118.895,20.346,118.895,20.346L118.895,20.346z"
/>
<path
@onsclom
onsclom / day9.cpp
Last active December 27, 2021 20:45
#include <algorithm>
#include <array>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
vector<vector<int>> parseInput(const string &fileName) {
void MakePathAndConnect(Maze *mazeData, Vector2 pos1, Vector2 pos2)
{
const Vector2 inbetweenWall = (Vector2){
(pos1.x + pos2.x) / 2,
(pos1.y + pos2.y) / 2};
MakePath(mazeData, inbetweenWall);
MakePath(mazeData, pos2);
}
void PrintMaze(const Maze *mazeData)
bool IsWall(const Maze *mazeData, Vector2 pos)
{
const int mazeSize = mazeData->size;
if (pos.x < 0 || pos.y < 0 || pos.x >= mazeSize || pos.y >= mazeSize)
return false; //out of bounds neighbors not considered
return (mazeData->grid[mazeSize * pos.y + pos.x]) == WALL;
}
int GetWalledNeighbors(const Maze *mazeData, Vector2 neighbors[4], Vector2 pos)
{
@onsclom
onsclom / mazeGen.c
Last active December 26, 2021 17:37
void GenerateMaze(Maze *mazeData, Vector2 pos)
{
Vector2 neighbors[4];
const int neighborAmount = GetWalledNeighbors(mazeData, neighbors, pos);
if (neighborAmount == 0)
return;
const int randNeighborNum = rand() % neighborAmount;
const Vector2 randNeighbor = neighbors[randNeighborNum];
void MakePath(Maze *mazeData, Vector2 pos)
{
const int gridSize = mazeData->size;
mazeData->grid[pos.y * gridSize + pos.x] = PATH;
}
Vector2 PickRandomStart(int userSize)
{
srand(time(NULL)); // use current time as seed for rand
Vector2 randPoint = {rand() % userSize, rand() % userSize};
randPoint.x = randPoint.x * 2 + 1;
randPoint.y = randPoint.y * 2 + 1;
return randPoint;
}
Maze InitializeMazeData(int userSize)
{
const int gridSize = userSize * 2 + 1;
return (Maze){
calloc(sizeof(bool), gridSize * gridSize),
gridSize};
}