-
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.
- Loading branch information
1 parent
8480090
commit 4c668d8
Showing
6 changed files
with
210 additions
and
14 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 |
---|---|---|
|
@@ -2,6 +2,10 @@ | |
|
||
<head> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/p5.js"></script> | ||
<!-- <script src="sketch versions/v1.js"></script> --> | ||
<!-- <script src="sketch versions/v2.js"></script> --> | ||
<!-- <script src="sketch versions/v3.js"></script> --> | ||
<!-- <script src="sketch versions/v4.js"></script> --> | ||
<script src="sketch.js"></script> | ||
<link rel="stylesheet" type="text/css" href="style.css"> | ||
<meta charset="utf-8" /> | ||
|
33 changes: 33 additions & 0 deletions
33
semesterproject/noisealgorithms/snowflakes/sketch versions/v1.js
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,33 @@ | ||
/** Setup function is called by p5 once */ | ||
function setup() { | ||
// Create a canvas that fills the browser window | ||
createCanvas(windowWidth, windowHeight); | ||
// Set black as the background color | ||
background(0); | ||
// Move the origin to the center of the canvas | ||
translate(width / 2, height / 2); | ||
// Set the stroke color to white | ||
stroke(255); | ||
// Set the stroke weight to 2 pixels | ||
strokeWeight(2); | ||
|
||
drawSnowflakeArm(); | ||
} | ||
|
||
/** Draws a single snowflake arm */ | ||
function drawSnowflakeArm() { | ||
// Divide the arm into 10 sections | ||
const sections = 1; | ||
// Set the armlength to 100 pixels | ||
const armLength = 100; | ||
|
||
beginShape(); | ||
for (let sectionIndex = 0; sectionIndex <= sections; sectionIndex++) { | ||
// Calculate the x and y coordinates of the current arm section | ||
let x = armLength * sectionIndex; | ||
let y = armLength * sectionIndex; | ||
// Draw a vertex at the x and y coordinates | ||
vertex(x, y); | ||
} | ||
endShape(); | ||
} |
41 changes: 41 additions & 0 deletions
41
semesterproject/noisealgorithms/snowflakes/sketch versions/v2.js
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,41 @@ | ||
/** Setup function is called by p5 once */ | ||
function setup() { | ||
// Create a canvas that fills the browser window | ||
createCanvas(windowWidth, windowHeight); | ||
// Set black as the background color | ||
background(0); | ||
// Move the origin to the center of the canvas | ||
translate(width / 2, height / 2); | ||
// Set the stroke color to white | ||
stroke(255); | ||
// Set the stroke weight to 2 pixels | ||
strokeWeight(2); | ||
|
||
// Draw six arms of the snowflake | ||
const arms = 6; | ||
|
||
for (let armIndex = 0; armIndex < arms; armIndex++) { | ||
push(); | ||
rotate(TWO_PI / arms * armIndex); | ||
drawSnowflakeArm(); | ||
pop(); | ||
} | ||
} | ||
|
||
/** Draws a single snowflake arm */ | ||
function drawSnowflakeArm() { | ||
// Divide the arm into 10 sections | ||
const sections = 1; | ||
// Set the armlength to 100 pixels | ||
const armLength = 100; | ||
|
||
beginShape(); | ||
for (let sectionIndex = 0; sectionIndex <= sections; sectionIndex++) { | ||
// Calculate the x and y coordinates of the current arm section | ||
let x = armLength * sectionIndex; | ||
let y = armLength * sectionIndex; | ||
// Draw a vertex at the x and y coordinates | ||
vertex(x, y); | ||
} | ||
endShape(); | ||
} |
45 changes: 45 additions & 0 deletions
45
semesterproject/noisealgorithms/snowflakes/sketch versions/v3.js
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,45 @@ | ||
/** Setup function is called by p5 once */ | ||
function setup() { | ||
// Create a canvas that fills the browser window | ||
createCanvas(windowWidth, windowHeight); | ||
// Set black as the background color | ||
background(0); | ||
// Move the origin to the center of the canvas | ||
translate(width / 2, height / 2); | ||
// Set the stroke color to white | ||
stroke(255); | ||
// Set the stroke weight to 2 pixels | ||
strokeWeight(2); | ||
|
||
// Draw six arms of the snowflake | ||
const arms = 6; | ||
|
||
for (let armIndex = 0; armIndex < arms; armIndex++) { | ||
push(); | ||
rotate(TWO_PI / arms * armIndex); | ||
drawSnowflakeArm(); | ||
pop(); | ||
} | ||
} | ||
|
||
/** Draws a single snowflake arm */ | ||
function drawSnowflakeArm() { | ||
// Divide the arm into 10 sections | ||
const sections = 10; | ||
// Set the armlength to 100 pixels | ||
const armLength = 100; | ||
|
||
beginShape(); | ||
for (let sectionIndex = 0; sectionIndex <= sections; sectionIndex++) { | ||
// Calculate the length of the current arm section | ||
let armSectionLength = armLength / sections * sectionIndex; | ||
// Calculate the angle of the current arm section | ||
let angle = map(noise(sectionIndex * 0.2, frameCount * 0.01), 0, 1, -PI / 6, PI / 6); | ||
// Calculate the x and y coordinates of the current arm section | ||
let x = armSectionLength * cos(angle); | ||
let y = armSectionLength * sin(angle); | ||
// Draw a vertex at the x and y coordinates | ||
vertex(x, y); | ||
} | ||
endShape(); | ||
} |
54 changes: 54 additions & 0 deletions
54
semesterproject/noisealgorithms/snowflakes/sketch versions/v4.js
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,54 @@ | ||
/** Setup function is called by p5 once */ | ||
function setup() { | ||
// Create a canvas that fills the browser window | ||
createCanvas(windowWidth, windowHeight); | ||
// Set black as the background color | ||
background(0); | ||
// Move the origin to the center of the canvas | ||
translate(width / 2, height / 2); | ||
// Set the stroke color to white | ||
stroke(255); | ||
// Set the stroke weight to 2 pixels | ||
strokeWeight(2); | ||
|
||
// Draw six arms of the snowflake | ||
const arms = 6; | ||
|
||
for (let armIndex = 0; armIndex < arms; armIndex++) { | ||
// Draw the right part of an arm | ||
push(); | ||
rotate(TWO_PI / arms * armIndex); | ||
drawSnowflakeArm(); | ||
pop(); | ||
|
||
// Draw the left part of an arm | ||
push(); | ||
rotate(TWO_PI / arms * armIndex + PI / arms); | ||
// Flip the arm horizontally | ||
scale(-1, 1); | ||
drawSnowflakeArm(); | ||
pop(); | ||
} | ||
} | ||
|
||
/** Draws a single snowflake arm */ | ||
function drawSnowflakeArm() { | ||
// Divide the arm into 10 sections | ||
const sections = 10; | ||
// Set the armlength to 100 pixels | ||
const armLength = 100; | ||
|
||
beginShape(); | ||
for (let sectionIndex = 0; sectionIndex <= sections; sectionIndex++) { | ||
// Calculate the length of the current arm section | ||
let armSectionLength = armLength / sections * sectionIndex; | ||
// Calculate the angle of the current arm section | ||
let angle = map(noise(sectionIndex * 0.2, frameCount * 0.01), 0, 1, -PI / 6, PI / 6); | ||
// Calculate the x and y coordinates of the current arm section | ||
let x = armSectionLength * cos(angle); | ||
let y = armSectionLength * sin(angle); | ||
// Draw a vertex at the x and y coordinates | ||
vertex(x, y); | ||
} | ||
endShape(); | ||
} |
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