Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1010283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T09:03:32+00:00 2026-05-16T09:03:32+00:00

Using the Openframeworks library in C++, I have the radius of a glow (max_distance)

  • 0

Using the Openframeworks library in C++, I have the radius of a glow (max_distance) that is determined by the stretch of the mouse dragging across the screen (mouseDragX). It works fine.

But rather than every time I resize it (by dragging the mouse), I want it not to start at 0 and follow the mouse drag directly.

max_distance = mouseDragX/2;

But rather, if I have already dragged the mouse to the right to say 200 on a previous drag, that the next time I drag the mouse, and go into the opposite direction (negative numbers) that the value of max_distance decreases by that amount, instead of just being that amount.

I thought it would be

max_distance += mouseDragX/2;

but that seems to kill it altogether

Can you help me?

#include "testApp.h"


//--------------------------------------------------------------
void testApp::setup(){   

ofSetWindowShape(700,700);
max_distance = 700; // ofDist didn't work(?) // ofDist(0,0,700,700);
ofEnableSmoothing();
ofEnableAlphaBlending();


}

//--------------------------------------------------------------
void testApp::update(){
max_distance = mouseDragX/2;
if (max_distance < 0) max_distance = 0;
}

//--------------------------------------------------------------
void testApp::draw(){


string str = "mouseDragX: ";
str += ofToString(mouseDragX)+" ";
ofSetWindowTitle(str);

int i,j;
int height = ofGetHeight();
int width = ofGetWidth();

for(i = 0; i <= height; i += 20) {
   for(j = 0; j <= width; j += 20) {
      float dist_color = getDistance(mouseX, mouseY, i, j); // for definition of getDistance, look below!
      dist_color = dist_color/max_distance * 100;

  // to get the colors into the range between 0 and 255, multiply the values by 5.
  ofSetColor(dist_color*5,dist_color*5,dist_color*5, 123);
  ofEllipse(i, j, 20, 20);
  }
  }


}

//--------------------------------------------------------------
void testApp::keyPressed  (int key){

}

//--------------------------------------------------------------
void testApp::keyReleased  (int key){

}

//--------------------------------------------------------------
void testApp::mouseMoved(int x, int y ){
// shift values down
for (int i = 0; i < 1; /*<<- length of array*/ i++) {
pmouseX[i] = pmouseX[i+1];
pmouseY[i] = pmouseY[i+1];
}
// make pmouseX/Y[0] be the previous mouse position. [1] = current
pmouseX[1] = mouseX;
pmouseY[1] = mouseY;

}

//--------------------------------------------------------------
void testApp::mouseDragged(int x, int y, int button){

mouseDragX = (mouseX - pmouseX[0]);

}

//--------------------------------------------------------------
void testApp::mousePressed(int x, int y, int button){
// mouseDragX = mouseDragY = 0;  // The drag starts here
}

//--------------------------------------------------------------
void testApp::mouseReleased(){

}

float testApp::getDistance(int startX, int startY, int endX, int endY){
return sqrt((endX-startX)*(endX-startX) + (endY-startY)*(endY-startY));
}

Thank you so much.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T09:03:33+00:00Added an answer on May 16, 2026 at 9:03 am

    If I understand correctly, you want todo something like this.

    // Every time the mouse *stops* moving, (say on mouse-up
    // message) save previous max_distance
    int base = max_distance;
    
    // when mouse moves
    max_distance = base + mouseDragX/2;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working using openFrameworks, on a problem that is posted on the
Using EF Code First I have an model object that has multiple properties that
Using report builder 3.0, I have a report that queries a cube. How do
I'm starting a project using the Aubio library within openFrameworks , so I'm copying
Using CRM 4, I have an entity form that contains a tab with an
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
Using Android 2.1+. I have a service that gets killed from time to time
Using Rails 3.1. I have some pages that render same layout, except the contents
Using Nunit, I want to be able to write a test fixture that will
Using C# for ASP.NET and MOSS development, we often have to embed JavaScript into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.