Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Hello, how would you modify this so into WebGL? fern.html JS Bin Barnsleyfern BarnsleyFern.js function BarnsleyFern(canvasId, lim) { // DCLs var canvas = document.getElementById(canvasId); var
Hello, how would you modify this so into WebGL?
fern.html
JS Bin
Barnsleyfern
BarnsleyFern.js
function BarnsleyFern(canvasId, lim) { // DCLs var canvas = document.getElementById(canvasId); var ctx = canvas.getContext("2d"); var w = canvas.width; var h = canvas.height; var x = 0., y = 0., xw = 0., yw = 0., r; // Return random number 0..max-1 function randgp(max) { return Math.floor(Math.random() * max) } // Clean canvas ctx.fillStyle = "white"; ctx.fillRect(0, 0, w, h); // MAIN LOOP for (var i = 0; i < lim; i++) { r = randgp(100); if (r <= 1) { xw = 0; yw = 0.16 * y; } else if (r <= 8) { xw = 0.2 * x - 0.26 * y; yw = 0.23 * x + 0.22 * y + 1.6; } else if (r <= 15) { xw = -0.15 * x + 0.28 * y; yw = 0.26 * x + 0.24 * y + 0.44; } else { xw = 0.85 * x + 0.04 * y; yw = -0.04 * x + 0.85 * y + 1.6; } x = xw; y = yw; ctx.fillStyle = "green"; ctx.fillRect(x * 50 + 260, -y * 50 + 540, 1, 1); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started