User:Pseudosphere
Pages I made which are actually good, or took some time/effort to make
- Rotating CSS Tesseract
- Other shapes
- Hyperrotating CSS Order-5 Square Tiling but it's actually muscle man getting dragged through a forest orbifolded by the (2,4,5) triangle group
- The Cycle of Life
- Notepad (old version)
- Brainfuck (no longer works unless graphs get fixed)
- Make your own kaleidoscope
- /dev
- The Wiki Camp/Main Page
- Nether Portal
- Nim
- Balanced ternary
- Φιnary
- Calculator 2.0
- Notakto
- Discord/general
- /
- /home
- ℝ²
- ℘ (the formula took a lot of math to derive; it's the ℘ for Λ=ℤ)
- Game of Life
- Amiga
- Infinite matter generator
- Windows 98
- Windows 7
- Voting
- Title Screen
- O (group)
- Squircle
- Connect Four
- XHTML
- Clock 2.0
- Windows 3.1
- Webdriver Torso
- Rule 150
- 5a/Timer (I made just the timer part)
- 3-sphere
- What beats rock?
- Rotating SVG Cube
- Okinchest
- Okinchess
- Rule 110
- DVD in a triangle
- Exterior
- Text Mode
Templates
- Template:Tesseract CSS
- Template:Tesseract
- Template:Mono Dark
- Template:Windows 3.1
- Template:Select
- Template:CDD
- Template:Discord reply
- Template:Discord quote
- Template:Discord thread
- Template:Discord codeblock
- Template:Discord edited
- Template:Discord pfp
- Template:Drag CSS
- Template:Dimensional
- Template:Chrome sheen
- Template:Random page title
- Template:Random page link
- Template:Discord divider
- Template:Content only
- Template:Cubemap
- Template:Windows 98
- Template:Windows 7
- Template:VR Cubemap
- Template:Fandom
- Template:MCText
- Template:WBR
- Template:Text Cuboid
- Template:Disputedly imaginary number
- Template:Transclude guard
- Template:Bit
- Template:Unique number
- Template:Text Mode
- Template:Philosophical argument
- Template:House of Leaves
Scripts I made for pages
Licensing
- Anyone can use or modify these scripts for whatever, except for evil doings.
- Anyone can distribute any of these scripts or derivative works thereof, as long as they specify which of my scripts was used or modified, and link back to their source.
- These scripts can also be relicensed under any GPL-compatible license, as long as line 2 is still obeyed.
THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL I BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Bad Coding Practices Warning
Unfortunately, I usually don't comment my code. I might fix this at some point...
Tesseract CSS generator
#!/bin/python3
from math import tau, cos, sin
#Transform of v-w plane for w=1
# v w
#|A -B*100|
#|nC/100 -nD+n+1|
def S(x):
y = int(x)
if x == y:
return str(y)
r = str(x)
if r.find("e") != -1:
return "0"
return r
#def genTransform(theta, n):
# c = cos(theta)
# s = sin(theta)
# return ("transform:matrix3d(", S(c), ",0,0,", S(n * s * 0.01), ",0,1,0,0,0,0,1,0,", S(s * 100), ",0,0,", S(n - n * c + 1), ");")
def genTransform2(theta, n, A, B, C, D):
c = cos(theta)
s = sin(theta)
return ("transform:matrix3d(", S(c), ",0,0,", S(n * s * 0.01), ",0,", A, ",", C, ",0,0,", B, ",", D, ",0,", S(s * 100), ",0,0,", S(n - n * c + 1), ");")
#for n in range(64):
# k = n / 64
# print(k * 100, "%{", sep="")
# print(*genTransform(k * tau, 0.5), "}", sep="")
def genTransforms(name, offset, A, B, C, D):
print("@keyframes ", name, "{100%,", sep="", end="")
for n in range(256):
k = n / 256
print(S(k * 100), "%{", *genTransform2((k + offset) * tau, 0.5, A, B, C, D), "}", sep="", end="")
print("\n}", end="")
genTransforms("cell-front", 0, "1", "0", "0", "1")
genTransforms("cell-right", 0.25, "0", "1", "-1", "0")
genTransforms("cell-back", 0.5, "-1", "0", "0", "-1")
genTransforms("cell-left", 0.75, "0", "-1", "1", "0")
Brainfuck Rot13 Demo
----------[
[++++++++++<<,.----------] get str
>>[>>]<< go to start
[
---------------------------------------------------- to position plus 13
>++++++++++++++++++++++++++< d = 26
[>->+<[>]>[<+>-]<<[<]>-] modulo
>[-] clear junk
>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.[-] print character & clear cell
<<<< next char
]
++++++++++.---------- newline
----------]
Φιnary animation generator
#!/bin/python3
s="""0000000.000000
0000001.000000
0000010.010000
0000100.010000
0000101.010000
0001000.100100
0001010.000100
0010000.000100
0010001.000100
0010010.010100
0010100.010100
0010101.010100
0100000.101001
0100001.101001
0100100.001001
0100101.001001
0101000.100001
0101010.000001
1000000.000001
1000001.000001
1000010.010001
1000100.010001
1000101.010001
1001000.100101
1001010.000101
1010000.000101
1010001.000101
1010010.010101
1010100.010101
1010101.010101""".replace(".", "").split("\n")
for n in range(len(s[0])):
z.clear()
o.clear()
print("@keyframes flippyphi", n, " {", sep="")
for k in range(len(s)):
if s[k][n] == "1":
o.append(k * 100 / len(s))
else:
z.append(k * 100 / len(s))
print(*z, sep="%,", end="%,100% {height: 4px;}\n")
print(*o, sep="%,", end="% {height: 16px;}\n}\n")
Nim generator
#!/bin/python3
turns = 8
firstturn = turns - 1
print(end="<p class=\"nurpons\">")
for n in range(turns):
k = n * 4
print("<span class=\"mw-collapsible\" id=\"mw-customcollapsible-nerpyblock", n, "\">[[File:Nerpawhite.png|64px|link=]]<span class=\"mw-collapsible\" id=\"mw-customcollapsible-nerpy", k + 1, "\">[[File:Nerpawhite.png|64px|link=]]</span><span class=\"mw-collapsible\" id=\"mw-customcollapsible-nerpy", k + 2, "\">[[File:Nerpawhite.png|64px|link=]]</span><span class=\"mw-collapsible\" id=\"mw-customcollapsible-nerpy", k + 3, end="\">[[File:Nerpawhite.png|64px|link=]]</span></span>", sep="")
print("</p>")
print(end="<p class=\"nimbuttons\">")
for n in range(turns):
k = n * 4
print(end="<span class=\"mw-collapsible")
if n != firstturn:
print(end=" mw-collapsed")
print("\" id=\"mw-customcollapsible-turn", n, "\"><span class=\"mw-collapsible mw-collapsed nimbutton mw-customtoggle-nim", k + 1, " mw-customtoggle-nerpy", k + 1, "\" id=\"mw-customcollapsible-nim", k + 1, "\">Remove one</span><span class=\"mw-collapsible mw-collapsed nimbutton mw-customtoggle-nim", k + 1, " mw-customtoggle-nim", k + 2, " mw-customtoggle-nerpy", k + 2, "\" id=\"mw-customcollapsible-nim", k + 2, "\">Remove one</span><span class=\"mw-collapsible nimbutton mw-customtoggle-nim", k + 2, " mw-customtoggle-nim", k + 3, " mw-customtoggle-nerpy", k + 3, " mw-customtoggle-endturn", n, "\" id=\"mw-customcollapsible-nim", k + 3, end="\">Remove one</span><span class=\"nobutton\">Remove one</span></span>", sep="")
print("<span class=\"nobutton\">Remove one</span></p>")
print(end="<p class=\"nimbuttons\">")
for n in range(turns):
print("<span class=\"mw-collapsible mw-collapsed nimbutton mw-customtoggle-endturn", n, end="", sep="")
if n != 0:
print(" mw-customtoggle-turn", n - 1, end="", sep="")
else:
print(end=" mw-customtoggle-loser")
print(" mw-customtoggle-turn", n, " mw-customtoggle-nerpyblock", n, "\" id=\"mw-customcollapsible-endturn", n, end="\">End turn</span>", sep="")
print("<span class=\"nobutton\">End turn</span></p>\n<p style=\"font-size: 500%; font-weight: bold; text-align: center;\" class=\"mw-collapsible mw-collapsed\" id=\"mw-customcollapsible-loser\">YOU LOSE</p>")
mwcollapse.py
A python module for converting finite-state machines into mw-collapsible spaghetti. Works best with tree-like systems; is very inefficient for highly "symmetric" FSMs, since the output size is proportional to the number of state transitions.
class StateNode:
__slots__ = "state", "transitions"
def __init__(self, state, transitions=None):
self.state = tuple(state)
self.transitions = {} if transitions == None else transitions
def __call__(self, var):
return self.state[var]
def __len__(self):
return len(self.transitions)
def __length_hint__(self):
return len(self.transitions)
def __getitem__(self, key):
return self.transitions[key]
def __setitem__(self, key, value):
self.transitions[key] = value
def __delitem__(self, key):
del self.transitions[key]
def __iter__(self):
return iter(self.transitions)
def __reversed__(self):
return reversed(self.transitions)
def __contains__(self, item):
return item in self.transitions
class StateMachine:
__slots__ = "states"
def __init__(self, *states):
self.states = states
def __repr__(self):
return f"<StateMachine object of {len(self.states)} states>"
def __bool__(self):
return bool(self.states)
def __len__(self):
return len(self.states)
def __length_hint__(self):
return len(self.states)
def __getitem__(self, key):
return self.states[key]
def __iter__(self):
return iter(self.states)
def __reversed__(self):
return reversed(self.states)
def __contains__(self, item):
return item in self.states
def index(self, value):
return self.states.index(value)
class ElementContainer:
"""An Element-like sequence of Element-like objects."""
__slots__ = "_children", "_parent"
def __init__(self, *children):
self._children = children
self._parent = None
for c in children:
if isinstance(c, ElementContainer):
c._parent = self
def __str__(self):
return "".join(str(c) for c in self._children)
def compile(self, identifier, statemachine):
for child in self._children:
if isinstance(child, ElementContainer):
child.compile(identifier, statemachine)
def visible(self, state):
return self._parent == None or self._parent.visible(state)
class Element(ElementContainer):
"""An HTML element"""
__slots__ = "_attributes", "_children", "name", "_parent"
@staticmethod
def _gentag(l, name, attributes, children):
l.append("<")
l.append(name)
for k in attributes:
l.append(" ")
l.append(k)
l.append("=\"")
l.append(attributes[k].replace("&", "&").replace('"', """))
l.append("\"")
l.append(">")
l.extend(str(c) for c in children)
l.append("</")
l.append(name)
l.append(">")
def __init__(self, name, *children, attributes=None):
super().__init__(*children)
self._attributes = {} if attributes == None else attributes.copy()
self.name = name
def __str__(self):
l = []
self._gentag(l, self.name, self._attributes, self._children)
return "".join(l)
class Toggleable(Element):
"""An mw-collapsible HTML element; might still be visible when collapsed.
var = index into a boolean tuple of collapsible states;
should not be shared with other elements."""
__slots__ = "var"
def __init__(self, name, var, *children, attributes=None):
super().__init__(name, *children, attributes=attributes)
self.var = var
def compile(self, identifier, statemachine):
self._attributes["id"] = f"mw-customcollapsible-{identifier}-{self.var}"
self._attributes["class"] = self._attributes["class"] + (" mw-collapsible" if statemachine[0](self.var) else " mw-collapsible mw-collapsed") if "class" in self._attributes else ("mw-collapsible" if statemachine[0](self.var) else "mw-collapsible mw-collapsed")
super().compile(identifier, statemachine)
class Collapsible(Toggleable):
"""An mw-collapsible HTML element; should always be hidden while collapsed.
var = index into a boolean tuple of collapsible states;
should not be shared with other elements."""
def visible(self, state):
return state(self._var) and super().visible(state)
class Trigger(Element):
"""A sequence of mw-customtoggle HTML elements."""
__slots__ = "event", "_identifier", "_toggles"
def __init__(self, name, event, content="", attributes=None):
super().__init__(name, content, attributes=attributes)
self.event = event
def __str__(self):
hasclass = "class" in self._attributes
l = []
for i, toggle in enumerate(self._toggles):
if toggle != None:
attributes = self._attributes.copy()
attributes["id"] = f"mw-customcollapsible-{self._identifier}-t{i}-{self.event}"
attributes["class"] = " ".join((attributes["class"], *toggle) if hasclass else toggle)
self._gentag(l, self.name, attributes, self._children)
return "".join(l)
def compile(self, identifier, statemachine):
self._identifier = identifier
self._toggles = tuple(self._gentoggle(statemachine, state, i) for i, state in enumerate(statemachine))
def _gentoggle(self, states, state, index):
if self.event in state and self.visible(state):
s = {"mw-collapsible"}
if index != 0:
s.add("mw-collapsed")
tstate = state[self.event]
if state != tstate:
s.update(f"mw-customtoggle-{self._identifier}-{n}" for n in range(len(state.state)) if state(n) != tstate(n))
s.update(f"mw-customtoggle-{self._identifier}-t{index}-{event}" for event in state)
s.update(f"mw-customtoggle-{self._identifier}-t{states.index(tstate)}-{event}" for event in tstate)
else:
s.add("mw-redundanttoggle")
return s
return None
def _genNode(transitions, d, l, transition, stategen, s):
if s not in d:
node = StateNode(stategen(s))
d[s] = node
l.append(node)
for t in transitions:
newstate = transition(s, t)
if None != newstate:
node[t] = _genNode(transitions, d, l, transition, stategen, newstate)
return node
return d[s]
def genStateMachine(transitions, transition, stategen, initial):
"""Generates a state machine from a transition function.
transitions is an iterable of transition names (the inputs to the state machine).
transition is a function accepting a state (which can be any hashable object) and a transition name;
it returns a new state deterministically and without side effects, or None if the transition name is not applicable for this state.
stategen converts a state to an iterable of boolean values representing the states of collapsibles.
initial is the initial state of the machine."""
l = []
_genNode(transitions, {}, l, transition, stategen, initial)
return StateMachine(*l)
def collapseTrigger(name, event, var, content="", attributes=None):
"""Convenience function to generate a Trigger and Collapsible which can substitute each other."""
return ElementContainer(Trigger(name, event, content, attributes=attributes), Collapsible(name, var, content, attributes=attributes))
def example():
"""An example function generating a simple counter."""
# <!--HTML pseudocode for this example-->
#
# <initial>
# let $COUNTER = 0;
# </initial>
#
# <transition id="increment">
# if $COUNTER != 99 then increment $COUNTER;
# </transition>
# <transition id="decrement">
# if $COUNTER != 0 then decrement $COUNTER;
# </transition>
#
# <stategen>
# display collapsibles with id == ((tens digit of $COUNTER) + 10) or id == (ones digit of $COUNTER);
# </stategen>
#
# <span collapsible-id="10"></span><span collapsible-id="11">1</span><!--...--><span collapsible-id="19">9</span><span collapsible-id="0">0</span><!--...--><span collapsible-id="9">9</span><br/>
# <span trigger-id="increment" style="background-color:#000;border:1px solid;color:#0F0;">+</span><br/>
# <span trigger-id="decrement" style="background-color:#000;border:1px solid;color:red;">-</span>
def transition(state, transition):
if transition == "increment":
return None if state == 99 else state + 1
return None if state == 0 else state - 1
def stategen(state):
l = [n == state % 10 for n in range(10)]
l.extend(n == state // 10 for n in range(10))
return tuple(l)
stateMachine = genStateMachine(("increment", "decrement"), transition, stategen, 0)
elements = [Collapsible("span", 10, "")]
elements.extend(Collapsible("span", n + 10, str(n)) for n in range(1, 10))
elements.extend(Collapsible("span", n, str(n)) for n in range(10))
elements.append("<br/>\n")
elements.append(Trigger("span", "increment", "+", attributes={"style": "background-color:#000;border:1px solid;color:#0F0;"}))
elements.append("<br/>\n")
elements.append(Trigger("span", "decrement", "-", attributes={"style": "background-color:#000;border:1px solid;color:red;"}))
elementContainer = ElementContainer(*elements)
elementContainer.compile("counter", stateMachine)
print(elementContainer)
Calculator 2.0 generator
#!/bin/python3
import mwcollapse
def transition(state, transition):
if transition == "AC" and state[0] != -1:
return (-1, None, -1)
elif transition == "equ":
if state[2] != -1:
if state[1] == "add":
return ((state[0] + state[2]) % 10, None, -1)
if state[1] == "sub":
return ((state[0] - state[2]) % 10, None, -1)
if state[1] == "mul":
return (state[0] * state[2] % 10, None, -1)
return (state[0] // state[2] % 10, None, -1)
elif transition in "0123456789":
if state[0] == -1:
return (int(transition), None, -1)
if state[1] != None and (state[1] != "div" or transition != "0") and state[2] == -1:
return (state[0], state[1], int(transition))
elif transition in ("add", "sub", "mul", "div") and state[1] == None and state[2] == -1:
return (0 if state[0] == -1 else state[0], transition, -1)
return None
def stategen(state):
l = [n == state[0] for n in range(-1, 10)]
l.extend(s == state[1] for s in (None, "add", "sub", "mul", "div"))
l.extend(n == state[2] for n in range(-1, 10))
digits = state[0] != -1 and (state[1] == None or state[2] != -1)
ops = state[1] != None
l.extend(digits for n in range(10))
l.extend(ops for n in range(4))
l.append(state[0] == -1)
l.append(state[2] == -1)
return tuple(l)
table = mwcollapse.Element("table", '<tr><th colspan="4"><span class="display">', *(mwcollapse.Collapsible("span", i, v) for i, v in enumerate(" 0123456789 +-*/ 0123456789")), "</span></th></tr><tr>", *(mwcollapse.Element("td", mwcollapse.collapseTrigger("span", str(n), n + 27, str(n))) for n in range(7, 10)), "<td>", mwcollapse.collapseTrigger("span", "add", 37, "+", attributes={"class": "op"}), "</td></tr><tr>", *(mwcollapse.Element("td", mwcollapse.collapseTrigger("span", str(n), n + 27, str(n))) for n in range(4, 7)), "<td>", mwcollapse.collapseTrigger("span", "sub", 38, "-", attributes={"class": "op"}), "</td></tr><tr>", *(mwcollapse.Element("td", mwcollapse.collapseTrigger("span", str(n), n + 27, str(n))) for n in range(1, 4)), "<td>", mwcollapse.collapseTrigger("span", "mul", 39, "×", attributes={"class": "op"}), "</td></tr><tr><td>", mwcollapse.collapseTrigger("span", "AC", 41, "AC", attributes={"class": "AC"}), "</td><td>", mwcollapse.collapseTrigger("span", "0", 27, "0"), "</td><td>", mwcollapse.collapseTrigger("span", "equ", 42, "=", attributes={"class": "equ"}), "</td><td>", mwcollapse.collapseTrigger("span", "div", 40, "÷", attributes={"class": "op"}), "</td></tr>", attributes={"class": "calculator"})
table.compile("calc", mwcollapse.genStateMachine(("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "add", "sub", "mul", "div", "equ", "AC"), transition, stategen, (-1, None, -1)))
print(table)
Notakto generator
#!/bin/python3
import mwcollapse
boot = (49, 82, 148, 280, 49, 82, 148, 280)
class State:
__slots__ = "state", "bools", "transition"
def __init__(self, state, transition=None):
self.state = state
self.bools = tuple((state & 1 << n) != 0 for n in range(9) if n != 4)
self.transition = transition
def __eq__(self, other):
return self.state == other.state
def __hash__(self):
return self.state
def __len__(self):
return self.bools.count(True)
def __getitem__(self, key):
return True if key == None or key == ... else self.bools[key]
def gameover(self):
return (self.bools[0] and self.bools[1] and self.bools[2]) or (self.bools[0] and self.bools[3] and self.bools[5]) or (self.bools[0] and self.bools[7]) or (self.bools[1] and self.bools[6]) or (self.bools[2] and self.bools[5]) or (self.bools[2] and self.bools[4] and self.bools[7]) or (self.bools[3] and self.bools[4]) or (self.bools[5] and self.bools[6] and self.bools[7])
varToPos = lambda n: n if n < 4 else n + 1
posToVar = lambda n: n if n < 4 else n - 1
def transition(state, transition):
if not state[0].gameover():
if not state[1]:
if transition == None:
if len(state[0]) == 1:
return State(boot[state[0].transition]), True, False
for n in range(9):
if not state[0][n]:
s = State(state[0].state | 1 << varToPos(n))
if not s.gameover():
return s, True, False
elif not state[0][transition]:
s = State(state[0].state | 1 << varToPos(transition), transition)
return s, False, s.gameover()
elif transition == ...:
return (State(0b000010000), True, False)
return None
e = mwcollapse.ElementContainer(
'<p style="text-align: center;">',
mwcollapse.Trigger("span", None, "End turn", attributes={"class": "nimbutton"}),
mwcollapse.Collapsible("span", 8, "End turn", attributes={"class": "nobutton"}),
mwcollapse.Trigger("span", ..., "Try again", attributes={"class": "nimbutton"}),
'</p><table class="tictactoe">',
*(mwcollapse.Element("tr",
*(mwcollapse.Element("td",
'<span class="cell">X</span>' if k == 4 else mwcollapse.ElementContainer(
mwcollapse.Trigger("span", posToVar(k), attributes={"class": "cell"}),
mwcollapse.Collapsible("span", posToVar(k), "X", attributes={"class": "cell"})
),
) for k in range(n, n + 3))
) for n in (0, 3, 6)),
"</table>",
mwcollapse.Collapsible("p", 9, "YOU LOSE", attributes={"style": "font-size: 500%; font-weight: bold; text-align: center;"})
)
e.compile("notakto", mwcollapse.genStateMachine((*range(8), None, ...), transition, lambda state: (*state[0].bools, state[1], state[2]), (State(0b000010000), True, False)))
print(e)
Nim (Easy Mode) generator
#!/bin/python3
import random
import mwcollapse
nurpos = 99
def transition(state, transition):
if state[0] != 0:
if state[1] != 0 and transition != 0:
return (state[0] - 1, state[1] - 1)
elif transition == 0 and state[1] != 3:
if state[0] & 3 == 0:
return (state[0] - random.randrange(1, 4), 3)
return (state[0] & -4, 3)
return None
def stategen(state):
return (*(n < state[0] for n in range(nurpos)), state[0] == 0 and state[1] == 3, state[0] == 0 and state[1] != 3)
stateMachine = mwcollapse.genStateMachine((0, 1), transition, stategen, (nurpos, 3))
elementContainer = mwcollapse.ElementContainer('<p class="nurpons">', *(mwcollapse.Collapsible("span", n, "[[File:Nerpawhite.png|64px|link=]]") for n in range(nurpos)), '</p>\n<p class="nimbuttons">', mwcollapse.Trigger("span", 1, "Remove one", attributes={"class": "nimbutton"}), '<span class="nobutton">Remove one</span></p>\n<p class="nimbuttons">', mwcollapse.Trigger("span", 0, "End turn", attributes={"class": "nimbutton"}), '<span class="nobutton">End turn</span></p>', mwcollapse.Collapsible("p", nurpos, "YOU LOSE", attributes={"class": "bigtexty"}), mwcollapse.Collapsible("p", nurpos + 1, "YOU [[Win|WIN]]", attributes={"class": "bigtexty"}))
elementContainer.compile("nim", stateMachine)
print(elementContainer)
Nim (Pedantic Mode) generator
#!/bin/python3
import math
import mwcollapse
import warnings
class nimstate:
__slots__ = "piles", "prev"
def __init__(self, piles, prev):
self.piles = tuple(piles)
self.prev = prev
def __eq__(self, other):
return False if other == None else self.piles == other.piles and self.prev == other.prev
def __hash__(self):
return hash(self.piles) ^ hash(self.prev)
def parity(iterable):
p = 0
for n in iterable:
p ^= n
return p
nurpos = (2, 4, 3, 5)
offsets = tuple(sum(nurpos[0:n]) for n in range(len(nurpos)))
count = offsets[-1] + nurpos[-1]
def transition(state, transition):
l = list(state.piles)
if transition != None:
if (state.prev == None or transition == state.prev) and l[transition] != 0:
l[transition] -= 1
return nimstate(l, transition)
elif state.prev != None and max(l) != 0:
for n in range(1, max(nurpos) + 1):
for i in range(len(nurpos)):
l[i] -= n
if l[i] >= 0 and parity(l) == 0:
return nimstate(l, None)
l = list(state.piles)
warnings.warn(f"{state.piles}, {state.prev} : {transition}")
def stategen(state):
l = []
for i, n in enumerate(state.piles):
l.extend(k < n for k in range(nurpos[i]))
l.append(max(state.piles) == 0)
return l
stateMachine = mwcollapse.genStateMachine((*range(len(nurpos)), None), transition, stategen, nimstate(nurpos, None))
elementContainer = mwcollapse.ElementContainer(
*(mwcollapse.Element("div",
'<p class="nurpons">',
*(mwcollapse.Collapsible("span", k, "[[File:Nerpawhite.png|64px|link=]]") for k in range(o, o + nurpos[i])),
'</p>\n<p class="nimbuttons">',
mwcollapse.Trigger("span", i, "Remove one", attributes={"class": "nimbutton"}),
'<span class="nobutton">Remove one</span>',
"</p>\n", attributes={"class": "pile"}) for i, o in enumerate(offsets)),
'<p class="nimbuttons">',
mwcollapse.Trigger("span", None, "End turn", attributes={"class": "nimbutton"}),
'<span class="nobutton">End turn</span>',
"</p>\n",
mwcollapse.Collapsible("p", count, "YOU LOSE", attributes={"class": "bigtexty"}))
elementContainer.compile("nim", stateMachine)
print(elementContainer)
radio.c
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#ifdef WHITESPACE
#define LIVECONST_DEFAULT "background-color: red !important;"
#define DEAD_DEFAULT "background-color: #300;"
#define LIVE_DEFAULT "background-color: red;"
#define STR_LIVE "\n.%s%s {\n\t%s\n}"
#define SEP fputs(", ", stdout)
#define STR_100 ", 100%"
#define STR_A "\n.%s%s {\n\tanimation: %s step-end infinite %s%s;\n}\n@keyframes %s%s {\n\t"
#else
#define LIVECONST_DEFAULT "background-color:red!important"
#define DEAD_DEFAULT "background-color:#300"
#define LIVE_DEFAULT "background-color:red"
#define STR_LIVE ".%s%s{%s}"
#define SEP putchar(',')
#define STR_100 ",100%"
#define STR_A ".%s%s{animation:%s step-end infinite %s%s}@keyframes %s%s{"
#endif
typedef struct link {
struct link* next;
unsigned char data[];
} link_t;
static const char base64[] = {
'-', '0', '1', '2', '3', '4', '5', '6',
'7', '8', '9', 'A', 'B', 'C', 'D', 'E',
'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
'V', 'W', 'X', 'Y', 'Z', '_', 'a', 'b',
'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
};
static link_t start;
static void stdout_err() {
fputs("I/O error on stdout\n", stderr);
exit(EXIT_FAILURE);
}
int main(int argc, char* argv[]) {
const char* liveconst = LIVECONST_DEFAULT;
const char* deadprop = DEAD_DEFAULT;
const char* liveprop = LIVE_DEFAULT;
const char* prefix = "X";
const char* time = "1s";
unsigned int framesize = 256;
for (int c; (c = getopt(argc, argv, "L:c:d:l:o:p:s:t:")) != -1;) switch ((char)c) {
case 'L':
liveconst = optarg;
continue;
case 'd':
deadprop = optarg;
continue;
case 'l':
liveprop = optarg;
continue;
case 'o':
if (freopen(optarg, "wb", stdout) != NULL) continue;
perror("Could not create/open output file");
return EXIT_FAILURE;
case 'p':
prefix = optarg;
continue;
case 's':
framesize = atoi(optarg);
if (framesize && framesize <= 65536) continue;
fprintf(stderr, "Frame size must be in range [1,65536], but got \"%s\"\n", optarg);
return EXIT_FAILURE;
case 't':
time = optarg;
}
if (optind < argc && freopen(argv[optind], "r", stdin) == NULL) {
perror("Could not open input file");
return EXIT_FAILURE;
}
size_t len = strlen(deadprop);
#ifdef WHITESPACE
char deadstr[len + 11];
deadstr[0] = ' ';
deadstr[1] = '{';
deadstr[2] = '\n';
deadstr[3] = '\t';
deadstr[4] = '\t';
memcpy(deadstr + 5, deadprop, len);
deadstr[len + 5] = '\n';
deadstr[len + 6] = '\t';
deadstr[len + 7] = '}';
deadstr[len + 8] = '\n';
deadstr[len + 9] = '\t';
deadstr[len + 10] = 0;
#else
char deadstr[len + 3];
deadstr[0] = '{';
memcpy(deadstr + 1, deadprop, len);
deadstr[len + 1] = '}';
deadstr[len + 2] = 0;
#endif
len = strlen(liveprop);
#ifdef WHITESPACE
char livestr[len + 10];
livestr[0] = ' ';
livestr[1] = '{';
livestr[2] = '\n';
livestr[3] = '\t';
livestr[4] = '\t';
memcpy(livestr + 5, liveprop, len);
livestr[len + 5] = '\n';
livestr[len + 6] = '\t';
livestr[len + 7] = '}';
livestr[len + 8] = '\n';
livestr[len + 9] = 0;
#else
char livestr[len + 3];
livestr[0] = '{';
memcpy(livestr + 1, liveprop, len);
livestr[len + 1] = '}';
livestr[len + 2] = 0;
#endif
link_t* end = &start;
unsigned int n = 0;
unsigned int k = 0;
for (int c; (c = getchar()) != EOF;) {
switch ((char)c) {
default:
continue;
case 'X':
end->data[k++] = 1;
break;
case '.':
end->data[k++] = 0;
}
if (k == framesize) {
k = 0;
if (++n == 65536) {
while ((c = getchar()) != EOF) switch ((char)c) {
case 'X':
case '.':
fputs("Too many frames (>65536)\n", stdout);
return EXIT_FAILURE;
}
break;
}
link_t* l = calloc(1, sizeof(link_t*) + framesize);
if (l == NULL) {
fputs("Could not allocate memory\n", stderr);
return EXIT_FAILURE;
}
end->next = l;
end = l;
}
}
if (ferror(stdin)) {
fputs("I/O error on input", stderr);
return EXIT_FAILURE;
}
if (!n || (n == 1 && !k)) {
fputs("EOF on input before second frame\n", stderr);
return EXIT_FAILURE;
}
if (k) n++;
unsigned int buflen = (n + 1) >> 1;
unsigned short dead_buffer[buflen];
unsigned short live_buffer[buflen];
union {unsigned int block; char bytes[4];} buf;
for (unsigned int i = 0; i != framesize; i++) {
end = &start;
unsigned short depth = 0;
unsigned short dead = 0;
unsigned short live = 0;
unsigned char x;
unsigned char prev = 2;
do {
assert(depth < n);
x = end->data[i];
if (x != prev) {
prev = x;
if (x) {
assert(live < buflen);
live_buffer[live++] = depth;
}
else {
assert(dead < buflen);
dead_buffer[dead++] = depth;
}
}
end = end->next;
} while (++depth != n);
buf.block = 0;
assert((i & 0x003f) < 64);
buf.bytes[0] = base64[i & 0x003f];
if (i & 0xffc0) {
assert((i >> 6 & 0x003f) < 64);
buf.bytes[1] = base64[i >> 6 & 0x003f];
if (i & 0xf000) {
assert(i >> 12 < 64);
buf.bytes[2] = base64[i >> 12];
}
}
if (!dead) {
printf(STR_LIVE, prefix, buf.bytes, liveconst);
continue;
}
if (!live) continue;
if (printf(STR_A, prefix, buf.bytes, time, prefix, buf.bytes, prefix, buf.bytes) < 0) stdout_err();
depth = 0;
goto dead_loop;
do {
if (SEP < 0) stdout_err();
dead_loop:
assert(depth < dead);
if (printf("%.55f%%", (float)(dead_buffer[depth++] * 100) / n) < 0) stdout_err();
} while (depth != dead);
if ((x && fputs(STR_100, stdout) < 0) || fputs(deadstr, stdout)) stdout_err();
depth = 0;
goto live_loop;
do {
if (SEP < 0) stdout_err();
live_loop:
assert(depth < live);
if (printf("%.55f%%", (float)(live_buffer[depth++] * 100) / n) < 0) stdout_err();
} while (depth != live);
if ((!x && fputs(STR_100, stdout) < 0) || fputs(livestr, stdout)) stdout_err();
if (putchar('}') < 0) stdout_err();
}
return EXIT_SUCCESS;
}
Game of Life: ./radio -L "background-color:#000!important" -d "background-color:#FFF" -l "background-color:#000" -o biglife.css -s 1444 -t 16s biglife.txt
Amiga Boing Ball facet CSS generation
import math
w = 0.39018064403225655
sin = 0.3826834323650898
sinx = 0.39018064403225655
def height(y):
n = (y * 2 + 1) / 16 * math.pi
return math.hypot(math.sin(n) * sin, math.cos(n) * sinx)
width = lambda y: math.cos(y / 8 * math.pi) * w
def getCSS(y):
wid = width(y)
n = width(y + 1) / wid
print("clip-path: polygon(", (1 - n) / 2 * 100, "% 0, ", (1 + n) / 2 * 100, "% 0, 100% 100%, 0 100%);\nheight: ", height(y) * 50, "%;\ntransform: rotateX(", y / 16, "turn) ", "translateZ(96px) rotateX(0.03125turn) translateY(-50%);\nwidth: ", wid * 50, "%;", sep="")
O (group) generator
import mwcollapse
d = {
"R": (0, 0, 1, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 0, 1),
"L": (0, 0, -1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1),
"U": (1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1),
"D": (1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1)
}
n = 0
def transition(state, transition):
s = d[transition]
return tuple(sum(s[row + k * 4] * state[k + col * 4] for k in range(4)) for col, row in (divmod(n, 4) for n in range(16)))
def stategen(state):
global n
s = tuple(i == n for i in range(24))
print("#mw-customcollapsible-O-", n, ":not(.mw-collapsed) ~ * .cube {\n\ttransform: matrix3d", str(state), ";\n}", sep="")
n += 1
return s
elements = mwcollapse.ElementContainer(
*(mwcollapse.Collapsible("div", i) for i in range(24)),
'<table style="margin: auto"><tr><td colspan="3">',
mwcollapse.Trigger("span", "U", "⮝"),
"</td></tr><tr><td>",
mwcollapse.Trigger("span", "L", "⮜"),
"</td><td>{{Cube|[[File:FRONT.BMP.PNG]]|[[File:BACK.BMP.PNG]]|[[File:RIGHT.BMP.PNG]]|[[File:LEFT.BMP.PNG]]|[[File:TOP.BMP.PNG]]|[[File:BOTTOM.BMP.PNG]]|256}}</td><td>",
mwcollapse.Trigger("span", "R", "⮞"),
'</td></tr><tr><td colspan="3">',
mwcollapse.Trigger("span", "D", "⮟"),
"</td></tr></table>"
)
print("\n====== CSS ======\n")
elements.compile("O", mwcollapse.genStateMachine(d.keys(), transition, stategen, (1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)))
print("\n==== WIKITXT ====\n")
print(elements)
Nim (Pedantic Mode) (Easy Mode) generator
#!/bin/python3
import math
import random
import warnings
import mwcollapse
class nimstate:
__slots__ = "piles", "prev"
def __init__(self, piles, prev):
self.piles = tuple(piles)
self.prev = prev
def __eq__(self, other):
return False if other == None else self.piles == other.piles and self.prev == other.prev
def __hash__(self):
return hash(self.piles) ^ hash(self.prev)
def parity(iterable):
p = 0
for n in iterable:
p ^= n
return p
nurpos = (2, 4, 3, 6, 4)
nurposcount = tuple(range(len(nurpos)))
offsets = tuple(sum(nurpos[0:n]) for n in range(len(nurpos)))
count = offsets[-1] + nurpos[-1]
def transition(state, transition):
l = list(state.piles)
if transition != None:
if (state.prev == None or transition == state.prev) and l[transition] != 0:
l[transition] -= 1
return nimstate(l, transition)
elif state.prev != None:
m = max(l)
if m != 0:
moves = []
#Try to find a winning move
for n in range(1, m + 1):
for i in nurposcount:
l[i] -= n
if l[i] >= 0 and parity(l) == 0:
moves.append(nimstate(l, None))
l = list(state.piles)
if len(moves) != 0:
return random.choice(moves)
#If that fails, try to find a move resulting in no duplicate piles
for n in range(1, m + 1):
for i in nurposcount:
if l[i] >= n:
yes = True
l[i] -= n
for j in nurposcount:
if i != j and l[i] == l[j]:
yes = False
break
if yes:
moves.append(nimstate(l, None))
l = list(state.piles)
if len(moves) != 0:
return random.choice(moves)
#If that fails, just do whatever
n = random.choice([i for i in nurposcount if l[i] != 0])
l[n] -= random.randint(1, l[n])
return nimstate(l, None)
def stategen(state):
l = []
for i, n in enumerate(state.piles):
l.extend(k < n for k in range(nurpos[i]))
l.extend((state.prev == None, state.prev != None) if max(state.piles) == 0 else (False, False))
return l
stateMachine = mwcollapse.genStateMachine((*range(len(nurpos)), None), transition, stategen, nimstate(nurpos, None))
elementContainer = mwcollapse.ElementContainer(
*(mwcollapse.Element("div",
'<p class="nurpons">',
*(mwcollapse.Collapsible("span", k, "[[File:Nerpawhite.png|64px|link=]]") for k in range(o, o + nurpos[i])),
'</p>\n<p class="nimbuttons">',
mwcollapse.Trigger("span", i, "Remove one", attributes={"class": "nimbutton"}),
'<span class="nobutton">Remove one</span>',
"</p>\n", attributes={"class": "pile"}) for i, o in enumerate(offsets)),
'<p class="nimbuttons">',
mwcollapse.Trigger("span", None, "End turn", attributes={"class": "nimbutton"}),
'<span class="nobutton">End turn</span>',
"</p>\n",
mwcollapse.Collapsible("p", count, "YOU LOSE<br/>[https://camp2.rectangle.zone/index.php?title=Nim_(Pedantic_Mode)_(Easy_Mode) TRY AGAIN]", attributes={"class": "bigtexty"}),
mwcollapse.Collapsible("p", count + 1, "YOU [[Nim (Pedantic Mode) (Easy Mode)/Wiki Camp 2 Challenge Crystal|WIN]]", attributes={"class": "bigtexty"}))
elementContainer.compile("nim", stateMachine)
print(elementContainer)
Okinchess generator
import sys
alpha = "abcdefgh"
l = ["""{{#css:
#B table{
border-spacing:0;
height:512px;
width:512px
}
#B td:nth-child(2n+1),#B tr:nth-child(2n) td:nth-child(2n){
background-color:#FFF
}
#B td:nth-child(2n),#B tr:nth-child(2n) td:nth-child(2n+1){
background-color:#000;
}#B td{
padding:0;
vertical-align:top
}.D {
background-color:#0F07;
display:none;
height:48px;
margin:8px;
position:absolute;
width:48px
}.P{
align-items:center;
border-radius:50%;
display:flex;
height:64px;
position:absolute;
transition:0.5s ease translate;
width:64px
}.P:nth-child(2n) img{
filter:invert()
}
""".replace("\n", ""), ",".join(f"#mw-customcollapsible-w{x}:not(.mw-collapsed)~#B .w{x},#mw-customcollapsible-b{x}:not(.mw-collapsed)~#B .b{x}" for x in alpha), "{background-color: #0F07}"]
#Piece moving rules
for y in range(1, 9):
for i, x in enumerate(alpha):
L = []
#Rules for when a piece is in range of a destination
for k, z in enumerate(alpha):
if abs(i - k) < y - 1:
#White move up
L.append(f"#mw-customcollapsible-w{z}P{x}{y - 1}.mw-collapsed~#B #w{z}D{x}{y}")
if i != 0 and abs(i - k - 1) < y - 1:
#White capture right
L.extend(f"#mw-customcollapsible-w{z}P{alpha[i - 1]}{y - 1}.mw-collapsed~#mw-customcollapsible-b{c}P{x}{y}.mw-collapsed~#B #w{z}D{x}{y}R{c}" for l, c in enumerate(alpha) if abs(i - l) < 9 - y)
if i != 7 and abs(i - k + 1) < y - 1:
#White capture left
L.extend(f"#mw-customcollapsible-w{z}P{alpha[i + 1]}{y - 1}.mw-collapsed~#mw-customcollapsible-b{c}P{x}{y}.mw-collapsed~#B #w{z}D{x}{y}L{c}" for l, c in enumerate(alpha) if abs(i - l) < 9 - y)
if abs(i - k) < 8 - y:
#Black move down
L.append(f"#mw-customcollapsible-b{z}P{x}{y + 1}.mw-collapsed~#B #b{z}D{x}{y}")
if i != 0 and abs(i - k - 1) < 8 - y:
#Black capture right
L.extend(f"#mw-customcollapsible-w{c}P{x}{y}.mw-collapsed~#mw-customcollapsible-b{z}P{alpha[i - 1]}{y + 1}.mw-collapsed~#B #b{z}D{x}{y}R{c}" for l, c in enumerate(alpha) if abs(i - l) < y)
if i != 7 and abs(i - k + 1) < 8 - y:
#Black capture left
L.extend(f"#mw-customcollapsible-w{c}P{x}{y}.mw-collapsed~#mw-customcollapsible-b{z}P{alpha[i + 1]}{y + 1}.mw-collapsed~#B #b{z}D{x}{y}L{c}" for l, c in enumerate(alpha) if abs(i - l) < y)
l.append(",".join(L))
l.append("{display:block}")
#Rules for blocking motion
l.append(":is(")
l.append(",".join([f"#mw-customcollapsible-w{z}C:not(.mw-collapsed)~#mw-customcollapsible-w{z}P{x}{y}.mw-collapsed" for k, z in enumerate(alpha) if abs(i - k) < y] + [f"#mw-customcollapsible-b{z}C:not(.mw-collapsed)~#mw-customcollapsible-b{z}P{x}{y}.mw-collapsed" for k, z in enumerate(alpha) if abs(i - k) < 9 - y]))
l.append(")~#B :is(")
L = [f"#w{z}D{x}{y}" for k, z in enumerate(alpha) if abs(i - k) < y - 1] + [f"#b{z}D{x}{y}" for k, z in enumerate(alpha) if abs(i - k) < 8 - y]
while "" in L:
L.remove("")
l.append(",".join(L))
l.append("){display:none}")
#Piece positioning
for y in range(1, 9):
for i, x in enumerate(alpha):
l.append(",".join([f"#mw-customcollapsible-w{z}P{x}{y}.mw-collapsed~#B .w{z}" for k, z in enumerate(alpha) if abs(i - k) < y] + [f"#mw-customcollapsible-b{z}P{x}{y}.mw-collapsed~#B .b{z}" for k, z in enumerate(alpha) if abs(i - k) < 9 - y]))
l.append(f" {{translate:{i}00% {8 - y}00%}}")
print(sum(len(s) for s in l) - 7, file=sys.stderr)
l.append("}")
#Piece selection & capture memory
l.extend(f"{{{{Multitarget customcollapsible|w{x}|mw-collapsed|display:none !important}}}}{{{{Multitarget customcollapsible|w{x}C||display:none !important}}}}{{{{Multitarget customcollapsible|b{x}|mw-collapsed|display:none !important}}}}{{{{Multitarget customcollapsible|b{x}C||display: none !important}}}}" for x in "abcdefgh")
#Position memory
for y in range(1, 9):
for i, x in enumerate(alpha):
l.extend(f'<div class="mw-collapsible{" mw-collapsed" if y == 1 and x == z else ""}" id="mw-customcollapsible-w{z}P{x}{y}"></div>' for k, z in enumerate(alpha) if abs(i - k) < y)
l.extend(f'<div class="mw-collapsible{" mw-collapsed" if y == 8 and x == z else ""}" id="mw-customcollapsible-b{z}P{x}{y}"></div>' for k, z in enumerate(alpha) if abs(i - k) < 9 - y)
l.append('<div id="B">')
#The nerpas
l.extend(f'<div class="mw-customcollapsible-w{x}C P w{x} mw-customtoggle-w{x}">[[File:Nerpawhite.png|64x64px|link=]]</div><div class="mw-customcollapsible-b{x}C P b{x} mw-customtoggle-b{x}">[[File:Nerpawhite.png|64x64px|link=]]</div>' for x in alpha)
l.append("<table>")
#Moves
for y in range(8, 0, -1):
l.append("<tr>")
for i, x in enumerate(alpha):
l.append("<td>")
for k, z in enumerate(alpha):
d = abs(i - k)
if d < y - 1:
#White move up
l.append(f'<div class="mw-customcollapsible-w{z} mw-customcollapsible-w{z}C D mw-customtoggle-w{z} mw-customtoggle-w{z}P{x}{y - 1} mw-customtoggle-w{z}P{x}{y}" id="w{z}D{x}{y}"></div>')
if i != 0 and abs(i - k - 1) < y - 1:
#White capture right
l.extend(f'<div class="mw-customcollapsible-w{z} mw-customcollapsible-w{z}C mw-customcollapsible-b{c}C D mw-customtoggle-w{z} mw-customtoggle-b{c}C mw-customtoggle-w{z}P{alpha[i - 1]}{y - 1} mw-customtoggle-w{z}P{x}{y}" id="w{z}D{x}{y}R{c}"></div>' for l, c in enumerate(alpha) if abs(i - l) < 9 - y)
if i != 7 and abs(i - k + 1) < y - 1:
#White capture left
l.extend(f'<div class="mw-customcollapsible-w{z} mw-customcollapsible-w{z}C mw-customcollapsible-b{c}C D mw-customtoggle-w{z} mw-customtoggle-b{c}C mw-customtoggle-w{z}P{alpha[i + 1]}{y - 1} mw-customtoggle-w{z}P{x}{y}" id="w{z}D{x}{y}L{c}"></div>' for l, c in enumerate(alpha) if abs(i - l) < 9 - y)
if d < 8 - y:
#Black move down
l.append(f'<div class="mw-customcollapsible-b{z} mw-customcollapsible-b{z}C D mw-customtoggle-b{z} mw-customtoggle-b{z}P{x}{y + 1} mw-customtoggle-b{z}P{x}{y}" id="b{z}D{x}{y}"></div>')
if i != 0 and abs(i - k - 1) < 8 - y:
#Black capture right
l.extend(f'<div class="mw-customcollapsible-b{z} mw-customcollapsible-b{z}C mw-customcollapsible-w{c}C D mw-customtoggle-b{z} mw-customtoggle-w{c}C mw-customtoggle-b{z}P{alpha[i - 1]}{y + 1} mw-customtoggle-b{z}P{x}{y}" id="b{z}D{x}{y}R{c}"></div>' for l, c in enumerate(alpha) if abs(i - l) < y)
if i != 7 and abs(i - k + 1) < 8 - y:
#Black capture left
l.extend(f'<div class="mw-customcollapsible-b{z} mw-customcollapsible-b{z}C mw-customcollapsible-w{c}C D mw-customtoggle-b{z} mw-customtoggle-w{c}C mw-customtoggle-b{z}P{alpha[i + 1]}{y + 1} mw-customtoggle-b{z}P{x}{y}" id="b{z}D{x}{y}L{c}"></div>' for l, c in enumerate(alpha) if abs(i - l) < y)
l.append("</td>")
l.append("</tr>")
l.append("</table></div>[[Category:Minigames]][[Category:Collapsible minigames]][[Category:Pages which use over 10 kilobytes of CSS]][[Category:Pages which use over 100 kilobytes of CSS]][[Category:Pages which use over 500 kilobytes of CSS]][[Category:Two-player games]]")
print(sum(len(s) for s in l), file=sys.stderr)
print("".join(l))
Rule 110 generator
#!/bin/python3
#output is currently at least around 2x larger than it should be, since all triggers are reversible, but mwcollapse can't optimize for that yet
import mwcollapse
rulenum = 110
rule = tuple((1 << n & rulenum) != 0 for n in range(8))
depth = 8
def transition(state, transition):
return tuple(state[n] != (n == transition) for n in range(8))
def stategen(state):
result = list(state)
for n in range(depth - 1):
state = [rule[int(state[k - 1 & 7]) << 2 | int(state[k]) << 1 | int(state[k + 1 & 7])] for k in range(8)]
result.extend(state)
return (not x for x in result)
elementContainer = mwcollapse.ElementContainer(
f"""{{{{#css:
#w-{rulenum} {{
border-spacing: 0;
margin: auto;
}}
#w-{rulenum} span {{
display: inline-block;
height: 100%;
width: 100%;
}}
#w-{rulenum} td {{
background: #FFF;
display: table-cell !important;
height: 64px;
outline: 1px solid #CCC;
width: 64px;
}}
#w-{rulenum} .mw-collapsed {{
background: #000;
}}
}}}}
Click the top cells!""",
mwcollapse.Element("table",
mwcollapse.Element("tr",
*(mwcollapse.Toggleable("td", n, mwcollapse.Trigger("span", n)) for n in range(8))
),
*(mwcollapse.Element("tr",
*(mwcollapse.Toggleable("td", x + y * 8) for x in range(8))
) for y in range(1, depth)),
attributes={"id": "w-110"}),
"[[Category:Rules]][[Category:Math]][[Category:Cellular automata]][[Category:Pages that don't even remotely resemble a Wikipedia article]]"
)
elementContainer.compile("w", mwcollapse.genStateMachine(range(8), transition, stategen, tuple(False for n in range(8))))
print(elementContainer)
Kepler–Poinsot polyhedra
Subpages
:Þ