Giter VIP home page Giter VIP logo

sfml-lit's Introduction

SFML-lit

A simple light system made in SFML, thanks to Sight & Light

Demo

demo

Example

#include <SFML/Graphics.hpp>
#include "light.hpp"

int main()
{
    sf::RenderWindow window(sf::VideoMode(640, 360), "SFML Lit", sf::Style::Close);
    window.setFramerateLimit(60);
    window.setMouseCursorVisible(false);

    std::vector<lit::Line> segments = {
        // Border
        lit::Line{{0, 0}, {640, 0}},
        lit::Line{{640, 0}, {640, 360}},
        lit::Line{{640, 360}, {0, 360}},
        lit::Line{{0, 360}, {0, 0}},

        // Polygon #1
        lit::Line{{100, 150}, {120, 50}},
        lit::Line{{120, 50}, {200, 80}},
        lit::Line{{200, 80}, {140, 210}},
        lit::Line{{140, 210}, {100, 150}},

        // Polygon #2
        lit::Line{{100, 200}, {120, 250}},
        lit::Line{{120, 250}, {60, 300}},
        lit::Line{{60, 300}, {100, 200}},

        // Polygon #3
        lit::Line{{200, 260}, {220, 150}},
        lit::Line{{220, 150}, {300, 200}},
        lit::Line{{300, 200}, {350, 320}},
        lit::Line{{350, 320}, {200, 260}},

        // Polygon #4
        lit::Line{{340, 60}, {360, 40}},
        lit::Line{{360, 40}, {370, 70}},
        lit::Line{{370, 70}, {340, 60}},

        // Polygon #5
        lit::Line{{450, 190}, {560, 170}},
        lit::Line{{560, 170}, {540, 270}},
        lit::Line{{540, 270}, {430, 290}},
        lit::Line{{430, 290}, {450, 190}},

        // Polygon #6
        lit::Line{{400, 95}, {580, 50}},
        lit::Line{{580, 50}, {480, 150}},
        lit::Line{{480, 150}, {400, 95}}
    };
    
    lit::Light light(segments);
    light.init();

    light.setColor({255, 0, 0});
    light.setIntensity(0.5f);
    light.setEnergy(0.5f);
    light.setPosition({320, 140});

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
            {
                window.close();
            }
            else if (event.type == sf::Event::MouseMoved)
            {
                sf::Vector2f mouse(event.mouseMove.x, event.mouseMove.y);
                light.setPosition(mouse);
            }
        }

        window.clear();
        light.draw(window, true);
        window.display();
    }

    return 0;
}

sfml-lit's People

Contributors

rynmth avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.