Quantcast
Channel: 2D Latest Topics
Viewing all articles
Browse latest Browse all 623

How to display what I write inside of a canvas?

$
0
0

What I'm trying to accomplish:

First, an image:

3NDr59K.png

There is a textbox underneath the 'code' tab - what I want is for all the canvas-related code written inside the HTML to be displayed on the canvas on the right.

 

My problem:

I'm struggling with doing so, I tried doing this:

run.addEventListener('click', function() {
  canvas.innerHTML = '<script>' + jsarea.value + '</script>';
})

But it didn't work. I'm also getting a 'Cannot read property 'getContext' of null' error on:

var ctx = canvas.getContext('2d');

I think this might be because the canvas is in an iframe.

 

How could I achieve what I'm trying to accomplish?


Viewing all articles
Browse latest Browse all 623

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>