https://blog.jgc.org/2024/09/i-made-rubbish-clock.html John Graham-Cumming's blog 2024-09-27 I made a rubbish clock With separate plastic, metal, paper, and glass recycling, composting, and pick up of all the rest, knowing which days to put out which bins can be complicated. Some have turned to high-tech solutions like Darren Tarbard's wonderful "bindicator". [Del3rp-WsAES2IE] There's even a commercial version of that. I thought about making something similar, but decided that a high-tech solution isn't always the right one. Instead I made a clock, or rather a clock face. My rationale was as follows: the bin days don't change frequently so no need to call an API to get them, and anyway most councils don't have an API for this sort of thing. Also, I really didn't want yet another thing with a wall wart, or WiFi to configure, or code to debug (there comes a time in every programmer's life when they can't face debugging yet another thing that should be simple and just work). Not everything needs to be Turing Complete! But you can buy cheap clock mechanisms where the hands go full circle in seven days instead of 12 hours. Something like this. [lixo-2] So, I wrote a bunch of code to produce an SVG (and PDF and PNG) for the clock face. The code is here. You end up with something like this which can be printed. [lixo] The colours and wording are all determined by the schd and bins variables. The code should be easy to customize for your location's schedule. It supports up to two different bin types per day. If you need more you'll have to modify the code. bins = { "none": ["white", ""], "lixo": ["#72859E", "Lixo"], "papl": ["#255FC9", "Papel"], "embl": ["#DED044", "Embalagens"], } days = ["Sun", "Mon", "Tues", "Wednes", "Thurs", "Fri", "Satur"] schd = [["none"], ["lixo"], ["papl", "embl"], ["lixo"], ["papl"], ["lixo", "embl"], ["papl"]] There's no need for you to use Portuguese; I have because I'm dealing with Portuguese rubbish collection. The only interesting piece of code is the generation of the curves for the seven daily segments (and also for the curved wording). This is done by the function path: def getXY(p, r, s): a = 2.0 * math.pi * (p * pps + rot) return s % (r * math.cos(a), r * math.sin(a)) def path(p, r): s = " %.2f %.2f " pa = "M" pa += getXY(p, r, s) pa += "A %.2f %.2f 0 0 1" % (r, r) pa += getXY((p+1), r, s) return pa In SVG you can define a path element which can be used to make all sorts of curves, arcs, and lines. My path function takes two parameters: p is a number between zero and six representing the seven daily segments needed on the clock; r is the radius of the arc. The function uses getXY to find the position of a point on the arc. It does this twice to find the start and end point. So, path ends up returning something like M x0 y0 A r r 0 0 1 x1 y1 where x0, y0, x1, y1 are the calculated end points of the arc and r is the radius of the arc. The M x0 y0 means "move to (x0, y0)" The A r r 0 0 1 x1 y1 means "draw an arc of radius r to the point (x1, y1) ". The 0 0 1 in the middle correspond to three parameters: x-axis-rotation, large-arc-flag, and sweep-flag; it's best to refer to the documentation for those because they determine the direction in which the arc points and whether it is rotated. The final part of the path SVG element, L 0 0, is added elsewhere in the code. It sets the centre of the arc at (0, 0). I used the viewBox attribute of the SVG to make the SVG geometry be between (-1, -1) and (1, 1) thus making the centre of the image (0, 0). print('' % (wh, wh)) Armed with a suitable printed clock face, I got a simple square picture frame, a few bits of wood for spacers, and put it all together into a "rubbish clock". [lixo-4] [lixo-3] [lixo-5] [lixo-7] at September 27, 2024 Email ThisBlogThis!Share to TwitterShare to FacebookShare to Pinterest Labels: pseudo-randomness No comments: Post a Comment Older Post Home Subscribe to: Post Comments (Atom) Search This Blog [ ] [Search] Labels * pseudo-randomness * hardware * babbage * anti-spam * gnu make * retro * security * codes and ciphers * the geek atlas * mathematics * minitel * behind the screens * popfile * privacy * radio Popular Posts * [AEn0k_v6Hy] Steve Ballmer's incorrect binary search interview question In this short video Steve Ballmer talks about a puzzle question he would ask candidates interviewing at Microsoft. Solving it is based on b... * [171421935] Cracking an old ZIP file to help open source the ANC's "Operation Vula" secret crypto code It's not often that you find yourself staring at code that few people have ever seen, code that was an important part in bringing down t... * [Del3rp-WsA] I made a rubbish clock With separate plastic, metal, paper, and glass recycling, composting, and pick up of all the rest, knowing which days to put out which bins ... * [AEn0k_vDbt] Controlling the Taylor Swift Eras Tour wristbands with Flipper Zero Many large concerts feature wristbands that light up on command. They are used to produce varied visual effects across a stadium. One compan... * [casio1] Pimping my Casio with Oddly Specific Objects' alternate motherboard and firmware Some time ago I bought a replacement motherboard for my classic Casio F-91W from Crowd Supply. The project keeps the original Casio LCD but... * [proposal-1] The original WWW proposal is a Word for Macintosh 4.0 file from 1990, can we open it? The W3C has a page with the original WWW proposal from Tim Berners-Lee. One of the downloads says The original document file (I think - I ... * [mac-1] My daily driver is older than I thought; it's positively vintage! I was doing some clean up on my main laptop and realized it had been a while since bought a new computer. Turns out it was a lot older than ... * [light-sens] Two ways to use an LED as a light sensor with Arduino I needed to log when a light switched on and off during the night as part of debugging an oddly behaving movement sensor. To do that I built... * [Picture] Your last name contains invalid characters My last name is "Graham-Cumming". But here's a typical form response when I enter it: Does the web site have any idea how rud... * [tsb-1] "Hacker News" for retro computing and gaming I noticed over time that I was drawn to the retro computing or gaming posts on Hacker News . So, I've set up a dedicated web site in the... Blog Archive * V 2024 (14) + V September (3) o I made a rubbish clock o Cracking an old ZIP file to help open source the A... o Steve Ballmer's incorrect binary search interview ... + > June (3) + > May (1) + > April (1) + > March (3) + > February (2) + > January (1) * > 2023 (30) + > December (2) + > November (5) + > October (3) + > September (4) + > August (1) + > July (5) + > June (1) + > May (3) + > April (3) + > March (3) * > 2022 (24) + > December (2) + > November (3) + > October (8) + > September (1) + > July (2) + > June (2) + > April (2) + > March (4) * > 2021 (6) + > November (1) + > July (1) + > May (2) + > April (1) + > January (1) * > 2020 (2) + > June (2) * > 2018 (2) + > December (2) * > 2017 (4) + > May (1) + > April (3) * > 2016 (11) + > November (1) + > September (1) + > July (2) + > June (1) + > May (3) + > April (1) + > March (2) * > 2015 (11) + > November (1) + > July (2) + > May (1) + > April (5) + > March (1) + > January (1) * > 2014 (4) + > November (2) + > July (1) + > June (1) * > 2013 (39) + > September (4) + > August (1) + > July (4) + > June (2) + > May (5) + > April (12) + > March (3) + > February (2) + > January (6) * > 2012 (77) + > December (3) + > November (6) + > October (6) + > September (7) + > August (6) + > July (6) + > June (8) + > May (4) + > April (9) + > March (7) + > February (9) + > January (6) * > 2011 (79) + > December (5) + > November (7) + > October (2) + > September (5) + > August (2) + > July (8) + > June (10) + > May (6) + > April (9) + > March (6) + > February (12) + > January (7) * > 2010 (95) + > December (13) + > November (9) + > October (16) + > September (19) + > August (2) + > July (9) + > June (12) + > May (1) + > April (1) + > March (4) + > February (2) + > January (7) * > 2009 (31) + > December (1) + > November (8) + > October (3) + > September (6) + > August (9) + > June (1) + > May (1) + > January (2) * > 2008 (19) + > December (2) + > September (1) + > June (3) + > May (3) + > March (2) + > February (6) + > January (2) * > 2007 (34) + > December (2) + > November (3) + > October (5) + > August (2) + > July (2) + > June (4) + > May (3) + > April (1) + > March (6) + > February (4) + > January (2) * > 2006 (25) + > December (2) + > November (2) + > October (3) + > September (5) + > July (1) + > June (1) + > April (6) + > February (1) + > January (4) * > 2005 (3) + > December (1) + > November (2) Copyright (c) 1999-2024 John Graham-Cumming. Awesome Inc. theme. Powered by Blogger.