wiggly-circle

Inspired by Inconvergent's "path test".

the return to the fight

centrism

pointless breadth

volumous

breathe

pointedly degenerative

trans-gressive

pointedly home-of-sexual

drop-ped

c o m p e n s a t e

{2,3,4}-drop

back and ready for more trans jokes

from beyond the bilines

pancontinental

amorphous

re-homing

anachronistic

Code

// The MIT License (MIT)

// Copyright (c) 2019 nabijaczleweli

// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:

// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


#include <SFML/Graphics.hpp>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <random>
#include <vector>


static const auto tau         = 4 * std::acos(0);
static const auto increase    = 2 * 10. * 2;
static const auto wiggle      = 2 * 2. * 2 * 1.5;
static const auto min_opacity = .3;

static const sf::Color colour_set[]{
    {0x75, 0x07, 0x87},  //
    {0x00, 0x4d, 0xff},  //
    {0x00, 0x80, 0x26},  //
    {0xff, 0xed, 0x00},  //
    {0xff, 0x8c, 0x00},  //
    {0xe4, 0x03, 0x03},  //
};


int main() {
	std::clog << "Pre-c\n";

	sf::RenderTexture img;
	img.create(1600 * 2, 900 * 2);
	img.clear();

	std::clog << "Created\n";

	const auto img_s  = img.getSize();
	const auto center = img_s / 2u;
	const auto radius = 0;  //(((img_s.x + img_s.y) / 2.) / 2.) * .6;

	std::srand(std::time(nullptr));
	std::mt19937 rng{static_cast<unsigned int>(std::rand())};
	std::uniform_real_distribution<double> wiggle_dist{-wiggle, +wiggle};
	std::uniform_real_distribution<double> opacity_dist{min_opacity, 1.};

	std::uniform_int_distribution<std::size_t> colour_idx_dist{0, (sizeof(colour_set) / sizeof(*colour_set)) - 1};


	std::vector<sf::Vertex> points;
	points.reserve((60 + 1) * (1'000 + 2));

	for(auto i = 0u; i < 60; ++i) {
		std::clog << (i + 1) << '/' << 60 << '\n';
		// for(auto alpha = 0.; alpha <= tau; alpha += tau / (1'000 * (i / 60.))) {
		for(auto alpha = 0.; alpha <= tau; alpha += tau / 1'000) {
			const auto r = radius + wiggle_dist(rng) + increase * (i + alpha / tau);

			auto colour = colour_set[colour_idx_dist(rng)];
			colour.r    = opacity_dist(rng) * 255;
			colour.g    = opacity_dist(rng) * 255;
			colour.b    = opacity_dist(rng) * 255;
			colour.a    = opacity_dist(rng) * 255;

			sf::Vertex v{{static_cast<float>(center.x + std::cos(alpha) * r), static_cast<float>(center.y + std::sin(alpha) * r)}, colour};
			points.emplace_back(std::move(v));

			// std::cout << v.position.x << ' ' << v.position.y << ": " << r << ", " << static_cast<unsigned int>(colour.a) << '\n';
			// img.draw(&v, 1, sf::PrimitiveType::Points);
		}
	}

	// for(auto skip = 2u; skip <= 3; ++skip)
	//	 for(auto i = 0ull; i < points.size() - skip; ++i) {
	//		 sf::Vertex pts[]{points[i], points[i + skip]};
	//		 img.draw(pts, sizeof(pts) / sizeof(*pts), sf::PrimitiveType::LinesStrip);
	//	 }
	for(auto i = 0ull; i < points.size() - 4; i += 4)
		img.draw(points.data() + i, 4, sf::PrimitiveType::LinesStrip);
	// img.draw(points.data(), points.size(), sf::PrimitiveType::LinesStrip);

	img.display();
	img.getTexture().copyToImage().saveToFile("output.png");
}

Creative text licensed under CC-BY-SA 4.0, code licensed under The MIT License.
This page is open-source, you can find it at GitHub, and contribute and/or yell at me there.
Like what you see? Consider giving me a follow over at social medias listed here, or maybe even a sending a buck or two patreon my way if my software helped you in some significant way?
Automatically generated with Clang 14's C preprocessor on 11.09.2023 01:31:48 UTC from src/maths/wiggly-circle.html.pp.
See job on builds.sr.ht.
RSS feed