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

#51 2012-05-01 06:05:16

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

Re: kurt — Scratch file format Python library

s_federici wrote:

You are really doing an incredible job blob  smile  thanks a lot for all this!

Why thank you!  big_smile  have you been trying it?


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

Offline

 

#52 2012-05-01 20:01:28

Jwosty
Scratcher
Registered: 2009-12-19
Posts: 500+

Re: kurt — Scratch file format Python library

Well this looks pretty interesting; another reason to learn Python xD


http://i39.tinypic.com/18ert5.png Google it.  smile

Offline

 

#53 2012-05-02 01:52:24

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

Re: kurt — Scratch file format Python library

Jwosty wrote:

Well this looks pretty interesting; another reason to learn Python xD

Absolutely!  big_smile  Python's pretty nice; although I suspect Ruby's slightly nicer. And the Construct library is awesome for parsing stuff.  smile


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

Offline

 

#54 2012-06-12 17:07:48

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: kurt — Scratch file format Python library

I want to integrate kurt into a script that can generate projects based on input from the user. More specifically, a Python web-server who uses forms to pass data to Kurt, then allows the user to download the final .sb.


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#55 2012-06-12 17:15:00

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

Re: kurt — Scratch file format Python library

It's certainly possible; what kind of input, and what kind of projects?  smile


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

Offline

 

#56 2012-06-12 17:17:27

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: kurt — Scratch file format Python library

I'll give an example. I make an sb (in Scratch, not Kurt) of an empty sprite saying the text "__INPUT1__". I would like a user to upload an image and input some text. The image would be written as the sprites costume, and the text would replace the text __INPUT1__. Then, Kurt would output the new sb. (without overwriting the old one)


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#57 2012-06-13 02:56:43

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

Re: kurt — Scratch file format Python library

You can do something like this (leaving out the web stuff):

Code:

from kurt.files import *
from kurt import Form
# (just do a single `from kurt import *` if you prefer)

picture_path = "users_picture.png"
text = """User's text.
Can be multiple lines, but doesn't have to be.
One issue is that Scratch doesn't seem to automatically wrap the text (ie. you 
have to insert line breaks yourself in all the right places, which is quite hard 
without rendering the text yourself at some point.
"""

text = text.replace("\r\n", "\n")
text = text.replace("\r", "\n")
text_lines = [unicode(line+"\r") for line in text.split("\n")] 
    # Format text for Scratch costume — I need to add something like this to 
    # Kurt itself at some point

project = ScratchProjectFile("original_project.sb")

image = project.sprites[0].costumes[0] # Adjust as necessary

image.textBox.lines = text_lines
image.form = Form.load_png(picture_path) # Replace costume with new

image.compositeForm = None # Scratch keeps a copy of the text rendered onto
                           # the image — deleting this will force Scratch
                           # to redraw the image

project.save("new_project.sb")
    # pass a path argument to save() saves with new name, so won't overwrite old
    # project. FYI, subsequent calls to project.save() will use the new path.

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

Offline

 

#58 2012-06-13 08:03:38

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: kurt — Scratch file format Python library

I'll play around with that, thanks.


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#59 2012-06-13 09:25:03

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

Re: kurt — Scratch file format Python library

Just a quick note — you'll need to grab the dev branch of Kurt for now. It has loads of new stuff, like images; and I haven't quite gotten round to merging it back to master yet.  smile


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

Offline

 

#60 2012-06-13 15:44:28

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: kurt — Scratch file format Python library

blob8108 wrote:

Just a quick note — you'll need to grab the dev branch of Kurt for now. It has loads of new stuff, like images; and I haven't quite gotten round to merging it back to master yet.  smile

Oh, kay.


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#61 2012-06-13 16:50:01

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: kurt — Scratch file format Python library

File "/kurt/fixed_objects.py", line 663, in load_png
TypeError: can only extend array with array (not "int")


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#62 2012-06-14 03:08:39

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

Re: kurt — Scratch file format Python library

I just checked it again; it definitely works for me. What platform are you using? Are you sure it's a PNG file?


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

Offline

 

#63 2012-06-14 15:59:49

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: kurt — Scratch file format Python library

I used a different file, and that message isn't there, but kurt just hangs.


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#64 2012-06-14 16:09:55

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

Re: kurt — Scratch file format Python library

What traceback do you see if you Ctrl+C? Which platform are you using, again?

Are you sure it's the latest version of Kurt? (Try the version off PyPI.) Are you sure Construct and PyPNG are updated?


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

Offline

 

#65 2012-06-14 16:12:42

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: kurt — Scratch file format Python library

Wait! That's not true! It doesn't hang. It just takes a tremendously large time to process. The original file was 13 KB, and the image was a half a megabyte.
The output file was 31 megs.

Last edited by bobbybee (2012-06-14 16:13:04)


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#66 2012-06-14 16:21:37

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: kurt — Scratch file format Python library

Update: the image was too big for kurt to handle, thus causing the compression issues. It works fine with smaller files. Kurt should refuse to load files above X number of bytes.


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#67 2012-06-14 16:23:13

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

Re: kurt — Scratch file format Python library

bobbybee wrote:

Wait! That's not true! It doesn't hang. It just takes a tremendously large time to process. The original file was 13 KB, and the image was a half a megabyte.
The output file was 31 megs.

tongue

How big is the image, dimensions-wise? Can you link it?

The Scratch format uses run-length encoding to compress the images. Kurt decompresses the images fine, but I haven't got it to compress them yet. If you open them in Scratch and save, it should fix.

* This means it stores the whole image in memory while it's processing it. That might be the cause of the delay...

I'll admit this isn't great for what you're trying to do; I hope to do some work on fixing it soon.  smile

Last edited by blob8108 (2012-06-14 16:23:56)


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

Offline

 

#68 2012-06-14 16:24:26

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: kurt — Scratch file format Python library

Dimensions? (gulps) Erm...in the thousands.



With this fix down, I have gotten the sprites costumes to change right. How do I access the stages costumes?

Last edited by bobbybee (2012-06-14 16:25:11)


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#69 2012-06-14 16:31:10

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

Re: kurt — Scratch file format Python library

bobbybee wrote:

Dimensions? (gulps) Erm...in the thousands.

Why on earth would you want an image larger than 480x360 in a Scratch project...?  tongue

With this fix down, I have gotten the sprites costumes to change right. How do I access the stages costumes?

project.stage.backgrounds

Pro tip: .images (rather than .costumes or .backgrounds) works for both sprites and stage, if you prefer.

Last edited by blob8108 (2012-06-14 16:39:44)


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

Offline

 

#70 2012-06-14 16:39:30

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: kurt — Scratch file format Python library

blob8108 wrote:

bobbybee wrote:

Dimensions? (gulps) Erm...in the thousands.

Why on earth would you want an image larger than 480x360 in a Scratch project...?  tongue

I'm crazy... (well, I didn't resize the image)

With this fix down, I have gotten the sprites costumes to change right. How do I access the stages costumes?

project.stage.backgrounds

Pro tip: .images (rather than .costumes or .backgrounds) works for both sprites and stage if you prefer.

Thanks.


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#71 2012-06-14 16:50:21

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: kurt — Scratch file format Python library

For some reason, the PNGs I make in PhotoShop are incompatible with Kurt (it was what was causing the original error)


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#72 2012-06-14 16:54:59

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

Re: kurt — Scratch file format Python library

Weird. Maybe PyPNG has issues with them. Did you try "Save for Web"?


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

Offline

 

#73 2012-06-14 16:58:11

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: kurt — Scratch file format Python library

I just tried. Didn't seem to make a difference  hmm


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#74 2012-06-14 17:12:26

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

Re: kurt — Scratch file format Python library

That is extremely strange. Could you send me an example offending file? Thanks!  smile

Last edited by blob8108 (2012-06-14 17:12:36)


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

Offline

 

#75 2012-06-14 17:13:59

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: kurt — Scratch file format Python library

Sure...


I support the Free Software Foundation. Protect our digital rights!

Offline

 

Board footer