-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from Demonstrandum/devel
Devel
- Loading branch information
Showing
4 changed files
with
72 additions
and
34 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
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 |
---|---|---|
@@ -1,39 +1,33 @@ | ||
import * as BC from '../lib/BasicCanvas.js'; | ||
import {line} from '../lib/BasicShapes.js'; | ||
|
||
const sketch = BC.canvas_id('sketch'); | ||
use(BC); | ||
|
||
const sketch = canvas_id('sketch'); | ||
sketch.dimensions(400, 400); | ||
sketch.translate(sketch.width / 2, sketch.height / 2); | ||
|
||
sketch.fill = BC.RGB(50, 30, 80); | ||
sketch.stroke = BC.HSL(340, 100, 45, 170); | ||
sketch.fill = RGB(50, 30, 80); | ||
sketch.stroke = HSL(340, 100, 45, 170); | ||
sketch.stroke_weight = 4; | ||
sketch.stroke_cap = 'round'; | ||
|
||
const vector = (origin, length, angle) => { | ||
const final = BC.Point( | ||
length * Math.cos(-angle) + origin.x, | ||
length * Math.sin(-angle) + origin.y | ||
); | ||
sketch.shape(null, shape => { | ||
shape.vertex(origin); | ||
shape.vertex(final); | ||
}); | ||
return final; | ||
}; | ||
const branch = (previous, angle, depth, inc, first = true) => { | ||
if (depth < 0) return; | ||
|
||
const branch = (previus, angle, depth, inc) => { | ||
if (depth < 0) { | ||
return; | ||
let next = previous; | ||
if (!first) { | ||
next = Polar(Math.sqrt(depth) * 16, -angle, previous); | ||
sketch.render(line(next, previous)); | ||
} | ||
|
||
const next = vector(previus, (depth) ** (1 / 2) * 16, angle); | ||
|
||
branch(next, angle + inc, depth - 1, inc); | ||
branch(next, angle - inc, depth - 1, inc); | ||
branch(next, angle + inc, depth - 1, inc, false); | ||
branch(next, angle - inc, depth - 1, inc, false); | ||
}; | ||
|
||
const tree = P(0, 10); | ||
sketch.loop(frame => { | ||
sketch.background(); | ||
vector(BC.Point(0, 200), 130, Math.PI / 2); | ||
branch(BC.Point(0, 70), Math.PI / 2, 7, 0.6 + Math.sin(frame / 10) / 3); | ||
sketch.render(line(P(0, 200), tree)); | ||
branch(tree, Math.PI / 2, 7, 0.6 + Math.sin(frame / 20) / 3); | ||
}); |
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
b0e18d3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully aliased the URL https://basiccanvas-ilnhtrb0i.now.sh to the following aliases.