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

#6401 2012-12-15 18:58:31

fullmoon
Retired Community Moderator
Registered: 2007-06-04
Posts: 1000+

Re: BYOB 3 - Discussion Thread

bharvey wrote:

shadow_7283 wrote:

well, once its ready for a paint editor anyway.

Oh, we're ready.  We just farmed it out to volunteer labor...  hmm

Need some? I'm just getting done with college apps and I'm suddenly finding myself with lots of time...


http://i302.photobucket.com/albums/nn100/fullmoon32/wow.jpg

Offline

 

#6402 2012-12-15 22:06:00

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

Re: BYOB 3 - Discussion Thread

nXIII wrote:

Hardmath123 wrote:

Can't find it... hey Jens, do you know a good way to search a set of multiple files? I use Xcode to write my code, and normally I like to have all my code in the same file, all my styles in the same file, and all my HTML in the same file for web apps, for simplicity in editing.

1) Isn't Xcode's JavaScript formatting really messed up? I couldn't find a way to disable it…
EDIT: Oh, or you could just leave it on, I guess…
2) Click the third tab in the navigator area; it's a search utility.

Thanks.

Hardmath123 wrote:

One changeset for mosaic:

Code:

SpriteMorph.prototype.mosaicAmt = 1;
SpriteMorph.prototype.setEffect = function (effect, value) {
    var eff = effect instanceof Array ? effect[0] : null;
    if (eff === 'ghost') {
        this.alpha = 1 -
        Math.min(Math.max(parseFloat(value), 0), 100) / 100;
        this.changed();
    }
    if (eff === 'mosaic') {
        this.mosaicAmt = Number(value)>0 ? Number(value) : 1;
        this.changed();
        this.drawNew();
    }
};
SpriteMorph.prototype.changeEffect = function (effect, value) {
    var eff = effect instanceof Array ? effect[0] : null;
    if (eff === 'ghost') {
        this.setEffect(effect, this.getGhostEffect() + parseFloat(value));
    }
    if (eff === 'mosaic') {
        this.setEffect(effect, this.mosaicAmt + parseFloat(value));
    }
};

SpriteMorph.prototype.clearEffects = function () {
    this.setEffect(['ghost'], 0);
    this.setEffect(['mosaic'], 1);
};

SpriteMorph.prototype.drawNew = function () {
    var myself = this,
    currentCenter = this.center(),
    facing, // actual costume heading based on my rotation style
    isFlipped,
    pic, // (flipped copy of) actual costume based on my rotation style
    stageScale = this.parent instanceof StageMorph ?
    this.parent.scale : 1,
    newX,
    corners = [],
    origin,
    shift,
    corner,
    costumeExtent,
    ctx;
    
    facing = this.rotationStyle ? this.heading : 90;
    if (this.rotationStyle === 2) {
        facing = 90;
        if ((this.heading > 180 && (this.heading < 360))
            || (this.heading < 0 && (this.heading > -180))) {
            isFlipped = true;
        }
    }
    if (this.costume) {
        console.log(this.mosaicAmt);
        pic = isFlipped ? this.costume.flipped() : this.costume;
        
        // determine the rotated costume's bounding box
        corners = pic.bounds().corners().map(function (point) {
                                             return point.rotateBy(
                                                                   radians(facing - 90),
                                                                   myself.costume.center()
                                                                   );
                                             });
        origin = corners[0];
        corner = corners[0];
        corners.forEach(function (point) {
                        origin = origin.min(point);
                        corner = corner.max(point);
                        });
        costumeExtent = origin.corner(corner)
        .extent().multiplyBy(this.scale * stageScale);
        
        // determine the new relative origin of the rotated shape
        shift = new Point(0, 0).rotateBy(
                                         radians(-(facing - 90)),
                                         pic.center()
                                         ).subtract(origin);
        
        // create a new, adequately dimensioned canvas
        // and draw the costume on it
        this.image = newCanvas(costumeExtent);
        this.silentSetExtent(costumeExtent);
        ctx = this.image.getContext('2d');
        ctx.scale(this.scale * stageScale, this.scale * stageScale);
        ctx.translate(shift.x, shift.y);
        ctx.rotate(radians(facing - 90));
        
        for (var xpic = 0;  xpic < this.mosaicAmt; xpic++) {
            for (var ypic = 0;  ypic < this.mosaicAmt; ypic++) {
                ctx.drawImage(pic.contents, xpic*pic.contents.width/this.mosaicAmt, ypic*pic.contents.height/this.mosaicAmt, pic.contents.width/this.mosaicAmt, pic.contents.height/this.mosaicAmt);
            }
        }
        
        // adjust my position to the rotation
        this.setCenter(currentCenter);
        
        // determine my rotation offset
        this.rotationOffset = shift
        .translateBy(pic.rotationCenter)
        .rotateBy(radians(-(facing - 90)), shift)
        .scaleBy(this.scale * stageScale);
    } else {
        facing = isFlipped ? -90 : facing;
        newX = Math.min(
                        Math.max(
                                 this.normalExtent.x * this.scale * stageScale,
                                 5
                                 ),
                        1000
                        );
        this.silentSetExtent(new Point(newX, newX));
        this.image = newCanvas(this.extent());
        this.setCenter(currentCenter);
        SpriteMorph.uber.drawNew.call(this, facing);
        this.rotationOffset = this.extent().divideBy(2);
    }
    this.version = Date.now();
};

smile  I love your code, it's so organized.

Use (+value || 0) for casting a user value a number; it defaults to zero and avoids using the named Number function.

I need it to default to 1. Anything below 1 should become 1, too.


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

Offline

 

#6403 2012-12-15 23:55:03

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

Re: BYOB 3 - Discussion Thread

Hardmath123 wrote:

I need it to default to 1. Anything below 1 should become 1, too.

No, it should default to zero and be rounded up to one (which is essentially the same thing, but not what your current code does).

Code:

var value = +userValue || 0;
if (value < 1) value = 1;

Last edited by nXIII (2012-12-15 23:55:38)


nXIII

Offline

 

#6404 2012-12-16 07:19:33

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

Re: BYOB 3 - Discussion Thread

Fine. But I'd consider that nitpicking, since my code works perfectly fine anyway.

EDIT: Well, it depends. When you input a string in a number input, does the code get a string or parsed number?

Last edited by Hardmath123 (2012-12-16 07:20:28)


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

Offline

 

#6405 2012-12-16 09:23:50

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

Re: BYOB 3 - Discussion Thread

Hardmath123 wrote:

EDIT: Well, it depends. When you input a string in a number input, does the code get a string or parsed number?

We've been thinking that the silver lining of not having merged into Scratch is that we can rethink some elements of the Scratch design.  (Rethink for Snap!, I mean; none of what follows is meant to apply that the design of Scratch is flawed for Scratch.)

In order to avoid scaring away beginners, the Scratch Team chose to minimize the use of error messages, trying instead to make some sense of whatever the user does.  Hence, for example, all non-numbers where a number is expected are taken as zero.  That's indeed comforting on your first day, but it makes debugging your code harder than an error message would be, because when you eventually get bitten by the result of propagating that incorrect value through a computation, you have no help in finding out where the error actually happened.

So, Jens and I have been thinking that we should more freely give red borders instead of second-guessing the user when an input doesn't make sense.  I'd be inclined, if the user puts zero in a slot that demands a strictly positive number, to red-border it.  And even more strongly if the user puts a non-number there.

Maybe we should make the halo mauve instead of red, to be friendlier to the user.  smile

P.S.  We need to work on better error messages, along the lines of "perhaps you meant..." when appropriate, or "this input has to be greater than zero, because..."  Eventually.

Last edited by bharvey (2012-12-16 09:29:27)


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

Offline

 

#6406 2012-12-16 11:07:35

Jens
Scratcher
Registered: 2007-06-04
Posts: 1000+

Re: BYOB 3 - Discussion Thread

A string in a number slot gets transformed to a number or to zero, same as in Scratch. You can't even type non-numerical characters there, so the string has to come from a reporter.

Sorry about being abrupt, but right now I'm in release mode and not open to any kind of design discussion. Especially not in the forums. The only things which count until SIGCSE are cloud storage, documentation and materials about Snap, and eliminating showstopper bugs.


Jens Mönig

Offline

 

#6407 2012-12-16 11:11:56

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

Re: BYOB 3 - Discussion Thread

What about the actual change set? Will you use it?  smile


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

Offline

 

#6408 2012-12-16 13:36:36

Jens
Scratcher
Registered: 2007-06-04
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Thanks for the changeset. I'll play with it tomorrow and let you know sometime next week

Last edited by Jens (2012-12-16 13:37:09)


Jens Mönig

Offline

 

#6409 2012-12-16 17:58:30

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

Re: BYOB 3 - Discussion Thread

Hardmath123 wrote:

Fine. But I'd consider that nitpicking, since my code works perfectly fine anyway.

Your code accepts 0.1 and does not round it up to 1.

Also, don't abbreviate "amount" to "amt."


nXIII

Offline

 

#6410 2012-12-16 18:06:26

fillergames
Scratcher
Registered: 2012-10-15
Posts: 1000+

Re: BYOB 3 - Discussion Thread

What is this mod?


http://i50.tinypic.com/2ufvxc5_th.gif Grammer? Whats grammar?

Offline

 

#6411 2012-12-17 10:55:17

joefarebrother
Scratcher
Registered: 2011-04-08
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Jens wrote:

A string in a number slot gets transformed to a number or to zero, same as in Scratch. You can't even type non-numerical characters there, so the string has to come from a reporter.

Actually in scratch, if you have a string that starts with a number such as "32MB" it will return the number at the start of the string (32 in this case) and ignore the text, when put into a numerical slot.


My latest project is called http://tinyurl.com/d2m8hne! It has http://tinyurl.com/d395ygk views, http://tinyurl.com/cnasmt7 love-its, and http://tinyurl.com/bwjy8xs comments.
http://tinyurl.com/756anbk   http://tinyurl.com/iplaychess

Offline

 

#6412 2012-12-17 12:13:17

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

Re: BYOB 3 - Discussion Thread

bharvey wrote:

but what you want is Emacs, God's text editor.  No problem with multiple files.  And you can split your window in half and play ASCII Space Invaders in the other half while watching your code compiling.  smile

But viiiiimmm...


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

Offline

 

#6413 2012-12-17 15:34:01

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

Re: BYOB 3 - Discussion Thread

joefarebrother wrote:

Actually in scratch, if you have a string that starts with a number such as "32MB" it will return the number at the start of the string (32 in this case)

... whereas what the user clearly meant, if anything, is 32*10^6*8.

Not in 4.0, maybe not even in 4.1, but eventually we're going to get a good error handling system in place that will give good, useful error messages in a non-threatening way.


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

Offline

 

#6414 2012-12-17 16:03:04

AriArk
Scratcher
Registered: 2008-01-06
Posts: 25

Re: BYOB 3 - Discussion Thread

I need help with a block. How can I make a If received block (a circle one that goes in a IF block)

Offline

 

#6415 2012-12-17 18:47:34

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

Re: BYOB 3 - Discussion Thread

AriArk wrote:

I need help with a block. How can I make a If received block (a circle one that goes in a IF block)

It's not clear exactly what your desired block should do.  Is it true if that message has ever been broadcast?  Usually you want an asynchronous notification about broadcasts, which is why there's a hat block instead of a predicate.


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

Offline

 

#6416 2012-12-17 23:07:56

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

Re: BYOB 3 - Discussion Thread

Jens wrote:

Thanks for the changeset. I'll play with it tomorrow and let you know sometime next week

Great, thanks. Glad to help!  smile


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

Offline

 

#6417 2012-12-20 04:19:17

Jens
Scratcher
Registered: 2007-06-04
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Hi Hardmath123,

I've checked out your mosaic changeset and it's really cool! But at the moment I'm just too caught up in working on the cloud backend to integrate it now. The actual code isn't all that much (basically a short detour in the drawNew() method), but there are other areas of the code that need to adjust, too. And usually when I do things like this other things are likely to break. At this stage of development I'd like to freeze most features except for the cloud thing, so, if you don't mind I'll keep the changeset around and integrate it later, once I'm ready for it.

Thanks!

P.S. I like how you handle what you call the mosaicAmt, because it makes sense to me. But Scratch somehow converts it to change only every 10 steps, I guess so it doesn't completely blow up when going up to (and above) 100. Do you think you could adjust that?


Jens Mönig

Offline

 

#6418 2012-12-20 11:17:41

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

Re: BYOB 3 - Discussion Thread

Great! That's alright, and I'll be thrilled if any of my code is in Snap!!  smile  I understand what you mean about freezing new features; I'm paranoid about messing up some of my code too.

I can try to adjust the mosaic level thing. I'll need to mess with Scratch to see how it works. Currently I basically make an n by n array of the costume, but I'm not sure that's what Scratch does. I'll look into it.

P.S. How's the backend going? In what language are you coding it? I thought you were using JS+Node.js, but I'd personally suggest Google App Engine + Python, if you are still thinking about that. When are you planning to release some code?  smile


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

Offline

 

#6419 2012-12-20 12:14:19

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

Re: BYOB 3 - Discussion Thread

Hardmath123 wrote:

I understand what you mean about freezing new features; I'm paranoid about messing up some of my code too.

If we used real source control there would be no need for paranoia.

Last edited by nXIII (2012-12-20 12:14:28)


nXIII

Offline

 

#6420 2012-12-20 14:55:16

Jens
Scratcher
Registered: 2007-06-04
Posts: 1000+

Re: BYOB 3 - Discussion Thread

hey whaddaya mean, nxiii?!


Jens Mönig

Offline

 

#6421 2012-12-20 18:16:46

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

Re: BYOB 3 - Discussion Thread

Jens wrote:

hey whaddaya mean, nxiii?!

When you have something like git, you can branch easily (and revert to previous commits if you don't like the result), so you don't have to worry about messing up your code.


nXIII

Offline

 

#6422 2012-12-20 19:42:23

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

Re: BYOB 3 - Discussion Thread

*cough* SVN *cough*

By the way Jens, not sure if you're looking for a backend host for testing, but I've had extremely great results with AppFog. It uses real cloudracks, and you don't pay if you don't go above 2gb of RAM . Techwiq uses it to great (and free) effect.  big_smile

Last edited by shadow_7283 (2012-12-20 19:44:08)

Offline

 

#6423 2012-12-20 19:53:05

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

Re: BYOB 3 - Discussion Thread

shadow_7283 wrote:

*cough* SVN *cough*

Branching and merging is not as easy in SVN.

EDIT: But please don't turn this into a git vs. SVN flamewar. I only mention that because that's why I brought it up originally.

Last edited by nXIII (2012-12-20 19:53:33)


nXIII

Offline

 

#6424 2012-12-20 20:25:58

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

Re: BYOB 3 - Discussion Thread

Sorry, had no intentions of doing so. I just dislike GIT because its relatively difficult to use effectively on Windows. We had this discussion before, so just kidding around.  tongue  Anyway,
[/offtopic]

Offline

 

#6425 2012-12-21 02:28:56

Jens
Scratcher
Registered: 2007-06-04
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Snap's Morphic kernel is on github... is that 'real' enough?


Jens Mönig

Offline

 

Board footer