-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added generative art to music player
- Loading branch information
Showing
3 changed files
with
116 additions
and
38 deletions.
There are no files selected for viewing
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
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(); | ||
} |
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
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