0

I am making a programming language involving Javascript. However, it doesn't seem to work. My language is a js file called 'antimin'. The script looks like a one line code version of this:

 function (){

    var ctx;
    function setupCanvas(setupVariable){
        ctx=setupVariable;
        };
        function circ(x,y,lps,wps,fill,outline){
        if(outline===true){
        ctx.beginPath();ctx.arc(x,y,lps, wps,6.28);ctx.stroke();
        };
        if (fill===true){
        ctx.beginPath();ctx.arc(x,y,lps,wps,6.28);
        ctx.stroke();
        };
    }
}

However, when I pass it through the following HTML file, it doesn't work (note I deleted all </>):

<!doctype html>
<canvas length="100" width="100" id="minoun">
</canvas>
<script src="antimin.js">
</script>
<script>
setupCanvas(minoun.getContext("2d"))
circ(50,50,50,50,true,true)
</script>
3
  • 1
    function (){, function name is ? Commented Nov 29, 2015 at 3:27
  • 2
    You won't be able to call setupCanvas in your script tag because the function is inside another function which means it's local to that scope. You will either have to get rid of the outside function or call the setupCanvas function inside that outer function. If you choose to keep the outer function, you will have to invoke it immediately. I would look up how to use an IIFE. Commented Nov 29, 2015 at 3:29
  • I tried, a tiny arc is now on screen, thanks! Commented Nov 29, 2015 at 3:31

1 Answer 1

1

here is the solution of your question in full code

<!doctype html>
    <canvas length="100" width="100" id="minoun">
    </canvas>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>


    <script>
    $(function(){
        var ctx;
        function setupCanvas(setupVariable){
          ctx=setupVariable;
        };
        function circ(x,y,lps,wps,fill,outline){
        if(outline===true){
        ctx.beginPath();ctx.arc(x,y,lps, wps,6.28);ctx.stroke();
        };
        if (fill===true){
        ctx.beginPath();ctx.arc(x,y,lps,wps,6.28);
        ctx.stroke();
        };
        }
        setupCanvas(minoun.getContext("2d"))
            circ(50,50,50,50,true,true)
    });
    </script>
Sign up to request clarification or add additional context in comments.

1 Comment

If you need further explanation feel free to ask

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.