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

#151 2011-12-15 09:22:03

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

Re: JsScratch viewer development thread

MathWizz wrote:

Code:

function Vector2(x, y)
{
    this.x = x || 0;
    this.y = y || 0;
}

Don't leave out the lesser-known numbers:

Code:

new Vector2(NaN, NaN)
new Vector2(-0, -0)

(I have actually needed the former to do something before)

Code:

function Vector2(x, y) {
    this.x = x === undefined ? x : 0;
    this.y = y === undefined ? y : 0;
}

or maybe:

Code:

function Vector2(x, y) {
    this.x = arguments.length > 0 ? x : 0;
    this.y = arguments.length > 1 ? y : 0;
}

Anyways, that's not a great example of default arguments because I've never needed* to pass less than 2 arguments to a Vector2 constructor, but it's useful to know how to implement them.

* Except morphic.js, which uses

Code:

SubClass.prototype = new SuperClass();

when it should use

Code:

SubClass.prototype = Object.create(SuperClass.prototype);

because new is just an Object.create call and a constructor call on that object (which you don't want to happen).


nXIII

Offline

 

#152 2011-12-15 09:37:02

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

Re: JsScratch viewer development thread

Oh... be careful with forms that have fewer pixels than they should:

http://oi43.tinypic.com/s2tv0h.jpg

(that's the penTrails form)


nXIII

Offline

 

#153 2011-12-15 10:03:48

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

Re: JsScratch viewer development thread

nXIII wrote:

Oh... be careful with forms that have fewer pixels than they should:

http://oi43.tinypic.com/s2tv0h.jpg

(that's the penTrails form)

Yikes. Umm. How to avoid?


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

Offline

 

#154 2011-12-15 10:17:43

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

Re: JsScratch viewer development thread

MathWizz wrote:

nXIII wrote:

Oh... be careful with forms that have fewer pixels than they should:

http://oi43.tinypic.com/s2tv0h.jpg

(that's the penTrails form)

Yikes. Umm. How to avoid?

I'm not sure. I think it happens when the pixel data doesn't cover the image and only describes a region inside of it.

EDIT: Oh, actually I was using a 3 instead of a 4 in my loop. whoops  wink

http://oi44.tinypic.com/2unls.jpg

Last edited by nXIII (2011-12-15 10:26:24)


nXIII

Offline

 

#155 2011-12-15 11:30:29

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

Re: JsScratch viewer development thread

yikes  You make me jealous.


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

Offline

 

#156 2011-12-15 11:57:28

ProgrammingFreak
Scratcher
Registered: 2010-09-04
Posts: 1000+

Re: JsScratch viewer development thread

ProgrammingFreak wrote:

Okay, so I've done the code, but I can't get it to work with morphic. :l

Offline

 

#157 2011-12-15 12:25:32

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

Re: JsScratch viewer development thread

@nXIII Ok. So now I have an array of bytes with one byte for every pixel of the image, but every value except for every 4th one is 0. Is this supposed to happen?

I have a very small image with these bits:

Code:

860094464
860094464
287440896
287440896

I decode them into:

Code:

0: 209984
1: 0
2: 0
3: 0
4: 209984
5: 0
6: 0
7: 0
8: 70176
9: 0
10: 0
11: 0
12: 70176
13: 0
14: 0
15: 0

EDIT: I just realized... Is it run length encoded (or similar to that)?

EDIT: I ran the Java code and it returns the index of the colors for every pixel. Time to debug.

EDIT: LAST EDIT! I found the bugs but and I am sure it should work, but but I'm STILL not getting the right output. I think it may be caused by rounding er... OH WAIT! You said to split the 32 bits words to avoid ROUNDING ERRORS didn't you.  tongue

EDIT: Wowfail. So much trouble because the Java code rounded when it divided integer and JavaScript did not.  neutral

ProgrammingFreak wrote:

Okay, so I've done the code, but I can't get it to work with morphic. :l

Umm... Put it under the Morph's drawNew method?

EDIT: Scratch (no pun intended) that. It would probably go under drawOn instead.

Last edited by MathWizz (2011-12-15 14:45:34)


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

Offline

 

#158 2011-12-15 13:18:23

GP1
Scratcher
Registered: 2009-07-06
Posts: 1000+

Re: JsScratch viewer development thread

So, I'm guessing i'm in?


I am currently http://blocks.scratchr.org/API.php?user=GP1&action=onlineStatus&type=imagehttp://blocks.scratchr.org/API.php?user=GP1&action=onlineStatus&type=text and I finally got over 1000 posts.

Offline

 

#159 2011-12-15 13:32:31

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

Re: JsScratch viewer development thread

@GP1 *waits for midnightleopard to get on*

I've kinda had a monopoly on the code, haven't I?  tongue


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

Offline

 

#160 2011-12-15 15:37:33

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

Re: JsScratch viewer development thread

MathWizz wrote:

Lots of edits

Yeah, it's run-coded.
ColorForms end up with a ByteArray of indices in their colors array (which has 2^depth colors in it). Forms end up with an array of colors of the Form's depth. I treat it as a BitArray and let Color.depthData, which gets a single color from a stream + a known depth, deal with the Form's depth.

If you're doing int division for retrieving a number of bytes from an image, I would recommend the bitwise operator >>, which doesn't leave you with a decimal. You could also just make sure you use a bitwise & later.

EDIT: Oh, I forgot a bit shift is really the end of a boolean block. Why does [blocks] get automatically turned on?!

Last edited by nXIII (2011-12-15 15:38:53)


nXIII

Offline

 

#161 2011-12-15 16:54:47

ProgrammingFreak
Scratcher
Registered: 2010-09-04
Posts: 1000+

Re: JsScratch viewer development thread

Are we using jQuery for this? I think it would be helpful.

Offline

 

#162 2011-12-15 22:55:36

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

Re: JsScratch viewer development thread

ProgrammingFreak wrote:

Are we using jQuery for this? I think it would be helpful.

No.

@nXIII I had already fixed it.  tongue


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

Offline

 

#163 2011-12-16 10:58:01

GP1
Scratcher
Registered: 2009-07-06
Posts: 1000+

Re: JsScratch viewer development thread

So, could you guys fill me in on how this works and what I have to work on, and maybe the documentation of reading scratch projects?


I am currently http://blocks.scratchr.org/API.php?user=GP1&action=onlineStatus&type=imagehttp://blocks.scratchr.org/API.php?user=GP1&action=onlineStatus&type=text and I finally got over 1000 posts.

Offline

 

#164 2011-12-16 11:06:30

ProgrammingFreak
Scratcher
Registered: 2010-09-04
Posts: 1000+

Re: JsScratch viewer development thread

MathWizz wrote:

ProgrammingFreak wrote:

Are we using jQuery for this? I think it would be helpful.

No.

@nXIII I had already fixed it.  tongue

Alright. And yes, I'd love some kind of documentation also.  wink

Offline

 

#165 2011-12-16 11:19:55

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

Re: JsScratch viewer development thread

WOOOOO!!! Images with depths less than or equal to 8 work as of now.  big_smile

http://jsscratch.co.cc/player/player.ht … mg+test.sb


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

Offline

 

#166 2011-12-16 11:43:38

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

Re: JsScratch viewer development thread

Oh no, this can't be right...

Code:

isLarge: WatcherReadoutFrameMorph
isSpriteSpecific: "shrinkWrap"
owner: ScratchStageMorph
readout: Color
readoutFrame: "vertical"
scratchSlider: "center"
sliderMax: UpdatingStringMorph
sliderMin: StringMorph
submorphs: Array[2]
titleMorph: 1
unused: 0
watcher: "shrinkWrap"

I think I mixed up the field order  tongue

Last edited by nXIII (2011-12-16 11:43:50)


nXIII

Offline

 

#167 2011-12-16 11:46:46

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

Re: JsScratch viewer development thread

@nXIII  tongue


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

Offline

 

#168 2011-12-16 12:04:43

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

Re: JsScratch viewer development thread

Oh, actually, it just didn't initialize the AlignmentMorph fields.


nXIII

Offline

 

#169 2011-12-16 12:16:08

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

Re: JsScratch viewer development thread

Is the "Browser Unsupported" bit just a hint at "We're not done yet, so buzz off", or am I missing a plugin?


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

Offline

 

#170 2011-12-16 12:27:16

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

Re: JsScratch viewer development thread

Hardmath123 wrote:

Is the "Browser Unsupported" bit just a hint at "We're not done yet, so buzz off", or am I missing a plugin?

It's because I can't figure out how to read binary data with some browsers. Try Chrome or Firefox 4 or later.

Last edited by MathWizz (2011-12-16 12:27:34)


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

Offline

 

#171 2011-12-16 13:03:18

Dawgles
Scratcher
Registered: 2011-07-29
Posts: 100+

Re: JsScratch viewer development thread

This is coming along brilliantly! I'm really impressed.  smile

Offline

 

#172 2011-12-16 13:22:38

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

Re: JsScratch viewer development thread

Dawgles wrote:

This is coming along brilliantly! I'm really impressed.  smile

Thanks.  smile


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

Offline

 

#173 2011-12-16 13:24:55

ProgrammingFreak
Scratcher
Registered: 2010-09-04
Posts: 1000+

Re: JsScratch viewer development thread

MathWizz wrote:

WOOOOO!!! Images with depths less than or equal to 8 work as of now.  big_smile

http://jsscratch.co.cc/player/player.ht … mg+test.sb

Yesss!  big_smile

Offline

 

#174 2011-12-16 17:07:14

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

Re: JsScratch viewer development thread

Forms with depth of 16 are... Umm... Interesting. http://jsscratch.co.cc/player/player.ht … g+test3.sb  hmm


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

Offline

 

#175 2011-12-17 05:49:38

rookwood101
Scratcher
Registered: 2011-07-29
Posts: 500+

Re: JsScratch viewer development thread

MathWizz wrote:

WOOOOO!!! Images with depths less than or equal to 8 work as of now.  big_smile

http://jsscratch.co.cc/player/player.ht … mg+test.sb

You are officially amazing.


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

Offline

 

Board footer