about summary refs log tree commit diff stats
path: root/js/toadmode/toad.js
blob: 143c5f3482b885d38f01cc2c2b3be691a2bb1129 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
const viewportWidth = window.innerWidth;
const viewportHeight = window.innerHeight;
const canvas = document.getElementById('toad');
canvas.width = viewportWidth;
canvas.height = viewportHeight;
const context = canvas.getContext('2d');
const cellSize = 50;

let shapes = [];

const drawLine = (x1, y1, x2, y2) => {
    context.moveTo(x1, y1);
    context.lineTo(x2, y2);
    context.stroke();
};

const drawShape = (shape, x, y) => {
    context.beginPath();
    context.strokeStyle = '#2d2d2d';
    context.fillStyle = '#2d2d2d';
    const size = cellSize * 0.8;
    const offset = (cellSize - size) / 2;
    if (shape === 'square') {
        context.rect(x + offset, y + offset, size, size);
    } else if (shape === 'triangle') {
        context.moveTo(x + cellSize / 2, y + offset);
        context.lineTo(x + offset, y + size + offset);
        context.lineTo(x + size + offset, y + size + offset);
        context.closePath();
    } else if (shape === 'circle') {
        const radius = cellSize * 0.4;
        const centerX = x + cellSize / 2;
        const centerY = y + cellSize / 2;
        context.arc(centerX, centerY, radius, 0, 2 * Math.PI);
    } else if (shape === 'octagon') {
        const cellCenterX = x + cellSize / 2;
        const cellCenterY = y + cellSize / 2;
        const sideLength = cellSize / (2 + Math.sqrt(2));
        const angle = (2 * Math.PI) / 8;
        context.moveTo(cellCenterX + sideLength * Math.cos(0), cellCenterY + sideLength * Math.sin(0));
        [...Array(8).keys()].slice(1).forEach(i => {
            const newX = cellCenterX + sideLength * Math.cos(i * angle);
            const newY = cellCenterY + sideLength * Math.sin(i * angle);
            context.lineTo(newX, newY);
        });
        context.closePath();
    } else if (shape === 'pentagon') {
        const cellCenterX = x + cellSize / 2;
        const cellCenterY = y + cellSize / 2;
        const sideLength = cellSize / (1 + Math.sqrt(5 / 2));
        const angle = (2 * Math.PI) / 5;
        context.moveTo(cellCenterX + sideLength * Math.cos(0), cellCenterY + sideLength * Math.sin(0));
        [...Array(5).keys()].slice(1).forEach(i => {
            const newX = cellCenterX + sideLength * Math.cos(i * angle);
            const newY = cellCenterY + sideLength * Math.sin(i * angle);
            context.lineTo(newX, newY);
        });
        context.closePath();
    } else if (shape === 'diamond') {
        context.moveTo(x + cellSize / 2, y + offset);
        context.lineTo(x + offset, y + cellSize / 2);
        context.lineTo(x + cellSize / 2, y + size + offset);
        context.lineTo(x + size + offset, y + cellSize / 2);
        context.closePath();
    }
    context.fill();
    context.stroke();
    shapes.push({ type: shape, x, y, color: '#2d2d2d' });
};

const createContextMenuOption = (shape) => {
    const option = document.createElement('li');
    option.textContent = shape;
    option.style.cursor = 'pointer';
    option.addEventListener('click', (event) => {
        contextMenu.style.display = 'none';
        const cellX = Math.floor(lastRightClick.x / cellSize) * cellSize;
        const cellY = Math.floor(lastRightClick.y / cellSize) * cellSize;
        drawShape(shape.toLowerCase(), cellX, cellY);
    });
    if (shape === 'Nope') {
        option.style.color = 'lightcoral';
    }
    return option;
};

const contextMenu = document.createElement('ul');
contextMenu.id = 'context-menu';
contextMenu.style.display = 'none';
contextMenu.style.position = 'fixed';
contextMenu.style.listStyle = 'none';
contextMenu.style.lineHeight = '1.25';
contextMenu.style.padding = '10px';
contextMenu.style.fontSize = '18px';
contextMenu.style.backgroundColor = 'white';
contextMenu.style.border = '1px solid black';

['Square', 'Triangle', 'Circle', 'Octagon', 'Pentagon', 'Diamond', 'Nope'].forEach(shape => {
    const option = createContextMenuOption(shape);
    option.className = 'context-menu-item';
    contextMenu.appendChild(option);
}); // I mean, realistically shape should be label, but I got this far...so Nope is gonna be a shape

document.body.appendChild(contextMenu);

let lastRightClick = { x: 0, y: 0 };

canvas.addEventListener('click', (event) => {
    const cellX = Math.floor(event.clientX / cellSize) * cellSize;
    const cellY = Math.floor(event.clientY / cellSize) * cellSize;
    const clickedShape = shapes.find(shape => shape.x === cellX && shape.y === cellY);
    if (!clickedShape) {
        lastRightClick = { x: event.clientX, y: event.clientY };
        contextMenu.style.display = 'block';
        contextMenu.style.left = `${event.clientX}px`;
        contextMenu.style.top = `${event.clientY}px`;
    }
});

const removeShape = (x, y) => {
    shapes = shapes.filter(shape => !(shape.x === x && shape.y === y));
    drawGrid();
    context.fillStyle = '#f0f0f0';
    context.fillRect(x, y, cellSize, cellSize);
}

const drawGrid = () => {
    context.clearRect(0, 0, canvas.width, canvas.height);

    context.fillStyle = '#f0f0f0';
    context.fillRect(0, 0, canvas.width, canvas.height);

    context.strokeStyle = 'white';

    for (let x = 0; x < Math.ceil(viewportWidth / cellSize); x++) {
        drawLine(x * cellSize, 0, x * cellSize, viewportHeight);
    }

    for (let y = 0; y < Math.ceil(viewportHeight / cellSize); y++) {
        drawLine(0, y * cellSize, viewportWidth, y * cellSize);
    }

    shapes.forEach(shape => {
        drawShape(shape.type, shape.x, shape.y);
    });
}

let beatCounter = 0;
window.addEventListener('keydown', (event) => {
    if (event.key === ' ' || event.key === 'Enter') {
        beatCounter++;
        console.log(`Beat: ${beatCounter}`);
    }
});

canvas.addEventListener('dblclick', (event) => {
    const cellX = Math.floor(event.clientX / cellSize) * cellSize;
    const cellY = Math.floor(event.clientY / cellSize) * cellSize;
    removeShape(cellX, cellY);
});

drawGrid();
an class="nt">a>(y)&nbsp;&lt;==&gt;&nbsp;x==y</tt></dd></dl> <dl><dt><a name="BarSide-__ge__"><strong>__ge__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__ge__">__ge__</a>(y)&nbsp;&lt;==&gt;&nbsp;x&gt;=y</tt></dd></dl> <dl><dt><a name="BarSide-__getattribute__"><strong>__getattribute__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__getattribute__">__getattribute__</a>('name')&nbsp;&lt;==&gt;&nbsp;x.name</tt></dd></dl> <dl><dt><a name="BarSide-__getitem__"><strong>__getitem__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__getitem__">__getitem__</a>(y)&nbsp;&lt;==&gt;&nbsp;x[y]</tt></dd></dl> <dl><dt><a name="BarSide-__getslice__"><strong>__getslice__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__getslice__">__getslice__</a>(i,&nbsp;j)&nbsp;&lt;==&gt;&nbsp;x[i:j]<br> &nbsp;<br> Use&nbsp;of&nbsp;negative&nbsp;indices&nbsp;is&nbsp;not&nbsp;supported.</tt></dd></dl> <dl><dt><a name="BarSide-__gt__"><strong>__gt__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__gt__">__gt__</a>(y)&nbsp;&lt;==&gt;&nbsp;x&gt;y</tt></dd></dl> <dl><dt><a name="BarSide-__iadd__"><strong>__iadd__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__iadd__">__iadd__</a>(y)&nbsp;&lt;==&gt;&nbsp;x+=y</tt></dd></dl> <dl><dt><a name="BarSide-__imul__"><strong>__imul__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__imul__">__imul__</a>(y)&nbsp;&lt;==&gt;&nbsp;x*=y</tt></dd></dl> <dl><dt><a name="BarSide-__iter__"><strong>__iter__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__iter__">__iter__</a>()&nbsp;&lt;==&gt;&nbsp;iter(x)</tt></dd></dl> <dl><dt><a name="BarSide-__le__"><strong>__le__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__le__">__le__</a>(y)&nbsp;&lt;==&gt;&nbsp;x&lt;=y</tt></dd></dl> <dl><dt><a name="BarSide-__len__"><strong>__len__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__len__">__len__</a>()&nbsp;&lt;==&gt;&nbsp;len(x)</tt></dd></dl> <dl><dt><a name="BarSide-__lt__"><strong>__lt__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__lt__">__lt__</a>(y)&nbsp;&lt;==&gt;&nbsp;x&lt;y</tt></dd></dl> <dl><dt><a name="BarSide-__mul__"><strong>__mul__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__mul__">__mul__</a>(n)&nbsp;&lt;==&gt;&nbsp;x*n</tt></dd></dl> <dl><dt><a name="BarSide-__ne__"><strong>__ne__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__ne__">__ne__</a>(y)&nbsp;&lt;==&gt;&nbsp;x!=y</tt></dd></dl> <dl><dt><a name="BarSide-__repr__"><strong>__repr__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__repr__">__repr__</a>()&nbsp;&lt;==&gt;&nbsp;repr(x)</tt></dd></dl> <dl><dt><a name="BarSide-__reversed__"><strong>__reversed__</strong></a>(...)</dt><dd><tt>L.<a href="#BarSide-__reversed__">__reversed__</a>()&nbsp;--&nbsp;return&nbsp;a&nbsp;reverse&nbsp;iterator&nbsp;over&nbsp;the&nbsp;<a href="__builtin__.html#list">list</a></tt></dd></dl> <dl><dt><a name="BarSide-__rmul__"><strong>__rmul__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__rmul__">__rmul__</a>(n)&nbsp;&lt;==&gt;&nbsp;n*x</tt></dd></dl> <dl><dt><a name="BarSide-__setitem__"><strong>__setitem__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__setitem__">__setitem__</a>(i,&nbsp;y)&nbsp;&lt;==&gt;&nbsp;x[i]=y</tt></dd></dl> <dl><dt><a name="BarSide-__setslice__"><strong>__setslice__</strong></a>(...)</dt><dd><tt>x.<a href="#BarSide-__setslice__">__setslice__</a>(i,&nbsp;j,&nbsp;y)&nbsp;&lt;==&gt;&nbsp;x[i:j]=y<br> &nbsp;<br> Use&nbsp;&nbsp;of&nbsp;negative&nbsp;indices&nbsp;is&nbsp;not&nbsp;supported.</tt></dd></dl> <dl><dt><a name="BarSide-__sizeof__"><strong>__sizeof__</strong></a>(...)</dt><dd><tt>L.<a href="#BarSide-__sizeof__">__sizeof__</a>()&nbsp;--&nbsp;size&nbsp;of&nbsp;L&nbsp;in&nbsp;memory,&nbsp;in&nbsp;bytes</tt></dd></dl> <dl><dt><a name="BarSide-append"><strong>append</strong></a>(...)</dt><dd><tt>L.<a href="#BarSide-append">append</a>(<a href="__builtin__.html#object">object</a>)&nbsp;--&nbsp;append&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;to&nbsp;end</tt></dd></dl> <dl><dt><a name="BarSide-count"><strong>count</strong></a>(...)</dt><dd><tt>L.<a href="#BarSide-count">count</a>(value)&nbsp;-&gt;&nbsp;integer&nbsp;--&nbsp;return&nbsp;number&nbsp;of&nbsp;occurrences&nbsp;of&nbsp;value</tt></dd></dl> <dl><dt><a name="BarSide-extend"><strong>extend</strong></a>(...)</dt><dd><tt>L.<a href="#BarSide-extend">extend</a>(iterable)&nbsp;--&nbsp;extend&nbsp;<a href="__builtin__.html#list">list</a>&nbsp;by&nbsp;appending&nbsp;elements&nbsp;from&nbsp;the&nbsp;iterable</tt></dd></dl> <dl><dt><a name="BarSide-index"><strong>index</strong></a>(...)</dt><dd><tt>L.<a href="#BarSide-index">index</a>(value,&nbsp;[start,&nbsp;[stop]])&nbsp;-&gt;&nbsp;integer&nbsp;--&nbsp;return&nbsp;first&nbsp;index&nbsp;of&nbsp;value.<br> Raises&nbsp;ValueError&nbsp;if&nbsp;the&nbsp;value&nbsp;is&nbsp;not&nbsp;present.</tt></dd></dl> <dl><dt><a name="BarSide-insert"><strong>insert</strong></a>(...)</dt><dd><tt>L.<a href="#BarSide-insert">insert</a>(index,&nbsp;<a href="__builtin__.html#object">object</a>)&nbsp;--&nbsp;insert&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;before&nbsp;index</tt></dd></dl> <dl><dt><a name="BarSide-pop"><strong>pop</strong></a>(...)</dt><dd><tt>L.<a href="#BarSide-pop">pop</a>([index])&nbsp;-&gt;&nbsp;item&nbsp;--&nbsp;remove&nbsp;and&nbsp;return&nbsp;item&nbsp;at&nbsp;index&nbsp;(default&nbsp;last).<br> Raises&nbsp;IndexError&nbsp;if&nbsp;<a href="__builtin__.html#list">list</a>&nbsp;is&nbsp;empty&nbsp;or&nbsp;index&nbsp;is&nbsp;out&nbsp;of&nbsp;range.</tt></dd></dl> <dl><dt><a name="BarSide-remove"><strong>remove</strong></a>(...)</dt><dd><tt>L.<a href="#BarSide-remove">remove</a>(value)&nbsp;--&nbsp;remove&nbsp;first&nbsp;occurrence&nbsp;of&nbsp;value.<br> Raises&nbsp;ValueError&nbsp;if&nbsp;the&nbsp;value&nbsp;is&nbsp;not&nbsp;present.</tt></dd></dl> <dl><dt><a name="BarSide-reverse"><strong>reverse</strong></a>(...)</dt><dd><tt>L.<a href="#BarSide-reverse">reverse</a>()&nbsp;--&nbsp;reverse&nbsp;*IN&nbsp;PLACE*</tt></dd></dl> <dl><dt><a name="BarSide-sort"><strong>sort</strong></a>(...)</dt><dd><tt>L.<a href="#BarSide-sort">sort</a>(cmp=None,&nbsp;key=None,&nbsp;reverse=False)&nbsp;--&nbsp;stable&nbsp;sort&nbsp;*IN&nbsp;PLACE*;<br> cmp(x,&nbsp;y)&nbsp;-&gt;&nbsp;-1,&nbsp;0,&nbsp;1</tt></dd></dl> <hr> Data and other attributes inherited from <a href="__builtin__.html#list">__builtin__.list</a>:<br> <dl><dt><strong>__hash__</strong> = None</dl> <dl><dt><strong>__new__</strong> = &lt;built-in method __new__ of type object at 0x7fdbe703db00&gt;<dd><tt>T.<a href="#BarSide-__new__">__new__</a>(S,&nbsp;...)&nbsp;-&gt;&nbsp;a&nbsp;new&nbsp;<a href="__builtin__.html#object">object</a>&nbsp;with&nbsp;type&nbsp;S,&nbsp;a&nbsp;subtype&nbsp;of&nbsp;T</tt></dl> </td></tr></table> <p> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> <tr bgcolor="#ffc8d8"> <td colspan=3 valign=bottom>&nbsp;<br> <font color="#000000" face="helvetica, arial"><a name="ColoredString">class <strong>ColoredString</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr> <tr><td bgcolor="#ffc8d8"><tt>&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td> <td width="100%">Methods defined here:<br> <dl><dt><a name="ColoredString-__init__"><strong>__init__</strong></a>(self, string, *lst)</dt></dl> <dl><dt><a name="ColoredString-__len__"><strong>__len__</strong></a>(self)</dt></dl> <dl><dt><a name="ColoredString-__str__"><strong>__str__</strong></a>(self)</dt></dl> <dl><dt><a name="ColoredString-cut_off"><strong>cut_off</strong></a>(self, n)</dt></dl> <dl><dt><a name="ColoredString-cut_off_to"><strong>cut_off_to</strong></a>(self, n)</dt></dl> <hr> Data descriptors defined here:<br> <dl><dt><strong>__dict__</strong></dt> <dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd> </dl> <dl><dt><strong>__weakref__</strong></dt> <dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd> </dl> <hr> Data and other attributes defined here:<br> <dl><dt><strong>fixed</strong> = False</dl> </td></tr></table></td></tr></table> </body></html>