-
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.
Summary: I wanted to make a snake game, or the classic "read pixels from input and turn them into ASCII chars", but ended up making a tripping version of matrix.
- Loading branch information
Showing
3 changed files
with
53 additions
and
0 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,12 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<link rel="stylesheet" href="../reset.css" type="text/css" /> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<script src="../p5.min.js"></script> | ||
<script src="./index.js"></script> | ||
<title>Genuary 2024 - Day 9</title> | ||
</head> | ||
<body></body> | ||
</html> |
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,40 @@ | ||
const CHARS = | ||
" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; | ||
const TEXT_SIZE = 15; | ||
const PERIOD = 0.0000005; | ||
let hasClicked = false; | ||
|
||
function setup() { | ||
colorMode(HSB); | ||
textAlign(CENTER); | ||
|
||
const canvas = createCanvas(innerWidth, innerHeight); | ||
canvas.mouseClicked(() => (hasClicked = !hasClicked)); | ||
|
||
fill("white"); | ||
textSize(TEXT_SIZE); | ||
} | ||
|
||
function draw() { | ||
background(0, 0, 0); | ||
for (let row = 0; row < innerWidth; row += TEXT_SIZE) { | ||
for (let col = 0; col < innerHeight; col += TEXT_SIZE) { | ||
if (hasClicked) { | ||
stroke(360 * tan(frameCount * col * row * PERIOD), 100, 100); | ||
} else { | ||
stroke("white"); | ||
} | ||
text(pickChar(sin(frameCount * col * row * PERIOD)), row, col); | ||
} | ||
} | ||
} | ||
|
||
function windowResized() { | ||
resizeCanvas(innerWidth, innerHeight); | ||
} | ||
|
||
function pickChar(continuousValue) { | ||
continuousValue = Math.max(-1, Math.min(1, continuousValue)); | ||
|
||
return CHARS.charAt(Math.floor((continuousValue + 1) * CHARS.length) / 2); | ||
} |
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