Add Fractal tree initial commit
This commit is contained in:
@ -0,0 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>graphicsProgramming - Coursera</title>
|
||||
<script src="libraries/p5.min.js" type="text/javascript"></script>
|
||||
<script src="libraries/p5.sound.min.js" type="text/javascript"></script>
|
||||
|
||||
<script src="sketch.js" type="text/javascript"></script>
|
||||
|
||||
<style> body {padding: 0; margin: 0;} canvas {vertical-align: top;} </style>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
3
CM2030 Graphics Programming/Topic 9/9.1.6 Fractal tree/libraries/p5.min.js
vendored
Normal file
3
CM2030 Graphics Programming/Topic 9/9.1.6 Fractal tree/libraries/p5.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
28
CM2030 Graphics Programming/Topic 9/9.1.6 Fractal tree/libraries/p5.sound.min.js
vendored
Normal file
28
CM2030 Graphics Programming/Topic 9/9.1.6 Fractal tree/libraries/p5.sound.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@ -0,0 +1,37 @@
|
||||
// Code from a modified Daniel Shiffman example
|
||||
// https://thecodingtrain.com/
|
||||
|
||||
var angle = 0;
|
||||
var seed;
|
||||
|
||||
function setup() {
|
||||
createCanvas(400, 400);
|
||||
seed = random(1000);
|
||||
}
|
||||
////////////////////////////////////////////////
|
||||
function draw() {
|
||||
background(225);
|
||||
angleMode(DEGREES);
|
||||
randomSeed(seed);
|
||||
angle = 45;
|
||||
stroke(255);
|
||||
translate(200, height);
|
||||
branch(100, 3);
|
||||
}
|
||||
/////////////////////////////////////////////////
|
||||
function branch(len, thickness) {
|
||||
stroke(0);
|
||||
strokeWeight(thickness);
|
||||
line(0, 0, 0, -len);
|
||||
translate(0, -len);
|
||||
if (len > 4) {
|
||||
push();
|
||||
rotate(angle);
|
||||
branch(len * 0.67, thickness*0.8);
|
||||
pop();
|
||||
push();
|
||||
rotate(-angle);
|
||||
branch(len * 0.67, thickness*0.8);
|
||||
pop();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user