utf8: new function zalgo

utf8: new function zalgo

Former-commit-id: 7f7a97063592416690f5724f185ef07a32306143 [formerly 90ece014df04837a5e09ef7a54300bc32ea18f07]
Former-commit-id: b4a3c51f7e2f3de857399018ccfce405bb704289

html2unicode = require'html'
math = require'math'

an = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
ci = 'ⒶⒷⒸⒹⒺⒻⒼⒽⒾⒿⓀⓁⓂⓃⓄⓅⓆⓇⓈⓉⓊⓋⓌⓍⓎⓏⓐⓑⓒⓓⓔⓕⓖⓗⓘⓙⓚⓛⓜⓝⓞⓟⓠⓡⓢⓣⓤⓥⓦⓧⓨⓩ⓪①②③④⑤⑥⑦⑧⑨'
bl = '𝔄𝔅ℭ𝔇𝔈𝔉𝔊ℌℑ𝔍𝔎𝔏𝔐𝔑𝔒𝔓𝔔ℜ𝔖𝔗𝔘𝔙𝔚𝔛𝔜ℨ𝔞𝔟𝔠𝔡𝔢𝔣𝔤𝔥𝔦𝔧𝔨𝔩𝔪𝔫𝔬𝔭𝔮𝔯𝔰𝔱𝔲𝔳𝔴𝔵𝔶𝔷'

an2ci = {}
-- Circled letters are 3 bytes, just use sub string
for i=1, #an
  f = i*3+1-3
  t = i*3
  an2ci[an\sub(i,i)] = ci\sub(f, t)

an2bl = {}
i=1
-- Since blackletters have varying byte length, use the common lua pattern to find multibyte chars
for uchar in string.gfind(bl, "([%z\1-\127\194-\244][\128-\191]*)")
  an2bl[an\sub(i,i)] = uchar
  i = i +1

codepoints = (str) ->
  str\gmatch("[%z\1-\127\194-\244][\128-\191]*")

unichr = (n) ->
  html2unicode('&#x%x;'\format(n))

wireplace = (offset, arg) ->
    s = arg or ''
    t = {}
    for i = 1, #s
      bc = string.byte(s, i, i)
      -- Replace space width ideographic space for fullwidth offset
      if bc == 32 and offset == 0xFEE0
        t[#t + 1] = '\227\128\128'
      elseif bc == 32
        t[#t + 1] = ' '
      elseif bc < 0x80 then
        t[#t + 1] = html2unicode("&#" .. (offset + bc) .. ";")
      else
        t[#t + 1] = s\sub(i, i)

    table.concat(t, "")

remap = (map, s) ->
  table.concat [map[s\sub(i,i)] or s\sub(i,i) for i=1, #s], ''

zalgo = (text, intensity=50) ->
  zalgo_threshold = intensity
  zalgo_chars = {}
  for i=0x0300, 0x036
    zalgo_chars[i-0x2ff] = unichr(i)

  zalgo_chars[#zalgo_chars + 1] = unichr(0x0488)
  zalgo_chars[#zalgo_chars + 1] = unichr(0x0489)

  source = text\upper()
  --source = _insert_randoms(source)

  zalgoized = {}
  for letter in codepoints(source)
    zalgoized[#zalgoized + 1] = letter
    zalgo_num = math.random(1, zalgo_threshold)
    for i=1, zalgo_num
      zalgoized[#zalgoized + 1] = zalgo_chars[math.random(1, #zalgo_chars)]
  table.concat(zalgoized)

PRIVMSG:
  '^%pwide (.+)$': (source, destination, arg) =>
    @Msg 'privmsg', destination, source, wireplace(0xFEE0, arg)
  '^%pblackletter (.+)$': (source, destination, arg) =>
    @Msg 'privmsg', destination, source, remap(an2bl, arg)
  '^%pcircled (.+)$': (source, destination, arg) =>
    @Msg 'privmsg', destination, source, remap(an2ci, arg)
  '^%pzalgo (.+)$': (source, destination, arg) =>
    @Msg 'privmsg', destination, source, zalgo(arg, 10)

an = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
ci = 'ⒶⒷⒸⒹⒺⒻⒼⒽⒾⒿⓀⓁⓂⓃⓄⓅⓆⓇⓈⓉⓊⓋⓌⓍⓎⓏⓐⓑⓒⓓⓔⓕⓖⓗⓘⓙⓚⓛⓜⓝⓞⓟⓠⓡⓢⓣⓤⓥⓦⓧⓨⓩ⓪①②③④⑤⑥⑦⑧⑨'
bl = '𝔄𝔅ℭ𝔇𝔈𝔉𝔊ℌℑ𝔍𝔎𝔏𝔐𝔑𝔒𝔓𝔔ℜ𝔖𝔗𝔘𝔙𝔚𝔛𝔜ℨ𝔞𝔟𝔠𝔡𝔢𝔣𝔤𝔥𝔦𝔧𝔨𝔩𝔪𝔫𝔬𝔭𝔮𝔯𝔰𝔱𝔲𝔳𝔴𝔵𝔶𝔷'

an2ci = {}
-- Circled letters are 3 bytes, just use sub string
for i=1, #an
  f = i*3+1-3
  t = i*3
  an2ci[an\sub(i,i)] = ci\sub(f, t)

an2bl = {}
i=1
-- Since blackletters have varying byte length, use the common lua pattern to find multibyte chars
for uchar in string.gfind(bl, "([%z\1-\127\194-\244][\128-\191]*)")
  an2bl[an\sub(i,i)] = uchar
  i = i +1

wireplace = (offset, arg) ->
    html2unicode = require'html'
    s = arg or ''
    t = {}
    for i = 1, #s
      bc = string.byte(s, i, i)
      -- Replace space width ideographic space for fullwidth offset
      if bc == 32 and offset == 0xFEE0
        t[#t + 1] = '\227\128\128'
      elseif bc == 32
        t[#t + 1] = ' '
      elseif bc < 0x80 then
        t[#t + 1] = html2unicode("&#" .. (offset + bc) .. ";")
      else
        t[#t + 1] = s\sub(i, i)

    table.concat(t, "")

remap = (map, s) ->
  table.concat [map[s\sub(i,i)] or s\sub(i,i) for i=1, #s], ''

PRIVMSG:
  '^%pwide (.+)$': (source, destination, arg) =>
    @Msg 'privmsg', destination, source, wireplace(0xFEE0, arg)
  '^%pblackletter (.+)$': (source, destination, arg) =>
    @Msg 'privmsg', destination, source, remap(an2bl, arg)
  '^%pcircled (.+)$': (source, destination, arg) =>
    @Msg 'privmsg', destination, source, remap(an2ci, arg)


Forgot about accelerometer

Forgot about accelerometer

Gdx = java.require "com.badlogic.gdx.Gdx"

{
  get_x: ->
    Gdx.input\getAccelerometerX!

  get_y: ->
    Gdx.input\getAccelerometerY!

  get_z: ->
    Gdx.input\getAccelerometerZ!

  get_rotation: ->
    @get_x!, @get_y!, @get_z!
}

Gdx = java.require "com.badlogic.gdx.Gdx"

{
  getX: ->
    Gdx.input\getAccelerometerX!

  getY: ->
    Gdx.input\getAccelerometerY!

  getZ: ->
    Gdx.input\getAccelerometerZ!

  getRotation: ->
    @getX!, @getY!, @getZ!
}


Fix Screen

Fix Screen

* Forgot some returns for accessors
* Problem with using = in stead of : for class member functions

require "LovePunk.geometry.Matrix"

export ^

class Screen
	new: =>
		@init!
		-- LP.engine\addChild @__sprite if LP.renderMode == RenderMode.Buffer

	init: =>
		@__x, @__y = 0, 0
		@__originX, @__originY = 0, 0
		@__angle, @__current = 0, 0
		@__scale, @__scaleX, @__scaleY = 1, 1, 1
		@__matrix = Matrix!
		@__update!

	-- bd Bitmap
	disposeBitmap = (bd) =>

	-- Resizes the screen by recreating the bitmap buffer.
	resize: =>

	-- Swaps screen buffers.
	swap: =>

	-- Add a filter.
	--
	-- @param	filter	The filter to add.
	addFilter: (filter) =>

	-- Refreshes the screen.
	refresh: =>

	-- Redraws the screen.
	redraw: =>

	-- @private Re-applies transformation matrix.
	__update: =>
		return if @__matrix == nil -- prevent update on init
		@__matrix.b, @__matrix.c = 0, 0
		@__matrix.a, @__matrix.d = @fullScaleX!, @fullScaleY!
		@__matrix.tx = -@originX! * @__matrix.a
		@__matrix.ty = -@originY! * @__matrix.d
		@__matrix\rotate @__angle if @__angle != 0
		@__matrix.tx += @originX! * @fullScaleX! + @x!
		@__matrix.ty += @originY! * @fullScaleY! + @y!
		-- TODO
		-- _sprite.transform.matrix = _matrix;

	-- Refresh color of the screen.
	color: (value) =>
		return @__color if value == nil or @__color == value
		@__color = value
		@__color

	-- X offset of the screen.
	-- value int
	-- return int
	x: (value) =>
		return @__x if value == nil or @__x == value
		@__x = value
		@__update!
		@__x

	-- Y offset of the screen.
	-- value int
	-- return int
	y: (value) =>
		return @__y if value == nil or @__y == value
		@__y = value
		@__update!
		@__y

	-- X origin of transformations.
	-- value int
	-- return int
	originX: (value) =>
		return @__originX if value == nil or @__originX == value
		@__originX = value
		@__update!
		@__originX

	-- Y origin of transformations.
	-- value int
	-- return int
	originY: (value) =>
		return @__originY if value == nil or @__originY == value
		@__originY = value
		@__update!
		@__originY

	-- X scale of the screen.
	-- value float
	-- return float
	scaleX: (value) =>
		return @__scaleX if value == nil or @__scaleX == value
		@__scaleX = value
		@fullScaleX = => @scaleX! * @scale!
		@__update!
		@needsResize = => true
		@__scaleX

	-- Y scale of the screen.
	-- value float
	-- return float
	scaleY: (value) =>
		return @__scaleY if value == nil or @__scaleY == value
		@__scaleY = value
		@fullScaleY = => @scaleY! * @scale!
		@__update!
		@needsResize = => true
		@__scaleY

	-- Scale factor of the screen. Final scale is scaleX * scale by scaleY * scale, so
	-- you can use this factor to scale the screen both horizontally and vertically.
	-- value float
	-- return float
	scale: (value) =>
		return @__scale if value == nil or @__scale == value
		@__scale = value
		@fullScaleX = => @scaleX! * @scale!
		@fullScaleY = => @scaleY! * @scale!
		@__update!
		@needsResize = => true
		@__scale

	-- Final X scale value of the screen
	fullScaleX: => 1

	-- Final Y scale value of the screen
	fullScaleY: => 1

	-- True if the scale of the screen has changed.
	needsResize: => false

	-- Rotation of the screen, in degrees.
	angle: (value) =>
		return @__angle * LP.DEG if value == nil
		return value if @__angle == value * LP.RAD
		@__angle = value * LP.RAD
		@__update!
		@__angle

	-- Whether screen smoothing should be used or not.
	-- value bool
	-- return bool
	smoothing = (value) =>
		-- TODO
		@__smoothing = value if value != nil
		@__smoothing

	-- Width of the screen.
	width: => love.graphics.getWidth!

	-- Height of the screen.
	height: => love.graphics.getHeight!

	-- X position of the mouse on the screen.
	mouseX: => love.mouse.getX!

	-- Y position of the mouse on the screen.
	mouseY: => love.mouse.getY!

	-- Captures the current screen as an Image object.
	-- @return	A new Image object.
	capture: =>
	-- TODO return LovePunk.graphics.Image

require "LovePunk.geometry.Matrix"

export ^

class Screen
	new: =>
		@init!
		-- LP.engine\addChild @__sprite if LP.renderMode == RenderMode.Buffer

	init: =>
		@__x, @__y = 0, 0
		@__originX, @__originY = 0, 0
		@__angle, @__current = 0, 0
		@__scale, @__scaleX, @__scaleY = 1, 1, 1
		@__matrix = Matrix!
		@__update!

	-- bd Bitmap
	disposeBitmap = (bd) =>

	-- Resizes the screen by recreating the bitmap buffer.
	resize: =>

	-- Swaps screen buffers.
	swap: =>

	-- Add a filter.
	--
	-- @param	filter	The filter to add.
	addFilter: (filter) =>

	-- Refreshes the screen.
	refresh: =>

	-- Redraws the screen.
	redraw: =>

	-- @private Re-applies transformation matrix.
	__update: =>
		return if @__matrix == nil -- prevent update on init
		@__matrix.b, @__matrix.c = 0, 0
		@__matrix.a, @__matrix.d = @fullScaleX!, @fullScaleY!
		@__matrix.tx = -@originX! * @__matrix.a
		@__matrix.ty = -@originY! * @__matrix.d
		@__matrix\rotate @__angle if @__angle != 0
		@__matrix.tx += @originX! * @fullScaleX! + @x!
		@__matrix.ty += @originY! * @fullScaleY! + @y!
		-- TODO
		-- _sprite.transform.matrix = _matrix;

	-- Refresh color of the screen.
	color: (value) =>
		@__color if value == nil or @__color == value
		@__color = value
		@__color

	-- X offset of the screen.
	-- value int
	-- return int
	x = (value) =>
		@__x if value == nil or @__x == value
		@__x = value
		@__update!
		@__x

	-- Y offset of the screen.
	-- value int
	-- return int
	y = (value) =>
		@__y if value == nil or @__y == value
		@__y = value
		@__update!
		@__y

	-- X origin of transformations.
	-- value int
	-- return int
	originX = (value) =>
		return @__originX if value == nil or @__originX == value
		@__originX = value
		@__update!
		@__originX

	-- Y origin of transformations.
	-- value int
	-- return int
	originY = (value) =>
		return @__originY if value == nil or @__originY == value
		@__originY = value
		@__update!
		@__originY

	-- X scale of the screen.
	-- value float
	-- return float
	scaleX = (value) =>
		return @__scaleX if value == nil or @__scaleX == value
		@__scaleX = value
		@fullScaleX = => @scaleX! * @scale!
		@__update!
		@needsResize = => true
		@__scaleX

	-- Y scale of the screen.
	-- value float
	-- return float
	scaleY = (value) =>
		return @__scaleY if value == nil or @__scaleY == value
		@__scaleY = value
		@fullScaleY = => @scaleY! * @scale!
		@__update!
		@needsResize = => true
		@__scaleY

	-- Scale factor of the screen. Final scale is scaleX * scale by scaleY * scale, so
	-- you can use this factor to scale the screen both horizontally and vertically.
	-- value float
	-- return float
	scale = (value) =>
		return @__scale if value == nil or @__scale == value
		@__scale = value
		@fullScaleX = => @scaleX! * @scale!
		@fullScaleY = => @scaleY! * @scale!
		@__update!
		@needsResize = => true
		@__scale

	-- Final X scale value of the screen
	fullScaleX: => 1

	-- Final Y scale value of the screen
	fullScaleY: => 1

	-- True if the scale of the screen has changed.
	needsResize: => false

	-- Rotation of the screen, in degrees.
	angle: (value) =>
		return @__angle * LP.DEG if value == nil
		return value if @__angle == value * LP.RAD
		@__angle = value * LP.RAD
		@__update!
		@__angle

	-- Whether screen smoothing should be used or not.
	-- value bool
	-- return bool
	smoothing = (value) =>
		-- TODO
		@__smoothing = value if value != nil
		@__smoothing

	-- Width of the screen.
	width: => love.graphics.getWidth!

	-- Height of the screen.
	height: => love.graphics.getHeight!

	-- X position of the mouse on the screen.
	mouseX: => love.mouse.getX!

	-- Y position of the mouse on the screen.
	mouseY: => love.mouse.getY!

	-- Captures the current screen as an Image object.
	-- @return	A new Image object.
	capture: =>
	-- TODO return LovePunk.graphics.Image