![]() ![]() ![]() If you perform this experiment, heads will often come up 10 times, but not always, even though, supposedly, the probability of getting a head on a fair coin toss is 50%. Did the count match your explanation? Based on this experiment, could you conclude that your coin is fair or biased (not fair).Now flip the coin 20 times and count the number of heads.If you flip a fair coin 20 times - any type of coin will do - how many heads would you expect to get? Write down your answer.We'll explore the idea of randomness later in this Unit.īefore getting started on the Coin Flip app, try this simple experiment: unless the "randomness" that's built into App Inventor is not a very good model of true You simulate a coin flip lots of times, it should also come up heads close to 50% of the time You flip a real coin lots of times, it should come up heads close to 50% of the time. In part two, we will extend the app to perform the coin flip many times in order to experiment with the idea of "randomness" or "fairness". The result will be displayed as an image depicting either the heads or tails Heads will be representedīy 1 and tails by 2, and flipping the coin will be a matter of randomly assigning 1 or 2 to The coin will be represented by a global variable. In the first part we will build a simple app that simulatesĪ coin flip. That is, it may come closer than a real coin flip to producing "heads" 50% of the time. It may actually be fairer than a real coin flip. In fact, because it uses App Inventor's random number generator, See the Pen Coin Flip Donate Button by Cooper on CodePen.Coin Flip is an app that simulates a coin flip. The math uses sin/cos wave functions to similate the circular motion of 3D spinĬ(‘–front-scale-multiplier’, Math.max(s(coin.angle), 0))Ĭ(‘–front-y-multiplier’, Math.sin(coin.angle))Ĭ(‘–middle-scale-multiplier’, Math.abs(s(coin.angle), 0))Ĭ(‘–middle-y-multiplier’, s((coin.angle + Math.PI / 2) % Math.PI))Ĭ(‘–back-scale-multiplier’, Math.max(s(coin.angle – Math.PI), 0))Ĭ(‘–back-y-multiplier’, Math.sin(coin.angle – Math.PI))Ĭ(‘–shine-opacity-multiplier’, 4 * Math.sin((coin.angle + Math.PI / 2) % Math.PI) – 3.2)Ĭ(‘–shine-bg-multiplier’, -40 * (s((coin.angle + Math.PI / 2) % Math.PI) – 0.5) + ‘%’)ī(‘clicked’, ‘shrink-landing’, ‘coin-landed’) Calculate the scale and position values for the different coin faces Calculate the scale and position of the coin moving through the airĬ(‘–coin-y-multiplier’, -11 * Math.pow(percentageCompleted * 2 – 1, 4) + 11)Ĭ(‘–coin-x-multiplier’, percentageCompleted)Ĭ(‘–coin-scale-multiplier’, percentageCompleted * 0.6)Ĭ(‘–coin-rotation-multiplier’, percentageCompleted * coin.sideRotationCount) Let percentageCompleted = coin.moveLoopCount / coin.maxMoveLoopCountĬoin.angle = -coin.maxFlipAngle * Math.pow((percentageCompleted – 1), 2) + coin.maxFlipAngle Delay to give the reset animation some time before you can click again Randomize the flipping speeds just for funĬoin.sideRotationCount = Math.floor(Math.random() * 5) * 90Ĭoin.maxFlipAngle = (Math.floor(Math.random() * 4) + 3) * Math.PIĬ(‘–coin-x-multiplier’, 0)Ĭ(‘–coin-scale-multiplier’, 0)Ĭ(‘–coin-rotation-multiplier’, 0)Ĭ(‘–shine-opacity-multiplier’, 0.4)Ĭ(‘–shine-bg-multiplier’, ‘50%’) Wait to start flipping the coin because of the button tilt animation The larger the number, the slower the animation Loop through all buttons (allows for multiple buttons on page) Rotate(calc(var(–coin-rotation-multiplier) * 1deg)) Ĭonst tipButtons = document.querySelectorAll(‘.tip-button’) Transition: opacity 200ms linear 100ms, transform 300ms ease-out īottom: calc(var(–coin-y-multiplier) * 1rem – # / -2)) Transition: height 250ms ease-in-out 400ms, width 250ms ease-in-out 300ms Radial-gradient(circle at 65% 96%, rgba($bg-button, 0.4) 0.06rem, transparent 0.06rem) Make the little confetti looking dots on this wrapper Transition: margin-bottom 1s linear 200ms webkit-tap-highlight-color: transparent ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |