Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature P5.js #212

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
<link href="https://cdn.jsdelivr.net/npm/[email protected]/fonts/remixicon.css" rel="stylesheet" />
<link rel="stylesheet" href="css/button.css" />
<link rel="stylesheet" href="css/navbar.css" />
<link rel="stylesheet" href="css/canvas.css" />
<script src="https://unpkg.com/[email protected]/dist/typed.umd.js"></script>
<script src="js/script.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.0/p5.js"></script>
<script src="js/sketch.js"></script>
<!-- <link rel="stylesheet" href="button.css" /> -->
</head>

Expand Down Expand Up @@ -49,6 +52,9 @@
</div>
</nav>

<!-- Canvas -->
<canvas id="myCanvas"></canvas>

<!--Home -->
<div id="home" class="home">
<div class="container">
Expand Down
33 changes: 33 additions & 0 deletions js/sketch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
let angle;

function setup() {
let canvas = createCanvas(350, 350);
canvas.position(59, 50);
angle = Math.PI / 4;
}

function draw() {
background(255);
angle = map(Math.sin(frameCount * 0.01), -1, 1, Math.PI / 2, Math.PI / 16);
translate(width / 2, height);
branch(100);
}

function map(value, start1, stop1, start2, stop2) {
return start2 + (stop2 - start2) * ((value - start1) / (stop1 - start1));
}

function branch(len) {
line(0, 0, 0, -len);
translate(0, -len);
if (len > 4) {
push();
rotate(angle);
branch(len * 0.67);
pop();
push();
rotate(-angle);
branch(len * 0.67);
pop();
}
}