• Yes, I think likely what's happening is the IDE uploads the code and then doesn't get a response after a second or so, so it issues a Ctrl-C to break out of it.

    You could do:

    setTimeout(function() {
      invertCircle(g.getWidth() / 2, g.getHeight() / 2, 30);
    }, 1000);
    

    to run the command after a delay so the IDE can upload the code fine and see a response, but then the code happens after.

    BUT: iterating over every pixel is always going to be really slow I'm afraid - it's probably not something you want to be doing if there's any way to avoid it. What I'd suggest is actually making two images - one with what you want to draw and one with the circle, and XORing the actual binary data of the image together.

    ga = Graphics.createArrayBuffer(176,176,1,{msb:true});
    gb = Graphics.createArrayBuffer(176,176,1,{msb:true});
    var ba = new Uint32Array(ga.buffer);
    var bb = new Uint32Array(gb.buffer);
    
    ga.setFont("Vector:80").drawString("Hello");
    gb.fillCircle(40,40,40);
    
    // define this once so JIT only runs once
    function xor(a,i) { "jit"
      return a ^ bb[i];
    }
    
    function update() {
      var t = getTime();
      E.mapInPlace(ba, ba, xor);
      g.drawImage(ga); // draws with current FG and BG colors
      print("took",getTime()-t,"sec");
    }
    update();
    

    There are other ways to do it (eg compiled code) but this way a relatively straightforward.

    It still takes ~0.4sec to do the entire screen, but if you only wanted part of the screen done then it'd be a bit faster.

    I was considering adding different draw styles (add/xor/or/etc) to the Graphics lib which would really help with this, but I'm afraid that isn't implemented yet.

About

Avatar for Gordon @Gordon started