Giter Site home page Giter Site logo

Comments (6)

 avatar commented on September 28, 2024

In general, Skycons assumes that you've created your <canvas> objects with a square aspect ratio. (Usually one does this with the width and height properties of the canvas!)

How are you creating your canvas such that this is not the case? (Is its size set externally somehow?)

from skycons.

peternewman avatar peternewman commented on September 28, 2024

Hi @ironwallaby ,

Yeah they're just sized to fit within a div so the whole thing just scales dynamically depending on the page size (and ultimately the number of columns):
https://github.com/peternewman/casparcg-html-templates/blob/gh-pages/templates/fetch-weather-example/index.html#L27

https://peternewman.github.io/casparcg-html-templates/templates/fetch-weather-example/index.html

I can't see a way to set one off the other using CSS and given the horizontal and vertical movements require a 1:1 aspect ratio, it seems either it should be fixed in the Skycons, or the generating code should be tweaked to deal with non-square aspect ratios, which would be cool but I suspect a lot harder, especially to get that wind path looking nice.

from skycons.

 avatar commented on September 28, 2024

Sounds like you're mixing two different things! There's the canvas width and height (which is controlled by the HTML and/or JavaScript), and also it's display size (which is controlled by CSS). The way the canvas is displayed can be controlled automatically in CSS, but note that that doesn't control the canvas size itself! You will either need to set it manually in the HTML or else you will need to use JavaScript to fix the canvas element's size to match whatever the CSS says every time the window is resized.

This is kinda like how a PNG image has a width and height, but you are welcome to display that image on a webpage at any size you like using CSS.

My recommendation is to just set a width and height on the canvas tag that is large enough to account for what you want to do! (Using JS to reset the resolution of the canvases seems like overkill to me.)

As for supporting non-square aspect ratios... Skycons isn't really actively maintained any more, since we at The Dark Sky Company no longer use it for our own webpages. Consequently, we won't be making such a patch in the official version. That said, if anyone wishes to fork the library and implement that kind of a feature, they should do so!

from skycons.

peternewman avatar peternewman commented on September 28, 2024

Sounds like you're mixing two different things! There's the canvas width and height (which is controlled by the HTML and/or JavaScript), and also it's display size (which is controlled by CSS). The way the canvas is displayed can be controlled automatically in CSS, but note that that doesn't control the canvas size itself! You will either need to set it manually in the HTML or else you will need to use JavaScript to fix the canvas element's size to match whatever the CSS says every time the window is resized.

I'm very new to canvas, so that's quite likely.

My recommendation is to just set a width and height on the canvas tag that is large enough to account for what you want to do! (Using JS to reset the resolution of the canvases seems like overkill to me.)

Will that not risk anti-aliasing if you're trying to scale down every 2.5 canvas pixels to one screen pixel for example (a quick test seems to suggest it does)? In my use case I'm not actually interested in being dynamically responsive.

As for supporting non-square aspect ratios... Skycons isn't really actively maintained any more, since we at The Dark Sky Company no longer use it for our own webpages. Consequently, we won't be making such a patch in the official version. That said, if anyone wishes to fork the library and implement that kind of a feature, they should do so!

Would you accept a pull request to either handle non-square (by doing all the complicated maths), or a slightly tweaked version of my current code so the numbers used for calculations are the smaller of the two to keep the correct aspect ratio?

from skycons.

 avatar commented on September 28, 2024

It does risk anti-aliasing, yes. In our own usage, if we wanted the icon to show up as 32px by 32px on screen, we'd usually do something like this:

<canvas width="64" height="64" style="width:32px; height:32px"></canvas>

And then we'd attach Skycons to the canvas. (This was some years ago, when there were usually 2 physical pixels per CSS pixel. I'm personally honestly unsure if screens are higher resolution these days!)

As for accepting pull-requests, if the changes are not especially invasive, we may accept them, but since we can't test and vouch for and support them ourselves any more we tend to recommend people fork the repository. (If you would like us to officially link to your fork, we're happy to do so!) For Skycons generally, we'd probably opt for the "complicated maths" solution—it would be a large (and breaking) change of interface to modify the sizes of the canvases passed to the library, and it's much easier and safer to apply such a hack on your end rather than in Skycons proper!

from skycons.

 avatar commented on September 28, 2024

Skycons is no longer maintained; please fork to do any further work on it!

from skycons.

Related Issues (15)

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.