Author Topic: sprite editor  (Read 33161 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: sprite editor
« Reply #45 on: July 05, 2018, 12:11:46 pm »
Thanks Fellippe, that should do nicely.

Do you know of any InForm apps that did use 3 sliders for RGB, seems to me it would be THE Demo for slider bars.

FellippeHeitor

  • Guest
Re: sprite editor
« Reply #46 on: July 05, 2018, 01:17:54 pm »
Well, InForm Designer has three sliders for RGB color mixing, and it's been created using InForm Designer itself, so there's your app.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: sprite editor
« Reply #47 on: July 05, 2018, 01:29:44 pm »
That's where I saw it before!  :)

 Thanks Fellippe

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
Re: sprite editor
« Reply #48 on: July 05, 2018, 03:13:03 pm »
Thank you very much, Johnno56. What version of Linux do you use? I repaired one of the deferred older notebooks, so I would install it there to test it. First I will have to find instructions on installing QB64 under Linux ....

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
Re: sprite editor
« Reply #49 on: July 05, 2018, 03:45:27 pm »
Quote
Modify

Hmm... I wonder about reversing that process, click a point from the blown up image and set color selector to that color (along with the slider bars).

It is not difficult. This is a normal percent example: You have a R bar, a G bar and a B bar. 0% is on the left and it is 0. 100% is on right, the value for R and G i B is maximum 255. So if it loads with the POINT or _MEMGET command a pixel of the image, the function returns three R, G, B values. For example the color _RGB32 (128,255,0), so 128 is exactly 50 percent of 256, the driver for R is set in the middle. 255 for G is 100 percent, that set driver to the right. B is 0, ie zero percent. The driver for B will be at the beginning. On the same principle working drivers in my SNDRAW player.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
Re: sprite editor
« Reply #50 on: July 05, 2018, 05:39:52 pm »
Petr,

In regards to installing Linux, now days, it's not hard at all. You mentioned an "older" notebook... Some of the mainstream versions of Linux, as with newer versions of Windows, will probably be a bit sluggish on older machines mainly because the newer OS's can be quite taxing on older systems.

Linux has installations for older machines... Yay! Ubuntu has Lubuntu and Xubuntu for example... All you do is go to their homepage; Download the ISO image; Burn it to a DVD or USB drive; Pop it into the notebook and boot. You can either install or test it without installing... Just in case... lol

[abandoned, outdated and now likely malicious qb64 dot net website - don’t go there] has both 32 and 64 bit versions for Linux. (Oh no! [abandoned, outdated and now likely malicious qb64 dot net website - don’t go there] has problems! No. the main website is fine. It seems that the Forums are "on the fritz"...)

If you need help... You know where I am... lol

J
Logic is the beginning of wisdom.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
Re: sprite editor
« Reply #51 on: July 06, 2018, 03:45:19 pm »
Outside the topic: BPlus, Here's your realization, setings graphics drivers according to the returned color. Fullscreen is NOT USED :-D

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 600, 32)
  2.     i& = _LOADIMAGE("bart.jpg", 32)
  3.     _PUTIMAGE , i&
  4.     c& = POINT(_MOUSEX, _MOUSEY)
  5.     Red = _RED32(c&): green = _GREEN32(c&): blue = _BLUE32(c&)
  6.     clr$ = STR$(Red) + ", " + STR$(green) + ", " + STR$(blue)
  7.     LOCATE 4, 1: PRINT "Selected color is"; clr$
  8.     LINE (550, 10)-(750, 70), _RGB32(0, 0, 0), BF
  9.  
  10.     _PRINTSTRING (570, 12), "R"
  11.     R = Drive(600, 20, 255, Red)
  12.     _PRINTSTRING (570, 32), "G"
  13.     g = Drive(600, 40, 255, green)
  14.     _PRINTSTRING (570, 52), "B"
  15.     b = Drive(600, 60, 255, blue)
  16.  
  17.     LOCATE 1, 1: PRINT "R driver is set to"; R; " percent"
  18.     LOCATE 2, 1: PRINT "G driver is set to"; g; " percent"
  19.     LOCATE 3, 1: PRINT "B driver is set to"; b; " percent"
  20.     _DISPLAY
  21.  
  22. FUNCTION Drive (xpos, ypos, max, vlue)
  23.     LINE (xpos, ypos)-(xpos + 100, ypos)
  24.     Drive = (vlue / max) * 100
  25.     l2 = xpos + Drive
  26.     LINE (l2, ypos + 5)-(l2 + 5, ypos - 5), , BF
  27.  

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
Re: sprite editor
« Reply #52 on: July 06, 2018, 03:54:29 pm »
please, give LOADIMAGE before DO. This Odin politic - time limited edit for own sources is really bad.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
Re: sprite editor
« Reply #53 on: July 06, 2018, 07:41:21 pm »
Guys,

I have decided to shelve the Sprite Editor. I originally started it to, "See if I could", but came up against what "I" call a problem, of simply loading and saving each project. I ended up with the same problem using sdlbasic (original version) as I am now having with QB64. Projects can eventually be saved and loaded but not 'simply'. I feel the amount of work needed to complete the project kind of out weighs the concept of a "simple" editor. You guys have put in more work than I could have hoped for and for that I'm very appreciative. I think from now on I will restrict my ideas to what I can actually achieve...

Thanks guys.

J
Logic is the beginning of wisdom.

FellippeHeitor

  • Guest
Re: sprite editor
« Reply #54 on: July 06, 2018, 10:03:03 pm »
Steve also has a file select library that's cross platform, maybe he could repost it.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • Steve’s QB64 Archive Forum
Re: sprite editor
« Reply #55 on: July 07, 2018, 02:02:13 am »
Steve also has a file select library that's cross platform, maybe he could repost it.

http://qb64.freeforums.net/thread/63/file-directory-listing-arrays

Try the above. It's not a GUI file selection tool, but it's a crossplatform way to get information into a set of directory and file arrays.  I've got a GUI version around here somewhere as well, but most folks just seem to enjoy making their own interface and using the stripped down version here to get the information they need, instead.  ;)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
Re: sprite editor
« Reply #56 on: July 07, 2018, 04:29:06 am »
Johnno56, do not be sad. Every such project just wants to do it in small steps until you finally get a big result. I will continue with this and add commented source codes here. This time I will test them in both Linux and Windows before i post it here.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: sprite editor
« Reply #57 on: July 08, 2018, 12:29:29 pm »
Johnno, this is excellent project idea!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: sprite editor
« Reply #58 on: September 07, 2020, 04:42:54 pm »
OK here is an update of Johnno's v03 and some mods to get an image loaded and into the grid edit area.

Code: QB64: [Select]
  1. '   =========================================================
  2. '
  3. '       SPRITE DRAW v03 by johnno    b+ mods 2020-09-07  comment with " '<
  4. '
  5. '   =========================================================
  6.  
  7. SCREEN _NEWIMAGE(1280, 640, 32) '< reduce width to fit my screen
  8. _DELAY .25
  9. _SCREENMOVE 66, 50 '<  get it off my left side title bar, you will likely want some other adjustment
  10.  
  11. DIM SHARED currentcolour AS _UNSIGNED LONG
  12. 'DIM SHARED clr AS _UNSIGNED LONG
  13.  
  14.  
  15. gridcolour = _RGB32(64, 64, 64)
  16. red = _RGB32(255, 0, 0)
  17. darkred = _RGB32(160, 0, 0)
  18. green = _RGB32(0, 160, 0)
  19. yellow = _RGB32(160, 160, 0)
  20. black = _RGB32(0, 0, 0)
  21. gray = _RGB32(164, 164, 164)
  22. white = _RGB32(255, 255, 255)
  23. currentcolour = _RGB32(0, 0, 0)
  24.  
  25. DIM SHARED gridsize, gsize ' < the rest of these too
  26. gridsize = 64
  27. gsize = 9
  28. psize = 1
  29. tools = 5
  30. resetcurrentcolour = 0
  31. DIM SHARED symmetry AS INTEGER
  32. symmetry = 0
  33. exist = 0
  34.  
  35. ' < for ? don't need
  36. 'r5 = 0
  37. 'g5 = 0
  38. 'b5 = 0
  39.  
  40. zones = 9 ' < mouse cleck areas
  41. quit = 0
  42. 'mousegridx = 0
  43. 'mousegridy = 0
  44. 'mousegridx2 = 0
  45. 'mousegridy2 = 0
  46.  
  47. DIM SHARED maingrid(gridsize, gridsize) AS _UNSIGNED LONG
  48. 'DIM SHARED bgrid(gridsize, gridsize)
  49. 'DIM SHARED prevgrid(gridsize, gridsize)
  50. DIM SHARED tool(tools)
  51. DIM SHARED zone(zones)
  52.  
  53. buttonclick = _SNDOPEN("assets/buttonClick.wav")
  54. buttonclick2 = _SNDOPEN("assets/buttonClick2.wav")
  55. buttonclick3 = _SNDOPEN("assets/buttonClick3.wav")
  56. wip = _SNDOPEN("assets/bzzzt.wav")
  57.  
  58. DIM SHARED sample AS LONG
  59. sample = _LOADIMAGE("assets/sample64x64.png", 32) ' < ok let's try
  60. 'PRINT sample  '<  got it
  61. 'end ' < test sample load
  62.  
  63. setup '< dang where is sample
  64.  
  65.     '   Wait for mouse movement or button press
  66.     '
  67.     mx = _MOUSEX
  68.     my = _MOUSEY
  69.     mb1 = _MOUSEBUTTON(1)
  70.     mb2 = _MOUSEBUTTON(2)
  71.  
  72.     '   ----------------------------
  73.     '       Determine Mouse Zone
  74.     '   ----------------------------
  75.  
  76.     '   Zone 1 - Main Grid
  77.     '
  78.     IF mx > 0 AND mx < 640 AND my > 0 AND my < 640 THEN
  79.         zone(1) = 1
  80.     ELSE
  81.         zone(1) = 0
  82.     END IF
  83.  
  84.     '   Zone 2 - NEW Button
  85.     '
  86.     IF mx > 690 AND mx < 770 AND my > 520 AND my < 560 THEN
  87.         zone(2) = 1
  88.     ELSE
  89.         zone(2) = 0
  90.     END IF
  91.  
  92.     '   Zone 3 - LOAD Button
  93.     '
  94.     IF mx > 690 AND mx < 770 AND my > 570 AND my < 610 THEN
  95.         zone(3) = 1
  96.     ELSE
  97.         zone(3) = 0
  98.     END IF
  99.  
  100.     '   Zone 4 - SAVE Button
  101.     '
  102.     IF mx > 790 AND mx < 870 AND my > 570 AND my < 610 THEN
  103.         zone(4) = 1
  104.     ELSE
  105.         zone(4) = 0
  106.     END IF
  107.  
  108.     '   Zone 5 - QUIT Button
  109.     '
  110.     IF mx > 884 AND mx < 964 AND my > 520 AND my < 560 THEN
  111.         zone(5) = 1
  112.     ELSE
  113.         zone(5) = 0
  114.     END IF
  115.  
  116.     '   Zone 6 - PENCIL Button
  117.     '
  118.     IF mx > 1014 AND mx < 1094 AND my > 98 AND my < 138 THEN
  119.         zone(6) = 1
  120.     ELSE
  121.         zone(6) = 0
  122.     END IF
  123.  
  124.     '   Zone 7 - LINE Button
  125.     '
  126.     IF mx > 1014 AND mx < 1094 AND my > 148 AND my < 188 THEN
  127.         zone(7) = 1
  128.     ELSE
  129.         zone(7) = 0
  130.     END IF
  131.  
  132.     '   Zone 8 - MIRROR Button
  133.     '
  134.     IF mx > 1014 AND mx < 1094 AND my > 198 AND my < 238 THEN
  135.         zone(8) = 1
  136.     ELSE
  137.         zone(8) = 0
  138.     END IF
  139.  
  140.     '   Zone 9 - CLEAR Button
  141.     '
  142.     IF mx > 884 AND mx < 964 AND my > 570 AND my < 610 THEN
  143.         zone(9) = 1
  144.     ELSE
  145.         zone(9) = 0
  146.     END IF
  147.  
  148.     '   --------------------
  149.     '       Draw On Grid
  150.     '   --------------------
  151.     IF zone(1) = 1 AND mb1 THEN
  152.         drawongrid
  153.     END IF
  154.  
  155.     '   -----------------------
  156.     '       Erase From Grid
  157.     '   -----------------------
  158.     IF zone(1) = 1 AND mb2 THEN
  159.         erasefromgrid
  160.     END IF
  161.     'updatepreview   ' <  should these be outside IF?
  162.     'redrawgrid
  163.  
  164.     '   ------------
  165.     '       QUIT
  166.     '   ------------
  167.     IF zone(5) = 1 AND mb1 THEN
  168.         _SNDPLAY (buttonclick3)
  169.         _DELAY .2
  170.         COLOR darkred
  171.         LINE (884, 520)-STEP(80, 40), , B
  172.         COLOR red
  173.         _PRINTSTRING (891, 523), "Quit"
  174.         _DELAY .2
  175.         quit = 1
  176.     END IF
  177.  
  178.     '   ------------------
  179.     '       LOAD Image
  180.     '   ------------------
  181.     IF zone(3) = 1 AND mb1 THEN
  182.         _SNDPLAY (buttonclick2)
  183.         _DELAY .2
  184.         tool(1) = 0
  185.         pencil
  186.         loadfile
  187.     END IF
  188.  
  189.     '   ------------------
  190.     '       SAVE Image
  191.     '   ------------------
  192.     IF zone(4) = 1 AND mb1 THEN
  193.         _SNDPLAY (wip)
  194.         _DELAY .2
  195.         'savefile
  196.     END IF
  197.  
  198.     '   -----------------
  199.     '       NEW Image
  200.     '   -----------------
  201.     IF zone(2) = 1 AND mb1 THEN
  202.         _SNDPLAY (buttonclick2)
  203.         _DELAY .2
  204.         newimage
  205.     END IF
  206.  
  207.     '   -------------------
  208.     '       CLEAR Image
  209.     '   -------------------
  210.     IF zone(9) = 1 AND mb1 THEN
  211.         _SNDPLAY (buttonclick2)
  212.         _DELAY .2
  213.         clearimage
  214.     END IF
  215.  
  216.     '   ----------------------
  217.     '       TOOLS - Pencil
  218.     '   ----------------------
  219.     IF zone(6) = 1 AND mb1 THEN
  220.         _SNDPLAY (buttonclick2)
  221.         _DELAY .2
  222.         tool(1) = 1
  223.         pencil
  224.         tool(2) = 0
  225.         drawline
  226.         tool(3) = 0
  227.         symmetry = 0
  228.         mirror
  229.     END IF
  230.  
  231.     '   --------------------------
  232.     '       TOOLS - Line (wip)
  233.     '   --------------------------
  234.     IF zone(7) = 1 AND mb1 THEN
  235.         _SNDPLAY (wip)
  236.         _DELAY .2
  237.         'tool(1) = 1
  238.         'pencil
  239.         'tool(2) = 1
  240.         'drawline
  241.         'tool(3) = 0
  242.         'symmetry = 0
  243.         'mirror
  244.     END IF
  245.  
  246.     '   ---------------------------------
  247.     '       TOOLS - Mirror / Symmetry
  248.     '   ---------------------------------
  249.     IF mb1 AND zone(8) = 1 AND tool(3) = 0 THEN
  250.         _SNDPLAY (buttonclick2)
  251.         _DELAY .2
  252.         tool(1) = 1
  253.         pencil
  254.         tool(2) = 0
  255.         drawline
  256.         tool(3) = 1
  257.         symmetry = 1
  258.         mirror
  259.     END IF
  260.  
  261.     '   -----------------------------
  262.     '       Select Current Colour
  263.     '   -----------------------------
  264.     IF mx > 690 AND mx < 964 AND my > 300 AND my < 490 AND mb1 THEN
  265.         currentcolour = POINT(_MOUSEX, _MOUSEY)
  266.         'convert (currentcolour)
  267.         'r5 = getR(currentcolour)
  268.         'g5 = getG(currentcolour)
  269.         'b5 = getB(currentcolour)
  270.     END IF
  271.     COLOR currentcolour
  272.     LINE (821, 521)-STEP(28, 28), , BF
  273.  
  274.     _DISPLAY
  275.  
  276.     _LIMIT 60 ' <<< cut down the looping save the CPU!
  277. LOOP UNTIL quit = 1 OR INKEY$ = CHR$(27)
  278.  
  279. '==================================================================
  280.  
  281. '   ----------------------
  282. '       Convert to RGB
  283. '   ----------------------
  284. 'SUB convert (clr)
  285. '    r5 = _RED32(clr)
  286. '    g5 = _GREEN32(clr)
  287. '    b5 = _BLUE32(clr)
  288. 'END SUB
  289. '   ==================================================================
  290. '
  291. '       PROCEDURES AND FUNCTIONS
  292. '
  293. '   ==================================================================
  294.  
  295. '   -----------------------
  296. '       Initial Display
  297. '   -----------------------
  298.  
  299. SUB setup
  300.  
  301.     logo = _LOADIMAGE("assets/draw3.png", 32)
  302.     patch = _LOADIMAGE("assets/colourpatch.png", 32)
  303.  
  304.     gsize = 9
  305.  
  306.     '   ------------------------
  307.     '       Reset Tool flags
  308.     '   ------------------------
  309.     FOR i = 1 TO tools
  310.         tool(i) = 0
  311.     NEXT
  312.  
  313.     '   ------------------------
  314.     '       Reset Zone flags
  315.     '   ------------------------
  316.     FOR i = 1 TO zones
  317.         zone(i) = 0
  318.     NEXT
  319.  
  320.     '   ----------------------
  321.     '       Draw Main Grid
  322.     '   ----------------------
  323.     COLOR gridcolour
  324.     FOR x = 0 TO 640
  325.         LINE (x, 0)-(x, 640)
  326.         x = x + gsize
  327.     NEXT
  328.     FOR y = 0 TO 640
  329.         LINE (0, y)-(640, y)
  330.         y = y + gsize
  331.     NEXT
  332.     'redrawgrid
  333.  
  334.     '   ---------------------
  335.     '       Program Logo
  336.     '   ---------------------
  337.     _PUTIMAGE (720, 0), logo
  338.     COLOR _RGB32(0, 128, 128)
  339.     _PRINTSTRING (750, 620), "(C) 2015 John Baldwin"
  340.  
  341.     '   -----------------------------
  342.     '       Colour Selection Grid
  343.     '   -----------------------------
  344.     _PUTIMAGE (690, 300), patch
  345.  
  346.     '   ----------------------------------
  347.     '       Sprite Preview Box - 64x64
  348.     '   ----------------------------------
  349.     COLOR gridcolour
  350.     LINE (698, 98)-STEP(67, 67), , B
  351.     _PUTIMAGE (700, 100), sample, 0 ' < add sample
  352.     COLOR gray
  353.     _PRINTSTRING (703, 170), "Preview"
  354.     'update grid
  355.     preview2grid
  356.  
  357.     '   -----------------------------------------
  358.     '       Sprite Preview Box - Magnified x2
  359.     '   -----------------------------------------
  360.     COLOR gridcolour
  361.     LINE (798, 98)-STEP(134, 134), , B
  362.     _PUTIMAGE (800, 100)-STEP(128, 128), sample, 0 ' < add sample
  363.     COLOR gray
  364.     _PRINTSTRING (830, 235), "Preview x2"
  365.  
  366.     '   -----------------------------------
  367.     '       Current Selected Colour Box
  368.     '   -----------------------------------
  369.     COLOR gridcolour
  370.     LINE (820, 520)-STEP(30, 30), , B
  371.  
  372.     '   --------------------
  373.     '       Menu Buttons
  374.     '   --------------------
  375.     COLOR gridcolour
  376.     LINE (690, 520)-STEP(80, 40), , B
  377.     _PRINTSTRING (698, 523), "New"
  378.  
  379.     COLOR gridcolour
  380.     LINE (690, 570)-STEP(80, 40), , B
  381.     _PRINTSTRING (698, 573), "Load"
  382.  
  383.     COLOR gridcolour
  384.     LINE (790, 570)-STEP(80, 40), , B
  385.     _PRINTSTRING (798, 573), "Save"
  386.  
  387.     COLOR gridcolour
  388.     LINE (884, 520)-STEP(80, 40), , B
  389.     _PRINTSTRING (891, 523), "Quit"
  390.  
  391.     COLOR gridcolour
  392.     LINE (884, 570)-STEP(80, 40), , B
  393.     _PRINTSTRING (892, 573), "Clear"
  394.  
  395.     '   --------------------
  396.     '       TOOL BUTTONS
  397.     '   --------------------
  398.  
  399.     '   Pencil
  400.  
  401.     COLOR gridcolour
  402.     LINE (1014, 98)-STEP(80, 40), , B
  403.     _PRINTSTRING (1022, 101), "Pencil"
  404.     tool(1) = 0
  405.  
  406.     '   Line
  407.  
  408.     COLOR gridcolour
  409.     LINE (1014, 148)-STEP(80, 40), , B
  410.     COLOR gridcolour
  411.     _PRINTSTRING (1022, 151), "Line"
  412.     _PRINTSTRING (1059, 168), "wip"
  413.     tool(2) = 0
  414.  
  415.     '   Mirror / Symmetry
  416.  
  417.     COLOR gridcolour
  418.     LINE (1014, 198)-STEP(80, 40), , B
  419.     _PRINTSTRING (1022, 201), "Mirror"
  420.     tool(3) = 0
  421.  
  422.     '   Spares
  423.  
  424.     COLOR _RGB32(32, 32, 32)
  425.     LINE (1014, 248)-STEP(80, 40), , B
  426.     LINE (1014, 298)-STEP(80, 40), , B
  427.     LINE (1014, 348)-STEP(80, 40), , B
  428.     LINE (1014, 398)-STEP(80, 40), , B
  429.     LINE (1014, 448)-STEP(80, 40), , B
  430.  
  431.     LINE (1104, 98)-STEP(80, 40), , B
  432.     LINE (1104, 148)-STEP(80, 40), , B
  433.     LINE (1104, 198)-STEP(80, 40), , B
  434.     LINE (1104, 248)-STEP(80, 40), , B
  435.     LINE (1104, 298)-STEP(80, 40), , B
  436.     LINE (1104, 348)-STEP(80, 40), , B
  437.     LINE (1104, 398)-STEP(80, 40), , B
  438.     LINE (1104, 448)-STEP(80, 40), , B
  439.  
  440.     LINE (1194, 98)-STEP(80, 40), , B
  441.  
  442.  
  443. SUB drawongrid
  444.     IF tool(1) <> 0 THEN
  445.         COLOR currentcolour
  446.         mousegridx = INT(_MOUSEX / 10) * 10
  447.         mousegridy = INT(_MOUSEY / 10) * 10
  448.         LINE (mousegridx, mousegridy)-STEP(10, 10), , BF
  449.  
  450.         IF symmetry = 1 THEN
  451.             COLOR currentcolour
  452.             mousegridx2 = 640 - (INT(_MOUSEX / 10) * 10) - 9
  453.             mousegridy2 = INT(_MOUSEY / 10) * 10
  454.             LINE (mousegridx2, mousegridy2)-STEP(10, 10), , BF
  455.         END IF
  456.     END IF
  457.  
  458. SUB erasefromgrid
  459.     IF tool(1) <> 0 THEN
  460.         COLOR _RGB32(0, 0, 0)
  461.         mousegridx = INT(_MOUSEX / 10) * 10
  462.         mousegridy = INT(_MOUSEY / 10) * 10
  463.         LINE (mousegridx, mousegridy)-STEP(10, 10), , BF
  464.         _DISPLAY
  465.     END IF
  466.  
  467. SUB newimage
  468.     sure
  469.     IF exist = 1 THEN
  470.         savefile
  471.         exist = 0
  472.     END IF
  473.     tool(1) = 0
  474.     pencil
  475.     tool(2) = 0
  476.     drawline
  477.     tool(3) = 0
  478.     symmetry = 0
  479.     mirror
  480.     FOR imagex = 0 TO 63
  481.         FOR imagey = 0 TO 63
  482.             maingrid(imagex, imagey) = black
  483.             COLOR maingrid(imagex, imagey)
  484.             '   -------------------------
  485.             '       "Poor Man's" Fill
  486.             '   -------------------------
  487.             'r5 = getR(maingrid[imagex][imagey])
  488.             'g5 = getG(maingrid[imagex][imagey])
  489.             'b5 = getB(maingrid[imagex][imagey])
  490.             'set color r5,g5,b5
  491.             dotx = imagex * 10
  492.             doty = imagey * 10
  493.             LINE (dotx, doty)-STEP(10, 10), , BF
  494.             '   --------------------
  495.             '       Draw Preview
  496.             '   --------------------
  497.             PSET (700 + imagex, 100 + imagey)
  498.             '   ------------------------------
  499.             '       Draw Magnified Preview
  500.             '   ------------------------------
  501.             PSET (800 + imagex, 100 + imagey)
  502.         NEXT
  503.     NEXT
  504.  
  505.     resetcurrentcolour = 1
  506.  
  507.     redrawgrid
  508.  
  509.     _DELAY .1
  510.  
  511.     'free file 1
  512.  
  513.  
  514. SUB loadfile
  515.     sample = _LOADIMAGE("assets/sample64x64.png", 32)
  516.     _PUTIMAGE (700, 100), sample
  517.     COLOR gridcolour
  518.     '   --------------------
  519.     '       SCAN IMAGE ?
  520.     '   --------------------
  521.     FOR imagex = 0 TO 63
  522.         FOR imagey = 0 TO 63
  523.             maingrid(imagex, imagey) = POINT(700 + imagex, 100 + imagey)
  524.         NEXT
  525.     NEXT
  526.     '   -------------------------------
  527.     '       TRANSFER TO MAIN GRID ?
  528.     '   -------------------------------
  529.     FOR imagex = 0 TO 63
  530.         FOR imagey = 0 TO 63
  531.             COLOR maingrid(imagex, imagey)
  532.             '   -------------------------
  533.             '       "Poor Man's" Fill
  534.             '   -------------------------
  535.             'r5 = getR(maingrid[imagex][imagey])
  536.             'g5 = getG(maingrid[imagex][imagey])
  537.             'b5 = getB(maingrid[imagex][imagey])
  538.             'set color r5,g5,b5
  539.             dotx = imagex * 10
  540.             doty = imagey * 10
  541.             LINE (dotx, doty)-STEP(10, 10), , BF
  542.         NEXT
  543.     NEXT
  544.     redrawgrid
  545.  
  546. SUB savefile
  547.  
  548.  
  549. SUB clearimage
  550.     tool(1) = 0
  551.     pencil
  552.     tool(2) = 0
  553.     drawline
  554.     tool(3) = 0
  555.     mirror
  556.     FOR imagex = 0 TO 63
  557.         FOR imagey = 0 TO 63
  558.             maingrid(imagex, imagey) = black
  559.             COLOR maingrid(imagex, imagey)
  560.             '   -------------------------
  561.             '       "Poor Man's" Fill
  562.             '   -------------------------
  563.             'r5 = getR(maingrid[imagex][imagey])
  564.             'g5 = getG(maingrid[imagex][imagey])
  565.             'b5 = getB(maingrid[imagex][imagey])
  566.             'set color r5,g5,b5
  567.             dotx = imagex * 10
  568.             doty = imagey * 10
  569.             LINE (dotx, doty)-STEP(10, 10), , BF
  570.             '   --------------------
  571.             '       Draw Preview
  572.             '   --------------------
  573.             PSET (700 + imagex, 100 + imagey)
  574.             '   ------------------------------
  575.             '       Draw Magnified Preview
  576.             '   ------------------------------
  577.             PSET (800 + imagex, 100 + imagey)
  578.         NEXT
  579.     NEXT
  580.  
  581.     resetcurrentcolour = 1
  582.  
  583.     redrawgrid
  584.  
  585.     _DELAY .1
  586.  
  587.     'free file 1
  588.  
  589.  
  590. SUB sure
  591.     exist = 0
  592.     FOR imagex = 0 TO 63
  593.         FOR imagey = 0 TO 63
  594.             IF POINT(700 + imagex, 100 + imagey) <> black THEN
  595.                 exist = 1
  596.             END IF
  597.         NEXT
  598.     NEXT
  599.  
  600. SUB msgbox
  601.  
  602.  
  603. '   -----------------------
  604. '       TOOL PROCEDURES
  605. '   -----------------------
  606.  
  607. SUB pencil
  608.     IF tool(1) = 0 THEN
  609.         COLOR gridcolour
  610.         LINE (1014, 98)-STEP(80, 40), , B
  611.         _PRINTSTRING (1022, 101), "Pencil"
  612.     END IF
  613.     IF tool(1) = 1 THEN
  614.         COLOR white
  615.         LINE (1014, 98)-STEP(80, 40), , B
  616.         COLOR yellow
  617.         _PRINTSTRING (1022, 101), "Pencil"
  618.         COLOR gridcolour
  619.         tool(2) = 0
  620.         drawline
  621.         tool(3) = 0
  622.         symmetry = 0
  623.         mirror
  624.     END IF
  625.  
  626. SUB drawline
  627.     '   -------------------------------------
  628.     '       Change state of 'line' button
  629.     '   -------------------------------------
  630.     'IF tool(2) = 0 THEN
  631.     'COLOR gridcolour
  632.     'LINE (1014, 148)-STEP(80, 40), , B
  633.     '_PRINTSTRING (1022, 151), "Line"
  634.     'END IF
  635.     'IF tool(2) = 1 THEN
  636.     'COLOR white
  637.     'LINE (1014, 148)-STEP(80, 40), , B
  638.     'COLOR yellow
  639.     '_PRINTSTRING (1022, 151), "Line"
  640.     'COLOR gridcolour
  641.     'END IF
  642.     '   -----------------------------------------
  643.     '       Line function goes here... W.I.P.
  644.     '   -----------------------------------------
  645.     'COLOR currentcolour
  646.     'x1 = 0
  647.     'x2 = 0
  648.     'y1 = 0
  649.     'y2 = 0
  650.     'click = 0
  651.     'WHILE click = 0
  652.     'IF _MOUSEBUTTON(1) AND zone(1) = 1 THEN
  653.     'click = 1
  654.     'x = _MOUSEX
  655.     'y = _MOUSEY
  656.     'x1 = x
  657.     'y1 = y
  658.     'mousegridx = INT(x1 / 10) * 10
  659.     'mousegridy = INT(y1 / 10) * 10
  660.     'LINE (mousegridx, mousegridy)-STEP(10, 10), , BF
  661.     'END IF
  662.     'IF mb2 AND zone(1) = 1 THEN
  663.     '    x = _MOUSEX
  664.     'y = _MOUSEY
  665.     'x2 = x
  666.     'y2 = y
  667.     'mousegridx = INT(x2 / 10) * 10
  668.     'mousegridy = INT(y2 / 10) * 10
  669.     'LINE (mousegridx, mousegridy)-STEP(10, 10), , BF
  670.     'click = 1
  671.     'dx = ABS(x2 - x1)
  672.     'sx = -1
  673.     'IF x1 < x2 THEN sx = 1
  674.     'dy = ABS(y2 - y1)
  675.     'sy = -1
  676.     'IF y1 < y2 THEN sy = 1
  677.     'er = -dy
  678.     'IF dx > dy THEN er = dx
  679.     'er = INT(er / 2)
  680.     'DO
  681.     '    LINE (INT(x1 / 10) * 10, INT(y1 / 10) * 10)-STEP(10, 10), , BF
  682.     'e2 = er
  683.     'IF e2 > -dx THEN
  684.     '    er = er - dy
  685.     'x1 = x1 + sx
  686.     'END IF
  687.     'IF e2 < dy THEN
  688.     '    er = er + dx
  689.     'y1 = y1 + sy
  690.     'END IF
  691.     '_DISPLAY
  692.     'LOOP UNTIL x1 = x2 AND y1 = y2
  693.     'END IF
  694.     '_DISPLAY
  695.     'IF INKEY$ = CHR$(27) THEN SYSTEM
  696.     'WEND
  697.     'END IF
  698.  
  699. SUB mirror
  700.     '
  701.     '    Change state of 'symmetry' button
  702.     '
  703.     IF tool(3) = 0 THEN
  704.         COLOR gridcolour
  705.         LINE (1014, 198)-STEP(80, 40), , B
  706.         _PRINTSTRING (1022, 201), "Mirror"
  707.     END IF
  708.     IF tool(3) = 1 THEN
  709.         COLOR white
  710.         LINE (1014, 198)-STEP(80, 40), , B
  711.         COLOR yellow
  712.         _PRINTSTRING (1022, 201), "Mirror"
  713.         COLOR gridcolour
  714.     END IF
  715.  
  716. SUB redrawgrid
  717.     gsize = 9
  718.     COLOR gridcolour
  719.     FOR x = 0 TO 640
  720.         LINE (x, 0)-(x, 640)
  721.         x = x + gsize
  722.     NEXT
  723.     FOR y = 0 TO 640
  724.         LINE (0, y)-(640, y)
  725.         y = y + gsize
  726.     NEXT
  727.  
  728. SUB updatepreview
  729.     FOR prevx = 0 TO 63
  730.         FOR prevy = 0 TO 63
  731.             COLOR POINT((prevx * 10) + 5, (prevy * 10) + 5)
  732.             PSET (700 + prevx, 100 + prevy)
  733.         NEXT
  734.     NEXT
  735.     '    Magnified Preview
  736.     FOR prevx = 0 TO 63
  737.         FOR prevy = 0 TO 63
  738.             COLOR POINT((prevx * 10) + 5, (prevy * 10) + 5)
  739.             PSET (800 + (prevx * 2), 100 + (prevy * 2))
  740.             PSET (801 + (prevx * 2), 100 + (prevy * 2))
  741.  
  742.             PSET (800 + (prevx * 2), 101 + (prevy * 2))
  743.             PSET (801 + (prevx * 2), 101 + (prevy * 2))
  744.  
  745.             'REM draw rect 800+(prevx*2),100+(prevy*2),2,2,true
  746.         NEXT
  747.     NEXT
  748.  
  749. SUB preview2grid '< this whole sub
  750.     FOR prevx = 0 TO 63
  751.         FOR prevy = 0 TO 63
  752.             COLOR POINT(700 + prevx, 100 + prevy)
  753.             LINE (prevx * 10, prevy * 10)-STEP(gsize, gsize), , BF
  754.         NEXT
  755.     NEXT
  756.  


Hey looks like we are ready to save an image ;-)   

And looks like we will need a tool to set current color from the image!
SE mods 1.PNG
* SE mods 1.PNG (Filesize: 103.23 KB, Dimensions: 1282x665, Views: 178)
« Last Edit: September 07, 2020, 04:56:50 pm by bplus »

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
Re: sprite editor
« Reply #59 on: September 07, 2020, 05:32:35 pm »
As per your request... This is the current version (unmodified) including the assets...
* sprdraw.zip (Filesize: 335.22 KB, Downloads: 100)
Logic is the beginning of wisdom.