Skip to content

Commit

Permalink
new sketch
Browse files Browse the repository at this point in the history
  • Loading branch information
hspencer committed Jul 10, 2022
1 parent 9d70462 commit 36d853c
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 0 deletions.
Binary file added 001-noise-field/.DS_Store
Binary file not shown.
11 changes: 11 additions & 0 deletions 023-differential-growth/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html><html><head>
<script src="../js/p5.js"></script>
<link rel="stylesheet" type="text/css" href="style.css">
<meta charset="utf-8">
<title>crecimiento differencial</title>
</head>
<body>
<script src="sketch.js"></script>


</body></html>
62 changes: 62 additions & 0 deletions 023-differential-growth/sketch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
////////////////////////////////////////////////////////
// Reference: https://inconvergent.net/generative/
// https://openprocessing.org/sketch/871349
////////////////////////////////////////////////////////

let nodes = []
const r = 7

setup = () => {
createCanvas(windowWidth, windowHeight)
fill('lightgrey')
noStroke()
nodes.length = 0
for (let i = 3; i--;) {
const r = random(TWO_PI)
nodes[i] = createVector(cos(r) * 20 + width / 2, sin(r) * 5 + height / 2)
}
}

draw = () => {
background('white')
splits()
reject()
beginShape()
for (const p of nodes) curveVertex(p.x, p.y)
endShape(CLOSE)
}

reject = () => {
for (const p of nodes) {
force = createVector(0)
for (const q of nodes) {
if (p === q) continue;
const d = distance(p, q)
if (d < 2 * r) {
delta = p5.Vector.sub(p, q)
force.add(delta.mult((2 * r - d) * .025))
}
}
p.add(force.limit(1))
p.x = constrain(p.x, 0, width)
p.y = constrain(p.y, 0, height)
}
}

distance = (u, v) => sqrt((u.x - v.x) ** 2 + (u.y - v.y) ** 2)

splits = () => {
let next = []
for (let i = 0; i < nodes.length; i++) {
current = nodes[i]
next.push(current)
neighbor = nodes[(i + 1) % nodes.length]
const d = distance(current, neighbor)
if (d > 2 * r && nodes.length < 1000) {
next.push(p5.Vector.add(current, neighbor).mult(1 / 2))
}
}
nodes = next
}

mouseClicked = () => setup()
8 changes: 8 additions & 0 deletions 023-differential-growth/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
html, body {
margin: 0;
padding: 0;
}
canvas {
display: block;
margin: 0 auto;
}
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ <h2>Expo Casiopea</h2>
<li><a href="020-amereida-fourier/">amereida fourier</a></li>
<li><a href="021-dft-xy">dft xt</a></li>
<li><a href="022-dft-circle/">dft circle</a></li>
<li><a href="023-differential-growth/">crecimiento diferencial 2</a></li>
</ol>
</body>
</html>

0 comments on commit 36d853c

Please sign in to comment.