+ 1

Anyone to help me understand this code?

The recursive calls confuse. <html> <head> <script> window.onload=function create(){ var c=document.getElementById("cc").getContext("2d"); var deg = Math.PI/180; // For converting degrees to radians // Draw a level-n Koch Snowflake fractal in the context c, // with lower-left corner at (x,y) and side length len. function snowflake(c, n, x, y, len) { c.save(); // Save current transformation c.translate(x,y); // Translate to starting point c.moveTo(0,0); // Begin a new subpath there leg(n); // Draw the first leg of the fractal c.rotate(-120*deg); // Rotate 120 degrees anticlockwise leg(n); // Draw the second leg c.rotate(-120*deg); // Rotate again. leg(n); // Draw the final leg c.closePath(); // Close the subpath 1 c.restore(); // Restore original transformation // Draw a single leg of a level-n Koch snowflake. // This function leaves the current point at the end of // the leg it has

24th Jun 2020, 7:24 PM
Wadika
Wadika - avatar
1 Answer
0
There is no recursion in your code... maybe leg(), whose definition is missing You can try to understand the algorithm here: https://www.geeksforgeeks.org/koch-curve-koch-snowflake/
25th Jun 2020, 4:03 AM
Bilbo Baggins
Bilbo Baggins - avatar