Skip to content

Commit c5df4af

Browse files
author
Ayush Seth
committed
Added save tree
Added option to save the canvas as a png file!
1 parent c188e4f commit c5df4af

File tree

3 files changed

+35
-14
lines changed

3 files changed

+35
-14
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.bat

Fraternal Tree.js

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function setup() {
99
var root = new Branch(createVector(width / 2, height), createVector(width / 2, height - 100));
1010
tree[0] = root;
1111
shake = createCheckbox("Shaking", false);
12-
shake.position(100, 330);
12+
shake.position(windowWidth-470, 1000);
1313

1414
intensity = createSlider(0.1, 2, 0.5, 0);
1515
intensity.parent("shake");
@@ -20,28 +20,34 @@ function setup() {
2020
shrink = createSlider(0.30, 1, 0.75, 0);
2121
shrink.parent("shrink");
2222

23-
var sheds = createButton("SHED LEAVES");
24-
sheds.position(100, 400);
23+
var sheds = createButton("Shed Leaves");
24+
sheds.position(320, 1000);
2525
sheds.mousePressed(shedFlowers);
2626

27-
var grows = createButton("GROW LEAVES")
28-
grows.position(100, 370);
27+
var grows = createButton("Grow leaves")
28+
grows.position(320, 970);
2929
grows.mousePressed(growFlowers);
3030

31+
var save = createButton("Save Tree as png")
32+
save.position(windowWidth-470, 1100);
33+
save.mousePressed(saveTree);
34+
3135
gravity = createVector(0, 0.3);
3236
grav = createCheckbox("Gravity ON/OFF", true);
33-
grav.position(100, 430);
37+
grav.position(windowWidth-470, 970);
3438

3539
windcheck = createCheckbox("Wind ON/OFF", false);
36-
windcheck.position(100, 460);
40+
windcheck.position(windowWidth-470, 1030);
3741

3842
wind_dir = createRadio();
39-
wind_dir.position(250, 460);
43+
wind_dir.position(windowWidth-470, 1060);
4044
wind_dir.option("Left");
4145
wind_dir.option("Right");
4246
wind_dir.value("Right");
4347

44-
48+
document.getElementById('cpicker').style.position = "absolute";
49+
document.getElementById('cpicker').style.left = "320px";
50+
document.getElementById('cpicker').style.top = "920px";
4551
}
4652
var wind;
4753

@@ -97,6 +103,10 @@ function growFlowers() {
97103
}
98104
shed = false;
99105
}
106+
function saveTree() {
107+
saveCanvas("tree", "png");
108+
109+
}
100110

101111

102112
function mousePressed() {

index.html

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
<link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
2020
<style>
2121
h1,
22-
h2 {
22+
h2,
23+
h3 {
2324
font-family: 'Exo 2', sans-serif;
2425
}
2526

@@ -56,20 +57,29 @@ <h2>General Instructions</h2>
5657
New branch size(Relative to parent branch)
5758
</div>
5859

59-
<p>Select leaf color :
60+
<p id="cpicker">Select leaf color :
6061
<button id="colour" class="jscolor {valueElement:null,value:'00c42b'}" style="width:50px; height:20px;"></button>
6162
</p>
62-
6363

64+
<h2>Update History :</h2>
65+
<ul>
66+
<li>Now you can save your creations as a png file</li>
67+
<li>Added a colour picker for leaves</li>
68+
<li>Added gravity and wind forces</li>
69+
</ul>
6470

65-
6671
<div id="shake">
6772
Intensity of shaking
6873
</div>
74+
6975
<div id="flsize">
7076
Size of leaves
71-
</div>
77+
</div>
78+
7279
<p>Currently working on bug : Creating new branches will make leaves disappear (They reappear if you grow them again)</p>
80+
81+
<h3>For smooth animations keep the branch number under 510</h3>
82+
7383
<br><br>
7484
</body>
7585
<script>

0 commit comments

Comments
 (0)