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

Need help with a program

Started by SGunner2014, 03 October 2014 - 08:35 PM
SGunner2014 #1
Posted 03 October 2014 - 10:35 PM
So, I'm trying to create a program like npaintpro, but my own version.

I've got the basics set up, but I can't work out how to do the bit where it changes the color of an actual pixel without a long and arduous routine.

Here's the code so far:

y1x1=2
y2x1=2
y3x1=2
y4x1=2
y1x2=2
y2x2=2
y3x2=2
y4x2=2
y1x3=2
y2x3=2
y3x3=2
y4x3=2
y1x4=2
y2x4=2
y3x4=2
y4x4=2
x1 = {y1x1,y2x1,y3x1,y4x1}
x2 = {y1x2,y2x2,y3x2,y4x2}
x3 = {y1x3,y2x3,y3x3,y4x3}
x4 = {y1x4,y2x4,y3x4,y4x4}
term.setCursorPos(1,1)
paintutils.drawLine(1,17,2,17,colors.red)
paintutils.drawLine(3,17,4,17,colors.blue)
paintutils.drawLine(5,17,6,17,colors.green)
paintutils.drawLine(7,17,8,17,colors.yellow)
while true do
local event, but, x, y = os.pullEvent("mouse_click")
if but == 1 and x>=1 and x<=2 and y==17 then
color = 1
paintutils.drawLine(11,17,12,17,colors.red)
elseif but == 1 and x>=3 and x<=4 and y==17 then
color = 2
paintutils.drawLine(11,17,12,17,colors.blue)
elseif but == 1 and x>=5 and x<=6 and y==17 then
color = 3
paintutils.drawLine(11,17,12,17,colors.green)
elseif but == 1 and x>=7 and x<=8 and y==17 then
color = 4
paintutils.drawLine(11,17,12,17,colors.yellow)
elseif but == 1 and x>=9 and x<=10 and y==17 then
os.reboot()
else
if color == 1 then
color2 = "colors.red"
elseif color == 2 then
color2 = "colors.blue"
elseif color == 3 then
color2 = "colors.green"
elseif color == 4 then
color2 = "colors.yellow"
end
if but == 1 and  x==1 and y==1 then --#The long and arduous part
y1x1 = color --#The long and arduous part
paintutils.drawPixel(x,y,color2) --#The long and arduous part
end
end
end

How am I being stupid, and how to fix it?

Thanks,
- Sam
Edited on 03 October 2014 - 08:36 PM
Evil_Bengt #2
Posted 03 October 2014 - 10:50 PM
Why not just use:

paintutils.drawPixel(x, y, color2)

or do you wan't to save it to something?
Not really sure if I've understood your problem correctly……

Edit:

Ohhhhhh….. I see…….. You wan't to save the color to the corresponding variable….. Try to make them as a table somehow like:

instead of the line: y1x1 = color

for each combination…

position = tostring(x .. y)
coords[position] = color

Maybe will work, not sure… Try it :D/>
Edited on 03 October 2014 - 08:56 PM
SGunner2014 #3
Posted 03 October 2014 - 11:13 PM
Edit: Nevermind, fixed it!
Edited on 03 October 2014 - 09:32 PM