1. Shift-click the 'R' in the Scratch logo.
2. Click "turn fill screen off".
3. Click in the gray area.
4. Click "open...".
5. Click "browser".
6. Navigate to "Scratch-Objects -> ScriptableScratchMorph -> other ops -> mathFunctionNames".
7. Replace the text there with this:
mathFunctionNames
^ #('abs' 'sqrt' 'sin' 'cos' 'tan' 'asin' 'acos' 'atan' 'ln' 'log' 'e ^' '10 ^' 'square' )8. Alt click the text and click accept.
9. If asked, type in your initials.
10. Navigate to "Scratch-Objects -> ScriptableScratchMorph -> other ops -> computeFunction:of:".
11. Replace the text there with this:
computeFunction: t1 of: t2
'abs' = t1 ifTrue: [^ t2 abs].
'sqrt' = t1 ifTrue: [^ t2 sqrt].
'sin' = t1 ifTrue: [^ t2 degreesToRadians sin].
'cos' = t1 ifTrue: [^ t2 degreesToRadians cos].
'tan' = t1 ifTrue: [^ t2 degreesToRadians tan].
'asin' = t1 ifTrue: [^ (t2 within: -1.0 and: 1.0) arcSin radiansToDegrees].
'acos' = t1 ifTrue: [^ (t2 within: -1.0 and: 1.0) arcCos radiansToDegrees].
'atan' = t1 ifTrue: [^ t2 arcTan radiansToDegrees].
'ln' = t1 ifTrue: [^ t2 ln].
'log' = t1 ifTrue: [^ t2 log].
'e ^' = t1 ifTrue: [^ t2 exp].
'10 ^' = t1 ifTrue: [^ 10.0 raisedTo: t2].
'square' = t1 ifTrue: [^ t2 raisedTo: 2].12. Alt-click on the text and click accept.
13. If asked, type in your initials.
14. Close the browser.
15. Shift-click the 'R' in the Scratch logo.
16. Click "turn fillscreen off".
17. Try the new option in the ([abs ^] of (10)) block!
18. Shift-click the 'R' in the Scratch logo.
19. Click "save image for end-user".
20. Click "Yes".
And you're done! This was my first block that I made.
Code for the Scratch source:
_________________________________
mathFunctionNames
"Answer a collection of math function names."
^ #(
'abs'
'sqrt'
'sin'
'cos'
'tan'
'asin'
'acos'
'atan'
'e ^'
'10 ^'
'square')computeFunction: functionName of: aNumber
"Return the result of computing the given mathematical function on the given number."
'abs' = functionName ifTrue: [^ aNumber abs].
'sqrt' = functionName ifTrue: [^ aNumber sqrt].
'sin' = functionName ifTrue: [^ aNumber degreesToRadians sin].
'cos' = functionName ifTrue: [^ aNumber degreesToRadians cos].
'tan' = functionName ifTrue: [^ aNumber degreesToRadians tan].
'asin' = functionName ifTrue: [^ (aNumber within: -1.0 and: 1.0) arcSin radiansToDegrees].
'acos' = functionName ifTrue: [^ (aNumber within: -1.0 and: 1.0) arcCos radiansToDegrees].
'atan' = functionName ifTrue: [^ aNumber arcTan radiansToDegrees].
'ln' = functionName ifTrue: [^ aNumber ln].
'log' = functionName ifTrue: [^ aNumber log].
'e ^' = functionName ifTrue: [^ aNumber exp].
'10 ^' = functionName ifTrue: [^ 10.0 raisedTo: aNumber].
'square' = functionName ifTrue: [^ aNumber raisedTo: 2].
^ 0Last edited by ThePCKid (2010-05-09 19:50:14)
Offline
Offline
Uh, this has no use:
There's already a block that does that.
Sometimes looking at scratch blocks is a good idea.
Offline
Greatdane wrote:
Uh, this has no use:
http://i42.tinypic.com/314uyrq.gif
There's already a block that does that.
Sometimes looking at scratch blocks is a good idea.![]()
Yeah - but that only does 10 to any power - we want any number to any power...
Offline
Greatdane wrote:
Uh, this has no use:
http://i42.tinypic.com/314uyrq.gif
There's already a block that does that.
Sometimes looking at scratch blocks is a good idea.![]()
That does 10^foo.
The block that I made does foo^2.
Offline