MathWizz wrote:
Code:
function Vector2(x, y) { this.x = x || 0; this.y = y || 0; }
Don't leave out the lesser-known numbers:
new Vector2(NaN, NaN) new Vector2(-0, -0)
(I have actually needed the former to do something before)
function Vector2(x, y) { this.x = x === undefined ? x : 0; this.y = y === undefined ? y : 0; }
or maybe:
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
SubClass.prototype = new SuperClass();
when it should use
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).
Offline
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?
Offline
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
Last edited by nXIII (2011-12-15 10:26:24)
Offline
ProgrammingFreak wrote:
Okay, so I've done the code, but I can't get it to work with morphic. :l
Offline
@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:
860094464 860094464 287440896 287440896
I decode them into:
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.
EDIT: Wowfail. So much trouble because the Java code rounded when it divided integer and JavaScript did not.
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)
Offline
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)
Offline
Are we using jQuery for this? I think it would be helpful.
Offline
MathWizz wrote:
ProgrammingFreak wrote:
Are we using jQuery for this? I think it would be helpful.
No.
@nXIII I had already fixed it.
Alright. And yes, I'd love some kind of documentation also.
Offline
WOOOOO!!! Images with depths less than or equal to 8 work as of now.
http://jsscratch.co.cc/player/player.ht … mg+test.sb
Offline
Oh no, this can't be right...
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
Last edited by nXIII (2011-12-16 11:43:50)
Offline
Is the "Browser Unsupported" bit just a hint at "We're not done yet, so buzz off", or am I missing a plugin?
Offline
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)
Offline
This is coming along brilliantly! I'm really impressed.
Offline
MathWizz wrote:
WOOOOO!!! Images with depths less than or equal to 8 work as of now.
http://jsscratch.co.cc/player/player.ht … mg+test.sb
Yesss!
Offline
Forms with depth of 16 are... Umm... Interesting. http://jsscratch.co.cc/player/player.ht … g+test3.sb
Offline
MathWizz wrote:
WOOOOO!!! Images with depths less than or equal to 8 work as of now.
http://jsscratch.co.cc/player/player.ht … mg+test.sb
You are officially amazing.
Offline