Struggles in a graphics editor project

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Pospos
Citizen
Posts: 73
Joined: Sun Jun 18, 2017 11:10 am
Location: Agadir

Struggles in a graphics editor project

Post by Pospos »

i tried to make a graphics editor but i messed up somewhere.
The purpose is to write a text table 16x16 characters inside of it
with numbers to report inside of a text file, to then call them and draw them
any time using pixels of some colors.
the program isn't quite ready yet, but the purpose is simple.
The thing i would like is some help in writing this code and critiques
beacuse i struggle to make it correctly.
Maybe i'm too ambitious, but that would be awesome to create this little program.

Code: Select all

function graphic_write(a) -- write the graphics
writegraphic = io.open("graphlib/graph.lua", "w")
writegraphic:write(
	"graphic"a" = {}
	graphic"a"[1] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,} -- 0 corresponds to the red color.
	graphic"a"[2] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
	graphic"a"[3] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
	graphic"a"[4] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
	graphic"a"[5] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
	graphic"a"[6] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
	graphic"a"[7] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
	graphic"a"[8] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
	graphic"a"[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
   graphic"a"[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
   graphic"a"[11] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
   graphic"a"[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
   graphic"a"[13] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
   graphic"a"[14] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
   graphic"a"[15] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
   graphic"a"[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}")

end
function graphic_draw() -- call the graphics

	local line
	local colonne
	 for line=0, 16 do
	 for colonne=0, 16 do
	 	love.graphics.setColor(color[map[line+1][colonne+1]])
	 	love.graphics.rectangle("fill", colonne*16, line*16, 1, 1)
	 end
	end

end
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Struggles in a graphics editor project

Post by raidho36 »

You didn't put text concatenation marks.
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Struggles in a graphics editor project

Post by zorg »

raidho36 wrote: Tue Aug 01, 2017 1:42 am You didn't put text concatenation marks.
IMO the issue is not that, instead it's the fact that he wanted to use the same string delimiters both inside the string he wanted to write out and for the delimiters themselves... or in other words, the two outermost "-s should be replaced by '-s or [[ ]].
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
Pospos
Citizen
Posts: 73
Joined: Sun Jun 18, 2017 11:10 am
Location: Agadir

Re: Struggles in a graphics editor project

Post by Pospos »

like this?

Code: Select all

	[[graphic]]a[[
	graphic]]a[[ [1] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
	graphic]]a[[[2] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
	graphic]]a[[[3] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
	graphic]]a[[[4] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
	graphic]]a[[[5] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
	graphic]]a[[[6] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
	graphic]]a[[[7] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
	graphic]]a[[[8] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
	graphic]]a[[[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
   graphic]]a[[[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
   graphic]]a[[[11] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
   graphic]]a[[[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
   graphic]]a[[[13] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
   graphic]]a[[[14] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
   graphic]]a[[[15] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
   graphic]]a[[[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,})]] 
but how i handle the ) thing.
Santos
Party member
Posts: 384
Joined: Sat Oct 22, 2011 7:37 am

Re: Struggles in a graphics editor project

Post by Santos »

Have you considered using a serialization library like bitser?

Code: Select all

bitser = require('bitser')

function newMap()
	local map = {}

	for line=1, 16 do
		map[line] = {}
		for colonne=1, 16 do
			map[line][colonne] = math.random(1, 4)
		end
	end

	return map
end

function loadMap()
	return bitser.loads(love.filesystem.read(filename))
end

function saveMap()
	love.filesystem.write(filename, bitser.dumps(map))
end

function love.load()

	filename = 'map.txt'
	color = {
		{255, 0 , 0},
		{255, 255 , 0},
		{0,  255, 0},
		{0, 255 , 255},
	}
	if love.filesystem.isFile(filename) then
		map = loadMap()
	else
		map = newMap()
	end
end


function love.keypressed(key)
	if key == 'n' then
		map = newMap()
	elseif key == 'l' then
		map = loadMap()
	elseif key == 's' then
		saveMap()
	end
end

function love.draw()

	for line=0, 15 do
		for colonne=0, 15 do
			print(line, colonne)
			love.graphics.setColor(color[map[line+1][colonne+1]])
			love.graphics.rectangle("fill", colonne*16, line*16, 16, 16)
		end
	end

end
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Struggles in a graphics editor project

Post by zorg »

Pospos wrote: Tue Aug 01, 2017 9:48 am like this?

Code: Select all

	[[graphic]]a[[
	graphic]]a[[ [1] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
	graphic]]a[[[2] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
	graphic]]a[[[3] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
	graphic]]a[[[4] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
	graphic]]a[[[5] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
	graphic]]a[[[6] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
	graphic]]a[[[7] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
	graphic]]a[[[8] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
	graphic]]a[[[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
   graphic]]a[[[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
   graphic]]a[[[11] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
   graphic]]a[[[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
   graphic]]a[[[13] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
   graphic]]a[[[14] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
   graphic]]a[[[15] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
   graphic]]a[[[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,})]] 
but how i handle the ) thing.
No, more like this... though i must admit, i didn't test whether this worked or not:

Code: Select all

function graphic_write(a) -- write the graphics
    writegraphic = io.open("graphlib/graph.lua", "w")
    writegraphic:write([[
        graphic"a" = {}
        graphic"a"[1]   = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,} -- 0 corresponds to the red color.
        graphic"a"[2]   = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
        graphic"a"[3]   = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
        graphic"a"[4]   = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
        graphic"a"[5]   = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
        graphic"a"[6]   = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
        graphic"a"[7]   = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
        graphic"a"[8]   = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
        graphic"a"[9]   = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
        graphic"a"[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
        graphic"a"[11] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
        graphic"a"[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
        graphic"a"[13] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
        graphic"a"[14] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
        graphic"a"[15] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
        graphic"a"[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
    ]]:gsub([["a"]], a))

end
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
Pospos
Citizen
Posts: 73
Joined: Sun Jun 18, 2017 11:10 am
Location: Agadir

Re: Struggles in a graphics editor project

Post by Pospos »

also, do you have any idea of a lua function to read
file and store data inside of them?
i've taught about require, but i'm not sure.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 228 guests