Jump to content




Need help with a program


  • You cannot reply to this topic
2 replies to this topic

#1 SGunner2014

  • Members
  • 113 posts
  • LocationMaidstone, UK

Posted 03 October 2014 - 09: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 by SGunner2014, 03 October 2014 - 09:36 PM.


#2 Evil_Bengt

  • Members
  • 24 posts

Posted 03 October 2014 - 09: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 by Evil_Bengt, 03 October 2014 - 09:56 PM.


#3 SGunner2014

  • Members
  • 113 posts
  • LocationMaidstone, UK

Posted 03 October 2014 - 10:13 PM

Edit: Nevermind, fixed it!

Edited by SGunner2014, 03 October 2014 - 10:32 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users