Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
It's bad that our old forum got messed up. I hope to add some old programs back to the NaaLaa forum as I run across them.
    I think NaaLaa is one of the better languages on Internet and should not be allowed to die out. Compare to FreeBasic. Now that's
a nightmare.

    The following sprite editor was a project made by several of our members. Maybe someone can refresh my memory on that.

Attached Files
.zip (Size: 228.23 KB / Downloads: 16)
I originally wrote this using sdlbasic many moons ago. I could not figure out several aspects of the program. One being the ability to load and save files. Several of the Naalaa members were very helpful. I could not have gotten as far as I did without them. Unfortunately, I placed the editor on a shelf a long time ago, and gave it no mind until I read your post.

I thought the listing looked familiar. I'm not complaining or 'crying poor'. I'm just glad that someone had the skill and patience to convert it to N6. I know there are FAR better editors 'out there', I just wanted to know if I could write one. Probably 'bit off more than I could chew' with this one. May be the reason I shelved it... lol

I still have the original sdl listing if you need it.


This was an interesting project, sorry for not participating in it. Busy days :/

Some things could be simplified by doing all the actual drawing to a separate image (created with 'create image').

In this tiny example, I create an image with the size canvasW*canvasH. Then I define two areas (rectangles) on the screen. One of the areas is of the same size as the actual canvas image. The other area has the canvas dimensions multiplied by 8. The first area is set up as canvasX, canvasY, canvasW and canvasH. The second area is set up as zoomX, zoomY, zoomW and zoomH, where zoomW and zoomH are canvasW*zoom and canvasH*zoom.

So, if the mouse cursor is over the first area, all we need to do to transform the coordinates into canvas coordinates (coordinates ON the canvas image) is to subtract canvasX and canvasY from the mouse position. If the mouse cursor is over the second area, we subtract zoomX and zoomY from the mouse coordinates and then divide them with zoom to get the canvas coordinates.

If the user holds down the left mouse button and is over any of the areas, we transform the mouse coordinates as above and draw on the canvas image instead of the screen. Then, in our main loop, we draw the canvas image at canvasX, canvasY and a scaled version at zoomX, zoomY.

It might seem more complicated, but in the long run it could make things easier Smile For example, saving the image is just a matter of calling 'save image' for the canvas image.

In the example you can draw in any of the rectangles.

Sorry if I'm sounding like a besserwisser Big Grin

' Draw stuff with zoom thing.

import "Keycodes.lib"

set redraw off

' Create canvas.
canvasImg = 0
canvasW = 32
canvasH = 32
canvasX = 336
canvasY = 64
create image canvasImg, canvasW, canvasH

' Zoomed canvas.
zoomX = 64
zoomY = 64
zoom = 8
zoomW = canvasW*zoom
zoomH = canvasH*zoom

' Mouse position.
drawX = mousex()
drawY = mousey()

' Loop.
    ' Store mouse position.
    mx = mousex()
    my = mousey()

    ' Mouse over canvas?
    if mx >= canvasX and mx < canvasX + canvasW and my >= canvasY and my < canvasY + canvasH
        over = 1
    ' Mouse over zoomed canvas?
    elseif mx >= zoomX and mx < zoomX + zoomW and my >= zoomY and my < zoomY + zoomH
        over = 2
        over = 0

    ' Draw?
    if mousebutton(0) and over
        ' Save last mouse position.  
        lastDrawX = drawX
        lastDrawY = drawY

        ' New mouse position.
        drawX = mx
        drawY = my

        ' Over canvas?
        if over = 1
            ' Transform to coordinates on canvas image.
            drawX = drawX - canvasX
            drawY = drawY - canvasY
        ' Over zoomed canvas?
            ' Transform to coordinates on canvas image.
            drawX = (drawX - zoomX)/zoom
            drawY = (drawY - zoomY)/zoom

        ' Is last position valid?        
        if not mouseDown
            lastDrawX = drawX
            lastDrawY = drawY
        mouseDown = true

        ' Draw on canvas, not on the screen.
        set image canvasImg
        set color 255, 255, 255
        draw line lastDrawX, lastDrawY, drawX, drawY
        set image primary
        mouseDown = false
    ' Clear screen.
    set color 0, 0, 0

    ' Write instructions.
    set color 255, 255, 255
    set caret 64, 8
    wln "Draw in any of the rectangles"

    ' Draw canvas.
    set color 255, 255, 255
    draw image canvasImg, canvasX, canvasY

    ' Draw zoomed version using the raster command.
    set color 255, 255, 255, 0
    for y = 0 to zoomH - 1
        v# = float(y)/float(zoomH)
        draw hraster canvasImg, zoomY + y, zoomX, zoomX + zoomW, 0.0, v, 1.0, v

    ' Draw borders around canvas and zoomed canvas.
    set color 128, 128, 128
    draw rect canvasX - 1, canvasY - 1, canvasW + 2, canvasH + 2
    draw rect zoomX - 1, zoomY - 1, zoomW + 2, zoomH + 2

    wait 10
until keydown(VK_ESC, true)
Interesting method. I had never even thought of actually drawing in the 'preview' window... Many thanks.


ps: No need to apologize, after all, the program is almost 4 years old... lol
Nice concept. Someday someone needs to expand this into a full drawing program.
Hmm... Thought about that... unfortunately my skill (and I use that word VERY loosely) level is rather less than I had hoped... *sigh* Doing some research into how different drawing options are coded eg: Rectangles, Circles, Fill etc

I was hoping for something like MSPaint. Something simple. A full drawing program is WAY over my head... "Someday" has almost stretched out to 4 years... and the "someone" would probably be anyone but me... lol

(02-24-2018, 12:20 AM)Rick3137 Wrote: It's bad that our old forum got messed up. I hope to add some old programs back to the NaaLaa forum as I run across them.

Well, I think that examples should be kept in a dedicated space. Forums are for discussions. They tend to get messy, spammed, hacked, destroyed... Just a simple static page with examples grouped in categories and ready to download would be much clearer and easier to backup. Everyone could use wget to make a local copy. Bringing it back or moving to another hosting would be extremely easy. How should we call it? Naalaaland? Smile
+10 for naalaaland Big Grin

I still have a backup of the games section from the old webpage. I was thinking about recompiling everything there for Linux and create a new page. Might be interesting for those who just want to see what you can do with naalaa. But you're suggesting a more general page with cathegorized downloads?
Possibly. To be honest, my main point is that we shouldn't rely on the forum as a space for NaaLaa examples. Remember old forum? How many times was it down before, finally, it was gone forever? And every single time there was someone saying "So many examples are lost...". Then the forum was back and people kept posting examples again like nothing happened.

Forum Jump:

Users browsing this thread: 1 Guest(s)