--# Flower
Flower = class()
function Flower:init(l,w,p,r,g,b,cr,cg,cb)
--(petal length, petal width, number of petals ...
--.petal red, green, blue ...
--.center of flower red, green, blue)
self.pt = {} --petal table
local np
if p == nil then p = math.random(16)+4 end
--if p == nil then p = math.random(2)+4 end
if l == nil then l = math.random(320/4)+50 end
if w == nil then w = l/(math.random(8)+1) end
if r == nil then r = math.random(256) - 1 end
if g == nil then g = math.random(256) - 1 end
if b == nil then b = math.random(256) - 1 end
--if r == nil then r = math.random(64) + (64*3) end
--if g == nil then g = math.random(64) + (64*3) end
--if b == nil then b = math.random(64) + (64*3) end
if cr == nil then self.cr = math.random(256) - 1 else self.cr = cr end
if cg == nil then self.cg = math.random(256) - 1 else self.cg = cg end
if cb == nil then self.cb = math.random(256) - 1 else self.cb = cb end
--if cr == nil then self.cr = math.random(128) - 1 else self.cr = cr end
--if cg == nil then self.cg = math.random(128) - 1 else self.cg = cg end
--if cb == nil then self.cb = math.random(128) - 1 else self.cb = cb end
self.fc = w +(math.random()*w)
--self.fc = (math.random()*w)
for i = 1, p do
local pa = (i*(360/p))+(math.random()*9)-5
local pl = l +(math.random()*l*.1) - (l*.05)
local pw = w +(math.random()*w*.1) - (w*.05)
local pr = r + math.random(17) - 8
local pg = g + math.random(17) - 8
local pb = b + math.random(17) - 8
self.pt[math.random()] = {pa=pa,pl=pl,pw=pw,pr=pr,pg=pg,pb=pb}
end
self.st = {} --stem table
for i = 1, 10 do
self.st[i] = math.random(256) - 1
end
end
function Flower:draw(x,y)
pushMatrix()
strokeWidth(2)
local k, v
for k,v in pairs(self.st) do
stroke(0, v, 0, 255)
line(x-5+k,y,x-5+k,y-200)
end
strokeWidth(1)
stroke(0, 0, 0, 255)
for k,v in pairs(self.pt) do
fill(v.pr,v.pg,v.pb,255)
lrellipse(x-v.pl/2,y,v.pl,v.pw,v.pa)
end
fill(self.cr,self.cg,self.cr,255)
ellipse(x,y,self.fc,self.fc)
popMatrix()
end
function Flower:touched(touch)
-- Codea does not automatically call this method
end
--# Icon
Icon = class()
function Icon:init(x,y,v)
-- you can accept and set parameters here
self.x = x
self.y = y
self.hx = x + 100 -- hide x
self.hy = y + 100 -- hide y
self.ox = x
self.oy = y
end
function Icon:draw(hm)
pushMatrix()
rectMode(CENTER)
noFill()
strokeWidth(5)
rect(self.x,self.y,80,120)
popMatrix()
if hm and self.x < self.hx then
self.x = self.x + 1
elseif self.x > self.ox then
self.x = self.x - 2
end
end
function Icon:touched(touch)
-- Codea does not automatically call this method
end
--# Screen
Screen = class()
function Screen:init()
self.menu = 0
self.allpots = 1
self.apot = 2
self.newf = 3
self.cscreen = self.allpots
self.prompt = Words("Tap a flower",480,960)
self.camera = ""
self.mf = 1 --main flower
self.msi = Icon(450,120) --main screen icon
self.ti = Icon(450,240) --text icon
self.hm = false --hide menu
self.mcx = 450
self.mvx = 450
self.mhx = 550
self.ft = ""
end
function Screen:draw()
if self.cscreen == self.allpots then self:AllPotsDraw()
elseif self.cscreen == self.apot then self:APotDraw()
--elseif self.cscreen == self.newf then
end
end
function Screen:touched(touch)
if touch.state == BEGAN then
if self.cscreen == self.allpots then self:AllPotsTouch(touch)
elseif self.cscreen == self.apot then self:APotTouch(touch)
--self.help.x = touch.x*cs/2
--self.help.y = touch.y*cs/2
end
end
end
function Screen:keyboard(key)
if key ~= nil then
--string.byte(key) == 10
if string.byte(key) == nil then
if string.len(self.ftext) > 0 then
self.ftext = string.sub(self.ftext,1,string.len(self.ftext) - 1)
end
else
if self.ftext == nil then self.ftext = key
else self.ftext = self.ftext .. key end
end
end
end
function Screen:AllPotsDraw()
pushMatrix()
scale(1/cs)
local i
for i = 1, 13 do
pots[i].f:draw(pots[i].x,pots[i].y)
end
self.prompt:draw()
popMatrix()
end
function Screen:AllPotsTouch(touch)
local i
for i = 1, 13 do
local p = vec2(pots[i].x,pots[i].y)
if p:dist(vec2(touch.x*cs,touch.y*cs)) < 100 then
self.mf = i
self.cscreen = self.apot
--self.help = Words("?",(320+320+160)/2,240*2.5)
self.prompt = Words("Take a picture",480/2,960/2)
if itoip then
self.camera = Words(".",295,10)
else
self.camera = Words(".",125,10)
end
self.hm = true
end
end
end
function Screen:APotDraw()
pushMatrix()
scale(2/cs)
pots[self.mf].f:draw((320+160)/2,(240*3)/2)
self.prompt:draw()
self.camera:draw()
if self.hm and self.mcx < self.mhx then
self.mcx = self.mcx + 4
elseif not self.hm and self.mcx > self.mvx then
self.mcx = self.mcx - 16
end
self.msi.x = self.mcx
self.msi:draw()
self.ti.x = self.mcx
self.ti:draw()
pushStyle()
fontSize(32)
fill(111, 0, 255, 255)
text("A",self.ti.x -16,self.ti.y +32)
text("B",self.ti.x,self.ti.y)
text("C",self.ti.x +16,self.ti.y -32)
fill(255, 255, 255, 255)
font("Zapfino")
textWrapWidth(360)
fontSize(24)
textAlign(CENTER)
if self.ftext ~= nil then
if itoip then text(self.ftext.." ",240,600)
else text(self.ftext.." ",240,540) end
end
font()
popStyle()
translate(self.msi.x -40,self.msi.y -60)
scale(1/12)
local i
for i = 1, 13 do
pots[i].f:draw(pots[i].x,pots[i].y)
end
popMatrix()
end
function Screen:APotTouch(touch)
local t = vec2(touch.x*cs/2,touch.y*cs/2)
if t:dist(vec2(self.msi.x,self.msi.y)) < 50 then
self.cscreen = self.allpots
elseif t:dist(vec2(self.ti.x,self.ti.y)) < 50 then
self.hm = true
showKeyboard()
elseif touch.x*cs/2 > 100 then
if self.hm and self.mcx >= self.mhx then
self.hm = false
elseif self.mcx <= self.mvx then
self.hm = true
end
end
end
--# Words
Words = class()
function Words:init(words,x,y)
self.words = words
self.x = x
self.y = y
self.start = ElapsedTime
end
function Words:draw()
pushStyle()
rectMode(CENTER)
ellipseMode(CENTER)
fontSize(64)
local fade = 0
if (ElapsedTime - self.start) > 3 then
fade = (ElapsedTime - self.start - 3) * 64
end
fill(255,0,111,255-fade)
noStroke()
local bwidth = fontSize()*string.len(self.words)/2
ellipse(self.x,self.y,bwidth,fontSize()*2)
fill(111, 0, 255, 255-fade)
text(self.words,self.x,self.y)
popStyle()
-- Codea does not automatically call this method
end
function Words:touched(touch)
-- Codea does not automatically call this method
end