-1

I've declared a class gly that accesses a canvas made with node-canvas.

const width = 250;
const height = 250;
const canvas = createCanvas(height, width);
const gly = canvas.getContext("2d");

A separate function (outside that class) takes multiple arrays of [x,y] coordinates and should draw them onto the canvas. That function is initialized as

function drawShape(shapeClass, color, ...shapes) {

whereas shapeclass is gly.

I've already done this successfully without that function, but as I'm drawing so many shapes onto a canvas, I want to clean up the code by making that function draw the shapes whenever needed. The issue is that whenever gly's class functions are called from within function drawShape, nothing happens. There aren't any errors, and color and ...shapes pass perfectly fine into the function, but the function itself does nothing, leaving an empty space on the canvas.

Am I passing gly correctly into drawShape?

  • 1
    `gly` isn't a class, it's a variable. – Andy Mar 26 '22 at 18:43
  • All the same, why wouldn't its functions like gly.fill( ) and such not execute in drawShape( ) ? – Jeremy Marino Mar 26 '22 at 18:49
  • 1
    Please show the complete code in a [mcve]. It shouldn't matter whether you refer to the drawing context via the variable `gly` or the variable `shapeClass`. – Bergi Mar 26 '22 at 19:41
  • We can't help you unless you show us the actual running code that is causing you a problem and then ask a specific question about that code. Right now, you have a theoretical question that isn't showing us the actual code. Very hard for us to guess what is wrong. We need to see a minimal, reproducible example of the code that illustrates the problem and a good, clear explanation of what you want help with in that code. – jfriend00 Mar 26 '22 at 19:52

1 Answers1

0

I figured it out - it had nothing to do with how I was using either the functions or the classes. Junk data found itself into an array and threw everything off.

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 28 '22 at 03:18