Share to: share facebook share twitter share wa share telegram print page

Wikipedia talk:Lua/Archive 13

Archive 10Archive 11Archive 12Archive 13

Module Request: Implement the MIT licensed Spectral.js approach to subtractive color mixing in Module:colormix ?

I'm moving this from a declined Phab ticket (T395879) , given that phabricator focuses on changes in Mediawiki as opposed to User side Scribunto modules, which it is clear this would be implemented as:-

"Feature summary (what you would like to be able to do and where):

Mix two colors based on their XYZ or RGB values, using a subtractive model such as (Kubelka-Munk theory), generating a result which can be supplied as a color in situations where a CSS color would typically be provided.

Use case(s) (list the steps that you performed to discover that problem, and describe the actual underlying problem which you want to solve. Do not describe only a solution):

The specfic use case is at: https://en.wikisource.org/wiki/Page:The_color_printer_(1892).djvu/29 where the 'mixed' inks are based on a 'parts' mix of 2 or more defined base inks.

The current approach https://en.wikisource.org/wiki/Module:The_Color_Printer_tone and https://en.wikisource.org/wiki/Module:The_Color_Printer_tone/data uses as weighted blend as an interim measure ( this is understood to be an additive approach and thus may not reflect the behaviour intended in the original printed work.)

Benefits (why should this be implemented?):

Being able to mix color subtractively would assist in being able to potentially more accurately determine and transcribe diagramatic colors in older works. The desire for an algorithmic approach, would reduce the need to manually determine mixes, and allow for colors to be adjusted en-masse in a single location, if the 'base' inks were 'corrected' to account for efforts to 'defade' them.

A MIT Licensed library Spectral.JS exists. (https://github.com/rvanwijnen/spectral.js) which if adapted into a set of functions in a Module:Colormix that could be called from the above mentioned module, would meet the use case quite well.

Beyond the specfic use case provided, being able to support a 'subtractive' (albiet approximated model) more directly would assist various color theory topics on other Wikimedia projects."

I've asked here because I felt a module like this might have wider applicability. ShakespeareFan00 (talk) 06:43, 4 June 2025 (UTC)

Sounds interesting and feasible. Might be a good use of wikifunctions too? — Martin (MSGJ · talk) 09:20, 4 June 2025 (UTC)
Already put in a request : f:Wikifunctions:Suggest a function#Subtractive color mix_(Pigment_style) ShakespeareFan00 (talk) 08:21, 5 June 2025 (UTC)

Using string.gsub to substitute %20

I am trying to use string.gsub to replace space characters with %20 to make a URL work correctly. However gsub sees the %2 and treats it as a capture. I've tried escaping things like %%20 and %%%20. Any suggestions please? — Martin (MSGJ · talk) 13:48, 12 June 2025 (UTC)

Are you sure %%20 didn't solve the issue? Make sure you replace capturing terms on both the matching string and the replacement string, since both can use capture group references. If it still doesn't work, could you point to the code where this happens? Aidan9382 (talk) 14:37, 12 June 2025 (UTC)
(edit conflict)
I think that it works for me. When I write =string.gsub ("t t", ' ', '%%20') in the debug console, I get t%20t. That's what you want, right? Also, if you don't need to know how many space characters were replaced: mw:Extension:Scribunto/Lua reference manual#mw.uri.encode: =mw.uri.encode ('t t', 'PATH')t%20t
Trappist the monk (talk) 14:41, 12 June 2025 (UTC)
Yes thanks both, that is working now. I had another gsub in the next line of the code so I have put this one after both. — Martin (MSGJ · talk) 14:45, 12 June 2025 (UTC)

Use on other language wikis

I recently rewrote {{OSM Location map}} in Lua (vastly improved performance along with extra features). I have now been asked on the talk page if it might be available via commons to allow other language wikis to use it. Is that an option? and is it desirable? The template has a small amount of embeded bits of text, grouped together to make at least superficial translation possible. For that, plus the documentation, a pasted and customised language specific versions seem to me to make more sense. (A full-blown translation of all parameters etc would be a major piece of work, though).

Having looked at a couple of the 49 versions already on other language wikis, these appear to still be the old template version (or in some cases the 'graph' based broken version of 3 years ago). Is there any mechanism for these to update to the lua module in some way? or alerting someone at the relevant wikis? Thanks for any insights on these issues. RobinLeicester (talk) 22:57, 12 June 2025 (UTC)

Cross-wiki transclusion is not possible, so putting it on Commons is not helpful. (You can scroll through the children of phab:T121470 for an hour or two if you want for all the wishing.)
Supporting translation of output text is trivial and I try to do it with every module I work on (a prior piece of presently unused work might be illustrative). Supporting true translation of parameters (i.e. supporting both English and local language versions) is a bit more difficult but I don't think so difficult as major piece of work, per se. You can look through how Module:Citation/CS1 does things if you want, which is the only module locally I know that does it the full way. (There is a foreign module on a few wikis called I18n lying around that I guess makes these things somewhat easier...? It only seems to clog up our local transclusion lists whenever it gets recreated here since we're one of the wikis that can take care of ourselves on the point.)
Something to review is potentially mw:Synchronizer if you don't mind supporting other wiki use cases, which I guess somewhat answers your 'update to the Lua module'. Note that while this template may exist elsewhere, it may not do the exact same things elsewhere, even ignoring differences of parameter names. Otherwise you're essentially on the hook to alert the other wikis yourself. Putting comments at the relevant talk pages would be step 1, then at local equivalents of WP:VPT or WP:AN possibly (since protection may be a concern to deal with), and then probably step 3 of doing it yourself is to do it yourself.
Some minor code suggestions since you are here:
  1. If I have the choice, I try to initialize tables with the relevant values directly rather than appending new values many times in a row, as this module currently does through the first couple dozen lines. This is generally faster in non-interpreted languages so I'd guess that extends to here also.
  2. Consider where possible using TemplateStyles rather than inline CSS. It's just nicer to edit and I assume it's nicer for browsers to consume at the end of the day, etc.
  3. Add whitespace around math symbols and after commas please ;_;.
  4. Consistent capitalization of function names at least.
Izno (talk) 05:41, 13 June 2025 (UTC)
Izno has good ideas and I would add that consistent indentation (using tabs) would be nice. I can do that in the sandbox if you like but it would generate an ugly diff. Please investigate colorCap which is an undefined global used once. Johnuniq (talk) 09:26, 13 June 2025 (UTC)
Prefix: a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9

Portal di Ensiklopedia Dunia

Kembali kehalaman sebelumnya