Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add .coffee.md to Literate Coffeescript #4957

Merged
merged 1 commit into from
Aug 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/linguist/languages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2894,6 +2894,7 @@ Literate CoffeeScript:
- litcoffee
extensions:
- ".litcoffee"
- ".coffee.md"
language_id: 206
Literate Haskell:
type: programming
Expand Down
113 changes: 113 additions & 0 deletions samples/Literate CoffeeScript/pixi.coffee.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
Pixi Test
=========

Testing out Pixi.js

_ = require "./lib/underscore"

{applyStylesheet} = require "util"
applyStylesheet require("./style")
{width, height} = require "./pixie"

{update, applyProperties, hydrate} = require "./object_updater"
editor = require("./editor")()

PIXI = require "./lib/pixi"
# PIXI.Texture.SCALE_MODE.DEFAULT = PIXI.Texture.SCALE_MODE.NEAREST

stage = new PIXI.Stage(0x66FF99)

renderer = PIXI.autoDetectRenderer(width, height)

clickHandler = (mouseData) ->
if mouseData.originalEvent.ctrlKey or mouseData.originalEvent.metaKey
editor.activeObject mouseData.target.data
else
if data = mouseData.target.data
data.click?(data)

document.body.appendChild(renderer.view)

Load textures from a data file and map them into Pixi.js texture objects

textures = require "./textures"
Object.keys(textures).forEach (name) ->
value = textures[name]
textures[name] = PIXI.Texture.fromImage("http://a0.pixiecdn.com/#{value}", true)

Reload our app data or use our default data.

if data = ENV?.APP_STATE
data = JSON.parse(data)
else
data = require("./default_data")

Fill children

populate = (object) ->
[0..4].forEach (i) ->
[0..4].forEach (j) ->
c = new PIXI.Sprite(textures.pixie)
object.addChild c
c.position =
x: i * 50 - 125
y: j * 50 - 125

Reconstitute our objects using our app data.

objects = data.map (datum) ->
object = new PIXI.Sprite(textures[datum.sprite])

datum._host = object

object.anchor.x = object.anchor.y = 0.5

object.data = datum
object.interactive = true
object.click = clickHandler

# TODO: Figure out child object compositions
# something like
# object.data.children?.forEach (datum) ->
# recurse object, datum
# populate object

hydrate(object.data)
applyProperties(object)

# TODO: stage should be 'parent' or 'root' so we can handle trees of objects
stage.addChild(object)

return object

Our main loop, update and draw.

dt = 1/60
animate = ->
requestAnimationFrame(animate)

objects.forEach (object) ->
update(object, dt)

renderer.render(stage)

requestAnimationFrame(animate)

This is where we export and expose our app state.

global.appData = ->
JSON.stringify stage.children.map (child) ->
_.omit child.data, "_host"

Text sample (still need to figure out how to handle different PIXI types for our
objects)

addText = ->
textSample = new PIXI.Text "Pixi.js can has\nmultiline text!",
font: "35px Snippet"
fill: "white"
align: "left"
textSample.position.x = 20
textSample.position.y = 20
stage.addChild(textSample)