Answered step by step
Verified Expert Solution
Link Copied!

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2014 Nancy France September 15 19 2014 Proceedings Part 3 Lnai 8726

Authors: Toon Calders ,Floriana Esposito ,Eyke Hullermeier ,Rosa Meo

2014th Edition

3662448440, 978-3662448441

Students also viewed these Databases questions