User:Chrissy/projects/poetry

From XPUB & Lens-Based wiki

description

WRITE POETRY

In Manettas class we used a python script for automated poetry based on A House of Dust, Allison Knowles, 1968. I wanted to transfer it into JavaScript to use it on a webpage as a poem generator.

I'm using verbs, adjectives, nouns, locations (as where), prepositions, artivels, pronouns, emotions as smileys & emoijs and sparkles as decorative element. All of the words and elements are generated randomly.

AutomatedPoetrys screenshots.png

URL cerealbox porototype

https://hub.xpub.nl/cerealbox/~chrissy/poems/

sections

Do absolutely nothing

statement

recommendation

a poem

love letter

wrote with Eleni & Sevgi for valentines day for XPUB1 <3

Code

python script

#!/usr/bin/python

# A House of Dust, copyright (c) 2014 Nick Montfort <nickm@nickm.com>
# Original by Alison Knowles & James Tenney, 1967
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
# SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
# IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
# Updated 10 March 2015 to remove a duplicate value in "place".
# Updated 17 November 2015 to remove a near-duplicate value in "inhabitants".
# Updated 31 May 2018 to add compatibility with Python 3 (Python 2 still works)

from random import choice

material = ['SAND', 'DUST', 'LEAVES', 'PAPER', 'TIN', 'ROOTS', 'BRICK', 'STONE', 'DISCARDED CLOTHING', 'GLASS', 'STEEL', 'PLASTIC', 'MUD', 'BROKEN DISHES', 'WOOD', 'STRAW', 'WEEDS']

location = ['IN A GREEN, MOSSY TERRAIN', 'IN AN OVERPOPULATED AREA', 'BY THE SEA', 'BY AN ABANDONED LAKE', 'IN A DESERTED FACTORY', 'IN DENSE WOODS', 'IN JAPAN', 'AMONG SMALL HILLS', 'IN SOUTHERN FRANCE', 'AMONG HIGH MOUNTAINS', 'ON AN ISLAND', 'IN A COLD, WINDY CLIMATE', 'IN A PLACE WITH BOTH HEAVY RAIN AND BRIGHT SUN', 'IN A DESERTED AIRPORT', 'IN A HOT CLIMATE', 'INSIDE A MOUNTAIN', 'ON THE SEA', 'IN MICHIGAN', 'IN HEAVY JUNGLE UNDERGROWTH', 'BY A RIVER', 'AMONG OTHER HOUSES', 'IN A DESERTED CHURCH', 'IN A METROPOLIS', 'UNDERWATER']

light_source = ['CANDLES', 'ALL AVAILABLE LIGHTING', 'ELECTRICITY', 'NATURAL LIGHT']

inhabitants = ['PEOPLE WHO SLEEP VERY LITTLE', 'VEGETARIANS', 'HORSES AND BIRDS', 'PEOPLE SPEAKING MANY LANGUAGES WEARING LITTLE OR NO CLOTHING', 'ALL RACES OF MEN REPRESENTED WEARING PREDOMINANTLY RED CLOTHING', 'CHILDREN AND OLD PEOPLE', 'VARIOUS BIRDS AND FISH', 'LOVERS', 'PEOPLE WHO ENJOY EATING TOGETHER', 'PEOPLE WHO EAT A GREAT DEAL', 'COLLECTORS OF ALL TYPES', 'FRIENDS AND ENEMIES', 'PEOPLE WHO SLEEP ALMOST ALL THE TIME', 'VERY TALL PEOPLE', 'AMERICAN INDIANS', 'LITTLE BOYS', 'PEOPLE FROM MANY WALKS OF LIFE', 'NEGROS WEARING ALL COLORS', 'FRIENDS', 'FRENCH AND GERMAN SPEAKING PEOPLE', 'FISHERMEN AND FAMILIES', 'PEOPLE WHO LOVE TO READ']

print('')
print('A HOUSE OF ' + choice(material))
print('      ' + choice(location))
print('            USING ' + choice(light_source))
print('                  INHABITED BY ' + choice(inhabitants))
print('')

JS script

for five different poems

const verb = ["reading", "resting","listening ", "crying", "screaming", "crawling", "creeping", "running", "writing", "drinking", "relaxing", "playing", "riding", "baking", "hating", "singing"];
const verb2 = ["read", "rest", "cry", "scream", "crawl", "creep", "run", "write", "drink", "eat", "relax", "play", "ride", "bake", "hate", "sing"];
const adjectives = ["little", "high", "big", "deep", "tiny", "huge", "small", "large", "green", "hungry", "mini", "huge", "gigantic", "red", "pastel", "glitter", "shiny", "dark", "noisy", "silly"];
const noun = ["flower", "bird", "dog", "ant", "worm", "rainbow", "skyscraper", "wolve", "chili", "bowl", "bike", "raindrop", "teardrop", "book",];
const where = ["field", "rooftop", "grass", "cave", "mountain", "beach", "deep sea", "horse", "sheep", "wave", "cloud"];
const prepositions = ["in", "on", "at", "under", "above", "beside", "between", "behind", "in front of", "inside", "outside", "over", "through", "across", "around", "up", "down", "off", "on top of", "beneath", "towards", "against", "along", "among", "around", "in front of", "behind", "beneath", "beside", "between", "beyond", "inside", "outside", "under", "underneath", "upon"];
const articels = ["a"];
const pronouns = ["I", "me", "you", "she", "him", "it", "they"];
// const where = ["in a field", "in high grass", "in a cave", "on a mountain", "in high grass", "on a beach", "in the deep sea", "on a horse", "on a sheep", "on a wave", "in the clouds"];
const emotion=[":(", ":)", ":D", ":'(", ":o", ":p", ":|", ":/", "🤡", "💀", "👽", "🫠", "🫡", "🙄", "🤤", "🥵", "🥺", "🥹", "🥰"];
const sparkles=["・゚゚・。", "⋆✦", "───", ".·:¨ ¨:·. ", "・゚・", "• •", "・゚゚", "·.··", "·¨.", "·.··."];

// xpub love letter
const dear = ["beloved", "dear", "love", "sunshine", "honey", "stroopwafel", "appelflap", "cupcake", "schattig", "schatje", "snoepje"];
const name = ["XXX"];
const excite = ["excite", "perplex", "explode", "transform", "amaze", "see", "understand", "touch", "call", "love", "appreciate"];
const plotters = ["plotters", "printers", "servers", "memes", "flowers", "torrents", "vending machine coffee", "candy", "PDFs", "the library", "github", "chrissys mandarins", "are.na", "stack overflow", "etherpad", "the wiki", "webrings", "midi syths", "pen plotters", "riso printers", "pin printing", "screen printers", "internet archive", "graphviz", "online tools", "yarn", "neo cities", "newspapers"];
const peeps = ["beats", "peeps", "doki dokis", "stops", "yells", "freezes", "explodes", "jumps", "blips", "ticks", "squeaks", "smiles", "is filled with sunshine", "cheers", "beeps", "boops", "pumps"];
const printers = ["PINWRITER 20", "casette player", "broken pinwriter", "hungry tamagotchi", "Citizen Swift 90e", "HP 7550A", "Star SG-10", "OS error", "typewriter", "zulip mention", "error 404", "arduino sensor"];
const something = ["a paper jammed in a printer", "bluetooth connection", "eduroam", "a gilmore girls episode", "a final girl hugs her knife", "a staple binding a book", "a warming fireplace", "my broken bike", "the canal", "the canal seal", "a smoke break", "the caramel inside a stroopwafel", "a cd-rom"];
const love = ["love", "worry", "care", "wishes and thoughts", "xoxo"];

// old code
// const randomdrei = Math.floor(Math.random() * adjectives.length);
// const randomzwei = Math.floor(Math.random() * where.length);xw
// const random = Math.floor(Math.random() * verb.length);
// console.log("Do", where[random], verb[random]);

function getRandomElement(list) {
    return list[Math.floor(Math.random() * list.length)];
}

function generatePoetry() {
    const randomVerb2 = getRandomElement(verb);
    const randomWhere = getRandomElement(where);
    const randomAdjective = getRandomElement(adjectives);
    const randomAdjective2 = getRandomElement(adjectives);
    const randomAdjective3 = getRandomElement(adjectives);
    const randomNoun = getRandomElement(noun);
    const randomNoun2 = getRandomElement(noun);
    const randomNoun3 = getRandomElement(noun);
    const randomEmotion = getRandomElement(emotion);
    const randomVerb = getRandomElement(verb);
    const randomPrepositions = getRandomElement(prepositions);
    const randomSparkles = getRandomElement(sparkles);
    const randomSparkles2 = getRandomElement(sparkles);
    const randomSparkles3 = getRandomElement(sparkles);
    const randomSparkles4 = getRandomElement(sparkles);



    const poetry = `Do absolutely nothing 
    ${randomPrepositions} a ${randomAdjective} ${randomWhere}, ${randomVerb} with 
    ${randomAdjective} ${randomNoun}s and ${randomAdjective2} ${randomNoun2}s, 
    while ${randomVerb2} to ${randomNoun3}s ${randomEmotion}
    ${randomSparkles}${randomSparkles2}${randomSparkles3}${randomSparkles4}`;

document.getElementById('poetryText').innerText = poetry;

// console log
console.log(`Do absolutely nothing 
    ${randomWhere} ${randomVerb} 
    with ${randomAdjective} ${randomNoun} 
    and ${randomAdjective2} ${randomNoun2} 
    while ${randomVerb2} 
    to ${randomNoun3} ${randomEmotion}`);
}

function generatePoetryTwo() {
    const randomVerb2 = getRandomElement(verb);
    const randomWhere = getRandomElement(where);
    const randomAdjective = getRandomElement(adjectives);
    const randomAdjective2 = getRandomElement(adjectives);
    const randomNoun = getRandomElement(noun);
    const randomNoun2 = getRandomElement(noun);
    const randomNoun3 = getRandomElement(noun);
    const randomEmotion = getRandomElement(emotion);
    const randomVerb = getRandomElement(verb);
    const randomSparkles = getRandomElement(sparkles);
    const randomSparkles2 = getRandomElement(sparkles);
    const randomSparkles3 = getRandomElement(sparkles);

    const poetry = 
    `${randomAdjective} 
    ${randomNoun} 
    ${randomVerb2}
    ${randomSparkles}${randomSparkles2}`;

document.getElementById('poetryTextTwo').innerText = poetry;

// console log
console.log(`recipe
    ${randomVerb} 
    + ${randomAdjective} ${randomNoun} 
    + ${randomAdjective2} ${randomNoun2} 
    + ${randomVerb2} 
    = ${randomNoun3} ${randomEmotion}`);
}

function generatePoetryThree() {
    const randomVerb2 = getRandomElement(verb);
    const randomWhere = getRandomElement(where);
    const randomAdjective = getRandomElement(adjectives);
    const randomAdjective2 = getRandomElement(adjectives);
    const randomNoun = getRandomElement(noun);
    const randomNoun2 = getRandomElement(noun);
    const randomNoun3 = getRandomElement(noun);
    const randomEmotion = getRandomElement(emotion);
    const randomVerb = getRandomElement(verb);
    const randomSparkles = getRandomElement(sparkles);
    const randomSparkles2 = getRandomElement(sparkles);
    const randomSparkles3 = getRandomElement(sparkles);

    const poetry = 
    `${randomVerb} 
    + 
    ${randomAdjective} ${randomNoun} 
    = 
    ${randomEmotion}
    ${randomSparkles}${randomSparkles2}${randomSparkles3}`; 

document.getElementById('poetryTextThree').innerText = poetry;

// console log
console.log(`recipe
    ${randomVerb} 
    ${randomAdjective} ${randomNoun} 
    = ${randomNoun3} ${randomEmotion}`);
}

function generatePoetryFour() {
    const randomVerb2 = getRandomElement(verb);
    const randomVerbIng = getRandomElement(verb2);
    const randomVerbIng2 = getRandomElement(verb2);
    const randomWhere = getRandomElement(where);
    const randomAdjective = getRandomElement(adjectives);
    const randomAdjective2 = getRandomElement(adjectives);
    const randomNoun = getRandomElement(noun);
    const randomNoun2 = getRandomElement(noun);
    const randomNoun3 = getRandomElement(noun);    
    const randomNoun4 = getRandomElement(noun);
    const randomEmotion = getRandomElement(emotion);
    const randomVerb = getRandomElement(verb);
    const randomPrepositions = getRandomElement(prepositions);
    const randomSparkles = getRandomElement(sparkles);
    const randomSparkles2 = getRandomElement(sparkles);
    const randomSparkles3 = getRandomElement(sparkles);
    const randomPronouns = getRandomElement(pronouns);
    const randomPronouns2 = getRandomElement(pronouns);
    const randomPronouns3 = getRandomElement(pronouns);

    const poetry = 
    `${randomPronouns} ${randomVerbIng}

    ${randomPronouns2} ${randomVerbIng2} ${randomNoun}s
    ${randomPrepositions} the ${randomNoun3}

    and ${randomPronouns3}
    ${randomVerb}
    ${randomAdjective}
    ${randomSparkles}${randomSparkles2}${randomSparkles3}`;


document.getElementById('poetryTextFour').innerText = poetry;

// console log
console.log(`recipe
    ${randomVerb} ${randomVerbIng}
    ${randomAdjective} ${randomNoun} 
    = ${randomNoun3} ${randomEmotion}`);
}

// love letter
function getRandomElement(list) {
    return list[Math.floor(Math.random() * list.length)];
}

function generatePoetryFive() {
    const randomDear = getRandomElement(dear);
    const randomName = getRandomElement(name);
    const randomExcite = getRandomElement(excite);
    const randomPlotters = getRandomElement(plotters);
    const randomPeeps = getRandomElement(peeps);
    const randomPrinters = getRandomElement(printers);
    const randomSomething = getRandomElement(something);
    const randomLove = getRandomElement(love);
    const randomSparkles = getRandomElement(sparkles);
    const randomSparkles2 = getRandomElement(sparkles);
    const randomSparkles3 = getRandomElement(sparkles);
    const randomSparkles4 = getRandomElement(sparkles);

    const poetry = `My ${randomDear}, 
    You ${randomExcite} me more than ${randomPlotters}...
    When I see you my heart ${randomPeeps} like a ${randomPrinters}.
    This valentines day, hug me as tight as ${randomSomething}.
    
    with ${randomLove} 
    Chrissy&Eleni&Sevgi <33333
    ${randomSparkles}${randomSparkles2}${randomSparkles3}${randomSparkles4}`;

document.getElementById('poetryTextFive').innerText = poetry;
}

// const poetry = 
// `${randomPronouns} ${randomVerbIng} 
// ${randomPronouns2}
// a(n) ${randomNoun}
// ${randomNoun2}
// ${randomPrepositions}
// the ${randomNoun3}
// and ${randomPronouns3}
// ${randomVerb}
// a ${randomAdjective}
// ${randomNoun4}`;

HTML

<!DOCTYPE html>
<html lang=”en”>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>write poetry</title>
    <link rel="stylesheet " href="poetry.css">
    <!-- <link rel="stylesheet" href="https://unpkg.com/xp.css" /> -->

    <link rel="stylesheet" href="https://unpkg.com/98.css@0.1.4/build/98.css" />




</head>

<body>
    <!-- <button onclick="generatePoetry()">write poetry</button> 
    <button onclick="generatePoetry()">write poetry</button>  -->

<!-- POETRY 1 -->
<div class="variationOne">
<!-- Button 1 -->
    <div class="windows98Button"><button onclick="generatePoetry()">Do absolutely nothing</button></div>

<!-- Output 1 -->
    <div class="windows98Output" id="poetryText"></div>
</div>  

<!-- POETRY 2 -->
<div class="variationTwo">
<!-- Button 2 -->
    <div class="windows98Button"><button onclick="generatePoetryTwo()">statement</button></div>

<!-- Output 2 -->
    <div class="windows98Output" id="poetryTextTwo"></div>
</div>

<!-- POETRY 3 -->
<div class="variationThree">
    <!-- Button 3 -->
        <div class="windows98Button"><button onclick="generatePoetryThree()">recommendation</button></div>
    
    <!-- Output 3 -->
        <div class="windows98Output" id="poetryTextThree"></div>
</div>

<!-- POETRY 4 -->
<div class="variationThree">
    <!-- Button 4 -->
        <div class="windows98Button"><button onclick="generatePoetryFour()">a poem</button></div>
    
    <!-- Output 4 -->
        <div class="windows98Output" id="poetryTextFour"></div>
</div>

<!-- POETRY 5 -->
<div class="variationFive">
    <!-- Button 5 -->
        <div class="windows98Button"><button onclick="generatePoetryFive()">love letter</button></div>
    
    <!-- Output 4 -->
        <div class="windows98Output" id="poetryTextFive"></div>
</div>



   
    <!-- <div class="title-bar-text">Do absolutely nothing</div> -->


    <script src="poetry.js"></script>
</body>

</html>

CSS

::selection {
    background: #918851;
    /* color: #ffffff; */
}

body {
    display: block;
    height: 100%;
    width: 100%;
}

@font-face {
    font-family: KarrikRegular;
    src: url("./fonts/Karrik-Regular.otf") format("opentype");
  }

/* #poetryText {
    font-size: 1.5em;
    font-family: "Pixelated MS Sans Serif",Arial;
    color: #000000;
    line-height: 3em;
    margin: 0;
    padding: 0;
    text-align: center;
    width: 100%;
    display: block;
    margin-top: 20px;
    margin-left: 10px;
    margin-bottom: 20px;
} */

/* .window {
    box-shadow: inset -1px -1px #0a0a0a,inset 1px 1px #dfdfdf,inset -2px -2px grey,inset 2px 2px #fff;
    padding: 3px;
    background: silver;
} */

/* button {
input[type="submit"],
input[type="reset"] {
    display: grid;
}} */


/* .windowOutput::before {
    display: none;
} */

/* .windowsXpOutput {
    display: block;

    width: max-content;
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
    margin: 7px;
    padding: 7px;
    -webkit-font-smoothing: antialiased;
    box-shadow: inset -1px -1px #000735,inset 1px 1px #0831d9,inset -2px -2px #001ea0,inset 2px 2px #166aee,inset -3px -3px #003bda,inset 3px 3px #0855dd;
    filter: drop-shadow(16px 16px 20px red) hue-rotate(90deg); */
    /* filter: drop-shadow(16px 16px 20px red) invert(75%); */
/* } */

/* .windows98Button {
  border-radius: 0;
  padding: 0 12px;
  background: silver;
  border: none;
  border-radius: 0;
  box-shadow: inset -1px -1px #0a0a0a,inset 1px 1px #fff,inset -2px -2px grey,inset 2px 2px #dfdfdf;
  box-sizing: border-box;
  color: transparent;
  min-height: 23px;
  min-width: 75px;
  text-shadow: 0 0 #222;
  -webkit-font-smoothing: none;
  font-family: "Pixelated MS Sans Serif",Arial;
  font-size: 11px;
} */

.windows98Button {
    padding: 7px;  /* padding around both buttons */
    filter: hue-rotate(90deg);
}

.windows98Output {
    padding-left: 20px;  /* padding around both buttons */
    display: block;
    /* filter: drop-shadow(10px 5px 15px rgb(255, 50, 105)); */
    /* filter: drop-shadow(10px 5px 15px rgb(255, 50, 105)) hue-rotate(90deg); */
    /* font-family: KarrikRegular; */
    font-size: 1.2em;
    color: black;
}

/* .windowsXpButton {
    padding: 7px;  
    filter: hue-rotate(90deg);
} */

/* #poetryText::before {
    display: none !important;
} */

/* #poetryText:after {
    display: inline-flex;    
    /* text-align: center; */
    /* width: auto;
    height: auto;
    padding: 10px;
} */ 

/* .poetryTextTwo::before {
    display: none;
} */

/* .poetryTextTwo::after {
    display: inline-flex;    
    top: 100px;
    width: auto;
    height: auto;
    padding: 10px;
} */

/* divs different texts */

.variationOne {
    padding: 5px;
    filter: drop-shadow(10px 5px 15px rgb(255, 50, 101));
}

.variationTwo {
    padding: 5px;
    filter: drop-shadow(10px 5px 15px rgb(140, 203, 108));
}

.variationThree {
    padding: 5px;
    filter: drop-shadow(10px 5px 15px rgb(140, 203, 108));
}

.variationFour {
    padding: 5px;
    filter: drop-shadow(10px 5px 15px rgb(140, 203, 108));
}

.variationFive {
    padding: 5px;
    filter: drop-shadow(10px 5px 15px rgb(255, 50, 101));
}