Compare commits

..

No commits in common. 'main' and 'mako' have entirely different histories.
main ... mako

@ -1,57 +0,0 @@
# Xquisite Branch
A branching version of the [exquisite corpse](https://en.wikipedia.org/wiki/Exquisite_corpse) game. A drawing app developed for [SI17](https://issue.xpub.nl/17/).
Draw something, upload it and send the link to someone else: they will continue from your drawing. But wait! There's a catch!!!!! If you send to just one person the chain will continue linearly, but send it to more people and things will start branching in different directions.
## Install
Clone the repository.
```
git clone https://git.xpub.nl/kamo/exquisite-branch.git
```
Create a virtual environment.
```
python3 -m venv venv
```
Install the requirements with `pip` and the `requirements.txt` file.
```
pip install -r requirements.txt
```
Create an `.env` file in the root folder of the project with the following variables:
```
DEBUG=True
FLASK_ENV=development
FLASK_APP=exquisite_branch
```
Before running the app for the first time, be sure to initialize the database. __Watch out:__ this will delete the previous instance of the database along with its contents!
```
flask init-db
```
After initializing the database you can run the flask application
```
flask run
```
## Overview
_Xquisite Branch_ saves contents in a database, and join them together in a branching version of the exquisite corpse.
The original exquisite corpse data structure is something similar to a linked list, where every drawing is connected to the previous one. Contents in _Xquisite Branch_ are saved in a database with the same principle.
Each entry in the database has the following properties:
- `id`: a unique identifier for every entry
- `branch`: a random name for the excerpt
- `parent`: the random name of the previous excerpt
- `content`: the actual content of the writings
- `username`: the author of the excerpt
When generating the display page, every entry look up its `parent` property to position itself after that.
Mhh should rewrite this better bc is super convoluted ahah.

@ -1,45 +1,47 @@
from flask import (Blueprint)
from flask import (Blueprint, flash, g, redirect,
request, session, url_for)
from flask_mako import render_template
from exquisite_branch.db import get_db
bp = Blueprint('display', __name__, url_prefix='/display')
# @bp.route('/')
# def display():
# db = get_db()
@bp.route('/')
def display():
db = get_db()
# branches = db.execute(
# "SELECT content, branch, parent, username FROM branches"
# ).fetchall()
branches = db.execute(
"SELECT content, branch, parent, username FROM branches"
).fetchall()
# streams = []
# for branch in branches[::-1]:
# if branch not in flatten(streams):
# stream = [branch]
# parent = branch['parent']
# while parent != 'NEW':
# current = next(
# (x for x in branches if x['branch'] == parent), None)
# parent = current['parent']
# stream.append(current)
streams = []
for branch in branches[::-1]:
if branch not in flatten(streams):
stream = [branch]
parent = branch['parent']
while parent != 'NEW':
current = next(
(x for x in branches if x['branch'] == parent), None)
parent = current['parent']
stream.append(current)
# streams.append(stream[::-1])
streams.append(stream[::-1])
# return render_template('display_mako.html', branches=branches, streams=streams)
return render_template('display_mako.html', branches=branches, streams=streams)
# def flatten(t):
# return [item for sublist in t for item in sublist]
def flatten(t):
return [item for sublist in t for item in sublist]
@bp.route('/')
def display():
@bp.route('/linked')
def linked():
db = get_db()
branches = db.execute(
"SELECT content, branch, parent, username FROM branches"
).fetchall()
return render_template('display_linked_mako.html', branches=branches)
return render_template('display_linked_mako.html', branches=branches)

@ -4,20 +4,7 @@ from flask import (Blueprint, flash, g, redirect,
from exquisite_branch.db import get_db
from werkzeug.exceptions import abort
import shortuuid
import uuid
def get_uuid(d=7):
'''return a short uuid (default 7 chars)'''
u = uuid.uuid4()
s = shortuuid.encode(u)
return s[:d]
from shortuuid import uuid
bp = Blueprint('draw', __name__, url_prefix='/draw')
@ -44,8 +31,7 @@ def draw(parent=None):
print(url_for('share.share', branch=f"{branch}"))
return redirect(url_for('share.share', branch=branch))
branch = get_uuid()
branch = uuid()
previous = db.execute(
"SELECT content, branch, parent FROM branches"
@ -62,7 +48,7 @@ def draw(parent=None):
@bp.route('/last', methods=('GET', 'POST'))
def last():
branch = get_uuid()
branch = uuid()
db = get_db()
previous = db.execute(
'SELECT * FROM branches ORDER BY id DESC LIMIT 1'
@ -88,7 +74,7 @@ def last():
@bp.route('/', methods=('GET', 'POST'))
def new():
db = get_db()
branch = get_uuid()
branch = uuid()
parent = 'NEW'
if request.method == 'POST':

@ -13,8 +13,8 @@
<body>
<nav>
<%block name='nav' >
<a href="${url_for('home.home')}">Home</a>
<a href="${url_for('display.display')}">Results</a>
<a href="{{url_for('home.home')}}">Home</a>
<a href="{{url_for('display.display')}}">Results</a>
</%block>
</nav>
${self.body()}

@ -43,4 +43,4 @@
% endfor
</div>
</main>
</main>

@ -1,18 +1,21 @@
<%inherit file="base_mako.html" />
<%block name="head">
<link rel="stylesheet" href="${url_for('static', filename='css/display_mako.css')}">
<link rel="stylesheet" href="${url_for('static', filename='css/display_mako.css')}">
</%block>
<% from random import random %>
<% offset = 1 / (len(streams) + 1)%>
<% offset = 1 / (len(streams) - 1)%>
% for stream in streams:
<div class="stream">
<% transform = f'rotate({offset * loop.index}turn) translateX(100%) ' %>
% for branch in stream:
% for branch in stream:
<% transform = transform + ' rotate(' + str((random() * 2 - 1) * 0.02) + 'turn) translateX(100%)'%>
<div class="svg-container" style="transform: ${transform}">${branch['content']}</div>
% endfor
</div>
% endfor
% endfor

@ -8,20 +8,6 @@
<link rel="stylesheet" href="{{url_for('static', filename='css/variables.css')}}" />
<link rel="stylesheet" href="{{url_for('static', filename='css/global.css')}}" />
<link rel="stylesheet" href="{{url_for('static', filename='css/home.css')}}" />
<style>
.renovation
{
background-color: yellow;
display: inline-block;
transform: translateY(-90px) rotate(10deg);
padding: 8px;
font-size: 0.88rem;
font-family: 'Brush Script MT', cursive;
}
</style>
</head>
<body>
<header class="title">
@ -31,7 +17,6 @@
></object>
<h1>really exquisite indeed</h1>
<span class='renovation'>RENOVATION IN PROGRESS!</span>
</header>
<main>
<a href="{{url_for('draw.new')}}">Start new</a> <br />

Loading…
Cancel
Save