Created
June 27, 2012 03:42
-
-
Save devilstower/3001241 to your computer and use it in GitHub Desktop.
Battle chips 26 Jun 12 / part 2
This file contains hidden or 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
Frame = class() | |
-- Frame | |
-- ver. 1.0 | |
-- a simple rectangle for holding controls. | |
-- ==================== | |
function Frame:init(left, bottom, right, top) | |
self.left = left | |
self.right = right | |
self.bottom = bottom | |
self.top = top | |
end | |
function Frame:inset(dx, dy) | |
self.left = self.left + dx | |
self.right = self.right - dx | |
self.bottom = self.bottom + dy | |
self.top = self.top - dy | |
end | |
function Frame:offset(dx, dy) | |
self.left = self.left + dx | |
self.right = self.right + dx | |
self.bottom = self.bottom + dy | |
self.top = self.top + dy | |
end | |
function Frame:draw() | |
pushStyle() | |
rectMode(CORNERS) | |
rect(self.left, self.bottom, self.right, self.top) | |
popStyle() | |
end | |
function Frame:roundRect(r) | |
pushStyle() | |
insetPos = vec2(self.left + r,self.bottom + r) | |
insetSize = vec2(self:width() - 2 * r,self:height() - 2 * r) | |
rectMode(CORNER) | |
rect(insetPos.x, insetPos.y, insetSize.x, insetSize.y) | |
if r > 0 then | |
smooth() | |
lineCapMode(ROUND) | |
strokeWidth(r * 2) | |
line(insetPos.x, insetPos.y, | |
insetPos.x + insetSize.x, insetPos.y) | |
line(insetPos.x, insetPos.y, | |
insetPos.x, insetPos.y + insetSize.y) | |
line(insetPos.x, insetPos.y + insetSize.y, | |
insetPos.x + insetSize.x, insetPos.y + insetSize.y) | |
line(insetPos.x + insetSize.x, insetPos.y, | |
insetPos.x + insetSize.x, insetPos.y + insetSize.y) | |
end | |
popStyle() | |
end | |
function Frame:gloss(baseclr) | |
local i, t, r, g, b, y | |
pushStyle() | |
if baseclr == nil then baseclr = color(194, 194, 194, 255) end | |
fill(baseclr) | |
rectMode(CORNERS) | |
rect(self.left, self.bottom, self.right, self.top) | |
r = baseclr.r | |
g = baseclr.g | |
b = baseclr.b | |
for i = 1 , self:height() / 2 do | |
r = r - 1 | |
g = g - 1 | |
b = b - 1 | |
stroke(r, g, b, 255) | |
y = (self.bottom + self.top) / 2 | |
line(self.left, y + i, self.right, y + i) | |
line(self.left, y - i, self.right, y - i) | |
end | |
popStyle() | |
end | |
function Frame:shade(base, step) | |
pushStyle() | |
strokeWidth(1) | |
for y = self.bottom, self.top do | |
i = self.top - y | |
stroke(base - i * step, base - i * step, base - i * step, 255) | |
line(self.left, y, self.right, y) | |
end | |
popStyle() | |
end | |
function Frame:touched(touch) | |
if touch.x >= self.left and touch.x <= self.right then | |
if touch.y >= self.bottom and touch.y <= self.top then | |
return true | |
end | |
end | |
return false | |
end | |
function Frame:ptIn(x, y) | |
if x >= self.left and x <= self.right then | |
if y >= self.bottom and y <= self.top then | |
return true | |
end | |
end | |
return false | |
end | |
function Frame:overlaps(f) | |
if self.left > f.right or self.right < f.left or | |
self.bottom > f.top or self.top < f.bottom then | |
return false | |
else | |
return true | |
end | |
end | |
function Frame:width() | |
return self.right - self.left | |
end | |
function Frame:height() | |
return self.top - self.bottom | |
end | |
function Frame:midX() | |
return (self.left + self.right) / 2 | |
end | |
function Frame:midY() | |
return (self.bottom + self.top) / 2 | |
end |
This file contains hidden or 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
OpenBtn = class() | |
function OpenBtn:init(t, x, y) | |
self.frame = Frame(x, y, x + 100, y + 30) | |
self.text = t | |
self.selected = false | |
end | |
function OpenBtn:draw() | |
pushStyle() | |
noFill() | |
if self.selected then fill(101, 118, 134, 255) end | |
stroke(255, 255, 255, 255) | |
strokeWidth(1) | |
ellipse(self.frame.left, self.frame:midY(), self.frame:height()) | |
self.frame:draw() | |
fill(34, 34, 34, 255) | |
noStroke() | |
if self.selected then fill(101, 118, 134, 255) end | |
self.frame:inset(-2,2) | |
self.frame:draw() | |
self.frame:inset(2, -2) | |
fill(255, 255, 255, 255) | |
text(self.text, self.frame.left , self.frame.bottom) | |
popStyle() | |
end | |
function OpenBtn:touched(touch) | |
return self.frame:touched(touch) | |
end |
This file contains hidden or 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
Skeet = class() | |
function Skeet:init(x, y, bounds) | |
self.x = x | |
self.y = y | |
self.color = color(255, 250, 0, 255) | |
self.active = 1 | |
if math.random(4) > 2 then | |
self.dx = -1 | |
else | |
self.dx = 1 | |
end | |
self.dy = 1 | |
self.turn = 0 | |
self.maxX = bounds:width() | |
self.maxY = bounds:height() + 5 | |
self.bounds = Frame(self.x - 10, self.y - 10, | |
self.x + 10, self.y + 10) | |
end | |
function Skeet:draw(bounds) | |
pushMatrix() | |
pushStyle() | |
strokeWidth(1) | |
noFill() | |
translate(self.x, self.y) | |
rotate(self.turn) | |
scale(self.active) | |
if self.active > 1 then self.active = self.active + 1 end | |
stroke(0, 255, 244, 255 - self.active * 25) | |
ellipse(0, 0, 20) | |
line(- 10, 0, 10, 0) | |
line(0, - 10, 0, 10) | |
line(- 7, - 7, 7, 7) | |
line(- 7, 7, 7, -7) | |
popMatrix() | |
popStyle() | |
self.x = self.x + self.dx | |
self.y = self.y + self.dy | |
if self.x < 10 then self.dx = -self.dx end | |
if self.y < 10 then self.dy = -self.dy end | |
if self.x > self.maxX then self.dx = -self.dx end | |
if self.y > self.maxY then self.dy = -self.dy end | |
self.turn = self.turn + 5 | |
if self.turn > 359 then self.turn = 0 end | |
self.bounds = Frame(self.x - 10, self.y - 10, | |
self.x + 10, self.y + 10) | |
end |
This file contains hidden or 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
Socket = class() | |
function Socket:init(code, x, y) | |
self.code = code | |
self.x = x | |
self.y = y | |
self.frame = Frame(x, y, x + 145, y + 30) | |
self.value = 1 | |
end | |
function Socket:draw() | |
pushStyle() | |
if self.code == nil then | |
fill(16, 16, 16, 255) | |
stroke(189, 189, 189, 255) | |
strokeWidth(2) | |
self.frame:draw() | |
for i = 0,4 do | |
rect(self.frame.left + i * 30, self.frame.bottom + 2, | |
self.frame.left + i * 30, self.frame.bottom + 6) | |
rect(self.frame.left + i * 30, self.frame.top - 6 , | |
self.frame.left + i * 30, self.frame.top - 2) | |
end | |
else | |
strokeWidth(3) | |
tint(self.code.color) | |
sprite(chipImg, self.frame.left, self.frame.bottom, | |
self.frame.right, self.frame.top) | |
stroke(152, 130, 130, 255) | |
noFill() | |
self.frame:draw() | |
fontSize(16) | |
fill(255, 255, 255, 255) | |
if string.len(self.code.long2) > 0 then | |
text(self.code.long1, | |
self.frame.left + 10, self.frame.bottom + 13) | |
text(self.code.long2, | |
self.frame.left + 10, self.frame.bottom + 2) | |
else | |
text(self.code.long1, | |
self.frame.left + 10, self.frame.bottom + 6) | |
end | |
if self.code.hasValue then | |
if self.code.short ~= "P" then | |
fill(63, 58, 37, 219) | |
stroke(127, 127, 127, 211) | |
strokeWidth(5) | |
ellipse(self.x + 87, self.y + 16, 20) | |
line(self.x + 90, self.y + 16, self.x + 145, | |
self.y + 16) | |
noStroke() | |
fill(231, 227, 227, 255) | |
ellipse(self.x + 110, self.y + 16, 20) | |
ellipse(self.x + 125, self.y + 16, 20) | |
rect(self.x + 110, self.y + 6, | |
self.x + 125, self.y + 26) | |
fill(47, 47, 47, 255) | |
textMode(CENTER) | |
text(self.value, self.x + 120, self.y + 15) | |
else | |
fill(233, 233, 233, 255) | |
rect(self.x + 100, self.y + 6, | |
self.x + 135, self.y + 26) | |
fill(47, 47, 47, 255) | |
textMode(CENTER) | |
text(self.value, self.x + 120, self.y + 15) | |
fill(63, 58, 37, 219) | |
stroke(127, 127, 127, 229) | |
strokeWidth(5) | |
line(self.x + 87, self.y + 30, self.x + 87, | |
self.y + 14) | |
line(self.x + 87, self.y + 16, self.x + 102, | |
self.y + 16) | |
end | |
end | |
end | |
popStyle() | |
end | |
function Socket:touched(touch) | |
if self.frame:touched(touch) then | |
return true | |
end | |
return false | |
end |
This file contains hidden or 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
TextBox = class() | |
-- TextBox | |
-- ver. 1.0 | |
-- a control for basic string editing | |
-- ==================== | |
function TextBox:init(x, y, w, s) | |
self.x = x | |
self.y = y | |
self.w = w | |
self.text = s | |
self.blink = ElapsedTime | |
self.blinkstate = true | |
end | |
function TextBox:draw() | |
local x, w, h | |
pushStyle() | |
pushMatrix() | |
textMode(CENTER) | |
fontSize(18) | |
rectMode(CORNER) | |
strokeWidth(1) | |
stroke(0, 0, 0, 255) | |
fill(30, 30, 30, 180) | |
translate(self.x, self.y) | |
rect(0, 0, self.w, 24) | |
stroke(255, 255, 255, 255) | |
--noFill() | |
rect(2, 2, self.w - 4, 20) | |
fill(255, 255, 255, 255) | |
text(self.text, self.w / 2, 12) | |
w, h = textSize(self.text) | |
if self.blink < ElapsedTime - 0.3 then | |
self.blink = ElapsedTime | |
self.blinkstate = not self.blinkstate | |
end | |
if self.blinkstate then | |
strokeWidth(2) | |
stroke(255, 255, 255, 255) | |
x = self.w / 2 + w / 2 + 2 | |
line(x, 3, x, 21) | |
end | |
popMatrix() | |
popStyle() | |
end | |
function TextBox:touched(touch) | |
-- move cursor? For the moment, touching a textbox has no function | |
end | |
function TextBox:acceptKey(k) | |
if k ~= nil then | |
if string.byte(k) == nil then | |
if string.len(self.text) > 0 then | |
self.text = string.sub(self.text, | |
1, string.len(self.text) - 1) | |
end | |
end | |
self.text = self.text..k | |
end | |
end |
This file contains hidden or 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
Token = class() | |
function Token:init(code, x, y, d) | |
-- you can accept and set parameters here | |
self.x = x | |
self.y = y | |
self.divide = d | |
self.code = code | |
end | |
function Token:draw() | |
pushStyle() | |
tint(self.code.color) | |
--tint(98, 130, 152, 255) | |
sprite(chipImg, self.x, self.y, | |
self.x + 140, self.y + 32) | |
strokeWidth(2) | |
noFill() | |
stroke(152, 152, 152, 255) | |
rect(self.x, self.y, self.x + 140, self.y + 32) | |
fill(154, 154, 154, 255) | |
noStroke() | |
rect(self.x, self.y, self.x + 8, self.y - 8) | |
rect(self.x + 34, self.y, self.x + 42, self.y - 8) | |
rect(self.x + 66, self.y, self.x + 74, self.y - 8) | |
rect(self.x + 98, self.y, self.x + 106, self.y - 8) | |
rect(self.x + 132, self.y, self.x + 140, self.y - 8) | |
rect(self.x, self.y + 32, self.x + 8, self.y + 38) | |
rect(self.x + 34, self.y + 32, self.x + 42, self.y + 38) | |
rect(self.x + 66, self.y + 32, self.x + 74, self.y + 38) | |
rect(self.x + 98, self.y + 32, self.x + 106, self.y + 38) | |
rect(self.x + 132, self.y + 32, self.x + 140, self.y + 38) | |
fill(233, 233, 233, 255) | |
fontSize(16) | |
if string.len(self.code.long2) > 0 then | |
text(self.code.long2, self.x + 8, self.y + 2) | |
text(self.code.long1, self.x + 8, self.y + 14) | |
else | |
text(self.code.long1, self.x + 8, self.y + 6) | |
end | |
if self.code.hasValue then | |
if self.code.short ~= "P" then | |
fill(211, 211, 211, 255) | |
ellipse(self.x + 110, self.y + 16, 20) | |
ellipse(self.x + 125, self.y + 16, 20) | |
rect(self.x + 110, self.y + 6, self.x + 125, self.y + 26) | |
fill(127, 127, 127, 219) | |
stroke(127, 127, 127, 255) | |
strokeWidth(5) | |
ellipse(self.x + 87, self.y + 16, 20) | |
line(self.x + 90, self.y + 16, self.x + 100, self.y + 16) | |
else | |
fill(194, 194, 194, 255) | |
rect(self.x + 100, self.y + 6, | |
self.x + 135, self.y + 26) | |
fill(223, 168, 168, 255) | |
--textMode(CENTER) | |
text("1", self.x + 130, self.y + 15) | |
fill(63, 58, 37, 219) | |
stroke(127, 127, 127, 228) | |
strokeWidth(5) | |
line(self.x + 87, self.y + 30, self.x + 87, self.y + 14) | |
line(self.x + 87, self.y + 16, self.x + 102, self.y + 16) | |
end | |
end | |
end | |
function Token:touched(touch) | |
if touch.x >= self.x and touch.x <= self.x + 130 and | |
touch.y >= self.y and touch.y <= self.y + 30 then | |
return true | |
end | |
return false | |
end |
This file contains hidden or 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
Tourney = class() | |
function Tourney:init() | |
self.matches = {} | |
self.scores = {} | |
self.robots = {} | |
self.matchNum = 0 | |
self.matchCount = 1 | |
self.isActive = false | |
self.frame = Frame(50, 500, WIDTH - 50, HEIGHT - 50) | |
self.type = 0 | |
self.timer = 0 | |
end | |
function Tourney:load(t, a, b, c, d) | |
self.matchNum = 0 | |
self.scores = {} | |
self.type = t | |
self.robots = {a, b, c, d} | |
if self.type == 1 then | |
self.matches[1] = {a, b, c, d} | |
self.matches[2] = {a, b, c, d} | |
self.matches[3] = {a, b, c, d} | |
self.matches[4] = {a, b, c, d} | |
self.timer = 100 | |
self.matchNum = 0 | |
self.matchCount = 4 | |
else | |
self.matches[1] = {a, d, nil, nil} | |
self.matches[2] = {b, c, nil, nil} | |
self.matches[3] = {a, b, nil, nil} | |
self.matches[4] = {a, b, nil, nil} | |
self.timer = 100 | |
self.matchNum = 0 | |
self.matchCount = 4 | |
end | |
end | |
function Tourney:getNextMatch() | |
self.matchNum = self.matchNum + 1 | |
if self.matchNum <= self.matchCount then | |
return self.matches[self.matchNum] | |
end | |
end | |
function Tourney:recordScores(a, b, c, d) | |
self.scores[self.matchNum] = {a, b, c, d} | |
end | |
function Tourney:draw() | |
local bot, round, temp | |
fill(192, 174, 174, 218) | |
stroke(255, 255, 255, 104) | |
strokeWidth(3) | |
self.frame:draw() | |
noFill() | |
fontSize(32) | |
textMode(CORNER) | |
text("Tourney Results", self.frame.left + 35, self.frame.top - 50) | |
fontSize(22) | |
text("Bot", self.frame.left + 50, self.frame.top - 90) | |
text("1", self.frame.left + 275, self.frame.top - 90) | |
text("2", self.frame.left + 350, self.frame.top - 90) | |
text("3", self.frame.left + 425, self.frame.top - 90) | |
text("4", self.frame.left + 500, self.frame.top - 90) | |
line(self.frame.left + 50, self.frame.top - 100, | |
self.frame.left + 500, self.frame.top - 100) | |
text("Total", self.frame.left + 575, self.frame.top - 90) | |
for bot = 1,4 do | |
textAlign(LEFT) | |
text(self.matches[1][bot].name, self.frame.left + 50, | |
self.frame.top - 100 - bot * 35) | |
temp = 0 | |
for round = 1, 4 do | |
textAlign(RIGHT) | |
text(self.scores[round][bot], | |
self.frame.left + 200 + round * 75, | |
self.frame.top - 100 - bot * 35) | |
temp = temp + self.scores[round][bot] | |
end | |
text(temp, self.frame.left + 575, | |
self.frame.top - 100 - bot * 35) | |
end | |
end |
This file contains hidden or 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
Track = class() | |
function Track:init(x, y, dir) | |
self.x = x | |
self.y = y | |
self.dir = dir | |
self.active = 1 | |
self.turn = 0 | |
self.bounds = Frame(self.x - 5, self.y - 5, | |
self.x + 5, self.y + 5) | |
end | |
function Track:draw() | |
local i | |
i = self.active - 1 | |
if self.active > 1 then self.active = self.active + 1 end | |
pushStyle() | |
strokeWidth(1) | |
stroke(255, 198, 0, 176) | |
noFill() | |
pushMatrix() | |
translate(self.x, self.y) | |
rotate(self.dir) | |
rotate( i * 20) | |
scale(1 + i * 0.1) | |
rect(-15, -10, -5, 5) | |
rect(-18, 8, -14, 12) | |
rect(-12, 8, -8, 12) | |
rect(-6, 8, -2, 12) | |
rotate(-i * 40) | |
rect(5, 0, 15, 15) | |
rect(2, 18, 6, 22) | |
rect(8, 18, 12, 22) | |
rect(14, 18, 18, 22) | |
popMatrix() | |
popStyle() | |
end |
This file contains hidden or 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
TradingCenter = class() | |
function TradingCenter:init() | |
local i, x, y | |
self.frame = Frame(20, 160, WIDTH - 10, HEIGHT - 20) | |
self.cards = {} | |
self.images = {} | |
for x = 1, 5 do | |
for y = 1, 4 do | |
i = x + (y-1) * 5 | |
self.cards[i] = | |
Frame(x * 140 - 100, y * 200 - 10 , | |
x * 140 + 30, y * 200 + 180) | |
w = self.cards[i]:width() | |
h = self.cards[i]:height() | |
self.images[i] = image(w, h) | |
end | |
end | |
self.center = 1 | |
end | |
function TradingCenter:initImages() | |
local i, w, h | |
for i = 1,20 do | |
setContext(self.images[i]) | |
w = self.cards[i]:width() | |
h = self.cards[i]:height() | |
fill(179, 179, 179, 255) | |
stroke(57, 54, 54, 255) | |
strokeWidth(6) | |
rect(1, 1, w, h) | |
strokeWidth(2) | |
stroke(112, 113, 115, 132) | |
fill(0, 0, 0, 255) | |
rect(10, 10, w - 10, h - 10) | |
fill(0, 0, 0, 255) | |
translate(w / 2 - 15, h / 2 + 50) | |
robots[i]:drawBase() | |
noStroke() | |
fill(0, 0, 0, 255) | |
rect(40,-130,65,30) | |
for c = 1, 30 do | |
fill(255, 255, 255, 255) | |
if robots[i].program[c] ~= nil then | |
p = robots[i].program[c].code | |
if p ~= nil then | |
if p.short == "F" then | |
fill(255, 0, 0, 255) | |
elseif p.short == "L" then | |
fill(255, 0, 181, 255) | |
elseif p.short == "R" then | |
fill(255, 101, 0, 255) | |
elseif p.short == "B" then | |
fill(255, 220, 0, 255) | |
elseif p.short == "W" then | |
fill(255, 0, 241, 255) | |
elseif p.short == "H" then | |
fill(14, 0, 255, 255) | |
elseif p.short == "A" then | |
fill(0, 178, 255, 255) | |
elseif p.short == "D" then | |
fill(141, 0, 255, 255) | |
elseif p.short == "G" then | |
fill(3, 255, 0, 255) | |
elseif p.short == "5" then | |
fill(0, 255, 117, 255) | |
elseif p.short == "P" then | |
fill(95, 255, 0, 255) | |
end | |
end | |
rect(-30, -129 + c * 3, -20, -126 + c * 3) | |
v = robots[i].program[c].value | |
fill(255-v * 5, 255-v * 5, 255-v * 5) | |
rect(-20, -129 + c * 3, -10, -126 + c * 3) | |
end | |
end | |
strokeWidth(1) | |
fill(156, 146, 146, 182) | |
noFill() | |
rect(-30, -129 + 1 * 3, -20, -126 + 30 * 3) | |
rect(-20, -129 + 1 * 3, -10, -126 + 30 * 3) | |
rotate(90) | |
fill(255, 255, 255, 255) | |
text(robots[i].name, -120, -65) | |
resetMatrix() | |
setContext() | |
end | |
end | |
function TradingCenter:loadRobot(r) | |
--self.robots[1] = r | |
self:initImages() | |
end | |
function TradingCenter:draw() | |
local i | |
fill(174, 190, 195, 209) | |
stroke(59, 111, 158, 190) | |
strokeWidth(5) | |
self.frame:draw() | |
fontSize(120) | |
fill(135, 171, 172, 207) | |
text("Trade", 35, HEIGHT - 180) | |
fontSize(20) | |
for i = 1,20 do | |
sprite(self.images[i], | |
self.cards[i].left, self.cards[i].bottom, | |
self.cards[i].right, self.cards[i].top) | |
end | |
end | |
function TradingCenter:touched(touch) | |
local i | |
for i = 1,20 do | |
if self.cards[i]:touched(touch) then | |
saveImage("Dropbox:"..robots[i].name, self.images[i]) | |
end | |
end | |
end |
This file contains hidden or 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
colors = {} | |
colors[1] = color(255, 25, 0, 255) | |
colors[2] = color(223, 143, 145, 255) | |
colors[3] = color(255, 127, 0, 255) | |
colors[4] = color(223, 183, 152, 255) | |
colors[5] = color(255, 235, 0, 255) | |
colors[6] = color(223, 219, 168, 255) | |
colors[7] = color(96, 255, 0, 255) | |
colors[8] = color(0, 255, 10, 255) | |
colors[9] = color(130, 225, 121, 255) | |
colors[10] = color(0, 255, 220, 255) | |
colors[11] = color(152, 223, 216, 255) | |
colors[12] = color(0, 74, 255, 255) | |
colors[13] = color(129, 121, 225, 255) | |
colors[14] = color(223, 157, 220, 255) | |
colors[15] = color(188, 0, 255, 255) | |
colors[16] = color(255, 255, 255, 255) | |
tourney = Tourney() | |
backClr = color(25, 27, 46, 255) | |
function deepcopy(object) | |
local lookup_table = {} | |
local function _copy(object) | |
if type(object) ~= "table" then | |
return object | |
elseif lookup_table[object] then | |
return lookup_table[object] | |
end | |
local new_table = {} | |
lookup_table[object] = new_table | |
for index, value in pairs(object) do | |
new_table[_copy(index)] = _copy(value) | |
end | |
return setmetatable(new_table, getmetatable(object)) | |
end | |
return _copy(object) | |
end | |
function blurImage(img) | |
local x, y, count, r, g, b, a, ir, ig, ib, ia | |
timg = img:copy() | |
for x = 1, img.width do | |
for y = 1, img.height do | |
r = 0 | |
g = 0 | |
b = 0 | |
a = 0 | |
if x > 1 then | |
ir, ig, ib, ia = img:get(x - 1, y) | |
r = r + ir | |
g = g + ig | |
b = b + ib | |
a = a + ia | |
end | |
if x > 1 and y > 1 then | |
ir, ig, ib, ia = img:get(x - 1, y - 1) | |
r = r + ir | |
g = g + ig | |
b = b + ib | |
a = a + ia | |
end | |
if y > 1 then | |
ir, ig, ib, ia = img:get(x, y - 1) | |
r = r + ir | |
g = g + ig | |
b = b + ib | |
a = a + ia | |
end | |
if x < img.width and y > 1 then | |
ir, ig, ib, ia = img:get(x + 1, y - 1) | |
r = r + ir | |
g = g + ig | |
b = b + ib | |
a = a + ia | |
end | |
if x < img.width then | |
ir, ig, ib, ia = img:get(x + 1, y) | |
r = r + ir | |
g = g + ig | |
b = b + ib | |
a = a + ia | |
end | |
if x < img.width and y < img.height then | |
ir, ig, ib, ia = img:get(x + 1, y + 1) | |
r = r + ir | |
g = g + ig | |
b = b + ib | |
a = a + ia | |
end | |
if y < img.height then | |
ir, ig, ib, ia = img:get(x, y + 1) | |
r = r + ir | |
g = g + ig | |
b = b + ib | |
a = a + ia | |
end | |
if x > 1 and y < img.height then | |
ir, ig, ib, ia = img:get(x - 1, y + 1) | |
r = r + ir | |
g = g + ig | |
b = b + ib | |
a = a + ia | |
end | |
ir,ig,ib,ia = img:get(x,y) | |
r = (r + ir) / 9 | |
g = (g + ig) / 9 | |
b = (b + ib) / 9 | |
a = (a + ia) / 9 | |
c = color(r,g,b,a) | |
--print(r,g,b,a) | |
timg:set(x,y,c) | |
end | |
end | |
print(r,g,b,a) | |
displayMode(STANDARD) | |
return timg | |
end | |
function getDefault() | |
local s | |
s = "20,Lump,0,0,14,14,15,4,30,1,F,1,2,nil,1,3,L,1,4,nil,1,5,nil,1,6,nil,1,7,nil,1,8,nil,1,9,nil,1,10,nil,1,11,nil,1,12,nil,1,13,nil,1,14,nil,1,15,nil,1,16,nil,1,17,nil,1,18,nil,1,19,nil,1,20,nil,1,21,nil,1,22,nil,1,23,nil,1,24,nil,1,25,nil,1,26,nil,1,27,nil,1,28,nil,1,29,nil,1,30,nil,1,Turner,0,0,15,8,15,7,30,1,F,1,2,H,4,3,G,1,4,L,1,5,G,1,6,nil,1,7,nil,1,8,nil,1,9,nil,1,10,nil,1,11,nil,1,12,nil,1,13,nil,1,14,nil,1,15,nil,1,16,nil,1,17,nil,1,18,nil,1,19,nil,1,20,nil,1,21,nil,1,22,nil,1,23,nil,1,24,nil,1,25,nil,1,26,nil,1,27,nil,1,28,nil,1,29,nil,1,30,nil,1,Spinner,0,0,2,7,1,4,30,1,L,1,2,W,4,3,G,1,4,nil,1,5,nil,1,6,nil,1,7,nil,1,8,nil,1,9,nil,1,10,nil,1,11,nil,1,12,nil,1,13,nil,1,14,nil,1,15,nil,1,16,nil,1,17,nil,1,18,nil,1,19,nil,1,20,nil,1,21,nil,1,22,nil,1,23,nil,1,24,nil,1,25,nil,1,26,nil,1,27,nil,1,28,nil,1,29,nil,1,30,nil,1,Smart Spinner,0,0,1,7,1,13,30,1,L,1,2,A,4,3,G,1,4,W,1,5,G,2,6,nil,1,7,nil,1,8,nil,1,9,nil,1,10,nil,1,11,nil,1,12,nil,1,13,nil,1,14,nil,1,15,nil,1,16,nil,1,17,nil,1,18,nil,1,19,nil,1,20,nil,1,21,nil,1,22,nil,1,23,nil,1,24,nil,1,25,nil,1,26,nil,1,27,nil,1,28,nil,1,29,nil,1,30,nil,1,Killbot 1000,0,0,15,3,15,3,30,1,F,1,2,H,4,3,G,1,4,R,1,5,R,1,6,A,13,7,L,1,8,F,1,9,H,11,10,G,5,11,R,1,12,G,5,13,W,1,14,G,6,15,nil,1,16,nil,1,17,nil,1,18,nil,1,19,nil,1,20,nil,1,21,nil,1,22,nil,1,23,nil,1,24,nil,1,25,nil,1,26,nil,1,27,nil,1,28,nil,1,29,nil,1,30,nil,1,Generobot,0,0,14,14,15,4,0,Generobot,0,0,14,14,15,4,0,Generobot,0,0,14,14,15,4,0,Generobot,0,0,14,14,15,4,0,Generobot,0,0,14,14,15,4,0,Generobot,0,0,14,14,15,4,0,Generobot,0,0,14,14,15,4,0,Generobot,0,0,14,14,15,4,0,Generobot,0,0,14,14,15,4,0,Generobot,0,0,14,14,15,4,0,Generobot,0,0,14,14,15,4,0,Generobot,0,0,14,14,15,4,0,Generobot,0,0,14,14,15,4,0,Generobot,0,0,14,14,15,4,0,Generobot,0,0,14,14,15,4,0" | |
return s | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment