🙄Разминка для ума!
Треугольник Серпинского, интересная фигура которую построить достаточно просто.
Алгоритм такой:
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
🪐 In the spiral galaxy NGC 4438, astronomers have detected a massive black hole mysteriously offset from the galaxy’s center—an unusual finding, since black holes normally anchor the middle of their galaxies. This strange displacement may be the result of a past collision with another galaxy, suggesting black holes can be knocked off-center by cosmic crashes and altering our picture of how galaxies and their hidden giants interact. ✨
#blackholes⚡#galaxies⚡#collisions⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
🪐 The galaxy NGC 4676, known as the "Mice Galaxies," features two spiral galaxies caught in the act of colliding, with long, bright tails of stars and gas stretching far into space. These tails, called tidal tails, form as the galaxies' mutual gravity pulls their outer stars apart, creating a striking and highly unusual shape rarely seen in the cosmos. ✨
#galaxies⚡#collisions⚡#mysteries⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
🪐 In the galaxy ARP 299, astronomers have witnessed a truly strange cosmic phenomenon: two galaxies colliding and triggering a burst of more than a hundred supernova explosions in a single region. This dramatic event releases vast amounts of energy and creates a glowing cloud of hot gas, showing how cosmic crashes can transform entire regions of space in a dazzling display of stellar death and rebirth. ✨
#supernovae⚡#collisions⚡#galaxies⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
🪐 The galaxy known as the Cartwheel Galaxy, located about 500 million light-years away in the constellation Sculptor, displays a striking ring-and-spoke structure unlike ordinary spirals or ovals. Its unusual shape was created when a smaller galaxy crashed through its center, sending waves of star formation racing outward and leaving behind bright, circular rings and faint, radial arms—an extraordinary cosmic ripple frozen in space. ✨
#galaxies⚡#shapes⚡#collisions⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 The galaxy Arp 147 shows off one of the universe’s strangest shapes—a bright blue ring of young stars wrapped around a reddish core, formed after a dramatic collision with another galaxy. This kind of "ring galaxy" is extremely rare, created when one galaxy punches through another, sending waves through the gas and sparking new stars to ignite in a perfect circle, making Arp 147 a cosmic example of how galactic crashes can sculpt extraordinary structures. ✨
#galaxies⚡#collisions⚡#rings⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 The galaxy NGC 922, located about 157 million light-years away in the constellation Fornax, sports a dramatic ring-shaped structure that formed after it collided with a smaller galaxy. This "collisional ring galaxy" features a bright, blue ring of new stars encircling its core, revealing the powerful effects of galactic crashes and creating a cosmic shape rarely found in the universe. ✨
#galaxies⚡#rings⚡#collisions⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 In 2023, astronomers using gravitational wave observatories detected GW230307, a signal from the merger of two neutron stars in a distant galaxy. Neutron stars are the incredibly dense cores left behind after supernova explosions, and their collision sent ripples—gravitational waves—through space itself, allowing scientists to study the properties of matter squeezed far beyond anything found on Earth. ✨
#gravitationalwaves⚡#neutronstars⚡#collisions⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 The galaxy ESO 510-G13, located about 150 million light-years away in the Hydra constellation, has a warped, twisted disk that gives it a bizarre, "bent" appearance. Scientists think this unusual shape was caused when ESO 510-G13 merged with a smaller galaxy, distorting its spiral arms and creating a dramatic ripple through its structure—making it one of the most visually striking examples of cosmic collisions turning galaxies into real oddities. ✨
#galaxies⚡#collisions⚡#hydra⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 In the galaxy NGC 660, astronomers have discovered a rare and bizarre "polar ring"—a huge ring of gas and stars wrapping around the galaxy at a right angle to its main disk. These unusual rings may form after galactic collisions, twisting the cosmic structure into a shape unlike any other in the universe. ✨
#phenomenon⚡#galaxies⚡#collisions⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
🪐 The galaxy UGC 4881, located about 500 million light-years away, has a remarkable "double-tailed" structure—two long streams of stars and gas extending in opposite directions. This unusual shape was formed when two spiral galaxies collided and merged, creating a cosmic bridge and tidal tails that make UGC 4881 stand out among the universe’s strangest-looking galaxies. ✨
#galaxies⚡#collisions⚡#tidal-tails ⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 Far out in the Virgo Cluster, astronomers observed a rare cosmic event called an "ultra-compact dwarf galaxy collision," where two tiny, densely packed galaxies like M60-UCD1 have smashed together. The aftermath of such a collision can create ultrabright X-ray sources and disrupt the structure of both galaxies, showing that even small galaxies can undergo dramatic and strange transformations when they collide in deep space. ✨
#cosmicphenomena⚡#collisions⚡#virgo⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels