go-p5 / p5

p5 is a simple package that provides primitives resembling the ones exposed by p5js.org
https://go-p5.github.io/
BSD 3-Clause "New" or "Revised" License
150 stars 12 forks source link

add Loop, NoLoop, IsLooping and FrameCount #41

Closed psampaz closed 3 years ago

psampaz commented 3 years ago

closes #32 and #39

codecov[bot] commented 3 years ago

Codecov Report

Merging #41 (6ea7f0e) into main (6ea7f0e) will not change coverage. The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main      #41   +/-   ##
=======================================
  Coverage   80.59%   80.59%           
=======================================
  Files           9        9           
  Lines         567      567           
=======================================
  Hits          457      457           
  Misses         89       89           
  Partials       21       21           

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 6ea7f0e...fb788c7. Read the comment docs.

psampaz commented 3 years ago

@sbinet even if this test https://github.com/go-p5/p5/pull/41/files#diff-e65edbcd5a006378e11ec33d7b121f21a20ec2631433f0b75bfa54e11768e9caR85 passes, if you manually try to run one of the repo examples with NoLoop() the window that open has just a white background.

Is this somehow related with how Gio works?

sbinet commented 3 years ago

Yes and no.

As Gio is an immediate mode toolkit, one has to redraw the background for every new frame.

That's done here: https://github.com/go-p5/p5/blob/6ea7f0ea7c6f784c646608a70f32820e50812278/proc.go#L293

... in 'draw'.

I'll check tomorrow what the equivalent p5js code produces.

sbinet commented 3 years ago

I've just checked with p5js.

the following:

function setup() {
  background(0,0,0);
  noLoop();
}

function draw() {
  background(255,0,0);
  text(frameCount, 10, 30);
}

produces a red canvas with the number 1 being displayed. see on https://editor.p5js.org/.

so it would seem p5js draws at least 1 frame and then enters the "frame loop". ie: (in pseudo-code)

proc.Setup()
// create Gio window, then draw one frame.
proc.Draw()

for evt := range events {
   // ...
   proc.Draw()
}

do you want to give it a stab?