コード例 #1
0
int main() {
    sf::RenderWindow App(sf::VideoMode(imageWidth, imageHeight), 
        "SFML Graphics",sf::Style::Fullscreen);
    // This is the SFML application initialization with the app's parameters
    cx[0] = 255; cx[1] = 0; cx[2] = 0;
    // The initial colors for the shifting
    kradius = 0.1;
    imagen.create(imageWidth,imageHeight);
    mandtex.create(imageWidth,imageHeight);
    // The scaling factor, defined by the ranges in Real and Imaginary axis,
    // divided by the respective axis real length.
    mandelb.setOrigin(imageWidth/2,imageHeight/2);
    mandelb.setPosition(640,400);
    mandelb.scale(1.5,1.5);
    // Set the image positioning, centering and scaling.
    k.real = 0;
    k.imag = 0;
    // Original K seed values.
    dir = false;
    // Direction of scan over the complex plane
    mandel = false;
    // false if painting Julia Set, true if Mandelbrot Set.
    draw = true;
    // To tell the application to pause or continue drawing, its switched by
    // pressing the right click.
    while (App.isOpen()) {
        sf::Event Event;
        while (App.pollEvent(Event)) {
           // SFML works with an event loop
            if (Event.type == sf::Event::Closed){
            // If the window is closed, close the application
                App.close();
            }
            if( Event.type == Event.MouseButtonReleased
                && Event.mouseButton.button == sf::Mouse::Left){
            // If the left mouse is pressed and released, close the application
                App.close();
            }
            if( Event.type == Event.MouseButtonReleased
                && Event.mouseButton.button == sf::Mouse::Right){
            // If the right mouse is pressed and released, toggle randomness.
                draw = !draw;
            }
        }
        App.clear();
        if(!draw) continue;
        // If false, then stop animating and freeze in the last generated frame.
        resolve();
        //radialScan();
        horizontalScan();
        mandelb.setColor(sf::Color(cx[0], cx[1], cx[2]));
        // Shift the image hue.
        App.draw(mandelb);
        App.display();
    }
    return EXIT_SUCCESS;
}
コード例 #2
0
ファイル: Graphics.cpp プロジェクト: AquaticStanley/Engine
void Graphics::draw(sf::Vector2f position, sf::Vector2f hitbox, sf::Sprite sprite)
{
    sprite.setOrigin(0, hitbox.y);
    sf::Vector2f roundedPosition = sf::Vector2f(position.x - 0.5, position.y - 0.5);

    //Translate position
    translatePosition(roundedPosition, window_);

    //Set Position
    sprite.setPosition(roundedPosition);

    //Scale if necessary
    sprite.scale(hitbox.x / sprite.getTextureRect().width, hitbox.y / sprite.getTextureRect().height);

    window_->draw(sprite);
    return;
}
コード例 #3
0
    void display(sf::RenderWindow* window, std::string pathImage){
        open = true;
            t.loadFromFile(pathImage);
            s = sf::Sprite();
            s.setTexture(t);
            s.scale(window->getSize().y/s.getGlobalBounds().height,window->getSize().y/s.getGlobalBounds().height);
            s.setPosition(window->getSize().x/2 - s.getGlobalBounds().width/2, 0);
        while(open){
            
            sf::Event event;
            while (window->pollEvent(event)) {
                switch (event.type) {
                case sf::Event::Closed:
                    window->close();
                    break;
                case sf::Event::KeyPressed:
                    if (event.key.code == sf::Keyboard::Escape) window->close();
                    break;
                case sf::Event::MouseButtonPressed:
                    if (event.mouseButton.button == sf::Mouse::Left) {
                        open = false;
                    }
                    break;
                default:
                    break;
                }
                if( event.type == sf::Event::KeyPressed ||
                event.type == sf::Event::MouseButtonPressed||
                event.type == sf::Event::TouchEnded           )  open = false;
            }

            window->clear();
            window->draw(s);

            window->display();
                
        }
        
        sf::Clock timer;
        sf::Sprite dark;
        sf::Texture text;
        bool closing = true;
        text.loadFromFile("res/pics/black.png");
        
        dark.setTexture(text);
        dark.setOrigin(dark.getLocalBounds().width/2,dark.getLocalBounds().height/2);
        dark.setPosition(window->getSize().x/2,window->getSize().y/2);
        float scale = 1/dark.getGlobalBounds().width;;
        
        float time = 0;
        while(closing and wantAnimation){            
            dark.setScale(scale,scale);
            time += timer.restart().asSeconds();
            if(time > 0.1){
                scale *= 1.5;
                time = 0;
            }
            window->clear();
            window->draw(s);
            window->draw(dark);
            window->display();
            if(dark.getGlobalBounds().width > window->getSize().x) closing = false;
        }
        //clean events 
        sf::Event e; while (window->pollEvent(e)) { }
    }
コード例 #4
0
void ObjectStyle::scaleBanner(sf::Sprite & sprite)
{
	sf::Vector2i tile = Textures::tilesetUnits().getTileSize();
	sprite.scale(flag_size.x / tile.x, flag_size.y / tile.y);
}