I do not have a mac, but my friend asked me to do a quick program and I made it to find out he is on a mac. So can you compile this for a mac (32 bits) and also include and linked libraries? (Don't know what they are on mac)
#include <cmath>
#include <SFML/Graphics/Image.hpp>
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Graphics/Sprite.hpp>
#include <SFML/Window/Input.hpp>
#include <SFML/System/Randomizer.hpp>
using namespace sf;
const int W_WIDTH = 1200;
const int W_HEIGHT = 600;
float scaleFactor = 1;
float speed = 4;
Image gradientImage;
Sprite gradient;
int getRepetitions() {
return (int) (W_WIDTH/(gradientImage.GetWidth()*scaleFactor)) + 10;
}
float getWidth() {
return gradientImage.GetWidth()*scaleFactor;
}
void setRandomDirection() {
int random = Randomizer::Random(0,1);
if (random == 0) speed = -speed;
}
int main(int argc, char **argv) {
RenderWindow window(VideoMode(W_WIDTH,W_HEIGHT,24), "Optokinetic Simulator");
const Input & inp = window.GetInput();
gradientImage.LoadFromFile("gradient.png");
gradient.SetImage(gradientImage);
gradient.SetScaleY((float) W_HEIGHT);
Event e;
while (window.IsOpened()) {
while (window.GetEvent(e)) {
if (e.Type == Event::Closed)
window.Close();
if (inp.IsKeyDown(Key::Up)) {
setRandomDirection();
scaleFactor /= 1.3;
gradient.SetScaleX(scaleFactor);
}
if (inp.IsKeyDown(Key::Down)) {
setRandomDirection();
scaleFactor *= 1.3;
gradient.SetScaleX(scaleFactor);
}
}
window.Clear(Color(0,0,0)); //Set background to black
//Loop moving sequence
if (abs((int)gradient.GetPosition().x) > getWidth()*5) gradient.SetPosition(0,0);
else gradient.Move(speed,0);
Vector2f originalPos = gradient.GetPosition(); //To restore position after we are done drawing repetitions of the image
for (int i = -5; i < getRepetitions(); ++i) {
gradient.SetPosition(originalPos.x+i*getWidth(), -230); //Some bug in SFML?
if (gradient.GetPosition().x <= W_WIDTH) window.Draw(gradient);
}
gradient.SetPosition(originalPos);
window.Display();
}
return 0;
}
Please and thank you.
If mac wasn't so proprietary I could've done it myself. Sorry.
If you could also look over the code, the gradient is 1 pixel high, and I have to set the location of the image to be -230 in the y axis. I do not know why it doesn't start at 0,0 after I scale it.