Git Product home page Git Product logo

Comments (6)

santiaago avatar santiaago commented on September 15, 2024

Interesting, I will give it a try,
thanks for the feedback.

from tinygraphs.

santiaago avatar santiaago commented on September 15, 2024

@ajstarks when the I use the same style over the whole loop it definitly makes sense to use canvas.Gstyle(), Thanks.

In the case of multiple styles in the same loop it is a bit harder as you would have to create a loop for each style.

Should I also try to use Gstyle in this type of scenario?

for ... {
    style1 := ....
    style2 := ....
    if something {
        canvas.Line(...., style1)
    } else { 
        canvas.Line(..., style2)
    }
}

from tinygraphs.

ajstarks avatar ajstarks commented on September 15, 2024

Nah, it's not worth it in the case you cite. Gstyle is useful for invariants. However, if you can make the decision outside of the loop, you can assign two styles before the loop and then apply them.

      style1 := ....
      style2 := ...
      for ... {
         if something {
              canvas.Line(...., style1)
          } else {
              canvas.LIne(...., style2)
         }
     }

Another useful pattern is to combine Gstyle() for the common style items, and then add variation in the loop as needed.

from tinygraphs.

santiaago avatar santiaago commented on September 15, 2024

Cool, thanks

I was able to clean some of the roots where I was creating a fill each time.
See --> 60203d4

And I also manage to use the pattern you described (Gstyle() then add variations).
See --> c6cafeb

from tinygraphs.

ajstarks avatar ajstarks commented on September 15, 2024

in revision c6cafeb you can eliminate the var fill, and then do:

    if colorIndex[yL] == 0 {
        canvas.Polygon(xs, ys, draw.FillFromRGBA(colorMap[yL]))
    }

from tinygraphs.

santiaago avatar santiaago commented on September 15, 2024

good spot, I will simplify that 👍

from tinygraphs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.