Adjusting width of sine wave?

I want to create a sine wave which moves horizontally from the screen’s most left to most right position , how can I do this? I draw an “X” character on the screen which moves horizontally on the screen in a sine wave movement style(I did it by the help of online OfBook’s Experimental Game Development section) but I couldn’t understand how I can adjust it so that it moves horizontally from the screen’s most left position to most right position,then from most right position to most left position in a sine wave pattern(and in a repeating pattern), how can I do that?

A short version of my code:


ofPoint pos;
ofTrueTypeFont font1;


void ofApp::setup(){



void ofApp::update(){
   pos.x +=10.0*sin(ofGetElapsedTimef());


void ofApp::draw(){


“X” letter goes from left to right and from right to left in a sine wave pattern,but the problem is I want “X” to go from the most left to most right and from most right to most left(in a repating way) in a sine wave pattern.

You have to use ofMap. sin returns values between -1 and 1. -1 is the left part of your screen, + 1 is the right part of your screen.
something like this would solve your problem

auto maxWidth = getWidth();
pos.x = ofMap(sin(ofGetElapsedTimef()), -1, 1, 0.0, maxWidth);

Thanks, it works! :slight_smile: