Skip to content

Commit

Permalink
updated positioning math (assumed user will not change size once star…
Browse files Browse the repository at this point in the history
…ted) (#35)
  • Loading branch information
jeremyknight-me authored Feb 2, 2022
1 parent a08ee15 commit 442ecc1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 2 additions & 0 deletions PhotoCollageWeb/Client/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@
<NavLink class="start-button" href="collage">
Start Collage
</NavLink>

<p>For best results, do not resize window once collage has started.</p>
</div>

15 changes: 10 additions & 5 deletions PhotoCollageWeb/Client/wwwroot/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
}

frame.style.zIndex = `${settings.index}`;
const positionTop = this.getRandomIntFromZeroToMax(100);
const positionLeft = this.getRandomIntFromZeroToMax(100);
const half = settings.maximumSize / 2;
frame.style.left = `calc(${positionLeft}vw - ${half}px)`;
frame.style.top = `calc(${positionTop}vh - ${half}px)`;
const tenPercent = settings.maximumSize * 0.1;
const boundedHeight = window.innerHeight + tenPercent - settings.maximumSize;
const boundedWidth = window.innerWidth + tenPercent - settings.maximumSize;
const positionTop = this.getRandomIntegerInclusive(-tenPercent, boundedHeight);
const positionLeft = this.getRandomIntegerInclusive(-tenPercent, boundedWidth);
frame.style.left = `${positionLeft}px`;
frame.style.top = `${positionTop}px`;
const rotation = this.getRandomIntFromAbsoluteValue(settings.maximumRotation);
frame.style.transform = `rotate(${rotation}deg)`;

Expand Down Expand Up @@ -50,6 +52,9 @@
const maximum = max + 1;
return Math.floor(Math.random() * maximum);
},
getRandomIntegerInclusive: function (min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
},
handleRemovePhotoAnimationEnd: function (e) {
e.target.remove();
}
Expand Down

0 comments on commit 442ecc1

Please sign in to comment.