This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2010-05-09 19:29:51

ThePCKid
Scratcher
Registered: 2009-09-16
Posts: 1000+

How to make the ([square] of (10)) block

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:

Code:

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:

Code:

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:
_________________________________

Code:

mathFunctionNames
    "Answer a collection of math function names."
    
    ^ #(
        'abs'
        'sqrt'
        'sin'
        'cos'
        'tan'
        'asin'
        'acos'
        'atan'
        'e ^'
        '10 ^'
        'square')

Code:

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].
    
    ^ 0

Last edited by ThePCKid (2010-05-09 19:50:14)

Offline

 

#2 2010-05-10 17:10:38

ThePCKid
Scratcher
Registered: 2009-09-16
Posts: 1000+

Re: How to make the ([square] of (10)) block

Bump

Offline

 

#3 2010-05-10 18:34:45

Greatdane
Scratcher
Registered: 2007-06-05
Posts: 1000+

Re: How to make the ([square] of (10)) block

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.  tongue


The future belongs to those who believe in the beauty of their dreams.
        ~ Eleanor Roosevelt

Offline

 

#4 2010-05-10 18:39:12

Lucario621
Community Moderator
Registered: 2007-10-03
Posts: 1000+

Re: How to make the ([square] of (10)) block

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.  tongue

Yeah - but that only does 10 to any power - we want any number to any power...


http://i.imgur.com/WBkM2QQ.png

Offline

 

#5 2010-05-10 18:44:52

ThePCKid
Scratcher
Registered: 2009-09-16
Posts: 1000+

Re: How to make the ([square] of (10)) block

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.  tongue

That does 10^foo.
The block that I made does foo^2.

Offline

 

Board footer