Modify snippets/examples relying of fp div (#2571)

This commit is contained in:
Galen Nickel
2020-01-08 10:51:17 -08:00
committed by GitHub
parent c8443ec368
commit 029a06bbe9
2 changed files with 7 additions and 12 deletions

View File

@ -50,10 +50,8 @@ This method of filling coordinate points, counting them, and using the differenc
## Monte Carlo approximation of _pi_
```blocks
let pir = 0
let pid = 0
let pi = 0
let y = 0
let pin = 0
let x = 0
let r2 = 0
let r = 0
@ -87,10 +85,7 @@ basic.forever(() => {
// r * r * pi => inside / n ~= (r*r*pi) / (4*r*r) ~=
// pi / 4 pi = inside / n * 4
//
pin = inside * 4
// only integer arithmetic here...
pid = pin / n
pir = pin % n
pi = (inside * 4) / n
// show results
basic.showLeds(`
# # # # #
@ -99,6 +94,6 @@ basic.forever(() => {
. # . # .
. # . . #
`)
basic.showString(" " + pid + "." + pir)
basic.showString(" " + pi)
})
```

View File

@ -15,7 +15,7 @@ basic.forever(function() {
led.plot(eggX, eggY)
basic.pause(300)
let accX = input.acceleration(Dimension.X)
basketX = 2 + Math.min(2, Math.max(-2, accX / 200))
basketX = 2 + Math.min(2, Math.max(-2, Math.idiv(accX, 200)))
led.plot(basketX, 4)
if (eggY > 4) {
eggY = -1
@ -46,7 +46,7 @@ basic.forever(function() {
led.plot(eggX1, eggY1)
basic.pause(300)
let accX = input.acceleration(Dimension.X)
basketX1 = 2 + Math.min(2, Math.max(-2, accX / 200))
basketX1 = 2 + Math.min(2, Math.max(-2, Math.idiv(accX, 200)))
led.plot(basketX1, 4)
if (eggY1 > 4) {
eggY1 = -1
@ -85,7 +85,7 @@ basic.forever(function() {
led.plot(eggX2, eggY2)
basic.pause(300)
let accX2 = input.acceleration(Dimension.X)
basketX2 = 2 + Math.min(2, Math.max(-2, accX2 / 200))
basketX2 = 2 + Math.min(2, Math.max(-2, Math.idiv(accX2, 200)))
led.plot(basketX2, 4)
if (eggY2 > 4) {
eggY2 = -1
@ -124,7 +124,7 @@ basic.forever(function() {
led.plot(eggX3, eggY3)
basic.pause(300)
let accX3 = input.acceleration(Dimension.X)
basketX3 = 2 + Math.min(2, Math.max(-2, accX3 / 200))
basketX3 = 2 + Math.min(2, Math.max(-2, Math.idiv(accX3, 200)))
led.plot(basketX3, 4)
if (eggY3 > 4) {
eggY3 = -1