HTML and CSS Reference
In-Depth Information
The idea is that each snowflake can be defined as a number of branches that spread out in a different direc-
tion. Each branch then has a set number of smaller child branches spread out over some range of angles and so
on to a set limit. Because each step of the recursion is the same, a single method can be used that calls itself.
The only difference with the nested calls is that the state of the transformation matrix is set up so that the child
branches are drawn underneath the parent branches.
Figure 15-4 shows one of the more interesting outputs of the nearly infinite number of possible snowflakes.
The code for the snowflake generator is shown in Listing 15-5 .
Figure 15-4: Snowflake output.
Listing 15-5: Generating random snowflakes
<script src='jquery.min.js'></script>
<style> canvas { background-color:white; } </style>
<canvas id="mycanvas", width="600" height="400"></canvas>
<script>
var canvas = $("#mycanvas")[0],
ctx = canvas.getContext("2d");
function randInt(max) {
 
 
 
 
Search WWH ::




Custom Search