This forum has been archived. All content is frozen. Please use KDE Discuss instead.

DemosceneIsAlive

Tags: None
(comma "," separated)
User avatar
bodqhrohro
Registered Member
Posts
1
Karma
0
OS

DemosceneIsAlive

Wed May 22, 2019 10:22 am
But as it's 2019 now, this masterpiece is in Rust and 5K ;D

Image

Full resolution

The image is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Code: Select all
/*
 * Copyright (c) 2019, Bohdan Horbeshko
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * * Redistributions of source code must retain the above copyright notice, this
 * list of conditions and the following disclaimer.
 *
 * * Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

extern crate image;

use std::io;

const WIDTH: u32 = 5120;
const HEIGHT: u32 = 2880;

fn color_u8(color: f32) -> u8 {
    match color {
        _ if color < 0.0 => 0,
        _ if color > 255.0 => 255,
        _ => color as u8
    }
}

fn main() {
    let result_buffer = image::RgbImage::from_fn(WIDTH, HEIGHT, |x, y| {
        let mut r: f32;
        let mut g: f32;
        let mut b: f32;

        let x = x as f32;
        let y = y as f32;

        // main color zones
        r = (x / WIDTH as f32).asin() * 150.0;
        g = (y / HEIGHT as f32).asin() * 160.0;
        b = 128.0;

        // red beams
        if (x / 50.0 + y / 50.0) % ((780.0 + y / 50.0).sin() * 50.0) > 30.0 + (y / 500.0).sin() * 10.0 {
            r += 40.0;
            b += 20.0;
        }

        // grass
        if (x * y / 28000.0) % 100.0 > 80.0 {
            g += 30.0;
        }

        // triangle chains
        if ((x / 50.0 + y / 50.0) % 20.0 - 10.0).abs() < y / 10.0 % 5.0 {
            b -= 20.0 - g / 13.0;
        }

        image::Rgb {
            data: [
                color_u8(r),
                color_u8(g),
                color_u8(b),
            ]
        }
    });

    // export
    let mut stdout = io::stdout();
    let result_image = image::DynamicImage::ImageRgb8(result_buffer);
    result_image.write_to(&mut stdout, image::ImageFormat::PNG)
        .expect("Can't save the image");
}
flipwise
Registered Member
Posts
93
Karma
0
OS

Re: DemosceneIsAlive

Sat May 25, 2019 10:53 pm
Interesting idea, thanks! My gripe is with these sorts of elements, how jagged they get:

https://i.imgur.com/bJ46Y7E.png

Maybe you could tweak them?


Bookmarks



Who is online

Registered users: Bing [Bot], Evergrowing, Google [Bot], rblackwell