🙄Разминка для ума!
Треугольник Серпинского, интересная фигура которую построить достаточно просто.
Алгоритм такой:
1. создаём любые 3 точки на плоскости
2. из этих точек случайно выбираем любую, как начальную
3. случайно выбираем любую точку из этих же трёх точек как цель
4. перемещаемся в сторону цели на половину расстояния
5. повторяем бесконечно с пункта 3
Если сделать достаточно много итераций то вырисовывается интересная фигура. Треугольник, в который вписаны более мелкие треугольники. Это самый настоящий фрактал!
Я собрал пример построения такой фигуры на базе Qt.
🌎 Код можно посмотреть здесь.
С помощью paintEvent я рисую точки по озвученному алгоритму. Каждые 10 секунд либо по клику на виджете строится следующий треугольник.
Особенности примера:
🔸 Атрибут Qt.WA_OpaquePaintEvent позволяет сохранить то, что было нарисовано в прошлой итерации. Таким образом мы видим постепенное наполнение точек а не мелькающую одну точку.
🔸QTimer позволяет создавать отложенные вызовы один раз или с повторением через интервал.
🔸QColor.fromHsv() позволяет создать рандомный но предсказуемый цвет с помощью HSV схемы. Не слишком светлый и не слишком тёмный но всегда с разный. Рандомизации подвергается только смещение по цветовому кругу (Hue), яркость (Value) и насыщенность (Saturation) можно контролировать отдельно в своих пределах или оставить статичными. Обычный рандом цвета по RGB не даёт такой предсказуемый результат.
🔸 Каждый новый цикл с новым треугольником предварительно затемняет предыдущие через этот вызов
painter.fillRect(rec, QColor(0, 0, 0, 100))
То есть полупрозрачный цвет. Таким образом, чем старше треугольник, тем он темней.
Если сделать виджет фулскрин, то у нас получится некий ScreenSaver)))
🔸 Да, я знаю, что рисование в Qt не самый лучший способ сделать этот пример) Скорее всего самый НЕподходящий. Попробуйте сделать тоже самое но другими средствами.
#qt#source#tricks
Our Wordle of the day – did you manage to get yours right today?
Don’t forget to clear your table after eating at our hawker centres, coffeeshops and food courts.
P.S. You don’t have to clean your table, as cleaners will be cleaning and sanitising tables.
#ClearYourTable#ReturnYourTray#BinUsedTissues
Doesn't it feel shiok to have a clean table to enjoy your favourite hawker food? When you're done, don't forget to #ReturnYourTray and #BinUsedTissues so that fellow diners can feel the same shiok.
#ClearYourTable
As we begin dining out again, remember to practise good hygiene, to protect ourselves, other diners, and our cleaners – many of whom are seniors. When you’re done eating, remember to #ClearYourTable, #ReturnYourTray and #BinUsedTissues.
Leaving litter on tables at our public dining places is an offence. NEA is taking an advisory approach in the lead-up to 1 Sep 2021, after which enforcement action will be taken against patrons who fail to heed our officers’ advice. www.nea.gov.sg/media/news/advisories/index/clear-table-as-dine-in-resumes
As dine-in gradually resumes from today, let’s do our part in keeping our favourite public dining spaces and our cleaners safe by remembering to #ReturnYourTray, #ClearYourTable and #BinUsedTissues. If we simply get up and walk away, the dirty crockery and food remnants can attract unwanted pests. Our used tissues also carry germs that pose potential health risks to cleaners and other diners.
Expectation: All ready to order my beloved hawker delights 😍
Reality: Oh no, the previous diners did not clear their tables 🥴
Let's play our part in keeping #OurHawkerCentres clean, by clearing our used tray and crockery.
Details and FAQs here: www.nea.gov.sg/clean-tables
#ClearYourTable#ReturnYourTray#BinUsedTissues
Here’s what the same area at Queen’s St Hawker Centre looks like in 2016 and 2021. What a dramatic transformation we've seen lately! Better tray return infrastructure and a new cleaning workflow are initiatives we’ve adopted to ensure cleaner and safer public dining places.
Diners and cleaners at #OurHawkerCentres have played a great part in making this system work. So next time you’re dining at #OurHawkerCentres, be part of that change and #ClearYourTable, #ReturnYourTray and #BinUsedTissues to keep our public dining places clean and safe for everyone. Thank You - to our cleaners, fellow diners and all of you, for supporting us! ❤️
#DidYouKnow that our cleaners do more than just clear our tables? They also need to sanitise tables, clear the tray/crockery return stations, and return clean crockery to the stalls.
Let’s do our part to help our cleaners! #ReturnYourTray#ClearYourTable#BinUsedTissues
Heading out for a meal? Let’s remember to keep our public dining places clean, by clearing our tables after a meal. #ClearYourTables#BinUsedTissues#ReturnOurTrays
Savour the perfect blend of sweet, spicy, and tangy tastes of Rojak - Singapore's iconic hawker dish! 🥗🍍🥒
Whether you love it with a generous serving of thick savoury sauce or prefer it with a spicy kick, Rojak is certainly a good treat for our taste buds. P.S. Don’t forget to return your used tray and crockery after enjoying your meal!
#OurHawkerCentres#OurHawkerCulture#ClearYourTable#ReturnYourTray#BinUsedTissues
Keeping #OurHawkerCentres clean and safe is a shared responsibility!
When we #ClearOurTables, #ReturnOurTrays and #BinUsedTissues after our meals, it scores a hat-trick of kindness, making it a more pleasant dining experience for everyone!
#DidYouKnow these "dumplings" can be chock-full of germs? Ew, right? Don't forget to #BinUsedTissues, and help protect our cleaners from being exposed to potential health risks. #CleanYourTable#ThankYouCleaners
Extending our heartfelt appreciation to diners who have been returning their used trays and crockery. This small act goes a long way towards ensuring a pleasant dining experience for everyone.
Let's continue to keep #OurHawkerCentres clean this new year!
Details and #FAQs here: www.nea.gov.sg/clean-tables
#ClearYourTable#ReturnYourTray#BinUsedTissues