Skip to content

Commit

Permalink
added generative art to music player
Browse files Browse the repository at this point in the history
  • Loading branch information
idossha committed Apr 25, 2024
1 parent 4416048 commit 4d19f73
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 38 deletions.
62 changes: 62 additions & 0 deletions 00_functionality/sketch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
let used_points = [];
let border = 75;
let width, height;

function setup() {
width = windowWidth;
height = windowHeight;
createCanvas(width, height);
background(250);
stroke(0);
strokeWeight(1);

// Increase the border size by 5% of the smaller dimension of the canvas
let borderIncrease = min(width, height) * 0.05;
border += borderIncrease; // Increase the existing border

// Define initial corner points with updated border
let init_points = [
[border, border],
[width - border, border],
[width - border, height - border],
[border, height - border]
];

// Store initial points in used_points to extend lines from
used_points = [...init_points];

// Define initial directions for line growth
let directions = [[1, 1], [-1, 1], [-1, -1], [1, -1]];

for (let i = 0; i < init_points.length; i++) {
let point = init_points[i];
extendLine(point, directions[i]);
}
}


function draw() {
// Keep extending lines from random points
let index = floor(random(used_points.length));
let dirIndex = floor(random(4));
let direction = [[1, 1], [-1, 1], [-1, -1], [1, -1]][dirIndex];
extendLine(used_points[index], direction);
}

function extendLine(startPoint, direction) {
let step = 10; // Distance each line extends per frame
let endX = startPoint[0] + step * direction[0];
let endY = startPoint[1] + step * direction[1];

// Check if new point is within the border
if (endX > border && endX < width - border && endY > border && endY < height - border) {
line(startPoint[0], startPoint[1], endX, endY);
used_points.push([endX, endY]); // Add new point to array
}
}

function windowResized() {
resizeCanvas(windowWidth, windowHeight);
// Re-run setup to reset the drawing when the window is resized
setup();
}
67 changes: 47 additions & 20 deletions 00_styling/music_player.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,41 @@
box-sizing: border-box;
}

body {
font-family: "Poppins", sans-serif;
height: 100vh;
margin: 0;
background-image: linear-gradient(0deg,black,white);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;

body, html {
font-family: "Poppins", sans-serif;
height: 100%;
margin: 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
overflow: hidden; /* Prevents scrollbars if the canvas is larger than the window */
}


/* Additional styles for the canvas created by p5.js */
canvas {
display: block; /* Removes any margin/padding around the canvas */
position: fixed; /* So it doesn't scroll with the content */
top: 0;
left: 0;
z-index: -1; /* Ensures it's behind all other content */
}



.music-container {
background-color: white;
border-radius: 15px;
display: flex;
padding: 20px 30px;
position: relative;
margin: 100px 0;
z-index: 10;
}


/* ICONS */

.icon {
Expand All @@ -31,22 +53,27 @@ body {


/* FOOTER SECTION */

footer {
height: 26vh;
margin: 0;
}

footer p {
text-align: center;
}
height: auto; /* Adjusted from 1vh to auto to contain the content */
position: absolute; /* Position it at the bottom */
bottom: 0; /* Align to the bottom of the page */
width: 100%; /* Make it full width */
justify-content: center; /* Center horizontally */
align-items: center; /* Center vertically */
padding: 1rem; /* Add some padding */
}

footer p {
text-align: center;
width: 100%; /* Ensure the text is full width */
margin-top: 1rem; /* Add some space above the text */
}

/* SPECIFIC STYLING FOR THIS PAGE */

.music-container {
background-color: white;
border-radius: 15px;
box-shadow: 0 20px 20px 0;
display: flex;
padding: 20px 30px;
position: relative;
Expand Down Expand Up @@ -128,7 +155,6 @@ footer {
}

.music-info {
background-color: rgba(255,255,255,0.5);
border-radius: 15px 15px 0 0;
position: absolute;
top: 0;
Expand All @@ -137,7 +163,8 @@ footer {
opacity: 0;
transform: translateY(0%);
padding: 10px 10px 10px 150px;
transition: transform 0.3s ease-in, opacity 0.3s ease-in;
transition: transform 0.2s ease-in, opacity 0.2s ease-in;
background-color: #906666; /* Removed transparency for solid color */

}

Expand Down
25 changes: 7 additions & 18 deletions Pages/music_player.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,24 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Music Player</title>
<link rel="stylesheet" href="../00_styling/music_player.css">
<link rel="stylesheet" href="../00_mediaqueries.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha512-DTOQO9RWCH3ppGqcWaEA1BIZOC6xxalwEsw9c2QQeAIftl+Vegovlnee1c9QX4TctnWMn13TZye+giMm8e2LwA==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
</head>


</html>
<body>
<a href="../index.html" class="home-button">
<a href="#" class="home-button">
<i class="fas fa-home"></i>
</a>
</a>
<h1>My sets</h1>
<div class="music-container">
<div class="music-info">
<h4 id="title"></h4>
<div class="progress-container">
<div class="progress"></div>
</div>
</div>

</div>
<audio src="" id="audio"></audio>


<div class="img-container">
<img src="" alt="music-cover" id="cover">

</div>

<div class="navigation">
<button id="prev" class="action-btn">
<i class="fas fa-backward"></i>
Expand All @@ -43,15 +34,13 @@ <h4 id="title"></h4>
<i class="fas fa-forward"></i>
</button>
</div>

</div>


<footer>
<p>Copyright &#169; 2024 Ido Haber. </p>
<p>Disclaimer, I do not own the rights for the individual music tracks
but for the mix itself. </p>
<p>Disclaimer, I do not own the rights for the individual music tracks but for the mix itself. </p>
</footer>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.0/p5.js"></script>
<script src="../00_functionality/music_player.js"></script>
<script src="../00_functionality/sketch.js"></script>
</body>
</html>

0 comments on commit 4d19f73

Please sign in to comment.