pxt-common-packages 12.3.30 → 12.3.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/built/common-sim.js +2 -1
  2. package/libs/accelerometer/built/debug/binary.js +8 -8
  3. package/libs/azureiot/built/debug/binary.js +461 -461
  4. package/libs/base/docs/reference/math/constant.md +131 -0
  5. package/libs/base/math.ts +29 -5
  6. package/libs/color/built/debug/binary.js +8 -8
  7. package/libs/color-sensor/built/debug/binary.js +8 -8
  8. package/libs/controller/built/debug/binary.js +7388 -7377
  9. package/libs/controller---none/built/debug/binary.js +7368 -7357
  10. package/libs/core/built/debug/binary.js +2 -2
  11. package/libs/core---samd/built/debug/binary.js +8 -8
  12. package/libs/datalogger/built/debug/binary.js +63 -63
  13. package/libs/edge-connector/built/debug/binary.js +8 -8
  14. package/libs/esp32/built/debug/binary.js +462 -462
  15. package/libs/game/built/debug/binary.js +7307 -7296
  16. package/libs/game/sprite.ts +4 -0
  17. package/libs/gamepad/built/debug/binary.js +8 -8
  18. package/libs/keyboard/built/debug/binary.js +8 -8
  19. package/libs/lcd/built/debug/binary.js +8 -8
  20. package/libs/light/built/debug/binary.js +8 -8
  21. package/libs/light-spectrum-sensor/built/debug/binary.js +8 -8
  22. package/libs/lora/built/debug/binary.js +8 -8
  23. package/libs/matrix-keypad/built/debug/binary.js +8 -8
  24. package/libs/microphone/built/debug/binary.js +8 -8
  25. package/libs/mouse/built/debug/binary.js +8 -8
  26. package/libs/mqtt/built/debug/binary.js +176 -176
  27. package/libs/music/built/debug/binary.js +8 -8
  28. package/libs/net/built/debug/binary.js +176 -176
  29. package/libs/net-game/built/debug/binary.js +9024 -9013
  30. package/libs/palette/built/debug/binary.js +7306 -7295
  31. package/libs/pixel/built/debug/binary.js +8 -8
  32. package/libs/power/built/debug/binary.js +8 -8
  33. package/libs/proximity/built/debug/binary.js +8 -8
  34. package/libs/pulse/built/debug/binary.js +8 -8
  35. package/libs/radio/built/debug/binary.js +8 -8
  36. package/libs/radio-broadcast/built/debug/binary.js +8 -8
  37. package/libs/rotary-encoder/built/debug/binary.js +8 -8
  38. package/libs/screen/built/debug/binary.js +50 -50
  39. package/libs/screen/sim/image.ts +4 -3
  40. package/libs/servo/built/debug/binary.js +8 -8
  41. package/libs/sprite-scaling/built/debug/binary.js +7306 -7295
  42. package/libs/storyboard/built/debug/binary.js +7304 -7293
  43. package/libs/tests/built/debug/binary.js +15 -15
  44. package/libs/thermometer/built/debug/binary.js +8 -8
  45. package/package.json +1 -1
@@ -0,0 +1,131 @@
1
+ # Constant
2
+
3
+ A common mathematical constant value.
4
+
5
+ ```sig
6
+ Math._constant(Math.PI)
7
+ ```
8
+
9
+ There are several constant values that are important in calculations for science and engineering. The ``||math.constant||`` block provides several that you can use in your mathematical formulas and expressions.
10
+
11
+ ## π
12
+
13
+ The value of Pi (π) which is the ratio of a circle's circumference to its diameter.
14
+
15
+ ```block
16
+ Math._constant(Math.PI)
17
+ ```
18
+
19
+ ### Example
20
+
21
+ Get the area of a circle with a radius of `4`.
22
+
23
+ ```block
24
+ let circle_area = Math.PI * 4**2
25
+ ```
26
+
27
+ ## e
28
+
29
+ Euler's number (e) which is the base of the natural logrithm and the exponential function.
30
+
31
+ ```block
32
+ Math._constant(Math.E)
33
+ ```
34
+
35
+ ### Example
36
+
37
+ Find the half-life, in years, of radioactive decay for Carbon-14.
38
+
39
+ ```block
40
+ let time = 0
41
+ let decay = 0.000121
42
+ let carbon14 = 1
43
+ while (carbon14 > 0.5) {
44
+ carbon14 = Math.E ** (-1 * decay * time)
45
+ time += 1
46
+ }
47
+ ```
48
+
49
+ ## ln(2)
50
+
51
+ Natural log of 2.
52
+
53
+ ```block
54
+ Math._constant(Math.LN2)
55
+ ```
56
+
57
+ ### Example
58
+
59
+ Find out how many years will it take to double an investment using continuous compounding at 5% interest.
60
+
61
+ ```block
62
+ let years = Math.LN2 / 0.05
63
+ ```
64
+
65
+ ## ln(10)
66
+
67
+ Natural log of 10.
68
+
69
+ ```block
70
+ Math._constant(Math.LN10)
71
+ ```
72
+
73
+ ### Example
74
+
75
+ How many days will it take for bacteria in a culture to reach 10 times the start amount if they double in number each day.
76
+
77
+ ```block
78
+ let days = Math.LN10
79
+ ```
80
+
81
+ ## log₂(e)
82
+
83
+ Convert from a natural logrithm to a base-2 logrithm.
84
+
85
+ ```block
86
+ Math._constant(Math.LOG2E)
87
+ ```
88
+
89
+ The log₂(e) constant is equal to ln(e) / ln(2) which is also 1 / ln(2).
90
+
91
+ ## log₁₀(e)
92
+
93
+ Convert from a natural logrithm to a base-10 logrithm.
94
+
95
+ ```block
96
+ Math._constant(Math.LOG10E)
97
+ ```
98
+
99
+ The log₁₀(e) constant is equal to 1 / ln(10) which is also 1 / ln(10).
100
+
101
+ ## √½
102
+
103
+ The square root of one half (1/2).
104
+
105
+ ```block
106
+ Math._constant(Math.SQRT1_2)
107
+ ```
108
+
109
+ ### Example
110
+
111
+ Find the length of the sides of a square with a diagonal length of 9.
112
+
113
+ ```block
114
+ let side = 9 * Math.SQRT1_2
115
+ ```
116
+
117
+ ## √2
118
+
119
+ The square root of 2.
120
+
121
+ ```block
122
+ Math._constant(Math.SQRT2)
123
+ ```
124
+
125
+ ### Example
126
+
127
+ Find out how much shorter it is by walking across a square parking lot on a street corner than using the sidewalk on the sides. Each side of the parking lot is 50 meters.
128
+
129
+ ```block
130
+ let walk_diff = 2 * 50 - 50 * Math.SQRT2
131
+ ```
package/libs/base/math.ts CHANGED
@@ -1,12 +1,27 @@
1
1
  namespace Math {
2
-
2
+ //% blockIdentity="Math._constant"
3
+ //% block="π"
4
+ export const PI = 3.141592653589793;
5
+ //% blockIdentity="Math._constant"
6
+ //% block="e"
3
7
  export const E = 2.718281828459045;
8
+ //% blockIdentity="Math._constant"
9
+ //% block="ln(2)"
4
10
  export const LN2 = 0.6931471805599453;
11
+ //% blockIdentity="Math._constant"
12
+ //% block="ln(10)"
5
13
  export const LN10 = 2.302585092994046;
14
+ //% blockIdentity="Math._constant"
15
+ //% block="log₂(e)"
6
16
  export const LOG2E = 1.4426950408889634;
17
+ //% blockIdentity="Math._constant"
18
+ //% block="log₁₀(e)"
7
19
  export const LOG10E = 0.4342944819032518;
8
- export const PI = 3.141592653589793;
20
+ //% blockIdentity="Math._constant"
21
+ //% block="√½"
9
22
  export const SQRT1_2 = 0.7071067811865476;
23
+ //% blockIdentity="Math._constant"
24
+ //% block="√2"
10
25
  export const SQRT2 = 1.4142135623730951;
11
26
 
12
27
  /**
@@ -22,7 +37,7 @@ namespace Math {
22
37
  //% inlineInputMode=inline
23
38
  export function map(value: number, fromLow: number, fromHigh: number, toLow: number, toHigh: number): number {
24
39
  return ((value - fromLow) * (toHigh - toLow)) / (fromHigh - fromLow) + toLow;
25
- }
40
+ }
26
41
 
27
42
  /**
28
43
  * Constrains a number to be within a range
@@ -59,7 +74,7 @@ namespace Math {
59
74
  let b = b_m16[s2];
60
75
  let m16 = b_m16[s2+1];
61
76
  let mx = (m16 * secoffset) >> 4;
62
-
77
+
63
78
  let y = mx + b;
64
79
  if( theta & 0x80 ) y = -y;
65
80
 
@@ -69,13 +84,22 @@ namespace Math {
69
84
  }
70
85
 
71
86
  /**
72
- * Returns the cosine of an input angle. This is an 8-bit approximation.
87
+ * Returns the cosine of an input angle. This is an 8-bit approximation.
73
88
  * @param theta input angle from 0-255
74
89
  */
75
90
  //% help=math/icos weight=10 advanced=true blockGap=8
76
91
  export function icos(theta: number) {
77
92
  return isin(theta + 16384);
78
93
  }
94
+
95
+ //% shim=TD_ID
96
+ //% block="$MEMBER"
97
+ //% constantShim
98
+ //% weight=0
99
+ //% help=math/constant
100
+ export function _constant(MEMBER: number): number {
101
+ return MEMBER;
102
+ }
79
103
  }
80
104
 
81
105
  namespace Number {
@@ -56,7 +56,7 @@ const pxsim_pxtrt = pxsim.pxtrt;
56
56
  const pxsim_numops = pxsim.numops;
57
57
 
58
58
 
59
- function _main___P141198(s) {
59
+ function _main___P141246(s) {
60
60
  let r0 = s.r0, step = s.pc;
61
61
  s.pc = -1;
62
62
 
@@ -66,19 +66,19 @@ if (yieldSteps-- < 0 && maybeYield(s, step, r0) || runtime !== pxsim.runtime) re
66
66
  switch (step) {
67
67
  case 0:
68
68
 
69
- globals._intervals___141441 = (undefined);
70
- globals._pollEventQueue___141454 = (undefined);
69
+ globals._intervals___141490 = (undefined);
70
+ globals._pollEventQueue___141503 = (undefined);
71
71
  r0 = undefined;
72
72
  return leave(s, r0)
73
73
  default: oops()
74
74
  } } }
75
- _main___P141198.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"colorbuffer.ts","functionName":"<main>","argumentNames":[]}
76
- _main___P141198.continuations = [ ]
75
+ _main___P141246.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"colorbuffer.ts","functionName":"<main>","argumentNames":[]}
76
+ _main___P141246.continuations = [ ]
77
77
 
78
- function _main___P141198_mk(s) {
78
+ function _main___P141246_mk(s) {
79
79
  checkStack(s.depth);
80
80
  return {
81
- parent: s, fn: _main___P141198, depth: s.depth + 1,
81
+ parent: s, fn: _main___P141246, depth: s.depth + 1,
82
82
  pc: 0, retval: undefined, r0: undefined, overwrittenPC: false, lambdaArgs: null,
83
83
  } }
84
84
 
@@ -88,5 +88,5 @@ function _main___P141198_mk(s) {
88
88
 
89
89
  const breakpoints = setupDebugger(1, [])
90
90
 
91
- return _main___P141198
91
+ return _main___P141246
92
92
  })
@@ -56,7 +56,7 @@ const pxsim_pxtrt = pxsim.pxtrt;
56
56
  const pxsim_numops = pxsim.numops;
57
57
 
58
58
 
59
- function _main___P98756(s) {
59
+ function _main___P98792(s) {
60
60
  let r0 = s.r0, step = s.pc;
61
61
  s.pc = -1;
62
62
 
@@ -66,19 +66,19 @@ if (yieldSteps-- < 0 && maybeYield(s, step, r0) || runtime !== pxsim.runtime) re
66
66
  switch (step) {
67
67
  case 0:
68
68
 
69
- globals._intervals___98999 = (undefined);
70
- globals._pollEventQueue___99012 = (undefined);
69
+ globals._intervals___99036 = (undefined);
70
+ globals._pollEventQueue___99049 = (undefined);
71
71
  r0 = undefined;
72
72
  return leave(s, r0)
73
73
  default: oops()
74
74
  } } }
75
- _main___P98756.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"tcs34725.ts","functionName":"<main>","argumentNames":[]}
76
- _main___P98756.continuations = [ ]
75
+ _main___P98792.info = {"start":0,"length":0,"line":0,"column":0,"endLine":0,"endColumn":0,"fileName":"tcs34725.ts","functionName":"<main>","argumentNames":[]}
76
+ _main___P98792.continuations = [ ]
77
77
 
78
- function _main___P98756_mk(s) {
78
+ function _main___P98792_mk(s) {
79
79
  checkStack(s.depth);
80
80
  return {
81
- parent: s, fn: _main___P98756, depth: s.depth + 1,
81
+ parent: s, fn: _main___P98792, depth: s.depth + 1,
82
82
  pc: 0, retval: undefined, r0: undefined, overwrittenPC: false, lambdaArgs: null,
83
83
  } }
84
84
 
@@ -88,5 +88,5 @@ function _main___P98756_mk(s) {
88
88
 
89
89
  const breakpoints = setupDebugger(1, [])
90
90
 
91
- return _main___P98756
91
+ return _main___P98792
92
92
  })