-
-
Save calineFrangieh/8d3999148caac92fd78e to your computer and use it in GitHub Desktop.
drawing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Trial6 | |
-- Use this function to perform your initial setup | |
supportedOrientations(LANDSCAPE_LEFT) | |
tt = nil | |
last_touch = nil | |
touching = nil | |
moving = false | |
function setup() | |
buttonImages={"Documents:Back","Documents:Eraser","Documents:BlackPencil","Documents:BrownPencil","Documents:BluePencil","Documents:RedPencil","Documents:GreenPencil","Documents:Next"} | |
button2Position = vec2(250,50) | |
button3Position = vec2(350,50) | |
button4Position = vec2(450,50) | |
button5Position = vec2(550,50) | |
button6Position = vec2(650,50) | |
button7Position = vec2(750,50) | |
button2= Button(buttonImages[2],button2Position) | |
button3= Button(buttonImages[3],button3Position) | |
button4= Button(buttonImages[4],button4Position) | |
button5= Button(buttonImages[5],button5Position) | |
button6= Button(buttonImages[6],button6Position) | |
button7= Button(buttonImages[7],button7Position) | |
ColorFill = color(0, 0, 0, 255) | |
tt = Touches() | |
eraser = false | |
end | |
function draw() | |
pushStyle() | |
background(255, 255, 255, 255) | |
button2:draw() button3:draw() button4:draw() button5:draw() button6:draw() button7:draw() | |
popStyle() | |
-- default seems to be 0 | |
strokeWidth(2) | |
lineCapMode(ROUND) | |
tt.color = ColorFill | |
touching = vec2(CurrentTouch.x, CurrentTouch.y) | |
if eraser == false and touching.y > 120 then | |
if CurrentTouch.state == ENDED then | |
-- to make sure we don't miss the touch began state | |
moving = false | |
elseif CurrentTouch.state == BEGAN then | |
if touching ~= last_touch then | |
moving = true | |
last_touch = touching | |
tt:add(touching) | |
table.insert (touchedlocationtable,touching) | |
end | |
elseif CurrentTouch.state == MOVING then | |
if touching ~= last_touch then | |
if moving then | |
tt:expand(touching) | |
table.insert (touchedlocationtable,touching) | |
else | |
-- Did not detect the move | |
moving = true | |
tt:add(touching) | |
table.insert (touchedlocationtable,touching) | |
end | |
last_touch = touching | |
end | |
end | |
end | |
tt:draw() | |
if eraser == true then | |
tt:remove(touching) | |
end | |
end | |
function touched(tch) | |
if button2:touched(tch)==true then eraser=true end | |
if button3:touched(tch)==true then ColorFill = color(0, 0, 0, 255) eraser=false end | |
if button4:touched(tch)==true then ColorFill = color(84, 61, 38, 255) eraser= false end | |
if button5:touched(tch)==true then ColorFill = color(21, 57, 187, 255) eraser= false end | |
if button6:touched(tch)==true then ColorFill = color(224, 26, 30, 255) eraser= false end | |
if button7:touched(tch)==true then ColorFill = color(84, 210, 55, 255) eraser= false end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Button = class() | |
function Button:init(buttonImage, buttonPosition) | |
self.buttonImage = buttonImage | |
self.buttonLocation = buttonPosition | |
self.buttonImageSize = vec2(spriteSize(self.buttonImage)) | |
self.currentButtonImage = self.buttonImage | |
self.selected = false | |
end | |
function Button:draw() | |
sprite(self.currentButtonImage, self.buttonLocation.x, self.buttonLocation.y) | |
end | |
function Button:touched(tch) | |
local currentTouchPosition = vec2(tch.x, tch.y) | |
if (tch.state == ENDED) then | |
if( (self.buttonLocation.x - self.buttonImageSize.x/2) < currentTouchPosition.x and | |
(self.buttonLocation.x + self.buttonImageSize.x/2) > currentTouchPosition.x and | |
(self.buttonLocation.y - self.buttonImageSize.y/2) < currentTouchPosition.y and | |
(self.buttonLocation.y + self.buttonImageSize.y/2) > currentTouchPosition.y ) then | |
return true end | |
end | |
end | |
-- touches code from codea | |
Touches = class() | |
function Touches:init() | |
-- you can accept and set parameters here | |
self.touches = {} | |
self.color= color(0, 0, 0, 255) | |
end | |
function Touches:add(t) | |
table.insert(self.touches, {t}) | |
end | |
function Touches:expand(t) | |
table.insert(self.touches[#self.touches],t) | |
end | |
function Touches:remove(t) | |
local tablecounter = 1 | |
while tablecounter<= #self.touches do | |
table.remove(self.touches,tablecounter) | |
tablecounter = tablecounter + 1 | |
end | |
end | |
function Touches:draw() | |
local last | |
if #self.touches > 0 then | |
for i,v in ipairs(self.touches) do | |
last = v[1] | |
for j,w in ipairs(v) do | |
stroke(self.color) | |
line(last.x,last.y,w.x,w.y) | |
last = w | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment