android
Prev Previous Post   Next Post Next
  #1  
Old 01-13-2010, 02:55 PM
kushndonuts kushndonuts is offline
Junior Member
 
Join Date: Jan 2010
Location: Maryland
Posts: 29
Default Help making a paint app

I am currently trying to make a paint program but I can't seem to figure out how to draw a line by tapping one point then tapping another point and have a line drawn between the two coordinates.

Heres what I have so far
Code:
cblk = color.new(0,0,0);
cwht = color.new(255,255,255);
cred = color.new(255,0,0);

screen.fillrect(0,0,400,240,blk);

function makeButton(x,y,width,height,bordercolor,bgcolor,textsize,textcolor,string)
 screen.fillrect(x,y,width,height,bgcolor);
 screen.drawrect(x,y,x+width,y+height,bordercolor);
 text.color(textcolor);
 text.size(textsize);
 text.draw(x,y,string);
end;

function get_pts()
 while true do 
  if (control.read() == 1) and (control.isTouch() == 1) then
   if (touch.click() == 1) then
    x1,y1 = touch.pos();
    screen.drawpixel(x1,y1,cwht);
    return x1,y1;
   end;
  end;
 end;
  if (control.read() == 1) and (control.isTouch() == 1) then
   if (touch.click() == 1) then
    x2,y2 = touch.pos();
   end;
  end;
end;

function draw_line(x1,y1,x2,y2,linecolor)
 get_pts
 screen.drawline(
 screen.update();
end;

function draw_dot(x,y)
 makeButton(0,0,53,40,cred,blk,20,cred," Exit");
 makeButton(0,41,53,40,cred,cblk,18,cred,"Clear");
 makeButton(0,82,53,40,cred,cblk,20,cred," Line");
 screen.drawpixel(x,y,cwht);
 screen.update();
end;
draw_dot(0,0);

while true do
 if (control.read() == 1) and (control.isTouch() == 1) then
  if (touch.move() == 1) then
   x,y = touch.pos();
   draw_dot(x,y);
  end;
  if (touch.click() == 1) then
   x,y = touch.pos();
   if (y < 40) and (x < 50) then
     break;
   end;
  end;
  if (touch.click() == 1) then
   x,y = touch.pos();
   if (y > 40) and (y < 80) and (x < 50) then
     screen.fillrect(0,0,400,240,cblk);
    screen.update();
    do_out(0,0);
   end;
  end;
  if (touch.click() == 1) then
   x,y = touch.pos();
    if (y > 81) and (y < 122) and (x < 50) then
      draw_line();
   end;
  end;  
 end;
 os.sleep(1);
end;
I know there are some incomplete parts that are probably entirely wrong.
If there is a way to interrupt a while loop I could make it all work eventually but I can't seem to find that info. If somebody can point me in the right direction or give me any help it would be great.
Reply With Quote

Advertisement [Remove Advertisement]

 

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 01:41 PM.