#6 2011-03-16 15:58:03

YourLocalBlockLib
Scratcher
Registered: 2011-03-10
Posts: 100+

Re: ITopic: Welcome to your local block library!

Sensing
/img/tinypic/rc3i41.jpg

/img/dropbox/BlockLibDiv2.png

/img/weebly/6956901.gif Shared by midnightleopard
blockspec:

('%j %s' #- #doThis:on:)

code (place under sensing ops)

Code:

doThis: t1 on: t2 
    'google' = t1 ifTrue: [ScratchPlugin primOpenURL: 'http://www.google.com/#sclient=psy&hl=en&q=' , t2 , '&aq=f&aqi=g5&aql=&oq=&gs_rfai=&pbx=1&fp=ab5cdb1806fef4aa&safe=activet1'].
    'yahoo' = t1 ifTrue: [ScratchPlugin primOpenURL: 'http://search.yahoo.com/search;_ylt=Aj.OqjGVrkBmY6mZqA_PSu.bvZx4?p=' , t2 , '&toggle=1&cop=mss&ei=UTF-8&fr=yfp-t-701'].
    'scratch.mit.edu/' = t1 ifTrue: [ScratchPlugin primOpenURL: 'http://scratch.mit.edu/' , t2].
    'search scratch for' = t1 ifTrue: [ScratchPlugin primOpenURL: 'http://scratch.mit.edu/pages/results?cx=010101365770046705949:gg_q9cry0mq&cof=FORID:11&q=' , t2 , '&safe=active&sa=search'].
    'IMDB' = t1 ifTrue: [ScratchPlugin primOpenURL: 'http://www.imdb.com/find?s=all&q=' , t2].
    'load' = t1 ifTrue: [^ 0].
    ^ 0

Code (Scratch-Blocks -> CommandBlockMorph -> private -> uncoloredArgMorphFor:
add a line:

$j = t2 ifTrue: [^ ChoiceArgMorph new getOptionsSelector: #engineNames;
         choice: 'google'].

Last bit of code (Scratch-Objects -> ScriptableScratchMorph -> sensing ops ->)

engineNames
    ^ #('google' 'yahoo' 'scratch.mit.edu/' 'search scratch for' 'IMDB' 'load' )

What it does:
Lets you search google, yahoo!, the scratch site, scratch.mit.edu and IMDB! (Opens your default web browser.)

/img/dropbox/BlockLibDiv2.png

/img/weebly/825264504.gif Shared by Hardmath123.
Blockspec:

('costume center' #r #rotationCenter)

Code:
no code needed
What it does:
Reports the costume center.

/img/dropbox/BlockLibDiv2.png

/img/tinypic/5bqjxh.jpg/img/weebly/1875422.gif
Shared by LS97
blockspec:

('get %s' #r #getTime: 'date')

Code

getTime: t1
    t1 = 'date' ifTrue: [^ Date today].
    t1 = 'short date' ifTrue: [^ Date today printFormat: #(1 2 3 $- 2 2 )].
    t1 = 'time' ifTrue: [^ Time now].
    t1 = 'seconds' ifTrue: [^ Time now seconds].
    t1 = 'minutes' ifTrue: [^ Time now minutes].
    t1 = 'hours' ifTrue: [^ Time now hours].
    t1 = 'day' ifTrue: [^ Date today weekday].
    t1 = 'help' ifTrue: [^ 'type date, short date, time, seconds, minutes, day, hours'].
    ^  self error

What it does:
Reports the date and time, including seconds, minutes, hours, day and date.

/img/dropbox/BlockLibDiv2.png

/img/weebly/1875422.gif
Shared by jsombla
Blockspec:

('get %Q' #r #getTime: 'date')

Code:
Scratch-Objects >> ScriptableScratchMorph >> sensing ops

getTime: t1
    t1 = 'date' ifTrue: [^ Date today].
    t1 = 'short date' ifTrue: [^ Date today printFormat: #(1 2 3 $- 2 2 )].
    t1 = 'time' ifTrue: [^ Time now].
    t1 = 'seconds' ifTrue: [^ Time now seconds].
    t1 = 'minutes' ifTrue: [^ Time now minutes].
    t1 = 'hours' ifTrue: [^ Time now hours].
    t1 = 'day' ifTrue: [^ Date today weekday].
    t1 = 'help' ifTrue: [^ 'type date, short date, time, seconds, minutes, day, hours'].
    ^  self error

dateTime
    ^ #('date' 'short date' 'time' 'seconds' 'minutes' 'hours' 'day')

Scratch-Blocks >> CommandBlockMorph> private >> uncoloredArgMorphFor: add a strip:

$Q = t2 ifTrue: [^ ChoiceOrExpressionArgMorph new getOptionsSelector: #dateTime;
choice: 'date'].

What this block does:
Dropdown version of the above block.

/img/dropbox/BlockLibDiv2.png

/img/weebly/903063377.gif Shared by Pecola1.
Click here for the code
What it does:
Adds a lot of other sprite attributes to the original block.

/img/dropbox/BlockLibDiv2.png

/img/weebly/269330400.gif Shared by Pecola1.
Click here for the code (2 blocks)
What it does:
Adds a lot of other keyboard keys to the current blocks.

/img/dropbox/BlockLibDiv2.png

/img/weebly/924199023.gif Shared by Hardmath123

Blockspec:

('distance to x %n y %n' #r #dist:and:)

Code:

dist: t1 and: t2
    ^ (self xpos - t1 * (self xpos - t1) + (self ypos - t2 * (self ypos - t2))) abs sqrt

What this block does:
Reports the distance of the sprite from a given coordinate.

/img/dropbox/BlockLibDiv2.png

/img/weebly/538891418.gif Shared by Pecola1

Blockspec:

( %m touching %m ?' #b #sprite:touching:)

Code:

Code:

sprite: t1 touching: t2 
    | t3 t4 t5 t6 t7 t8 t9 |
    t3 _ self coerceSpriteArg: t2.
    t3 = #mouse
        ifTrue: 
            [(t4 _ self ownerThatIsA: ScratchStageMorph) ifNil: [^ false].
            ^ t1 containsPoint: t4 adjustedCursorPoint].
    t3 = #edge ifTrue: [^ t1 isOnEdge].
    t1 = #mouse
        ifTrue: 
            [(t4 _ self ownerThatIsA: ScratchStageMorph) ifNil: [^ false].
            ^ t3 containsPoint: t4 adjustedCursorPoint].
    (t3 isKindOf: t1 class)
        ifFalse: [^ false].
    (t1 isHidden not and: [t3 isHidden not])
        ifFalse: [^ false].
    t5 _ t1 bounds intersect: t3 bounds.
    (t5 width > 0 and: [t5 height > 0])
        ifFalse: [^ false].
    t6 _ Form extent: t5 extent depth: 2.
    t7 _ t6 deepCopy.
    t9 _ self visibility.
    self visibility: 100.
    t1 drawOn: ((FormCanvas on: t6)
            copyOffset: t5 topLeft negated).
    t1 visibility: t9.
    t9 _ t3 visibility.
    t3 visibility: 100.
    t3 drawOn: ((FormCanvas on: t7)
            copyOffset: t5 topLeft negated).
    t3 visibility: t9.
    t8 _ Bitmap new: 4 withAll: 1.
    t8 at: 1 put: 0.
    t6
        copyBits: t6 boundingBox
        from: t6
        at: 0 @ 0
        colorMap: t8.
    t7
        copyBits: t7 boundingBox
        from: t7
        at: 0 @ 0
        colorMap: t8.
    t7
        displayOn: t6
        at: 0 @ 0
        rule: Form and.
    ^ (t6 tallyPixelValues at: 1)
        < (t6 width * t6 height)

What this block does:
Reports whether two sprites (or the mouse-pointer) are touching. Note: does not work if mouse and edge are entered.

/img/dropbox/BlockLibDiv2.png

/img/weebly/6421624.gif Shared by Pecola1

Blockspec:

('open project with the id of %n' #- #openProjectId:)

Code:

openProjectId: t1
Cursor wait showWhile: [ScratchPlugin primOpenURL: 'http://scratch.mit.edu/api/getproject/' , t1]

What this block does:
Opens a web browser with the project of the ID that is entered.

/img/dropbox/BlockLibDiv2.png

/img/weebly/6396941.gif Shared by Pecola1

Blockspec:

('password for %s is %s ?' #b #username:password:)

Code:

username: t1 password: t2
    (HTTPSocket httpGet: 'contentshttp://scratch.mit.edu/api/authenticateuser?username=' , t1 , '&password=' , t2) contents = 'false' ifTrue: [^false].
^true

What this block does:
Reports whether the password for the username that is inserted is the right password. Useful for making a project which requires you have a Scratch account.

/img/dropbox/BlockLibDiv2.png

/img/tinypic/5bqjxh.jpg/img/weebly/2111844.gif Shared by Hardmath123
Blockspec:

('ask %s' #r #askReport: 'What is your name?')

Code:

askReport: t1
    ^ StringDialog ask: t1

What this block does:
Asks a question in a dialog box and reports the answer.

/img/dropbox/BlockLibDiv2.png

/img/tinypic/5bqjxh.jpg/img/weebly/46682.gif Shared by Hardmath123
Blockspec:

('warn %s' #- #warn: 'Invalid input')

Code:

warn: t1
    DialogBoxMorph warn: t1

What this block does:
Pops up a dialog with the text specified.

/img/dropbox/BlockLibDiv2.png

/img/weebly/8588685.gif
Shared by jsombla
Blockspec:

('if online then stop' #- #ifOnlineThenStop)

Code:

ifOnlineThenStop
    | t1 t2 t3 |
    t1_t2

What this block does:
Stops the script if online; it becomes an obsolete block.

/img/dropbox/BlockLibDiv2.png

/img/weebly/5774192.gif
Shared by jsombla
Blockspec:

('confirm %s' #b #confirm:)

Code:
No code needed
What this block does:
Asks the content. Choosing "yes" will report true, while "no" reports false.

/img/dropbox/BlockLibDiv2.png

/img/weebly/1995652.gif
Shared by jsombla
Blockspec:

('alert %s' #- #inform:)

Code:
No code needed
What this block does:
Alerts the user in a dialog.

/img/dropbox/BlockLibDiv2.png

/img/weebly/2436787.gif Shared by TuragaTreeko, improved by Scimonster
Blockspec:

('rename me as %s' #- #rename: 'Sprite1')

Code:

rename: t1
         self objName: t1

What this block does:
Renames the sprite.

/img/dropbox/BlockLibDiv2.png

/img/weebly/9599825.gif Shared by TuragaTreeko
Blockspec:

('my name' #r #name)

Code:

name
      ^objName

What this block does:
Reports the sprite's name.

/img/dropbox/BlockLibDiv2.png

/img/polyeztahpuppies/maxx.gif Shared by Greenatic
Blockspec:

('max x' #r #MaxX)

Code:

MaxX
    ^ self xpos + (0.5 * self width)

What this block does:
Reports the right end of the rectangle the sprite is in.

/img/dropbox/BlockLibDiv2.png

/img/polyeztahpuppies/minx.gif Shared by Greenatic
Blockspec:

('min x' #r #MinX)

Code:

MinX
    ^ self xpos - (0.5 * self width)

What this block does:
Reports the left end of the rectangle the sprite is in.

/img/dropbox/BlockLibDiv2.png

/img/polyeztahpuppies/maxy.gif Shared by Greenatic
Blockspec:

('max y' #r #MaxY)

Code:

MaxX
    ^ self ypos + (0.5 * self height)

What this block does:
Reports the top end of the rectangle the sprite is in.

/img/dropbox/BlockLibDiv2.png

/img/polyeztahpuppies/miny.gif Shared by Greenatic
Blockspec:

('min y' #r #MinY)

Code:

MinY
    ^ self ypos - (0.5 * self height)

What this block does:
Reports the bottom end of the rectangle the sprite is in.

/img/dropbox/BlockLibDiv2.png

/img/polyeztahpuppies/fontexists.gif Shared by Greenatic, improved by Baderous
Blockspec:

('font %s exists?' #b #FontExists:)

Code:

FontExists: t1
    | t2 |
    t2 _ UnicodePlugin getFontList collect: [:f | f asUTF8].
    ^ t2 includes: t1

What this block does:
Checks if you have a specified font.

/img/dropbox/BlockLibDiv2.png

/img/polyeztahpuppies/fontnumber.gif Shared by Greenatic
Blockspec:

('font #%n' #r #FontNumber:)

Code:

FontNumber: t1
    | t2 t3 |
    t1 isInf ifTrue: [^ nil].
    t1 isNaN ifTrue: [^ nil].
    t1 = t1 rounded ifFalse: [^ nil].
    t1 < 1 ifTrue: [^ nil].
    t2 _ UnicodePlugin getFontList.
    t2 size < t1 ifTrue: [^ nil].
    t3 _ 1.
    t2 do:
        [:t4 |
        t3 = t1 ifTrue: [^ t4].
        t3 _ t3 + 1]

/img/dropbox/BlockLibDiv2.png

^ Back to Scratch Blocks
^ Back to Contents
 

Last edited by YourLocalBlockLib (2011-12-17 14:54:04)


/img/dropbox/BlockLibraryTitle.png

Offline