Author Topic: The start of a Painting program  (Read 3305 times)

Offline backspace

  • Mr. Drawsprite
  • **
  • Posts: 53
    • View Profile
The start of a Painting program
« on: 2013-Jan-13 »
After a lot of fun and headaches with the MEM* commands, some of which still need to be resolved, I finally got the basic ideas for a painting program to work.
There's still a lot of work to do, but this should serve as a sample of having some simple "painting" fun

Left mouse button to paint
Right mouse button to reset

Images uses in this sample are attached.

Code: GLBasic [Select]
// --------------------------------- //
// Project: mem-paint-test
// --------------------------------- //


SETCURRENTDIR("Media")


LOCAL PX1%[], PX2%[]
LOCAL x,y,r,c,i,mx,my,mbl,mbr,rr,cc
LOCAL cr,cg,cb,ca
LOCAL argb%


CREATESCREEN 1,1,640,480
CREATESCREEN 2,2,40,40
CREATESCREEN 3,3,640,480

LOADSPRITE "catndog1.png",1
LOADSPRITE "ball.png",2


WHILE TRUE

        //get mouse state
        MOUSESTATE mx,my,mbl,mbr
       
        //reset image - should build load safety timer here.. but its a test anyway.
        IF mbr = 1 THEN LOADSPRITE "catndog1.png",1


        //check that the mouse right and bottom are on the screen
        //.....else the arrays fall over
       
        IF mx+39 < 640 AND my+39 < 480
                //get the background
                SPRITE2MEM (PX1[],1)
               
                //get paintbrush  
                SPRITE2MEM (PX2[],2)
               
                //paste brush onto background
                IF mbl = 1
                        rr = -1
                        FOR r = my TO my + 39   //for each row
                                rr = rr + 1
                                cc = -1
                                FOR c = mx TO mx + 39  //for each column
                                        cc = cc + 1
                                       
                                        argb = PX2[cc+rr*40]
                                        cr = BAND(argb, 0xff)
                                        cg = BAND(ASR(argb,8), 0xff)
                                        cb = BAND(ASR(argb,16), 0xff)
                                        ca = BAND(ASR(argb,24), 0xff)
                                       
                                        IF ca <> 0
                                                PX1[c+r*640] = argb
                                        ENDIF
                                               
                                NEXT
                        NEXT
                        MEM2SPRITE (PX1[],1,640,480)
                 
                ENDIF
        ENDIF     //mouse in screen    

        //START DRAWING from here
        USESCREEN -1
       
        //dump background
        DRAWSPRITE 1,0,0
       
       
        //display paintbrush
        DRAWSPRITE 2,mx,my
       
        PRINT "Right Mouse button to reset", 5,450
        SHOWSCREEN
WEND
 

[attachment deleted by admin]
I came, I saw, I coded.

Offline Brick Redux

  • Mr. Drawsprite
  • **
  • Posts: 60
    • View Profile
Re: The start of a Painting program
« Reply #1 on: 2013-Apr-26 »
Alot of time and thought went into that and thats good.  Well done. 
A mournful owner of a HP HDX18 Laptop that has died...FECK!

Offline Darmakwolf

  • Dr. Type
  • ****
  • Posts: 341
  • Aoooooooo - the werewolves of London!
    • View Profile
Re: The start of a Painting program
« Reply #2 on: 2013-Apr-26 »
After a lot of fun and headaches with the MEM* commands, some of which still need to be resolved, I finally got the basic ideas for a painting program to work.
There's still a lot of work to do, but this should serve as a sample of having some simple "painting" fun

Left mouse button to paint
Right mouse button to reset

Images uses in this sample are attached.

Hello backspace! I took the liberty of creating a dynamic brush system for you to sample. It does not use any of the mem commands, but it allows for a technically infinite number of brushes to be thrown into the media folder without having to update the code. You're more than welcome to use it, I was just bored. You use the mouse scroll wheel to change brushes. Added brushes just get named the next one up... brush6.bmp, brush7.bmp, etc.
« Last Edit: 2013-Apr-26 by Darmakwolf »

Offline backspace

  • Mr. Drawsprite
  • **
  • Posts: 53
    • View Profile
Re: The start of a Painting program
« Reply #3 on: 2013-Apr-26 »
Thanks Darmakwolf, I am sure the kids will love playing with it. I'll incorporate it into one of my edu-kits (with full kudo to you).
I have stopped my exploration into brush effects due to limited time in my curriculum, but I always refer back to enhancements on things I have touched on, such as painting, in order to re-inforce the knowledge with the thrill of applying new technology to them. So you have my sincere thanks.
I came, I saw, I coded.

Offline Darmakwolf

  • Dr. Type
  • ****
  • Posts: 341
  • Aoooooooo - the werewolves of London!
    • View Profile
Re: The start of a Painting program
« Reply #4 on: 2013-Apr-26 »
No problem! It only took me a few minutes to make anyhow. You can make new brushes with any image editor and saving it to the media folder.

I had an interesting idea though... I noticed painting like this relies on the user's smooth movements to make smooth lines... which are sometimes choppy. Perhaps I could simply calculate the change in the cursor's X and Y each frame, and loop through several times to paint the in-between coordinates creating a smoother arc.