sorcery  Artifact [680d9162e2]

Artifact 680d9162e24fef19df6382e7128e297c6beaae9f910ea3a075d11b5199e8e520:


local image
image = sorcery.lib.class {

	__concat   = function(self,with) return self:blit(with) end;
	__tostring = function(self)      return self:render()   end;

	construct = function(file) return {
		string = file;
		atop = {};
		fx = {};

		render = function(self)
			local str = ''
			for _,i in pairs(self.atop) do
				str = '(' .. i:render() .. ')^' .. str
			end
			local bracket = false
			if str ~= '' then str = str .. '(' bracket = true end
			str = str .. self.string
			for _,e in pairs(self.fx) do
				str = str .. '^[' .. e
				-- be sure to escape ones that take arguments
				-- correctly!
			end
			if bracket then str = str .. ')' end
			return str
		end;

		blit = function(self, img)
			if img then return image.change(self, {
				atop = sorcery.lib.tbl.append(self.atop, {img})
			}) else return self end
		end;

		multiply = function(self, color)
			return image.change(self, {
				fx = sorcery.lib.tbl.append(self.fx, {'multiply:' .. tostring(color)})
			})
		end;

		colorize = function(self, color, ratio)
			return image.change(self, {
				fx = sorcery.lib.tbl.append(self.fx, {'colorize:' .. tostring(color) .. ':' .. ratio})
			})
		end;

		fade = function(self, fac)
			return image.change(self, {
				fx = sorcery.lib.tbl.append(self.fx, {'opacity:' .. (255 - 255*fac)})
			})
		end;

		transform = function(self, kind)
			return image.change(self, {
				fx = sorcery.lib.tbl.append(self.fx, {'transform' .. tostring(kind)})
			})
		end;
	} end;
}
return image