Last active
October 16, 2017 13:16
-
-
Save JoshCheek/85c362e566ed8cfffa9bab4a9b6701dd to your computer and use it in GitHub Desktop.
Visual analysis of lyrical repetition with self-similar matrices
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Based on https://colinmorris.github.io/SongSim/#/about/intro | |
# inspired by https://www.youtube.com/watch?v=HzzmqUoQobc | |
MAX_HEIGHT = 900 | |
MIN_LUMINOSITY = 0.35 # b/c the background is black, making it difficult to see dark colours | |
REMOVE_STOPWORDS = false # cut down on size by removing spammy low-quality words | |
EXPLORE_MODE = true # add crosshairs and the current word | |
SONG = | |
# 'BAA_BAA_BLACK_SHEEP' | |
# 'CALL_ME_MAYBE' | |
# 'RUMOUR_HAS_IT' | |
# 'LEAN_ON' | |
# '212' | |
'AINT_NO_SUNSHINE' | |
# 'BEAST_OF_BURDEN' | |
# 'TEST' # need to turn off stopwords to see this one | |
# find the song | |
songs = DATA.read.split(/^(?=\S)/) | |
.map { |s| [s.lines.first.chomp, s.lines.drop(1).join(' ')] } | |
.to_h | |
song = songs.fetch SONG | |
words = song.downcase.split(/[ \t\n,?.]+/m).reject(&:empty?) | |
# maybe remove stopwords? | |
stopwords = %w[a am an and as be but by do I if in it no of on or that the to we].map(&:downcase) | |
words.reject! { |word| stopwords.include? word } if REMOVE_STOPWORDS | |
# build the matrix | |
matrix = words.map { Array.new words.length, nil } | |
words.each_with_index do |wordx, x| | |
words.each_with_index do |wordy, y| | |
next unless wordx == wordy | |
matrix[y][x] = wordx | |
end | |
end | |
# map words to colours | |
colours = { | |
background: [0]*3, # black | |
crosshairs: [50]*3, # brighter than bg, not as bright as word colours | |
} | |
words.uniq.each do |word| | |
loop do | |
hash = rand 256**3 | |
red = (hash / 256**2) % 256 | |
green = (hash / 256**1) % 256 | |
blue = (hash / 256**0) % 256 | |
luminance = 0.299*red + 0.587*green + 0.114*blue # https://stackoverflow.com/questions/596216/formula-to-determine-brightness-of-rgb-color | |
colour = [red, green, blue] | |
next if luminance < MIN_LUMINOSITY || colours.values.include?(colour) | |
break colours[word] = colour | |
end | |
end | |
# draw it | |
require 'graphics' | |
cell_size = MAX_HEIGHT / words.length | |
cell_size = 1 if cell_size < 1 | |
drawing = Graphics::Simulation.new cell_size*words.length, cell_size*words.length, 24 | |
drawing.color.default_proc = -> h, k { k } | |
# 1, 2, and 3 to change how fast you move | |
stride = 1 | |
drawing.add_keydown_handler("1") { stride = 1 } | |
drawing.add_keydown_handler("2") { stride = 5 } | |
drawing.add_keydown_handler("3") { stride = 20 } | |
# vim keybindings move the crosshairs, return and space move diagonally | |
col = row = 0 | |
{ h: -> { col -= stride }, | |
l: -> { col += stride }, | |
j: -> { row += stride }, | |
k: -> { row -= stride }, | |
" ": -> { col -= stride; row -= stride }, | |
"\r": -> { col += stride; row += stride }, | |
}.each do |key, block| | |
drawing.add_keydown_handler key.to_s do | |
block.call | |
col %= words.length | |
row %= words.length | |
end | |
end | |
# helpers | |
define_method(:index_word) { |index| matrix[index][index] } | |
define_method(:index_colour) { |index| colours[index_word index] } | |
define_method :mix_colours do |*colours| | |
colours.transpose.map { |cs| cs.reduce(:+) / cs.length } | |
end | |
define_method :draw_cell do |y, x, colour| | |
x_start = x*cell_size | |
y_start = drawing.h - y.succ*cell_size - 1 # start from top instead of bottom | |
drawing.rect x_start, y_start, cell_size, cell_size, colour, :fill | |
end | |
# draw it! | |
drawing.define_singleton_method :draw do |n; words| | |
clear colours[:background] | |
EXPLORE_MODE and matrix.length.times do |i| | |
draw_cell i, col, mix_colours(index_colour(col), colours[:background]) | |
draw_cell row, i, mix_colours(index_colour(row), colours[:background]) | |
end | |
matrix.each_with_index do |row, y| | |
row.each_with_index do |word, x| | |
draw_cell y, x, colours[word] if word | |
end | |
end | |
EXPLORE_MODE and begin | |
text index_word(row), 50, 100, index_colour(row) | |
text index_word(col), 50, 60, index_colour(col) | |
end | |
end | |
drawing.run | |
__END__ | |
BAA_BAA_BLACK_SHEEP | |
Baa, baa, black sheep, | |
Have you any wool? | |
Yes sir, yes sir, | |
Three bags full; | |
One for the master, | |
And one for the dame, | |
And one for the little boy | |
Who lives down the lane. | |
CALL_ME_MAYBE | |
I threw a wish in the well, | |
Don't ask me, I'll never tell | |
I looked to you as it fell, | |
And now you're in my way | |
I'd trade my soul for a wish, | |
Pennies and dimes for a kiss | |
I wasn't looking for this, | |
But now you're in my way | |
Your stare was holdin', | |
Ripped jeans, skin was showin' | |
Hot night, wind was blowin' | |
Where you think you're going, baby? | |
Hey, I just met you, | |
And this is crazy, | |
But here's my number, | |
So call me, maybe! | |
It's hard to look right | |
At you baby, | |
But here's my number, | |
So call me, maybe! | |
Hey, I just met you, | |
And this is crazy, | |
But here's my number, | |
So call me, maybe! | |
And all the other boys, | |
Try to chase me, | |
But here's my number, | |
So call me, maybe! | |
You took your time with the call, | |
I took no time with the fall | |
You gave me nothing at all, | |
But still, you're in my way | |
I beg, and borrow and steal | |
At first sight and it's real | |
I didn't know I would feel it, | |
But it's in my way | |
Your stare was holdin', | |
Ripped jeans, skin was showin' | |
Hot night, wind was blowin' | |
Where you think you're going, baby? | |
Hey, I just met you, | |
And this is crazy, | |
But here's my number, | |
So call me, maybe! | |
It's hard to look right | |
At you baby, | |
But here's my number, | |
So call me, maybe! | |
Hey, I just met you, | |
And this is crazy, | |
But here's my number, | |
So call me, maybe! | |
And all the other boys, | |
Try to chase me, | |
But here's my number, | |
So call me, maybe! | |
Before you came into my life | |
I missed you so bad | |
I missed you so bad | |
I missed you so, so bad | |
Before you came into my life | |
I missed you so bad | |
And you should know that | |
I missed you so, so bad (bad, bad) | |
It's hard to look right | |
At you baby, | |
But here's my number, | |
So call me, maybe! | |
Hey, I just met you, | |
And this is crazy, | |
But here's my number, | |
So call me, maybe! | |
And all the other boys, | |
Try to chase me, | |
But here's my number, | |
So call me, maybe! | |
Before you came into my life | |
I missed you so bad | |
I missed you so bad | |
I missed you so, so bad | |
Before you came into my life | |
I missed you so bad | |
And you should know that | |
So call me, maybe! | |
RUMOUR_HAS_IT | |
She, she ain't real | |
She ain't gonna be able to love you like I will | |
She is a stranger | |
You and I have history | |
Or don't you remember | |
Sure, she's got it all | |
But, baby, is that really what you want | |
Bless your soul, you've got your head in the clouds | |
You made a fool out of you | |
And, boy, she's bringing you down | |
She made your heart melt | |
But you're cold to the core | |
Now rumor has it she ain't got your love anymore | |
Rumor has it, ooh | |
Rumor has it, ooh | |
Rumor has it, ooh | |
Rumor has it, ooh | |
Rumor has it, ooh | |
Rumor has it, ooh | |
Rumor has it, ooh | |
Rumor has it, ooh | |
She is half your age | |
But I'm guessing that's the reason that you stayed | |
I heard you've been missing me | |
You've been telling people things that you shouldn't be | |
Like when we creep out and she ain't around | |
Haven't you heard the rumors | |
Bless your soul, you've got your head in the clouds | |
You made a fool out of me | |
And, boy, you're bringing me down | |
You made my heart melt, yet I'm cold to the core | |
But rumor has it I'm the one you're leaving her for | |
Rumor has it, ooh | |
Rumor has it, ooh | |
Rumor has it, ooh | |
Rumor has it, ooh | |
Rumor has it, ooh | |
Rumor has it, ooh | |
Rumor has it, ooh | |
Rumor has it, ooh | |
All of these words whispered in my ear | |
Tell a story that I cannot bear to hear | |
Just 'cause I said it, it don't mean that I meant it | |
People say crazy things | |
Just 'cause I said it, don't mean that I meant it | |
Just 'cause you heard it | |
Rumor has it, ooh, | |
Rumor has it, ooh, | |
Rumor has it, ooh, | |
Rumor has it, ooh, | |
Rumor has it, ooh, | |
Rumor has it, ooh, | |
Rumor has it, ooh, | |
Rumor has it, ooh, | |
Rumor has it, ooh, | |
Rumor has it, ooh, | |
Rumor has it, ooh, | |
Rumor has it, ooh, | |
Rumor has it, ooh, | |
Rumor has it, ooh | |
But rumor has it he's the one I'm leaving you for | |
LEAN_ON | |
Do you recall, not long ago | |
We would walk on the sidewalk | |
Innocent, remember? | |
All we did was care for each other | |
But the night was warm | |
We were bold and young | |
All around the wind blows | |
We would only hold on to let go | |
Blow a kiss, fire a gun | |
We need someone to lean on | |
Blow a kiss, fire a gun | |
All we need is somebody to lean on | |
Blow a kiss, fire a gun | |
We need someone to lean on | |
Blow a kiss, fire a gun | |
All we need is somebody to lean on | |
What will we do when we get old? | |
Will we walk down the same road? | |
Will you be there by my side? | |
Standing strong as the waves roll over | |
When the nights are long | |
Longing for you to come home | |
All around the wind blows | |
We would only hold on to let go | |
Blow a kiss, fire a gun | |
We need someone to lean on | |
Blow a kiss, fire a gun | |
All we need is somebody to lean on | |
Blow a kiss, fire a gun | |
We need someone to lean on | |
Blow a kiss, fire a gun | |
All we need is somebody to lean on | |
All we need is somebody to lean on | |
All we need is somebody to lean on | |
Blow a kiss, fire a gun | |
We need someone to lean on | |
Blow a kiss, fire a gun | |
All we need is somebody to lean on | |
Blow a kiss, fire a gun | |
We need someone to lean on | |
Blow a kiss, fire a gun | |
All we need is somebody to lean on | |
212 | |
Hey, I can be the answer | |
I'm ready to dance when the vamp up | |
And when I hit that dip get your camera | |
You can see I been that bitch since the pamper | |
And that I am that young sis the beacon | |
The bitch who wants to compete and | |
I can freak a fit that pump with the peep and | |
You know what your bitch become when her weave in | |
I just wanna sip that punch with your peeps and | |
Sit in that lunch if you're treatin' | |
Kick it with the bitch who comes from Parisian | |
She know where I get mine from and the season | |
Now she wanna lick my plum in the evenin' | |
And fit that tongue tongue d-deep in | |
I guess that cunt gettin' eaten | |
I guess that cunt gettin' eaten | |
I guess that cunt gettin' eaten | |
I guess that cunt gettin' eaten | |
I guess that cunt gettin'... | |
I was in the 212 | |
On the uptown A | |
Nigga you know what's up | |
Or don't you? | |
Word to who made ya | |
I'm a rude bitch nigga | |
What are you made up of? | |
I'm a eat your food up boo | |
I could bust your 8 | |
I'm a do one too | |
Fuck you gone do? | |
I want you to make bucks | |
I'm a look right nigga | |
Bet you do want to fuck | |
Fuck em like you do want to cum | |
Your gay to get discovered in my 2 1 deuce | |
Cock-a-lickin' in the water by the blue bayou | |
Caught the warm goo | |
In your doo-rag too son? | |
Nigga you're a kool-aid dude | |
Plus your bitch might lick it | |
Wonder who let you come to 1 2 | |
With your doo-doo crew son | |
Fuck, are you into, huh? | |
Niggas better ohh run-run | |
You could get shot homie | |
If you do want to put your guns up | |
Tell your crew don't front | |
I'm a hoodlum nigga | |
You know you were too once | |
Bitch I'm 'bout to blew up too | |
I'm the one today | |
I'm the new shit boo | |
Young Rapunzel | |
Who are you bitch, new lunch? | |
I'm a ruin you cunt | |
I'm a ruin you cunt | |
I'm a ruin you cunt | |
I'm a ruin you cunt | |
A-yo, A-yo, | |
I heard you ridin' with the same tall, tall tale | |
Tellin' em you made some | |
Sayin' you runnin' but you ain't goin' no where | |
Why you procrastinate girl? | |
You got a lot but you just waste all yourself | |
They'll forget your name soon | |
And won't nobody be to blame but yourself, yeah | |
What you gone do when I appear? | |
W-when I premier? | |
Bitch the end of your life are near | |
This shit been mine, mine | |
What you gone do when I appear? | |
W-when I premier? | |
Bitch the end of your life are near | |
This shit been mine, mine | |
Bitch I'm in the 212 | |
With the 5th cocked nigga | |
It's the 2 1 zoo | |
Fuck you gone do | |
When your goons sprayed up | |
Bet his bitch won't get em | |
Betcha you won't do much | |
See even if you do want to bust | |
Your bitch'll get you cut and touch your crew up too | |
Pop you playin' with your butter | |
Like your boo won't chew | |
Cock the gun too | |
Where you do eat poon hun | |
I'm fuckin' with your cutie-q | |
What's your dick like homie? | |
What are you into? | |
What's the run dude? | |
Where do you wake up? | |
Tell your bitch keep hatin' | |
I'm a new one too, huh? | |
See I remember you when you were | |
The young new face but you do like to | |
Slumber don't you? | |
Now your boo up too hun | |
I'm a ruin you cunt | |
What you gone do when I appear? | |
W-when I premier? | |
Bitch the end of your lives are near | |
This shit been mine, mine | |
What you gone do when I appear? | |
W-when I premier? | |
Bitch the end of your lives are near | |
This shit been mine, mine | |
This shit been mine, mine | |
This shit been mine, mine | |
AINT_NO_SUNSHINE | |
Ain't no sunshine when she's gone | |
It's not warm when she's away | |
Ain't no sunshine when she's gone | |
And she's always gone too long | |
Anytime she goes away | |
Wonder this time where she's gone | |
Wonder if she's gone to stay | |
Ain't no sunshine when she's gone | |
And this house just ain't no home | |
Anytime she goes away | |
And I know, I know, I know, I know, | |
I know, I know, I know, I know, I know | |
I know, I know, I know, I know, I know | |
I know, I know, I know, I know, I know | |
I know, I know, I know, I know, I know | |
I know, I know, | |
Hey, I oughtta leave young thing alone | |
But ain't no sunshine when she's gone | |
Ain't no sunshine when she's gone | |
Only darkness every day | |
Ain't no sunshine when she's gone | |
And this house just ain't no home | |
Anytime she goes away | |
Anytime she goes away | |
Anytime she goes away | |
Anytime she goes away | |
BEAST_OF_BURDEN | |
I'll never be your beast of burden | |
My back is broad but it's a hurting | |
All I want is for you to make love to me | |
I'll never be your beast of burden | |
I've walked for miles my feet are hurting | |
All I want is for you to make love to me | |
Am I hard enough | |
Am I rough enough | |
Am I rich enough | |
I'm not too blind to see | |
I'll never be your beast of burden | |
So let's go home and draw the curtains | |
Music on the radio | |
Come on baby make sweet love to me | |
Am I hard enough | |
Am I rough enough | |
Am I rich enough | |
I'm not too blind to see | |
Oh little sister | |
Pretty, pretty, pretty, pretty, girl | |
Pretty, pretty | |
Such a pretty, pretty, pretty girl | |
Come on baby please, please, please | |
I'll tell you you can put me out on the street | |
Put me out with no shoes on my feet | |
But, put me out, put me out | |
Put me out of misery | |
Yeah, all your sickness I can suck it up | |
Throw it all at me I can shrug it off | |
There's one thing baby that I don't understand | |
You keep on telling me I ain't your kind of man | |
Ain't I rough enough, oh honey | |
Ain't I tough enough | |
Ain't I rich enough in love enough | |
Oh please | |
I'll never be your beast of burden | |
I'll never be your beast of burden | |
Never, never, never, never, never, never, never be | |
I'll never be your beast of burden | |
I've walked for miles my feet are hurting | |
All I want is for you to make love to me | |
I'll never be your beast of burden | |
I'll never be your beast of burden | |
Never, never, never, never, never, never, never be | |
TEST | |
a b c | |
1 2 3 | |
a b c | |
4 a 6 | |
a b c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment