We are about to switch to a new forum software. Until then we have removed the registration on this forum.
int x = 0;
int y = 0;
int valx;
int valy;
void setup() {
size(200, 200);
background(0);
}
void draw() {
valx = map(x, 0, 195, 0, 80);
valy = map(y, 0, 195, 0, 80);
println("X" + " ", mouseX, " Y" + " ", mouseY);
}
i even try this and nothing
valx = map(x, mouseX, mouseX, 0, 80);
valy = map(y, mouseY, mouseY, 0, 80);
Answers
Here's one way to use the function:
@Eeyorelife where are you getting this values from?
and more importantly why did you ignore my map value of 0, 80); ? this is the most important part of the map being used.
this is debugging
println("X ", valx, " Y ", valy);
I didn't know which numbers were important or not, I just made an example where you have a video of height 600 and width 800.
The thing is, you were displaying the mouseX and mouseY, which doesn't change whether you map some numbers or not.
he's mapping the range mouseX to mouseX onto the range 0 to 80
but the range mouseX to mouseX is nonsensical, there is no range there as both values are the same.
tbh i'm struggling with this question due to lack of details. 'map the screen size of a video'? what does that mean? map it to what?
@koogs what do you mean map it to what ?? lol it says right there map it to 80 im not sure why is that so hard to comprehend ? map the range of the screen to the range of 80 so 0 x 0 y map that to 0 range of x and 0 range of y so that when the mouse gets dragged across the entire screen we always have range of 0 through 80 no matter where in the screen you have gone, but obviously the more you travel outside of screen x and y the more you increment on the rang of 0-80
If you read map()'s reference: https://processing.org/reference/map_.html
You'll see it doesn't clamp/constrain the resultant range in any way:
For that we need to use constrain(): https://Processing.org/reference/constrain_.html
hmmm i come from arduino and in arduino this action im looking to do would do just that, i thought processing was just like arduino, though i must say im not looking to constrain anything i want to be able to move across the entire screen
AFaIK, when converting some range to another range via map(), we've gotta be "frank" about the actual range of the former.
mouxeX's range is from
0
up towidth - 1
. mouxeY's range is from0
up toheight - 1
.Let's say you wanna convert that range pair to vid.width, vid.height:
That's pretty much like @Eeyorelife's former solution btW. :>
BUT AGAIN where is my 80 >? why do you guys keep taking my 80 out of the map THIS IS WHAT I WANT TO MAP IT TO ! lol do we need to do 2 diff map functions and then contain one map function inside a variable then use that variable to use it in the second map call ?
mouseX and mouseY AND screen width & height should be the same thing?! the second should be that 0, 80);
finally why is the screen datatype a float? there is no 0.0 is 0-what ever the size of the screen in pixels thats a int not a float even RGB's are int
the lack of punctuation?
you still understood what i said right? is not like that dot was going to translate my msg into something else right? and is not like you had to hold your breathe till your done reading right?
come on now what is this grammar academy ? if i had the same education as you i wouldn't be here asking question.
vid.height can be ANYTHING. You can switch it out with 80 if that's the perfect number!
What do you want to map? You want to map "it" to the range 0 - 80, but what is "it"?
mouseX and mouseY are not one value, they can be any value from 0 to width/height-1. width and height, once they are set with size(), are one value.
In a sketch with size(200,200) you have 200 pixels on the x-axis and 200 pixels on the y-axis. But you can place a point between two pixels (150.5). So in order to be able use those in-between points you will have to use a float.
Processing doesn't detect your mouse position outside of the window you are running, so you won't get a value larger than 79.6.
three people here don't understand the question. which suggests the question is unclear.
and all their attempts at answers or asking you to clarify have been met with derision.
you're the one wanting help. try and be clearer. and yes, punctuation and proper sentences do help.
alternatively, draw us a picture.
Actually pixels are always integral values. When it comes the time to render them, coordinates are automatically round() 1st. ;)
My new theory is what he's actually looking for is mouse to rectangle intersection. >-)
That is, he wants to know whether the mouse pointer is hovering above his Movie frame.
i think he just wants to map mouse position to 0-80 -
map(mouseX, 0, width, 0, 80);
but possibly with the added complication that he wasn't to use the full width of the screen, not just the processing window. which means he'll need to use java.awt.Robot (which i've never used. does it even work with processing3?)
i think the 'video' in the subject line is irrelevant and has thrown us all off.
Guys first of thanks for trying without the attitude i get into huge fights with people over stack exchange because they want to be smart asses and they assume that everyone is as "smart as they are" (NOT!), you guys really try and i appreciate it a lot!
NOW for @GoToLoop thanks for enforcing my point about the int in pixels i been really hard core on Daniel Shiftman youtube's so i think i knew what i was saying was true, as far as what im trying to do i think out of everyone @Eeyorelife should have a more clear idea of what im looking to do considering that i wrote him a personal msg being extremely detail with supporting example code, so im not sure why is he even asking?! oh well i guess ima have to say whats the dam 80 for lol specially since @Koogs keep reiterating what everyone's vote here is the not understanding where im going.
Guys that 80 is the degrees in range of my servo over at arduino, im trying to do Visual Servoing i already am controlling the servo using the mouse so now i want to NOT use the mouse and use the face detection found in OpenCV in Processing as the mouse, "so rather then the mouse be hovering over the video screen and thus the servo moves across it following it.
NOW as Koogs just stated about the throwing off THIS IS THE MAIN REASON why i did not want to mention anything about the 80 cuz i just wanted you guys to focus on the current issue which is the MAP FUNCTION, feel me? if i would of just chub the whole entire sketch in here which is in many tabs not all in one i would of been here all day just copy and pasting and then another entire day talking about my way of programming and another day talking about why my approach and THIS is what i did not want.
Processing already has a servo mouse follow sketch which i been complaining about on the github for awhile now because they uploaded a sketch that does not work and they want to give me attitude because i called dem out on the sloppy job, like what da hell i thought feedback was how people get better not by ignoring it or fighting with those who found bugs or issues with their uploads
This assumes that ocvX / ocvY represents a pixel position in the video frame and that the video size is videoWidth x videoHeight. This position is mapped to the range 0-80 for the arduino
You sendt me the whole code and this: "thats what im looking to fix without the drawing of the bar"
I am still confused, do you want to map the valuea of the mouse position or not? If you do then @koogs has already given you this:
map(mouseX, 0, width, 0, 80);
why cant i get the draw3 to over lap the draw2 ? @Quark i had this issue before with merging one of your old game example and as you can see i never actually learned nothing about what you were trying to get me to do because im now faced with the same issue as before with another completely diff code
Which version of Processing are you using?
2.2.1
@Eeyorelife i have already made myself clear in my long most recent msg
I can't run your code example above because it doesn't recognize the library imported with
import gab.opencv.*;
why is it so hard to map the area of the screen using pixel to send the values over to serial over to the Servo
why cant i just use
so that the servo can just follow my face ?
everything runs good with no issues, face detection works camera is obviously running and the arduino tx/rx is flickering fast implying that it is getting values. so WTF?
thanks, i guess
Have you checked the values being sent? Are they valid?
For your mapping use.
i cant if i knew how i would of love to attack it that way but the thing is that while processing is using serial i cant use serial on the arduino else i would ,the same goes for arduino if i have terminal open i cant open serial on the processing
is there a way ?
I have never used the serial or arduino so I can't help you there. Sorry.
i dont get it why ask if i checked the values unless you knew how to ? i dont think you would have considered something unless you knew how to right?
This thread went somewhere I wasn't expecting...
Beware that the scale on line 29 will stay in effect for the rest of the draw(), including all of draw3(). You can stop this by putting pushMatrix() and popMatrix() around draw2.
thank you @Koogs the issue is that i cant see draw 2 if im using draw3 so i have to comment out one to use the other one, so your saying that using pushMatrix() will solve that issue?
once i learn how to use one function on top of the other i will be satisfy and learn from that block of code for future sketches but as in right now i get video from draw2 and draw3 is somewhere in the background still working but not seen through out the draw() process and my objective is to display draw3 over draw2
The scale(2) in draw2 will double all the values in draw3 meaning they are off screen...
(I'll write something showing this when it's not 4am)
this fills the screen in draw2 the same way your video does. then draws the bars like your draw3 does. all the numbers are identical to yours.
if you run this as i pasted it you will see the bars but only at the very bottom.
if you change the two commented lines in draw2 (11, 15) so they are no longer commented and run it again you'll see that they are now central.
basically the scale(2) in draw2 applies to everything after it, even it it's in a different method, unless you surround it by pushMatrix/popMatrix...
@koogs one last thing, how would i go about flipping the image or mirror the image ?
untested but...
but beware that if you have a rectangle (0, 0, x, y) that'll end up at (0, 0, -x, y), which is probably off screen. so you have to change the coords too to compensate (or use rectMode center, or translate everything so that origin is in the center of the screen)
no i meant to mirror the video, because im using the video function twice in one screen but i want the right side to mirror the first video "left" you know?
/********************************/
yeah, that should just work. if you reflect an image it reflects the image. and a video is just an image.
annoyingly i did exactly this for some other question a couple of weeks ago but can't find it now...
hmmm dam this is not working
also i did just
and
nothing adding those negative value just makes the second screen go away
i said it would unless you also changed the coords. it's printing the second image at -x or -y, offscreen.
i own you a beer koogs thanks!
cool. we got there in the end 8)