# Smooth Moving code

**URL:** https://discourse.processing.org/t/smooth-moving-code/7126
**Category:** Coding Questions
**Created:** [January 3, 2019, 4:17am UTC](https://discourse.processing.org/t/smooth-moving-code/7126 "2019-01-03T04:17:38Z")
**Posts on this page:** 1
**Showing post:** 6

<div class="post-metadata">

### Author: ![Architector\_4](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/architector_4/32/813_2.png) [@Architector\_4](https://discourse.processing.org/u/Architector_4)
#### Post date: [January 4, 2019, 5:04am UTC](https://discourse.processing.org/t/smooth-moving-code/7126/6 "2019-01-04T05:04:28Z")

</div>

Yes, `>>` and `<<` are bit-shifting operations. Doing `number<<1` shifts bits one to the left, effectively doubling the number - a little bit faster alternative to `number*2`. Doing `number>>1` shifts bits one to the right , effectively halving the number - a faster alternative to `number/2`.  
It’s not applicable to `float`s and `double`s though, as you can’t just bit-shift these to halve/double them, unlike with `byte`s, `short`s, `integer`s, `long`s etc…

And yes, `constrain(a,b,c)` function could be completely replaced with `min(max(a,b),c)`. So, his code could be understood easier as:

```auto
void move() {
    x = min(max(x + v*(int(isRight) - int(isLeft)), d>>1) , width - (d>>1));
    y = min(max(y + v*(int(isDown) - int(isUp)), d>>1) , height - (d>>1));
  }

```

It calculates how much `x` and `y` should change based on keys, and then clamps it between half the diameter and the other side minus half the diameter, resulting in the `Player`'s edge aligning with the borders of the screen.

---

_[View the full topic](https://discourse.processing.org/t/smooth-moving-code/7126)._
