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

#7501 2013-03-20 08:58:58

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Hardmath123 wrote:

Obsolete blocks?  hmm

In which format? The Flash editor can already convert 1.4 to 2.0, so I'll imitate that for that conversion.

Also, what about vector graphics?

Eh, there's no neat trick.  tongue  I already do lazy loading/conversion of images to some extent. If the target format supports SVGs, I'll copy them across. I don't know about rasterising; I guess I could use Cairo or similar, but I'd rather avoid adding a dependency, so I might just throw an error or convert it with a blank image (and a warning). (Although I could have optional dependencies?)

How about (take a deep breath) writing Kurt 2.0 in JavaScript?

I've thought about it; but all the existing code uses Kurt from Python.  tongue  And I can't find a good Construct-like library, so defining the binary format is a pain.


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#7502 2013-03-20 09:23:12

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: BYOB 3 - Discussion Thread

blob8108 wrote:

I've thought about it; but all the existing code uses Kurt from Python.  tongue  And I can't find a good Construct-like library, so defining the binary format is a pain.

Aww… why not rip MathWizz' lib?


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#7503 2013-03-20 09:45:33

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Hardmath123 wrote:

blob8108 wrote:

I've thought about it; but all the existing code uses Kurt from Python.  tongue  And I can't find a good Construct-like library, so defining the binary format is a pain.

Aww… why not rip MathWizz' lib?

I dunno; the only uses I can think of for kurt.js would be
a) a little browser-based scratchblocks generator for Scratch 2.0 projects
b) for integrating with Snap!

But the scratchblocks generator is pretty trivial based off the raw project.json, and Snap! only really needs [everything else] -> Snap!, not universal two-way conversion.

And I'd end up maintaining two codebases, which is never fun.  tongue

So, yeah, it solves the vector images problem without requiring another Python library (although I would need another JS library; where's the logic?  wink ); but I think it creates too many other problems.

Kurt's mainly used for analysing Scratch projects from Python code, so I guess that's my main use case.  smile

Last edited by blob8108 (2013-03-20 09:48:01)


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#7504 2013-03-20 10:29:16

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Oh, well.  sad  It was worth a try.  tongue


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#7505 2013-03-20 11:11:53

MathWizz
Scratcher
Registered: 2009-08-31
Posts: 1000+

Re: BYOB 3 - Discussion Thread

...unless I write a JS version of Kurt.  tongue  I've pretty much got 1.4 and 2.0 support so it shouldn't be too hard to convert my current lib to individual plugins.

Last edited by MathWizz (2013-03-20 11:27:41)


http://block.site90.net/scratch.mit/text.php?size=30&text=%20A%20signature!&color=333333

Offline

 

#7506 2013-03-20 11:14:04

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Neat! Can you put up the code somewhere?


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#7507 2013-03-20 11:28:59

MathWizz
Scratcher
Registered: 2009-08-31
Posts: 1000+

Re: BYOB 3 - Discussion Thread

I've had the sb.js code on github for a while. https://github.com/MathWizz/sb.js


http://block.site90.net/scratch.mit/text.php?size=30&text=%20A%20signature!&color=333333

Offline

 

#7508 2013-03-20 15:19:49

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Hardmath123 wrote:

Also, I can use the dot syntax for list querying too, right? Why is mylist.5 a bad idea? Which looks nicer:

Code:

print colors.(indices.5)
print colors[indices[5]]

The reason most languages don't is because it's harder to parse—the tokenizer isn't sure if you mean <indices> <.> <5> or <indices> <.5>, and the picks the latter because it's greedy.


nXIII

Offline

 

#7509 2013-03-20 21:04:05

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: BYOB 3 - Discussion Thread

That's it? I was expecting something more reasonable.

I'm not planning on allowing .5, anyway, you have to use 0.5.


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#7510 2013-03-20 21:06:19

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: BYOB 3 - Discussion Thread

MathWizz wrote:

I've had the sb.js code on github for a while. https://github.com/MathWizz/sb.js

That's awesome! blob, you convinced yet?  smile


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#7511 2013-03-20 23:00:19

bharvey
Scratcher
Registered: 2008-08-10
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Hardmath123 wrote:

I'm not planning on allowing .5, anyway, you have to use 0.5.

Nope, you definitely can't call it Pravic!  tongue


http://cs.berkeley.edu/~bh/sig5.png

Offline

 

#7512 2013-03-20 23:11:41

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: BYOB 3 - Discussion Thread

nXIII wrote:

Hardmath123 wrote:

Also, I can use the dot syntax for list querying too, right? Why is mylist.5 a bad idea? Which looks nicer:

Code:

print colors.(indices.5)
print colors[indices[5]]

The reason most languages don't is because it's harder to parse—the tokenizer isn't sure if you mean <indices> <.> <5> or <indices> <.5>, and the picks the latter because it's greedy.

Oops, that was just about the inside one ("indices.5"). The outside one ("colors.(indices.5)") is a contradiction—the value after the dot is not evaluated in "colors.indices", but it is in "colors.(indices.5)"—unless you meant that ".(…)" is the equivalent of the "[…]" operator and ".<identifier|number>" is the equivalent of the "." operator….


nXIII

Offline

 

#7513 2013-03-21 02:37:04

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: BYOB 3 - Discussion Thread

bharvey wrote:

Hardmath123 wrote:

I'm not planning on allowing .5, anyway, you have to use 0.5.

Nope, you definitely can't call it Pravic!  tongue

big_smile  My language, my rules.

It's really annoying to see people write CSS like

Code:

-webkit-animation-duation:.5s;

tongue

@nXIII: I see what you mean. There seem to be two cases:
object.expression_to_get_a_key_or_index
object.name_of_property_without_quotes_for_convenience

Maybe I should use the underscore operator for evaluated subscripting:
object.property
object_"property"


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#7514 2013-03-21 04:06:20

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Hardmath123 wrote:

MathWizz wrote:

I've had the sb.js code on github for a while. https://github.com/MathWizz/sb.js

That's awesome! blob, you convinced yet?  smile

"Kurt is written in Python ".replace(" ", ". ").upper() #  tongue

However, if you (and Math?) want to go rewrite it in JS — go ahead!  smile


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#7515 2013-03-21 05:23:54

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: BYOB 3 - Discussion Thread

blob8108 wrote:

Hardmath123 wrote:

MathWizz wrote:

I've had the sb.js code on github for a while. https://github.com/MathWizz/sb.js

That's awesome! blob, you convinced yet?  smile

"Kurt is written in Python ".replace(" ", ". ").upper() #  tongue

OK. OK. I. GET. IT.  tongue

However, if you (and Math?) want to go rewrite it in JS — go ahead!  smile

Erm… I have no clue how to deal with a binary format.  hmm


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#7516 2013-03-21 06:52:19

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Hardmath123 wrote:

blob8108 wrote:

Hardmath123 wrote:


That's awesome! blob, you convinced yet?  smile

"Kurt is written in Python ".replace(" ", ". ").upper() #  tongue

OK. OK. I. GET. IT.  tongue

"".join(map(dict(enumerate(map(chr, range(97, 123)), 1)).get, [23, 5, 1, 18, 5, 20, 15, 15, 3, 15, 15, 12]))


However, if you (and Math?) want to go rewrite it in JS — go ahead!  smile

Erm… I have no clue how to deal with a binary format.  hmm

MathWizz wrote:

I've had the sb.js code on github for a while. https://github.com/MathWizz/sb.js

(Math and math. Eh heh heh.  tongue )


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#7517 2013-03-21 06:55:37

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: BYOB 3 - Discussion Thread

blob8108 wrote:

Hardmath123 wrote:

blob8108 wrote:


"Kurt is written in Python ".replace(" ", ". ").upper() #  tongue

OK. OK. I. GET. IT.  tongue

"".join(map(dict(enumerate(map(chr, range(97, 123)), 1)).get, [23, 5, 1, 18, 5, 20, 15, 15, 3, 15, 15, 12]))

(lambda x:x[10]+x[9]+x[7])("just for kicks")

(Math and math. Eh heh heh.   tongue  )

You can eh-heh-heh when we're on Wheel of Fortune's Before and After.


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#7518 2013-03-21 08:36:26

shadow_7283
Scratcher
Registered: 2007-11-07
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Hardmath123 wrote:

Erm… I have no clue how to deal with a binary format.  hmm

Are you talking about Typed Arrays? I think all modern web browsers support it, save IE.

EDIT: Works in IE 10

Last edited by shadow_7283 (2013-03-21 08:38:28)

Offline

 

#7519 2013-03-21 09:42:04

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Hardmath123 wrote:

bharvey wrote:

Hardmath123 wrote:

I'm not planning on allowing .5, anyway, you have to use 0.5.

Nope, you definitely can't call it Pravic!  tongue

big_smile  My language, my rules.

It's really annoying to see people write CSS like

Code:

-webkit-animation-duation:.5s;

tongue

Stuff like rgba(0,0,0,.3) does look better without the leading zero, though.

shadow_7283 wrote:

Hardmath123 wrote:

Erm… I have no clue how to deal with a binary format.  hmm

Are you talking about Typed Arrays? I think all modern web browsers support it, save IE.

EDIT: Works in IE 10

Well, Opera mini doesn'ttongue

IE8 and IE9 don't either, but nobody cares about them (or Opera mini).


nXIII

Offline

 

#7520 2013-03-21 14:14:46

technoboy10
Scratcher
Registered: 2007-08-25
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Snapduino pre-pre-alpha is out now (you can turn on and off a digital pin  tongue )! http://www.github.com/technoboy10/snapduino


So long, 1.4.
http://goo.gl/3JEV9

Offline

 

#7521 2013-03-21 23:08:40

bharvey
Scratcher
Registered: 2008-08-10
Posts: 1000+

Re: BYOB 3 - Discussion Thread

technoboy10 wrote:

Snapduino pre-pre-alpha is out now (you can turn on and off a digital pin  tongue )! http://www.github.com/technoboy10/snapduino

You're awesome.  Let us know when it's ready to put on the Snap! page.

@Hm: Is there a single link for Snapin8r we should put there?

@blob: I'm not asking about Kurt b/c it sounds like we should wait for version 2, right?

Last edited by bharvey (2013-03-21 23:34:08)


http://cs.berkeley.edu/~bh/sig5.png

Offline

 

#7522 2013-03-21 23:42:57

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: BYOB 3 - Discussion Thread

I'll give you the gdocs zip link…

EDIT: Here's the closed-source mac-only version: https://docs.google.com/file/d/0B1UC0dD … sp=sharing. I'll make a new ZIP with annotated source and instructions later today, but for now this should suffice.  smile

Last edited by Hardmath123 (2013-03-21 23:48:13)


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#7523 2013-03-21 23:45:33

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Here's a patch to add support for device orientation/rotation natively. It does not check whether the features exist yet.

Code:

// changes.js
// Hardware stuff, and declaring blocks
DeviceSensor = {
    "acceleration": {
        "x": 0,
        "y": 0,
        "z": 0
    },
    "acceleration (with gravity)": {
        "x": 0,
        "y": 0,
        "z": 0
    },
    "rotation": {
        "x": 0,
        "y": 0,
        "z": 0
    },
    "rotation rate": {
        "x": 0,
        "y": 0,
        "z": 0
    },
    "compass": 0
}

SpriteMorph.prototype.blocks.device = {
    "spec": "Device %mtype %mdir",
    "category": "sensing",
    "type": "reporter"
}
SpriteMorph.prototype.device = function (mtype, mdir) {
    return DeviceSensor[mtype][mdir];
}
SpriteMorph.prototype.blocks.compass = {
    "spec": "Compass heading",
    "category": "sensing",
    "type": "reporter"
}
SpriteMorph.prototype.compass = function () {
    return DeviceSensor["compass"];
}

window.addEventListener("devicemotion", function (event) {
    var a = event.acceleration;
    var ag = event.accelerationIncludingGravity;
    var rr = event.rotationRate;

    DeviceSensor.acceleration = {
        x: a.x,
        y: a.y,
        z: a.z
    };
    DeviceSensor["acceleration (with gravity)"] = {
        x: ag.x,
        y: ag.y,
        z: ag.z
    };
    DeviceSensor["rotation rate"] = {
        x: rr.alpha,
        y: rr.beta,
        z: rr.gamma
    };
});
window.addEventListener("deviceorientation", function (event) {
    DeviceSensor.rotation = {
        x: event.alpha,
        y: event.beta,
        z: event.gamma
    };
    DeviceSensor.compass = event.webkitCompassHeading;
});
// Declarations done
// Adding blocks, declaring special input slots
SpriteMorph.prototype.blockTemplates = function (category) {
    var blocks = [],
        myself = this,
        varNames, button, cat = category || 'motion',
        txt;

    function block(selector) {
        var newBlock = SpriteMorph.prototype.blockForSelector(selector, true);
        newBlock.isTemplate = true;
        return newBlock;
    }

    function variableBlock(varName) {
        var newBlock = SpriteMorph.prototype.variableBlock(varName);
        newBlock.isDraggable = false;
        newBlock.isTemplate = true;
        return newBlock;
    }

    function watcherToggle(selector) {
        var info = SpriteMorph.prototype.blocks[selector];
        return new ToggleMorph('checkbox', this,

        function () {
            myself.toggleWatcher(
            selector, localize(info.spec), myself.blockColor[info.category]);
        }, null,

        function () {
            return myself.showingWatcher(selector);
        }, null);
    }

    function variableWatcherToggle(varName) {
        return new ToggleMorph('checkbox', this,

        function () {
            myself.toggleVariableWatcher(varName);
        }, null,

        function () {
            return myself.showingVariableWatcher(varName);
        }, null);
    }

    if (cat === 'motion') {
        blocks.push(block('forward'));
        blocks.push(block('turn'));
        blocks.push(block('turnLeft'));
        blocks.push('-');
        blocks.push(block('setHeading'));
        blocks.push(block('doFaceTowards'));
        blocks.push('-');
        blocks.push(block('gotoXY'));
        blocks.push(block('doGotoObject'));
        blocks.push(block('doGlide'));
        blocks.push('-');
        blocks.push(block('changeXPosition'));
        blocks.push(block('setXPosition'));
        blocks.push(block('changeYPosition'));
        blocks.push(block('setYPosition'));
        blocks.push('-');
        blocks.push(block('bounceOffEdge'));
        blocks.push('-');
        blocks.push(watcherToggle('xPosition'));
        blocks.push(block('xPosition'));
        blocks.push(watcherToggle('yPosition'));
        blocks.push(block('yPosition'));
        blocks.push(watcherToggle('direction'));
        blocks.push(block('direction'));

    } else if (cat === 'looks') {

        blocks.push(block('doSwitchToCostume'));
        blocks.push(block('doWearNextCostume'));
        blocks.push(watcherToggle('getCostumeIdx'));
        blocks.push(block('getCostumeIdx'));
        blocks.push('-');
        blocks.push(block('doSayFor'));
        blocks.push(block('bubble'));
        blocks.push(block('doThinkFor'));
        blocks.push(block('doThink'));
        blocks.push('-');
        blocks.push(block('changeEffect'));
        blocks.push(block('setEffect'));
        blocks.push(block('clearEffects'));
        blocks.push('-');
        blocks.push(block('changeScale'));
        blocks.push(block('setScale'));
        blocks.push(watcherToggle('getScale'));
        blocks.push(block('getScale'));
        blocks.push('-');
        blocks.push(block('show'));
        blocks.push(block('hide'));
        blocks.push('-');
        blocks.push(block('comeToFront'));
        blocks.push(block('goBack'));

        // for debugging: ///////////////
        if (this.world().isDevMode) {
            blocks.push('-');
            txt = new TextMorph(localize('development mode \ndebugging primitives:'));
            txt.fontSize = 9;
            txt.setColor(new Color(230, 230, 230));
            blocks.push(txt);
            blocks.push('-');
            blocks.push(block('log'));
            blocks.push(block('alert'));
        }

        /////////////////////////////////
    } else if (cat === 'sound') {

        blocks.push(block('playSound'));
        blocks.push(block('doPlaySoundUntilDone'));
        blocks.push(block('doStopAllSounds'));
        blocks.push('-');
        blocks.push(block('doRest'));
        blocks.push('-');
        blocks.push(block('doPlayNote'));
        blocks.push('-');
        blocks.push(block('doChangeTempo'));
        blocks.push(block('doSetTempo'));
        blocks.push(watcherToggle('getTempo'));
        blocks.push(block('getTempo'));

    } else if (cat === 'pen') {

        blocks.push(block('clear'));
        blocks.push('-');
        blocks.push(block('down'));
        blocks.push(block('up'));
        blocks.push('-');
        blocks.push(block('setColor'));
        blocks.push(block('changeHue'));
        blocks.push(block('setHue'));
        blocks.push('-');
        blocks.push(block('changeBrightness'));
        blocks.push(block('setBrightness'));
        blocks.push('-');
        blocks.push(block('changeSize'));
        blocks.push(block('setSize'));
        blocks.push('-');
        blocks.push(block('doStamp'));

    } else if (cat === 'control') {

        blocks.push(block('receiveGo'));
        blocks.push(block('receiveKey'));
        blocks.push(block('receiveClick'));
        blocks.push(block('receiveMessage'));
        blocks.push('-');
        blocks.push(block('doBroadcast'));
        blocks.push(block('doBroadcastAndWait'));
        blocks.push('-');
        blocks.push(block('doWarp'));
        blocks.push('-');
        blocks.push(block('doWait'));
        blocks.push(block('doWaitUntil'));
        blocks.push('-');
        blocks.push(block('doForever'));
        blocks.push(block('doRepeat'));
        blocks.push(block('doUntil'));
        blocks.push('-');
        blocks.push(block('doIf'));
        blocks.push(block('doIfElse'));
        blocks.push('-');
        blocks.push(block('doReport'));
        blocks.push('-');
        blocks.push(block('doStopBlock'));
        blocks.push(block('doStop'));
        blocks.push(block('doStopAll'));
        blocks.push('-');
        blocks.push(block('doRun'));
        blocks.push(block('fork'));
        blocks.push(block('evaluate'));
        blocks.push('-');
/*
         // list variants commented out for now (redundant)
         blocks.push(block('doRunWithInputList'));
         blocks.push(block('forkWithInputList'));
         blocks.push(block('evaluateWithInputList'));
         blocks.push('-');
         */
        blocks.push(block('doCallCC'));
        blocks.push(block('reportCallCC'));
        blocks.push('-');
        blocks.push(block('receiveOnClone'));
        blocks.push(block('createClone'));
        blocks.push(block('removeClone'));

    } else if (cat === 'sensing') {

        blocks.push(block('reportTouchingObject'));
        blocks.push(block('reportTouchingColor'));
        blocks.push(block('reportColorIsTouchingColor'));
        blocks.push('-');
        blocks.push(block('doAsk'));
        blocks.push(watcherToggle('getLastAnswer'));
        blocks.push(block('reportLastAnswer'));
        blocks.push('-');
        blocks.push(block('reportMouseX'));
        blocks.push(block('reportMouseY'));
        blocks.push(block('reportMouseDown'));
        blocks.push('-');
        blocks.push(block('reportKeyPressed'));
        blocks.push('-');
        blocks.push(block('reportDistanceTo'));
        blocks.push('-');
        blocks.push(block('doResetTimer'));
        blocks.push(watcherToggle('getTimer'));
        blocks.push(block('reportTimer'));
        blocks.push('-');
        blocks.push(block('reportAttributeOf'));
        blocks.push('-');
        blocks.push(block('reportURL'));
        blocks.push('-');
        blocks.push(block('reportIsFastTracking'));
        blocks.push(block('doSetFastTracking'));
        blocks.push('-');
        blocks.push(block('device'));
        blocks.push(block('compass'));
        // for debugging: ///////////////
        if (this.world().isDevMode) {

            blocks.push('-');
            txt = new TextMorph(localize('development mode \ndebugging primitives:'));
            txt.fontSize = 9;
            txt.setColor(new Color(230, 230, 230));
            blocks.push(txt);
            blocks.push('-');
            blocks.push(block('colorFiltered'));
            blocks.push(block('reportStackSize'));
            blocks.push(block('reportFrameCount'));
        }

    } else if (cat === 'operators') {

        blocks.push(block('reifyScript'));
        blocks.push(block('reifyReporter'));
        blocks.push(block('reifyPredicate'));
        blocks.push('#');
        blocks.push('-');
        blocks.push(block('reportSum'));
        blocks.push(block('reportDifference'));
        blocks.push(block('reportProduct'));
        blocks.push(block('reportQuotient'));
        blocks.push('-');
        blocks.push(block('reportModulus'));
        blocks.push(block('reportRound'));
        blocks.push(block('reportMonadic'));
        blocks.push(block('reportRandom'));
        blocks.push('-');
        blocks.push(block('reportLessThan'));
        blocks.push(block('reportEquals'));
        blocks.push(block('reportGreaterThan'));
        blocks.push('-');
        blocks.push(block('reportAnd'));
        blocks.push(block('reportOr'));
        blocks.push(block('reportNot'));
        blocks.push('-');
        blocks.push(block('reportTrue'));
        blocks.push(block('reportFalse'));
        blocks.push('-');
        blocks.push(block('reportJoinWords'));
        blocks.push(block('reportLetter'));
        blocks.push(block('reportStringSize'));
        blocks.push('-');
        blocks.push(block('reportUnicode'));
        blocks.push(block('reportUnicodeAsLetter'));
        blocks.push('-');
        blocks.push(block('reportIsA'));
        blocks.push(block('reportIsIdentical'));

        // for debugging: ///////////////
        if (this.world().isDevMode) {
            blocks.push('-');
            txt = new TextMorph('development mode \ndebugging primitives:');
            txt.fontSize = 9;
            txt.setColor(new Color(230, 230, 230));
            blocks.push(txt);
            blocks.push('-');
            blocks.push(block('reportTypeOf'));
        }

        /////////////////////////////////
    } else if (cat === 'variables') {

        button = new PushButtonMorph(
        null,

        function () {
            new VariableDialogMorph(
            null,

            function (pair) {
                if (pair) {
                    myself.addVariable(pair[0], pair[1]);
                    myself.toggleVariableWatcher(pair[0], pair[1]);
                    myself.blocksCache[cat] = null;
                    myself.paletteCache[cat] = null;
                    myself.parentThatIsA(IDE_Morph).refreshPalette();
                }
            }, myself).prompt('Variable name', null, myself.world());
        }, 'Make a variable');
        blocks.push(button);

        if (this.variables.allNames().length > 0) {
            button = new PushButtonMorph(
            null,

            function () {
                var menu = new MenuMorph(
                myself.deleteVariable, null, myself);
                myself.variables.allNames().forEach(function (name) {
                    menu.addItem(name, name);
                });
                menu.popUpAtHand(myself.world());
            }, 'Delete a variable');
            blocks.push(button);
        }

        blocks.push('-');

        varNames = this.variables.allNames();
        if (varNames.length > 0) {
            varNames.forEach(function (name) {
                blocks.push(variableWatcherToggle(name));
                blocks.push(variableBlock(name));
            });
            blocks.push('-');
        }

        blocks.push(block('doSetVar'));
        blocks.push(block('doChangeVar'));
        blocks.push(block('doShowVar'));
        blocks.push(block('doHideVar'));
        blocks.push(block('doDeclareVariables'));

        blocks.push('=');

        blocks.push(block('reportNewList'));
        blocks.push('-');
        blocks.push(block('reportCONS'));
        blocks.push(block('reportListItem'));
        blocks.push(block('reportCDR'));
        blocks.push('-');
        blocks.push(block('reportListLength'));
        blocks.push(block('reportListContainsItem'));
        blocks.push('-');
        blocks.push(block('doAddToList'));
        blocks.push(block('doDeleteFromList'));
        blocks.push(block('doInsertInList'));
        blocks.push(block('doReplaceInList'));

        blocks.push('=');

        button = new PushButtonMorph(
        null,

        function () {
            var ide = myself.parentThatIsA(IDE_Morph),
                stage = myself.parentThatIsA(StageMorph);
            new BlockDialogMorph(
            null,

            function (definition) {
                if (definition.spec !== '') {
                    if (definition.isGlobal) {
                        stage.globalBlocks.push(definition);
                    } else {
                        myself.customBlocks.push(definition);
                    }
                    ide.flushPaletteCache();
                    ide.refreshPalette();
                    new BlockEditorMorph(definition, myself).popUp();
                }
            }, myself).prompt('Make a block', null, myself.world());
        }, 'Make a block');
        blocks.push(button);
    }
    return blocks;
};

SyntaxElementMorph.prototype.labelPart = function (spec) {
    var part;
    if ((spec[0] === '%') && (spec.length > 1)) {

        // check for variable multi-arg-slot:
        if ((spec.length > 5) && (spec.slice(0, 5) === '%mult')) {
            part = new MultiArgMorph(spec.slice(5));
            part.addInput();
            return part;
        }

        // single-arg and specialized multi-arg slots:
        switch (spec) {
        case '%inputs':
            part = new MultiArgMorph('%s', 'with inputs');
            part.isStatic = false;
            part.canBeEmpty = false;
            break;
        case '%scriptVars':
            part = new MultiArgMorph('%t', null, 1, spec);
            part.canBeEmpty = false;
            break;
        case '%parms':
            part = new MultiArgMorph('%t', 'Input Names:', 0, spec);
            part.canBeEmpty = false;
            break;
        case '%ringparms':
            part = new MultiArgMorph('%t', 'input names:', 0, spec);
            break;
        case '%cmdRing':
            part = new RingMorph();
            part.color = SpriteMorph.prototype.blockColor.other;
            part.selector = 'reifyScript';
            part.setSpec('%rc %ringparms');
            part.isDraggable = true;
            break;
        case '%repRing':
            part = new RingMorph();
            part.color = SpriteMorph.prototype.blockColor.other;
            part.selector = 'reifyReporter';
            part.setSpec('%rr %ringparms');
            part.isDraggable = true;
            part.isStatic = true;
            break;
        case '%predRing':
            part = new RingMorph(true);
            part.color = SpriteMorph.prototype.blockColor.other;
            part.selector = 'reifyPredicate';
            part.setSpec('%rp %ringparms');
            part.isDraggable = true;
            part.isStatic = true;
            break;
        case '%words':
            part = new MultiArgMorph('%s', null, 0);
            part.addInput(); // allow for default value setting
            part.addInput(); // allow for default value setting
            part.isStatic = false;
            break;
        case '%exp':
            part = new MultiArgMorph('%s', null, 0);
            part.addInput();
            part.isStatic = true;
            part.canBeEmpty = false;
            break;
        case '%br':
            part = new Morph();
            part.setExtent(new Point(0, 0));
            part.isBlockLabelBreak = true;
            part.getSpec = function () {
                return '%br';
            };
            break;
        case '%inputName':
            part = new ReporterBlockMorph();
            part.category = 'variables';
            part.color = SpriteMorph.prototype.blockColor.variables;
            part.setSpec(localize('Input name'));
            break;
        case '%s':
            part = new InputSlotMorph();
            break;
        case '%anyUE':
            part = new InputSlotMorph();
            part.isUnevaluated = true;
            break;
        case '%txt':
            part = new InputSlotMorph();
            part.minWidth = part.height() * 1.7; // "landscape"
            part.fixLayout();
            break;
        case '%obj':
            part = new ArgMorph('object');
            break;
        case '%n':
            part = new InputSlotMorph(null, true);
            break;
        case '%dir':
            part = new InputSlotMorph(
            null, true, {
                '(90) right': 90,
                '(-90) left': -90,
                '(0) up': '0',
                '(180) down': 180
            });
            part.setContents(90);
            break;
        case '%mdir':
            part = new InputSlotMorph(
            null, false, {
                'x': 'x',
                'y': 'y',
                'z': 'z',
            }, true);
            part.setContents("x");
            break;
        case '%mtype':
            part = new InputSlotMorph(
            null, false, {
                'acceleration': 'acceleration',
                'acceleration (with gravity)': 'acceleration (with gravity)',
                'rotation': 'rotation',
                'rotation rate': 'rotation rate'
            }, true);
            part.setContents("acceleration");
            break;
        case '%inst':
            part = new InputSlotMorph(
            null, true, {
                '(1) Acoustic Grand': 1,
                '(2) Bright Acoustic': 2,
                '(3) Electric Grand': 3,
                '(4) Honky Tonk': 4,
                '(5) Electric Piano 1': 5,
                '(6) Electric Piano 2': 6,
                '(7) Harpsichord': 7
            });
            part.setContents(1);
            break;
        case '%month':
            part = new InputSlotMorph(
            null, // text
            false, // numeric?
            {
                'January': ['January'],
                'February': ['February'],
                'March': ['March'],
                'April': ['April'],
                'May': ['May'],
                'June': ['June'],
                'July': ['July'],
                'August': ['August'],
                'September': ['September'],
                'October': ['October'],
                'November': ['November'],
                'December': ['December']
            }, true // read-only
            );
            break;
        case '%ida':
            part = new InputSlotMorph(
            null, true, {
                '1': 1,
                last: ['last'],
                '~': null,
                all: ['all']
            });
            part.setContents(1);
            break;
        case '%idx':
            part = new InputSlotMorph(
            null, true, {
                '1': 1,
                last: ['last'],
                any: ['any']
            });
            part.setContents(1);
            break;
        case '%spr':
            part = new InputSlotMorph(
            null, false, 'objectsMenu', true);
            break;
        case '%col':
            // collision detection
            part = new InputSlotMorph(
            null, false, 'collidablesMenu', true);
            break;
        case '%dst':
            // distance measuring
            part = new InputSlotMorph(
            null, false, 'distancesMenu', true);
            break;
        case '%cln':
            // clones
            part = new InputSlotMorph(
            null, false, 'clonablesMenu', true);
            break;
        case '%cst':
            part = new InputSlotMorph(
            null, false, 'costumesMenu', true);
            break;
        case '%eff':
            part = new InputSlotMorph(
            null, false, {
/*
                                           color : 'color',
                                           fisheye : 'fisheye',
                                           whirl : 'whirl',
                                           pixelate : 'pixelate',
                                           mosaic : 'mosaic',
                                           brightness : 'brightness',
                                           */
                ghost: ['ghost']
            }, true);
            part.setContents(['ghost']);
            break;
        case '%snd':
            part = new InputSlotMorph(
            null, false, 'soundsMenu', true);
            break;
        case '%key':
            part = new InputSlotMorph(
            null, false, {
                'up arrow': ['up arrow'],
                'down arrow': ['down arrow'],
                'right arrow': ['right arrow'],
                'left arrow': ['left arrow'],
                space: ['space'],
                a: ['a'],
                b: ['b'],
                c: ['c'],
                d: ['d'],
                e: ['e'],
                f: ['f'],
                g: ['g'],
                h: ['h'],
                i: ['i'],
                j: ['j'],
                k: ['k'],
                l: ['l'],
                m: ['m'],
                n: ['n'],
                o: ['o'],
                p: ['p'],
                q: ['q'],
                r: ['r'],
                s: ['s'],
                t: ['t'],
                u: ['u'],
                v: ['v'],
                w: ['w'],
                x: ['x'],
                y: ['y'],
                z: ['z'],
                '0': ['0'],
                '1': ['1'],
                '2': ['2'],
                '3': ['3'],
                '4': ['4'],
                '5': ['5'],
                '6': ['6'],
                '7': ['7'],
                '8': ['8'],
                '9': ['9']
            }, true);
            part.setContents(['space']);
            break;
        case '%keyHat':
            part = this.labelPart('%key');
            part.isStatic = true;
            break;
        case '%msg':
            part = new InputSlotMorph(
            null, false, 'messagesMenu', true);
            break;
        case '%msgHat':
            part = new InputSlotMorph(
            null, false, 'messagesMenu', true);
            part.isStatic = true;
            break;
        case '%att':
            part = new InputSlotMorph(
            null, false, 'attributesMenu', true);
            part.isStatic = true;
            break;
        case '%fun':
            part = new InputSlotMorph(
            null, false, {
                abs: ['abs'],
                sqrt: ['sqrt'],
                sin: ['sin'],
                cos: ['cos'],
                tan: ['tan'],
                asin: ['asin'],
                acos: ['acos'],
                atan: ['atan'],
                ln: ['ln'],
                // log : 'log',
                'e^': ['e^']
                // '10^' : '10^'
            }, true);
            part.setContents(['sqrt']);
            break;
        case '%typ':
            part = new InputSlotMorph(
            null, false, {
                number: ['number'],
                text: ['text'],
                Boolean: ['Boolean'],
                list: ['list'],
                command: ['command'],
                reporter: ['reporter'],
                predicate: ['predicate']
                // ring : 'ring'
                // object : 'object'
            }, true);
            part.setContents(['number']);
            break;
        case '%var':
            part = new InputSlotMorph(
            null, false, 'getVarNamesDict', true);
            part.isStatic = true;
            break;
        case '%lst':
            part = new InputSlotMorph(
            null, false, {
                list1: 'list1',
                list2: 'list2',
                list3: 'list3'
            }, true);
            break;
        case '%l':
            part = new ArgMorph('list');
            break;
        case '%b':
        case '%boolUE':
            part = new BooleanSlotMorph(null, true);
            break;
        case '%cmd':
            part = new CommandSlotMorph();
            break;
        case '%rc':
            part = new RingCommandSlotMorph();
            part.isStatic = true;
            break;
        case '%rr':
            part = new RingReporterSlotMorph();
            part.isStatic = true;
            break;
        case '%rp':
            part = new RingReporterSlotMorph(true);
            part.isStatic = true;
            break;
        case '%c':
            part = new CSlotMorph();
            part.isStatic = true;
            break;
        case '%cs':
            part = new CSlotMorph(); // non-static
            break;
        case '%clr':
            part = new ColorSlotMorph();
            part.isStatic = true;
            break;
        case '%t':
            part = new TemplateSlotMorph('a');
            break;
        case '%upvar':
            part = new TemplateSlotMorph('\u2191'); // up-arrow
            break;
        case '%f':
            part = new FunctionSlotMorph();
            break;
        case '%r':
            part = new ReporterSlotMorph();
            break;
        case '%p':
            part = new ReporterSlotMorph(true);
            break;

            // symbols:
        case '%turtle':
            part = new SymbolMorph('turtle');
            part.size = this.fontSize * 1.2;
            part.color = new Color(255, 255, 255);
            part.shadowColor = this.color.darker(this.labelContrast);
            part.shadowOffset = this.embossing;
            part.drawNew();
            break;
        case '%turtleOutline':
            part = new SymbolMorph('turtleOutline');
            part.size = this.fontSize;
            part.color = new Color(255, 255, 255);
            part.isProtectedLabel = true; // doesn't participate in zebraing
            part.shadowColor = this.color.darker(this.labelContrast);
            part.shadowOffset = this.embossing;
            part.drawNew();
            break;
        case '%clockwise':
            part = new SymbolMorph('turnRight');
            part.size = this.fontSize * 1.5;
            part.color = new Color(255, 255, 255);
            part.isProtectedLabel = false; // zebra colors
            part.shadowColor = this.color.darker(this.labelContrast);
            part.shadowOffset = this.embossing;
            part.drawNew();
            break;
        case '%counterclockwise':
            part = new SymbolMorph('turnLeft');
            part.size = this.fontSize * 1.5;
            part.color = new Color(255, 255, 255);
            part.isProtectedLabel = false; // zebra colors
            part.shadowColor = this.color.darker(this.labelContrast);
            part.shadowOffset = this.embossing;
            part.drawNew();
            break;
        case '%greenflag':
            part = new SymbolMorph('flag');
            part.size = this.fontSize * 1.5;
            part.color = new Color(0, 200, 0);
            part.isProtectedLabel = true; // doesn't participate in zebraing
            part.shadowColor = this.color.darker(this.labelContrast);
            part.shadowOffset = this.embossing;
            part.drawNew();
            break;
        case '%stop':
            part = new SymbolMorph('octagon');
            part.size = this.fontSize * 1.5;
            part.color = new Color(200, 0, 0);
            part.isProtectedLabel = true; // doesn't participate in zebraing
            part.shadowColor = this.color.darker(this.labelContrast);
            part.shadowOffset = this.embossing;
            part.drawNew();
            break;
        default:
            // nop();
        }
    } else {
        part = new StringMorph(spec);
        part.fontName = this.labelFontName;
        part.fontStyle = this.labelFontStyle;
        part.fontSize = this.fontSize;
        part.color = new Color(255, 255, 255);
        part.isBold = true;
        part.shadowColor = this.color.darker(this.labelContrast);
        part.shadowOffset = this.embossing;
        part.drawNew();
    }
    return part;
};

To test it on an iPad, dump this file into a the snap source, add changes.js to the HTML file, and then run this server:

Code:

#!/usr/bin/python

from twisted.web.server import Site
from twisted.web.static import File
from twisted.web.resource import Resource
from twisted.internet import reactor

import socket
IP = socket.gethostbyname(socket.gethostname())

root = Resource()

mstatic = File(raw_input("Input the directory where Snap! is located:\n>>> "))
root.putChild("snap",mstatic)

factory = Site(root)
reactor.listenTCP(8000, factory, interface=IP)
print "Connection successful. Open Safari on an iPad and go to:"
print IP+":8000/snap/snap.html"
reactor.run()

Then follow the instructions on-screen.

(sorry for the laziness/lack of fancy hosting).


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#7524 2013-03-22 04:15:08

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Hardmath123 wrote:

To test it on an iPad, dump this file into a the snap source, add changes.js to the HTML file, and then run this server:

Code:

#!/usr/bin/python

from twisted.web.server import Site
from twisted.web.static import File
from twisted.web.resource import Resource
from twisted.internet import reactor

import socket
IP = socket.gethostbyname(socket.gethostname())

root = Resource()

mstatic = File(raw_input("Input the directory where Snap! is located:\n>>> "))
root.putChild("snap",mstatic)

factory = Site(root)
reactor.listenTCP(8000, factory, interface=IP)
print "Connection successful. Open Safari on an iPad and go to:"
print IP+":8000/snap/snap.html"
reactor.run()

Is that just a static webserver to serve up a directory?


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#7525 2013-03-22 04:19:15

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: BYOB 3 - Discussion Thread

bharvey wrote:

I'm not asking about Kurt b/c it sounds like we should wait for version 2, right?

Yup!  smile


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

Board footer