# Help with a when pinched code!

#1

Can someone help me make a when pinched code.

#2

Sorry I don’t know that much about code and math but you just came up with an idea for a new block!

#3

This code requires three variables.
One to measure the x position of where you first tap, one to remember the y position of where you first tap, and one to remember the distance from the second tap to the first tap when you first place down your second finger.

It requires three rules:
1 when is tapped.
In here, we have two check once ifs. The first one is if the first variable, the original tap position, is > than zero, set the third variable, the original distance between the two fingers, to the square root of distance x between last touch and first touch, which we can get by doing last touch x - original last touch, the first variable I mentioned, squared plus the same thing for y squared. If the reason this works isn’t clear, check this out:

The second checks if the first variable is zero. If it is, we set the first variable to last touch x and the second variable to last touch y, in order to record the first tap position.

The second rule is when not pressed.
In here we set all three variables to 0.

The third rule is when pressed.
Here we check if the formula we used above to set the third variable is less than the third variable itself. This means your two fingers have gotten closer together.

Here is my project I made:

#4

#5

Thank you peppyWafer21

#6

Could you go on hopscotch and show me the code?

#7

I put a link in that post

The pinch code is inside of Gonzalo.

#8

I don’t know. That would be a good new block though, like @tankt2016 said.

#9

I don’t think JS would allow that (JavaScript is used to run projects in a web browser)