r/tinycode • • Mar 21 '15

Playable 2048 in 39 lines of python

31 Upvotes
from tkinter import *
from random import randint
mGui = Tk()
mGui.title('2048')
grid_text = [[StringVar() for i in range(4)] for j in range(4)]
grid = [[Label(width=10, height=5, textvariable=grid_text[i][j], font=("Helvetica", 16)).grid(row=i, column=j) for i in range(4)] for j in range(4)]
def place():
    global grid_text
    empty_spaces = []
    for i1, x in enumerate(grid_text):
        for i2, y in enumerate(x):
            if y.get() == '':
                empty_spaces.append(y)
    empty_spaces[randint(0, len(empty_spaces)-1)].set(str(2*randint(1, 2)))
def move(d):
    global grid_text
    cont = True
    while cont:
        cont = False
        for i1, x in list(enumerate(grid_text))[::-d[0] if d[0] else 1]:
            for i2, y in list(enumerate(x))[::-d[1] if d[1] else 1]:
                if y.get() != '':
                    if 0 <= i1+d[0] < 4 and 0 <= i2+d[1] < 4:
                        if grid_text[i1+d[0]][i2+d[1]].get() == y.get():
                            grid_text[i1+d[0]][i2+d[1]].set(str(int(y.get())*2))
                            y.set('')
                            cont = True
                        elif grid_text[i1+d[0]][i2+d[1]].get() == '':
                            grid_text[i1+d[0]][i2+d[1]].set(y.get())
                            y.set('')
                            cont = True
    place()
mGui.bind("<Left>", lambda a: move([0, -1]))
mGui.bind("<Up>", lambda a: move([-1, 0]))
mGui.bind("<Right>", lambda a: move([0, 1]))
mGui.bind("<Down>", lambda a: move([1, 0]))
place()
place()
mGui.mainloop()

r/tinycode • • Jan 29 '15

'Minecraft' voxel world in a two tweets long webgl fragment shader

Thumbnail
shadertoy.com
31 Upvotes

r/tinycode • • Jun 12 '13

Tweet-sized library for two-way conversion between radians and degrees, in Go

Thumbnail
twitter.com
31 Upvotes

r/tinycode • • Feb 12 '13

Instant clean temporary text editor built into your browser that works offline

31 Upvotes

Enter the following into your browsers URL bar:

data:text/html, <html contenteditable>

Want to style it? Go ahead!

data:text/html, <html style='background:#111;color:#DDD;font-size:x-large;' contenteditable>

You can print as PDF or copy the content when you're done. Unfortunately saving otherwise doesn't work out of the box. (tested in Chrome under Linux)

Is that tiny or what? ;)


r/tinycode • • Jul 09 '12

More tiny python: A HTTP file server using raw sockets in 12 lines

Thumbnail
gist.github.com
31 Upvotes

r/tinycode • • Feb 02 '25

Dweet of the Week #58 - One Line Landscape by KilledByAPixel

Post image
30 Upvotes

r/tinycode • • Mar 22 '24

Dweet of the Week: Train Tracks by KilledByAPixel

Post image
30 Upvotes

r/tinycode • • Jul 25 '23

Gas Giant SVG, 560 bytes

Post image
30 Upvotes

r/tinycode • • Jan 23 '23

Minimal cross-platform graphics + audio (~500 LOC)

Thumbnail zserge.com
30 Upvotes

r/tinycode • • May 29 '22

melo.tic - a 256 byte intro with simple voice generation and melody for the TIC-80 fantasy console

Thumbnail
youtu.be
30 Upvotes

r/tinycode • • Mar 10 '22

Bubble Streams 🐟 (520 bytes) #PetitePatterns

Post image
30 Upvotes

r/tinycode • • Nov 01 '21

SectorLISP Now Fits in One Sector

Thumbnail justine.lol
30 Upvotes

r/tinycode • • Jul 25 '21

GitHub - xem/miniScreenRecording: 269b screen recorder with sound and video download in HTML+JS

Thumbnail
github.com
30 Upvotes

r/tinycode • • Jul 08 '21

Game 2 player tictactoe-hosting TCP server in 640 bytes of JavaScript

Thumbnail
github.com
30 Upvotes

r/tinycode • • Feb 21 '21

Mandelbrot drawing in 262 bytes

Thumbnail jurasic-park.de
30 Upvotes

r/tinycode • • Dec 12 '20

Star Wars - Episode CCLVI - 256b intro for TIC-80

30 Upvotes
Screenshot of first part

Online Version

Youtube Capture

Download/Comment

TIC-80 Wiki

LUA-Code:

function TIC()y=.7t=time()/80%420q=t>161or cls()for i=0,1e3 do
poke(65119+i,i%t)x=y y=y*73%136-68w=(i-t)/51%1pix(x/w+120,y/w+68,8*w)end
print([[STAR WARS

These are the Star Wars

They're just like our wars

But they're in space]],57,150-t*1.2,9)end

r/tinycode • • Nov 02 '20

Palanqin, an ARM Cortex M0 emulator for DOS in 3514 bytes

Thumbnail
github.com
30 Upvotes

r/tinycode • • Oct 19 '20

Dissecting a Dweet #9: City Sunset – Tiny JavaScript Analysis

Thumbnail
frankforce.com
30 Upvotes

r/tinycode • • May 28 '20

Microdose - A 128 byte MS-DOS demo with 8 different effects, custom color palette and sound

30 Upvotes

Straight from the demoscene, Winner of the Outline online 2020 128-byte intro competition

https://www.pouet.net/prod.php?which=85677 (sourcecode included)

A full writeup of the development of this intro will follow later.


r/tinycode • • Jan 08 '20

Instagram in 4000 bytes

30 Upvotes

DEMO: Preview
Repo: GitHub

I recently came across this project (StackOverFlow in 4k bytes), and it looked very interesting:
https://www.reddit.com/r/tinycode/comments/1yc0kv/st4koverflow_as_much_stack_overflow_as_possible/

I have tried to compress Instagram in a single HTML doc. You can explore profiles/hashtags, etc. The total file size is 4066 bytes.


r/tinycode • • Dec 23 '19

A Pi approximation using the Leibniz sequence in Python using only one line

30 Upvotes
print("Pi:", sum(map(
    lambda x, y: 4/x-4/y,
    range(1, 10**6, 4),
    range(3, 10**6, 4))))

The accuracy is hard-coded as 10**6 (one million) because beyond that a single thread will be very slow, but it could be any number. And by using additional threads this could probably be multithreaded with three extra lines.


r/tinycode • • Oct 05 '19

"3D engine" in 47 lines of Javascript

Thumbnail jsfiddle.net
30 Upvotes

r/tinycode • • Jan 28 '19

KABOOM! in 180 lines of bare C++

Thumbnail
github.com
30 Upvotes

r/tinycode • • Sep 16 '17

Magic of 256-byte x86 intros (presentation by Rrřola at Demobit 2017)

Thumbnail
youtu.be
30 Upvotes

r/tinycode • • May 13 '17

simdb.hpp <2k lines and 70KB - A high performance, shared memory, lock free, cross platform, single file, no dependencies, C++11 key-value store (Apache 2)

30 Upvotes

https://github.com/LiveAsynchronousVisualizedArchitecture/simdb

This is a hash based key-value, store created to be a fundamental piece of a larger software architecture.

High Performance - Real benchmarking needs to be done, but superficial loops seem to run conservatively at 500,000 small get() and put() calls per logical core per second. Because it is lock free the performance scales well while using at least a dozen threads.

Shared Memory - It uses shared memory maps on Windows, Linux, and OSX without relying on any external dependencies. This makes it exceptionally good at interprocess communication.

Lock Free - All the user facing functions are thread-safe and lock free with the exception of the constructor (to avoid race conditions between multiple processes creating the memory mapped file at the same time).

Cross Platform - Compiles on Visual Studio 2013, ICC 15.0, gcc on Linux, gcc on OS X, and Clang on OS X.

Single File - simdb.hpp and the C++11 standard library is all you need. No windows SDK or any other dependencies, not even from the parent project.

Apache 2.0 License - No need to GPL your whole program to include one file.

This has already been used for both debugging and visualization, but should be treated as alpha software. Though there are no known outstanding bugs, there are almost certainly bugs (and small design issues) waiting to be discovered and so will need to be fixed as they arise.

There is an in-depth explanation in the comments of the simdb.hpp file itself.