This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Creator's profile picture

Problems with drawImage()!

Started by Creator, 27 February 2015 - 07:21 PM
Creator #1
Posted 27 February 2015 - 08:21 PM
Hi guys,

I'm having problems with the paintutils.drawImage() function. What I am trying to do is to not use paintutils.loadImage() but rather use a table that has the value of the loaded image in it.

For example

insted of


image = paintutils.loadImage(path)
paintutils.drawImage(image,x,y)

I use

image = {
1.0={1.0=2.0, 2.0=2.0, 4.0=2.0, 8.0=16.0, 5.0=16.0, 3.0=2.0, 6.0=16.0, 7.0=16.0},
2.0={1.0=2.0, 2.0=2.0, 4.0=2.0, 8.0=2.0, 5.0=2.0, 3.0=2.0, 6.0=2.0, 7.0=2.0},
4.0={1.0=2.0, 2.0=2.0, 4.0=2.0, 8.0=2.0, 5.0=2.0, 3.0=2.0, 6.0=2.0, 7.0=2.0},
3.0={1.0=2.0, 2.0=2.0, 4.0=2.0, 8.0=2.0, 5.0=2.0, 3.0=2.0, 6.0=2.0, 7.0=2.0}
}
paintutils.drawImage(image,x,y)

The image itself is :


11114444
11111111
11111111
11111111

As always any help is appreciated and thanks.

~Creator
TheOddByte #2
Posted 27 February 2015 - 08:35 PM
That may be because paintutils.loadImage returns a table like this

local image = {
	{
		1,
		1,
	},
	{
		1,
		1,
	}
}

Proof
Edited on 27 February 2015 - 07:37 PM
Creator #3
Posted 27 February 2015 - 08:38 PM
That may be because paintutils.loadImage returns a table like this

local image = {
	{
		1,
		1,
	},
	{
		1,
		1,
	}
}

Proof

Thanks I'll definatelly do that
Bomb Bloke #4
Posted 27 February 2015 - 10:18 PM
In regards to why this wouldn't work:

image = {
1.0={1.0=2.0, 2.0=2.0, 4.0=2.0, 8.0=16.0, 5.0=16.0, 3.0=2.0, 6.0=16.0, 7.0=16.0},
2.0={1.0=2.0, 2.0=2.0, 4.0=2.0, 8.0=2.0, 5.0=2.0, 3.0=2.0, 6.0=2.0, 7.0=2.0},
4.0={1.0=2.0, 2.0=2.0, 4.0=2.0, 8.0=2.0, 5.0=2.0, 3.0=2.0, 6.0=2.0, 7.0=2.0},
3.0={1.0=2.0, 2.0=2.0, 4.0=2.0, 8.0=2.0, 5.0=2.0, 3.0=2.0, 6.0=2.0, 7.0=2.0}
}

… if you want to manually specify the number of every numeric index, you need to enclose them within square brackets. Eg:

image = {
[1.0]={[1.0]=2.0, [2.0]=2.0,

However, so long as you put your data values in order, there's no need to specify the numbers they should be assigned to - the VM will work that out on its own. Specifying a ".0" against each number is also pointless (if you made a script to generate that other array, using tostring(val) would strip the excess baggage). Eg, a neater way to build the table would be:

image = {
{ 2, 2, 2, 2,16,16,16,16},
{ 2, 2, 2, 2, 2, 2, 2, 2},
{ 2, 2, 2, 2, 2, 2, 2, 2},
{ 2, 2, 2, 2, 2, 2, 2, 2}
}
Edited on 27 February 2015 - 09:18 PM
Creator #5
Posted 27 February 2015 - 10:46 PM
In regards to why this wouldn't work:

image = {
1.0={1.0=2.0, 2.0=2.0, 4.0=2.0, 8.0=16.0, 5.0=16.0, 3.0=2.0, 6.0=16.0, 7.0=16.0},
2.0={1.0=2.0, 2.0=2.0, 4.0=2.0, 8.0=2.0, 5.0=2.0, 3.0=2.0, 6.0=2.0, 7.0=2.0},
4.0={1.0=2.0, 2.0=2.0, 4.0=2.0, 8.0=2.0, 5.0=2.0, 3.0=2.0, 6.0=2.0, 7.0=2.0},
3.0={1.0=2.0, 2.0=2.0, 4.0=2.0, 8.0=2.0, 5.0=2.0, 3.0=2.0, 6.0=2.0, 7.0=2.0}
}

… if you want to manually specify the number of every numeric index, you need to enclose them within square brackets. Eg:

image = {
[1.0]={[1.0]=2.0, [2.0]=2.0,

However, so long as you put your data values in order, there's no need to specify the numbers they should be assigned to - the VM will work that out on its own. Specifying a ".0" against each number is also pointless (if you made a script to generate that other array, using tostring(val) would strip the excess baggage). Eg, a neater way to build the table would be:

image = {
{ 2, 2, 2, 2,16,16,16,16},
{ 2, 2, 2, 2, 2, 2, 2, 2},
{ 2, 2, 2, 2, 2, 2, 2, 2},
{ 2, 2, 2, 2, 2, 2, 2, 2}
}

Well actually what I did was save the paintutils.loadImage(path) to a file in order to be able to retrieve it. So that table was not generated by me.