├── demos
├── PiratePig
│ ├── public
│ │ ├── fonts
│ │ │ ├── FreebooterUpdated.svg
│ │ │ ├── FreebooterUpdated.eot
│ │ │ ├── FreebooterUpdated.ttf
│ │ │ └── FreebooterUpdated.woff
│ │ ├── favicon.png
│ │ ├── sounds
│ │ │ ├── 3.mp3
│ │ │ ├── 3.ogg
│ │ │ ├── 3.wav
│ │ │ ├── 4.mp3
│ │ │ ├── 4.ogg
│ │ │ ├── 4.wav
│ │ │ ├── 5.mp3
│ │ │ ├── 5.ogg
│ │ │ ├── 5.wav
│ │ │ ├── theme.mp3
│ │ │ ├── theme.ogg
│ │ │ └── theme.wav
│ │ ├── images
│ │ │ ├── logo.png
│ │ │ ├── cursor.png
│ │ │ ├── game_bear.png
│ │ │ ├── game_carrot.png
│ │ │ ├── game_lemon.png
│ │ │ ├── game_panda.png
│ │ │ ├── center_bottom.png
│ │ │ ├── game_bunny_02.png
│ │ │ ├── game_piratePig.png
│ │ │ ├── background_tile.png
│ │ │ └── cursor_highlight.png
│ │ └── index.html
│ ├── .gitignore
│ ├── build.hxml
│ ├── webpack.config.js
│ ├── package.json
│ └── src
│ │ └── piratepig
│ │ ├── Main.hx
│ │ ├── PiratePig.hx
│ │ ├── Tile.hx
│ │ └── GamepadWrapper.hx
├── BunnyMark
│ ├── .gitignore
│ ├── build.hxml
│ ├── public
│ │ ├── wabbit_alpha.png
│ │ └── index.html
│ ├── src
│ │ ├── Bunny.hx
│ │ └── Main.hx
│ ├── webpack.config.js
│ └── package.json
├── HerokuShaders
│ ├── .gitignore
│ ├── public
│ │ ├── assets
│ │ │ ├── readme.txt
│ │ │ ├── heroku.vert
│ │ │ ├── 6286.frag
│ │ │ ├── 5733.frag
│ │ │ ├── 6284.1.frag
│ │ │ ├── 5398.8.frag
│ │ │ ├── 6288.1.frag
│ │ │ ├── 5891.5.frag
│ │ │ ├── 6238.frag
│ │ │ ├── 6223.2.frag
│ │ │ ├── 5812.frag
│ │ │ ├── 6147.1.frag
│ │ │ ├── 5805.18.frag
│ │ │ ├── 6022.frag
│ │ │ ├── 4278.1.frag
│ │ │ ├── 6162.frag
│ │ │ ├── 6043.1.frag
│ │ │ ├── 5454.21.frag
│ │ │ ├── 5492.frag
│ │ │ ├── 5359.8.frag
│ │ │ ├── 6049.frag
│ │ │ └── 6175.frag
│ │ └── index.html
│ ├── build.hxml
│ ├── webpack.config.js
│ └── package.json
└── NyanCat
│ ├── .gitignore
│ ├── build.hxml
│ ├── assets
│ ├── library.fla
│ └── library.swf
│ ├── public
│ ├── index.html
│ └── favicon.png
│ ├── src
│ └── App.hx
│ ├── webpack.config.js
│ └── package.json
├── .gitignore
├── features
├── text
│ └── AddingText
│ │ ├── .gitignore
│ │ ├── build.hxml
│ │ ├── public
│ │ ├── assets
│ │ │ ├── KatamotzIkasi.eot
│ │ │ ├── KatamotzIkasi.ttf
│ │ │ └── KatamotzIkasi.woff
│ │ ├── index.html
│ │ └── favicon.png
│ │ ├── webpack.config.js
│ │ ├── package.json
│ │ └── src
│ │ └── App.hx
├── media
│ ├── PlayingSound
│ │ ├── .gitignore
│ │ ├── build.hxml
│ │ ├── public
│ │ │ ├── assets
│ │ │ │ ├── stars.mp3
│ │ │ │ └── stars.ogg
│ │ │ ├── index.html
│ │ │ └── favicon.png
│ │ ├── webpack.config.js
│ │ ├── package.json
│ │ └── src
│ │ │ └── App.hx
│ └── PlayingVideo
│ │ ├── .gitignore
│ │ ├── build.hxml
│ │ ├── public
│ │ ├── assets
│ │ │ ├── example.mp4
│ │ │ ├── example.ogv
│ │ │ └── example.webm
│ │ ├── index.html
│ │ └── favicon.png
│ │ ├── webpack.config.js
│ │ ├── package.json
│ │ └── src
│ │ └── App.hx
├── display
│ ├── AddingAnimation
│ │ ├── .gitignore
│ │ ├── build.hxml
│ │ ├── public
│ │ │ ├── assets
│ │ │ │ └── openfl.png
│ │ │ ├── index.html
│ │ │ └── favicon.png
│ │ ├── webpack.config.js
│ │ ├── package.json
│ │ └── src
│ │ │ └── App.hx
│ ├── CustomRendering
│ │ ├── .gitignore
│ │ ├── build.hxml
│ │ ├── public
│ │ │ ├── assets
│ │ │ │ └── openfl.png
│ │ │ ├── index.html
│ │ │ └── favicon.png
│ │ ├── webpack.config.js
│ │ ├── package.json
│ │ └── src
│ │ │ └── App.hx
│ ├── DisplayingABitmap
│ │ ├── .gitignore
│ │ ├── build.hxml
│ │ ├── public
│ │ │ ├── openfl.png
│ │ │ └── index.html
│ │ ├── webpack.config.js
│ │ ├── package.json
│ │ └── src
│ │ │ └── Main.hx
│ ├── DrawingShapes
│ │ ├── .gitignore
│ │ ├── build.hxml
│ │ ├── public
│ │ │ ├── index.html
│ │ │ └── favicon.png
│ │ ├── webpack.config.js
│ │ ├── package.json
│ │ └── src
│ │ │ └── App.hx
│ ├── UsingBitmapData
│ │ ├── .gitignore
│ │ ├── build.hxml
│ │ ├── public
│ │ │ ├── assets
│ │ │ │ └── openfl.png
│ │ │ └── index.html
│ │ ├── webpack.config.js
│ │ ├── package.json
│ │ └── src
│ │ │ └── App.hx
│ └── UsingSWFAssets
│ │ ├── .gitignore
│ │ ├── build.hxml
│ │ ├── assets
│ │ ├── layout.fla
│ │ └── layout.swf
│ │ ├── public
│ │ └── index.html
│ │ ├── webpack.config.js
│ │ ├── package.json
│ │ └── src
│ │ └── App.hx
├── display3D
│ ├── HelloTriangle
│ │ ├── .gitignore
│ │ ├── build.hxml
│ │ ├── public
│ │ │ └── index.html
│ │ ├── webpack.config.js
│ │ ├── package.json
│ │ └── src
│ │ │ └── App.hx
│ ├── Stage3DCamera
│ │ ├── .gitignore
│ │ ├── build.hxml
│ │ ├── public
│ │ │ ├── openfl.png
│ │ │ └── index.html
│ │ ├── webpack.config.js
│ │ └── package.json
│ └── Stage3DMipmap
│ │ ├── .gitignore
│ │ ├── build.hxml
│ │ ├── public
│ │ ├── checkers.png
│ │ └── index.html
│ │ ├── webpack.config.js
│ │ └── package.json
└── events
│ ├── CreatingAMainLoop
│ ├── .gitignore
│ ├── build.hxml
│ ├── public
│ │ └── index.html
│ ├── webpack.config.js
│ ├── package.json
│ └── src
│ │ └── App.hx
│ ├── CreatingCustomEvents
│ ├── .gitignore
│ ├── build.hxml
│ ├── public
│ │ └── index.html
│ ├── webpack.config.js
│ ├── src
│ │ ├── CustomEvent.hx
│ │ └── App.hx
│ └── package.json
│ ├── HandlingKeyboardEvents
│ ├── .gitignore
│ ├── build.hxml
│ ├── public
│ │ ├── assets
│ │ │ └── openfl.png
│ │ └── index.html
│ ├── webpack.config.js
│ ├── package.json
│ └── src
│ │ └── App.hx
│ └── HandlingMouseEvents
│ ├── .gitignore
│ ├── build.hxml
│ ├── public
│ ├── assets
│ │ └── openfl.png
│ └── index.html
│ ├── webpack.config.js
│ ├── package.json
│ └── src
│ └── App.hx
├── .vscode
└── settings.json
├── hxformat.json
├── NOTICE.md
├── README.md
├── LICENSE.md
└── script.hx
/demos/PiratePig/public/fonts/FreebooterUpdated.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules
3 | npm-debug.log
4 |
--------------------------------------------------------------------------------
/demos/BunnyMark/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | src/app.js
3 | dist/
4 | *.map
--------------------------------------------------------------------------------
/demos/HerokuShaders/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | src/app.js
3 | dist/
4 | *.map
--------------------------------------------------------------------------------
/demos/PiratePig/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | src/app.js
3 | dist/app.js
4 | *.map
--------------------------------------------------------------------------------
/features/text/AddingText/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | src/app.js
3 | dist/
4 | *.map
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "[haxe]": {
3 | "editor.formatOnSave": true
4 | }
5 | }
--------------------------------------------------------------------------------
/demos/NyanCat/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | src/app.js
3 | dist/
4 | *.map
5 | *.bundle
--------------------------------------------------------------------------------
/features/media/PlayingSound/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | src/app.js
3 | dist/
4 | *.map
--------------------------------------------------------------------------------
/features/media/PlayingVideo/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | src/app.js
3 | dist/
4 | *.map
--------------------------------------------------------------------------------
/features/display/AddingAnimation/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | src/app.js
3 | dist/
4 | *.map
--------------------------------------------------------------------------------
/features/display/CustomRendering/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | src/app.js
3 | dist/
4 | *.map
--------------------------------------------------------------------------------
/features/display/DisplayingABitmap/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | src/app.js
3 | dist/
4 | *.map
--------------------------------------------------------------------------------
/features/display/DrawingShapes/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | src/app.js
3 | dist/
4 | *.map
--------------------------------------------------------------------------------
/features/display/UsingBitmapData/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | src/app.js
3 | dist/
4 | *.map
--------------------------------------------------------------------------------
/features/display3D/HelloTriangle/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | src/app.js
3 | dist/
4 | *.map
--------------------------------------------------------------------------------
/features/display3D/Stage3DCamera/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | src/app.js
3 | dist/
4 | *.map
--------------------------------------------------------------------------------
/features/display3D/Stage3DMipmap/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | src/app.js
3 | dist/
4 | *.map
--------------------------------------------------------------------------------
/features/events/CreatingAMainLoop/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | src/app.js
3 | dist/
4 | *.map
--------------------------------------------------------------------------------
/demos/HerokuShaders/public/assets/readme.txt:
--------------------------------------------------------------------------------
1 | These shaders are taken from http://glsl.heroku.com
--------------------------------------------------------------------------------
/features/events/CreatingCustomEvents/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | src/app.js
3 | dist/
4 | *.map
--------------------------------------------------------------------------------
/features/events/HandlingKeyboardEvents/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | src/app.js
3 | dist/
4 | *.map
--------------------------------------------------------------------------------
/features/events/HandlingMouseEvents/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | src/app.js
3 | dist/
4 | *.map
--------------------------------------------------------------------------------
/features/display/UsingSWFAssets/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | src/app.js
3 | dist/
4 | *.map
5 | *.bundle
--------------------------------------------------------------------------------
/demos/BunnyMark/build.hxml:
--------------------------------------------------------------------------------
1 | -main Main
2 | -js dist/app.js
3 | -cp node_modules/openfl/lib
4 | -cp src
5 | -D source-map
--------------------------------------------------------------------------------
/demos/HerokuShaders/build.hxml:
--------------------------------------------------------------------------------
1 | -main App
2 | -js dist/app.js
3 | -cp node_modules/openfl/lib
4 | -cp src
5 | -D source-map
--------------------------------------------------------------------------------
/demos/NyanCat/build.hxml:
--------------------------------------------------------------------------------
1 | -main App
2 | -js dist/app.js
3 | -cp node_modules/openfl/lib
4 | -cp src
5 | -D source-map
6 |
--------------------------------------------------------------------------------
/demos/NyanCat/assets/library.fla:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openfl/openfl-samples-haxe/HEAD/demos/NyanCat/assets/library.fla
--------------------------------------------------------------------------------
/demos/NyanCat/assets/library.swf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openfl/openfl-samples-haxe/HEAD/demos/NyanCat/assets/library.swf
--------------------------------------------------------------------------------
/features/text/AddingText/build.hxml:
--------------------------------------------------------------------------------
1 | -main App
2 | -js dist/app.js
3 | -cp node_modules/openfl/lib
4 | -cp src
5 | -D source-map
--------------------------------------------------------------------------------
/demos/PiratePig/public/favicon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openfl/openfl-samples-haxe/HEAD/demos/PiratePig/public/favicon.png
--------------------------------------------------------------------------------
/demos/PiratePig/public/sounds/3.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openfl/openfl-samples-haxe/HEAD/demos/PiratePig/public/sounds/3.mp3
--------------------------------------------------------------------------------
/demos/PiratePig/public/sounds/3.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openfl/openfl-samples-haxe/HEAD/demos/PiratePig/public/sounds/3.ogg
--------------------------------------------------------------------------------
/demos/PiratePig/public/sounds/3.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openfl/openfl-samples-haxe/HEAD/demos/PiratePig/public/sounds/3.wav
--------------------------------------------------------------------------------
/demos/PiratePig/public/sounds/4.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openfl/openfl-samples-haxe/HEAD/demos/PiratePig/public/sounds/4.mp3
--------------------------------------------------------------------------------
/demos/PiratePig/public/sounds/4.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openfl/openfl-samples-haxe/HEAD/demos/PiratePig/public/sounds/4.ogg
--------------------------------------------------------------------------------
/demos/PiratePig/public/sounds/4.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openfl/openfl-samples-haxe/HEAD/demos/PiratePig/public/sounds/4.wav
--------------------------------------------------------------------------------
/demos/PiratePig/public/sounds/5.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openfl/openfl-samples-haxe/HEAD/demos/PiratePig/public/sounds/5.mp3
--------------------------------------------------------------------------------
/demos/PiratePig/public/sounds/5.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openfl/openfl-samples-haxe/HEAD/demos/PiratePig/public/sounds/5.ogg
--------------------------------------------------------------------------------
/demos/PiratePig/public/sounds/5.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openfl/openfl-samples-haxe/HEAD/demos/PiratePig/public/sounds/5.wav
--------------------------------------------------------------------------------
/features/display/DrawingShapes/build.hxml:
--------------------------------------------------------------------------------
1 | -main App
2 | -js dist/app.js
3 | -cp node_modules/openfl/lib
4 | -cp src
5 | -D source-map
--------------------------------------------------------------------------------
/features/display/UsingSWFAssets/build.hxml:
--------------------------------------------------------------------------------
1 | -main App
2 | -js dist/app.js
3 | -cp node_modules/openfl/lib
4 | -cp src
5 | -D source-map
--------------------------------------------------------------------------------
/demos/PiratePig/public/images/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openfl/openfl-samples-haxe/HEAD/demos/PiratePig/public/images/logo.png
--------------------------------------------------------------------------------
/features/display/CustomRendering/build.hxml:
--------------------------------------------------------------------------------
1 | -main App
2 | -js dist/app.js
3 | -cp node_modules/openfl/lib
4 | -cp src
5 | -D source-map
--------------------------------------------------------------------------------
/features/display/DisplayingABitmap/build.hxml:
--------------------------------------------------------------------------------
1 | -main Main
2 | -js dist/app.js
3 | -cp node_modules/openfl/lib
4 | -cp src
5 | -D source-map
--------------------------------------------------------------------------------
/features/display/UsingBitmapData/build.hxml:
--------------------------------------------------------------------------------
1 | -main App
2 | -js dist/app.js
3 | -cp node_modules/openfl/lib
4 | -cp src
5 | -D source-map
--------------------------------------------------------------------------------
/features/display3D/HelloTriangle/build.hxml:
--------------------------------------------------------------------------------
1 | -main App
2 | -js dist/app.js
3 | -cp node_modules/openfl/lib
4 | -cp src
5 | -D source-map
--------------------------------------------------------------------------------
/features/display3D/Stage3DCamera/build.hxml:
--------------------------------------------------------------------------------
1 | -main App
2 | -js dist/app.js
3 | -cp node_modules/openfl/lib
4 | -cp src
5 | -D source-map
--------------------------------------------------------------------------------
/features/display3D/Stage3DMipmap/build.hxml:
--------------------------------------------------------------------------------
1 | -main App
2 | -js dist/app.js
3 | -cp node_modules/openfl/lib
4 | -cp src
5 | -D source-map
--------------------------------------------------------------------------------
/features/events/CreatingAMainLoop/build.hxml:
--------------------------------------------------------------------------------
1 | -main App
2 | -js dist/app.js
3 | -cp node_modules/openfl/lib
4 | -cp src
5 | -D source-map
--------------------------------------------------------------------------------
/features/events/CreatingCustomEvents/build.hxml:
--------------------------------------------------------------------------------
1 | -main App
2 | -js dist/app.js
3 | -cp node_modules/openfl/lib
4 | -cp src
5 | -D source-map
--------------------------------------------------------------------------------
/demos/BunnyMark/public/wabbit_alpha.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openfl/openfl-samples-haxe/HEAD/demos/BunnyMark/public/wabbit_alpha.png
--------------------------------------------------------------------------------
/demos/PiratePig/public/images/cursor.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openfl/openfl-samples-haxe/HEAD/demos/PiratePig/public/images/cursor.png
--------------------------------------------------------------------------------
/demos/PiratePig/public/sounds/theme.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openfl/openfl-samples-haxe/HEAD/demos/PiratePig/public/sounds/theme.mp3
--------------------------------------------------------------------------------
/demos/PiratePig/public/sounds/theme.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openfl/openfl-samples-haxe/HEAD/demos/PiratePig/public/sounds/theme.ogg
--------------------------------------------------------------------------------
/demos/PiratePig/public/sounds/theme.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openfl/openfl-samples-haxe/HEAD/demos/PiratePig/public/sounds/theme.wav
--------------------------------------------------------------------------------
/features/events/HandlingKeyboardEvents/build.hxml:
--------------------------------------------------------------------------------
1 | -main App
2 | -js dist/app.js
3 | -cp node_modules/openfl/lib
4 | -cp src
5 | -D source-map
--------------------------------------------------------------------------------
/demos/PiratePig/public/images/game_bear.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openfl/openfl-samples-haxe/HEAD/demos/PiratePig/public/images/game_bear.png
--------------------------------------------------------------------------------
/demos/PiratePig/public/images/game_carrot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openfl/openfl-samples-haxe/HEAD/demos/PiratePig/public/images/game_carrot.png
--------------------------------------------------------------------------------
/demos/PiratePig/public/images/game_lemon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openfl/openfl-samples-haxe/HEAD/demos/PiratePig/public/images/game_lemon.png
--------------------------------------------------------------------------------
/demos/PiratePig/public/images/game_panda.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openfl/openfl-samples-haxe/HEAD/demos/PiratePig/public/images/game_panda.png
--------------------------------------------------------------------------------
/demos/PiratePig/public/images/center_bottom.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openfl/openfl-samples-haxe/HEAD/demos/PiratePig/public/images/center_bottom.png
--------------------------------------------------------------------------------
/demos/PiratePig/public/images/game_bunny_02.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openfl/openfl-samples-haxe/HEAD/demos/PiratePig/public/images/game_bunny_02.png
--------------------------------------------------------------------------------
/demos/PiratePig/public/images/game_piratePig.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openfl/openfl-samples-haxe/HEAD/demos/PiratePig/public/images/game_piratePig.png
--------------------------------------------------------------------------------
/demos/PiratePig/build.hxml:
--------------------------------------------------------------------------------
1 | -main piratepig.Main
2 | -js dist/app.js
3 | -cp node_modules/openfl/lib
4 | -cp node_modules/actuate/lib
5 | -cp src
6 | -D source-map
--------------------------------------------------------------------------------
/demos/PiratePig/public/fonts/FreebooterUpdated.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openfl/openfl-samples-haxe/HEAD/demos/PiratePig/public/fonts/FreebooterUpdated.eot
--------------------------------------------------------------------------------
/demos/PiratePig/public/fonts/FreebooterUpdated.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openfl/openfl-samples-haxe/HEAD/demos/PiratePig/public/fonts/FreebooterUpdated.ttf
--------------------------------------------------------------------------------
/demos/PiratePig/public/images/background_tile.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openfl/openfl-samples-haxe/HEAD/demos/PiratePig/public/images/background_tile.png
--------------------------------------------------------------------------------
/demos/PiratePig/public/images/cursor_highlight.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openfl/openfl-samples-haxe/HEAD/demos/PiratePig/public/images/cursor_highlight.png
--------------------------------------------------------------------------------
/features/display/UsingSWFAssets/assets/layout.fla:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openfl/openfl-samples-haxe/HEAD/features/display/UsingSWFAssets/assets/layout.fla
--------------------------------------------------------------------------------
/features/display/UsingSWFAssets/assets/layout.swf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openfl/openfl-samples-haxe/HEAD/features/display/UsingSWFAssets/assets/layout.swf
--------------------------------------------------------------------------------
/features/display3D/Stage3DCamera/public/openfl.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openfl/openfl-samples-haxe/HEAD/features/display3D/Stage3DCamera/public/openfl.png
--------------------------------------------------------------------------------
/features/media/PlayingSound/build.hxml:
--------------------------------------------------------------------------------
1 | -main App
2 | -js dist/app.js
3 | -cp node_modules/openfl/lib
4 | -cp node_modules/actuate/lib
5 | -cp src
6 | -D source-map
--------------------------------------------------------------------------------
/features/media/PlayingVideo/build.hxml:
--------------------------------------------------------------------------------
1 | -main App
2 | -js dist/app.js
3 | -cp node_modules/openfl/lib
4 | -cp node_modules/actuate/lib
5 | -cp src
6 | -D source-map
--------------------------------------------------------------------------------
/demos/PiratePig/public/fonts/FreebooterUpdated.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openfl/openfl-samples-haxe/HEAD/demos/PiratePig/public/fonts/FreebooterUpdated.woff
--------------------------------------------------------------------------------
/features/display/AddingAnimation/build.hxml:
--------------------------------------------------------------------------------
1 | -main App
2 | -js dist/app.js
3 | -cp node_modules/openfl/lib
4 | -cp node_modules/actuate/lib
5 | -cp src
6 | -D source-map
--------------------------------------------------------------------------------
/features/display/DisplayingABitmap/public/openfl.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openfl/openfl-samples-haxe/HEAD/features/display/DisplayingABitmap/public/openfl.png
--------------------------------------------------------------------------------
/features/display3D/Stage3DMipmap/public/checkers.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openfl/openfl-samples-haxe/HEAD/features/display3D/Stage3DMipmap/public/checkers.png
--------------------------------------------------------------------------------
/features/media/PlayingSound/public/assets/stars.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openfl/openfl-samples-haxe/HEAD/features/media/PlayingSound/public/assets/stars.mp3
--------------------------------------------------------------------------------
/features/media/PlayingSound/public/assets/stars.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openfl/openfl-samples-haxe/HEAD/features/media/PlayingSound/public/assets/stars.ogg
--------------------------------------------------------------------------------
/features/media/PlayingVideo/public/assets/example.mp4:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openfl/openfl-samples-haxe/HEAD/features/media/PlayingVideo/public/assets/example.mp4
--------------------------------------------------------------------------------
/features/media/PlayingVideo/public/assets/example.ogv:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openfl/openfl-samples-haxe/HEAD/features/media/PlayingVideo/public/assets/example.ogv
--------------------------------------------------------------------------------
/features/events/HandlingMouseEvents/build.hxml:
--------------------------------------------------------------------------------
1 | -main App
2 | -js dist/app.js
3 | -cp node_modules/openfl/lib
4 | -cp node_modules/actuate/lib
5 | -cp src
6 | -D source-map
--------------------------------------------------------------------------------
/features/media/PlayingVideo/public/assets/example.webm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openfl/openfl-samples-haxe/HEAD/features/media/PlayingVideo/public/assets/example.webm
--------------------------------------------------------------------------------
/features/display/AddingAnimation/public/assets/openfl.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openfl/openfl-samples-haxe/HEAD/features/display/AddingAnimation/public/assets/openfl.png
--------------------------------------------------------------------------------
/features/display/CustomRendering/public/assets/openfl.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openfl/openfl-samples-haxe/HEAD/features/display/CustomRendering/public/assets/openfl.png
--------------------------------------------------------------------------------
/features/display/UsingBitmapData/public/assets/openfl.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openfl/openfl-samples-haxe/HEAD/features/display/UsingBitmapData/public/assets/openfl.png
--------------------------------------------------------------------------------
/features/text/AddingText/public/assets/KatamotzIkasi.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openfl/openfl-samples-haxe/HEAD/features/text/AddingText/public/assets/KatamotzIkasi.eot
--------------------------------------------------------------------------------
/features/text/AddingText/public/assets/KatamotzIkasi.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openfl/openfl-samples-haxe/HEAD/features/text/AddingText/public/assets/KatamotzIkasi.ttf
--------------------------------------------------------------------------------
/features/text/AddingText/public/assets/KatamotzIkasi.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openfl/openfl-samples-haxe/HEAD/features/text/AddingText/public/assets/KatamotzIkasi.woff
--------------------------------------------------------------------------------
/features/events/HandlingMouseEvents/public/assets/openfl.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openfl/openfl-samples-haxe/HEAD/features/events/HandlingMouseEvents/public/assets/openfl.png
--------------------------------------------------------------------------------
/features/events/HandlingKeyboardEvents/public/assets/openfl.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/openfl/openfl-samples-haxe/HEAD/features/events/HandlingKeyboardEvents/public/assets/openfl.png
--------------------------------------------------------------------------------
/demos/BunnyMark/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | OpenFL | BunnyMark
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/features/display/DisplayingABitmap/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | OpenFL | DisplayingABitmap
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/demos/BunnyMark/src/Bunny.hx:
--------------------------------------------------------------------------------
1 | import openfl.display.Tile;
2 |
3 | class Bunny extends Tile
4 | {
5 | public var speedX:Float = 0;
6 | public var speedY:Float = 0;
7 |
8 | public function new()
9 | {
10 | super(0);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/hxformat.json:
--------------------------------------------------------------------------------
1 | {
2 | "lineEnds": {
3 | "leftCurly": "both",
4 | "rightCurly": "both"
5 | },
6 | "sameLine": {
7 | "ifBody": "same",
8 | "ifElse": "next",
9 | "doWhile": "next",
10 | "tryBody": "next",
11 | "tryCatch": "next"
12 | }
13 | }
--------------------------------------------------------------------------------
/demos/NyanCat/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | OpenFL | NyanCat
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/demos/HerokuShaders/public/assets/heroku.vert:
--------------------------------------------------------------------------------
1 |
2 | attribute vec3 position;
3 | attribute vec2 surfacePosAttrib;
4 | varying vec2 surfacePosition;
5 |
6 | void main() {
7 |
8 | surfacePosition = surfacePosAttrib;
9 | gl_Position = vec4( position, 1.0 );
10 |
11 | }
--------------------------------------------------------------------------------
/demos/HerokuShaders/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | OpenFL | HerokuShaders
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/features/display/DrawingShapes/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | OpenFL | DrawingShapes
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/features/media/PlayingSound/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | OpenFL | PlayingSound
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/features/media/PlayingVideo/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | OpenFL | PlayingVideo
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/features/display/AddingAnimation/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | OpenFL | AddingAnimation
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/features/display/CustomRendering/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | OpenFL | CustomRendering
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/features/display/UsingBitmapData/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | OpenFL | UsingBitmapData
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/features/display3D/HelloTriangle/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | OpenFL | HelloTriangle
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/features/display3D/Stage3DCamera/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | OpenFL | Stage3DCamera
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/features/display3D/Stage3DMipmap/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | OpenFL | Stage3DMipmap
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/features/events/CreatingAMainLoop/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | OpenFL | CreatingAMainLoop
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/features/events/CreatingCustomEvents/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | OpenFL | CreatingCustomEvents
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/features/events/HandlingMouseEvents/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | OpenFL | HandlingMouseEvents
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/features/events/HandlingKeyboardEvents/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | OpenFL | HandlingKeyboardEvents
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/features/display/UsingSWFAssets/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | OpenFL | UsingSWFAssets
5 |
6 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/NOTICE.md:
--------------------------------------------------------------------------------
1 | Notices
2 | =======
3 |
4 | ### OpenFL Samples
5 | Copyright (c) 2013-2025 Joshua Granick and other OpenFL contributors
6 |
7 | Portions of other MIT-license projects are also used, including content that is
8 |
9 | Copyright (c) 2011-2012 Philippe Elsass
10 | Copyright (c) 2010 Iain Lobb
11 | Copyright (c) 2009-2015 Joshua Granick
12 |
13 | Portions of the song "Stars Come Out" by Brother Android (copyright 2010) is used
14 | under the CreativeCommons license: http://creativecommons.org/licenses/by-nc/3.0/
15 |
--------------------------------------------------------------------------------
/demos/NyanCat/src/App.hx:
--------------------------------------------------------------------------------
1 | import openfl.display.Sprite;
2 | import openfl.display.Stage;
3 | import openfl.utils.AssetLibrary;
4 | import js.Lib.require;
5 |
6 | class App extends Sprite
7 | {
8 | public function new()
9 | {
10 | super();
11 |
12 | AssetLibrary.loadFromFile(require("./assets/library.swf")).onComplete(function(library:AssetLibrary)
13 | {
14 | var cat = library.getMovieClip("NyanCatAnimation");
15 | addChild(cat);
16 | }).onError(function(e) trace(e));
17 | }
18 |
19 | static function main()
20 | {
21 | var stage = new Stage(550, 400, 0xFFFFFF, App);
22 | js.Browser.document.body.appendChild(stage.element);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/demos/BunnyMark/webpack.config.js:
--------------------------------------------------------------------------------
1 | const path = require ("path");
2 | const CopyWebpackPlugin = require("copy-webpack-plugin");
3 |
4 | module.exports = {
5 | entry: "./build.hxml",
6 | output: {
7 | path: path.resolve (__dirname, "dist"),
8 | filename: "app.js"
9 | },
10 | devtool: "source-map",
11 | resolve: {
12 | alias: {
13 | "openfl": path.resolve (__dirname, "node_modules/openfl/lib/openfl")
14 | }
15 | },
16 | module: {
17 | rules: [
18 | {
19 | test: /\.hxml$/,
20 | loader: 'haxe-loader',
21 | }
22 | ]
23 | },
24 | plugins: [
25 | new CopyWebpackPlugin({
26 | patterns: [
27 | "public"
28 | ]
29 | })
30 | ],
31 | performance: {
32 | hints: false
33 | }
34 | };
--------------------------------------------------------------------------------
/demos/HerokuShaders/public/assets/6286.frag:
--------------------------------------------------------------------------------
1 | //http://glsl.heroku.com/e#6286.0
2 |
3 |
4 | uniform float time;
5 | uniform vec2 mouse;
6 | uniform vec2 resolution;
7 | varying vec2 surfacePosition;
8 |
9 | void main( void ) {
10 | vec2 p = surfacePosition;
11 | float speed = 0.45;
12 | vec3 color = vec3(.4,.1,.8);
13 | vec2 loc = vec2(cos(time/1.6*speed)/1.9-cos(time/.8*speed)/3.8,
14 | sin(time/1.6*speed)/1.9-sin(time/.8*speed)/3.8
15 | );
16 | float depth;
17 | for(int i = 0; i < 100; i+=1){
18 | p = vec2(p.x*p.x-p.y*p.y,2.0*p.x*p.y)+loc;
19 | depth = float(i);
20 | if((p.x*p.x+p.y*p.y) >= 4.0) break;
21 | }
22 | gl_FragColor = vec4(clamp(color*depth*0.05, 0.0, 10.0)*mod(gl_FragCoord.y, 2.0), 1.0 );
23 | }
--------------------------------------------------------------------------------
/demos/HerokuShaders/webpack.config.js:
--------------------------------------------------------------------------------
1 | const path = require ("path");
2 | const CopyWebpackPlugin = require("copy-webpack-plugin");
3 |
4 | module.exports = {
5 | entry: "./build.hxml",
6 | output: {
7 | path: path.resolve (__dirname, "dist"),
8 | filename: "app.js"
9 | },
10 | devtool: "source-map",
11 | resolve: {
12 | alias: {
13 | "openfl": path.resolve (__dirname, "node_modules/openfl/lib/openfl")
14 | }
15 | },
16 | module: {
17 | rules: [
18 | {
19 | test: /\.hxml$/,
20 | loader: 'haxe-loader',
21 | }
22 | ]
23 | },
24 | plugins: [
25 | new CopyWebpackPlugin({
26 | patterns: [
27 | "public"
28 | ]
29 | })
30 | ],
31 | performance: {
32 | hints: false
33 | }
34 | };
--------------------------------------------------------------------------------
/features/text/AddingText/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | OpenFL | AddingText
5 |
6 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/features/text/AddingText/webpack.config.js:
--------------------------------------------------------------------------------
1 | const path = require ("path");
2 | const CopyWebpackPlugin = require("copy-webpack-plugin");
3 |
4 | module.exports = {
5 | entry: "./build.hxml",
6 | output: {
7 | path: path.resolve (__dirname, "dist"),
8 | filename: "app.js"
9 | },
10 | devtool: "source-map",
11 | resolve: {
12 | alias: {
13 | "openfl": path.resolve (__dirname, "node_modules/openfl/lib/openfl")
14 | }
15 | },
16 | module: {
17 | rules: [
18 | {
19 | test: /\.hxml$/,
20 | loader: 'haxe-loader',
21 | }
22 | ]
23 | },
24 | plugins: [
25 | new CopyWebpackPlugin({
26 | patterns: [
27 | "public"
28 | ]
29 | })
30 | ],
31 | performance: {
32 | hints: false
33 | }
34 | };
--------------------------------------------------------------------------------
/demos/HerokuShaders/public/assets/5733.frag:
--------------------------------------------------------------------------------
1 | //http://glsl.heroku.com/e#5733.0
2 |
3 |
4 | uniform float time;
5 | uniform vec2 mouse;
6 | uniform vec2 resolution;
7 | varying vec2 surfacePosition;
8 |
9 |
10 | void main( void ) {
11 | vec2 p = surfacePosition;
12 | float speed = 0.25;
13 | vec3 color = vec3(0.5,0.2,0.1);
14 | vec2 loc = vec2(cos(time/4.0*speed)/1.9-cos(time/2.0*speed)/3.8,
15 | sin(time/4.0*speed)/1.9-sin(time/2.0*speed)/3.8
16 | );
17 | float depth;
18 | for(int i = 0; i < 100; i+=1){
19 | p = vec2(p.x*p.x-p.y*p.y,2.0*p.y*p.x)+loc;
20 | depth = float(i);
21 | if((p.x*p.x-p.y*p.y) >= 25.0) break;
22 | }
23 | gl_FragColor = vec4(clamp(color*depth*0.9, 0.0, 2.0)*mod(gl_FragCoord.y, 2.0), 2.0 );
24 | }
--------------------------------------------------------------------------------
/features/display/CustomRendering/webpack.config.js:
--------------------------------------------------------------------------------
1 | const path = require ("path");
2 | const CopyWebpackPlugin = require("copy-webpack-plugin");
3 |
4 | module.exports = {
5 | entry: "./build.hxml",
6 | output: {
7 | path: path.resolve (__dirname, "dist"),
8 | filename: "app.js"
9 | },
10 | devtool: "source-map",
11 | resolve: {
12 | alias: {
13 | "openfl": path.resolve (__dirname, "node_modules/openfl/lib/openfl")
14 | }
15 | },
16 | module: {
17 | rules: [
18 | {
19 | test: /\.hxml$/,
20 | loader: 'haxe-loader',
21 | }
22 | ]
23 | },
24 | plugins: [
25 | new CopyWebpackPlugin({
26 | patterns: [
27 | "public"
28 | ]
29 | })
30 | ],
31 | performance: {
32 | hints: false
33 | }
34 | };
--------------------------------------------------------------------------------
/features/display/DrawingShapes/webpack.config.js:
--------------------------------------------------------------------------------
1 | const path = require ("path");
2 | const CopyWebpackPlugin = require("copy-webpack-plugin");
3 |
4 | module.exports = {
5 | entry: "./build.hxml",
6 | output: {
7 | path: path.resolve (__dirname, "dist"),
8 | filename: "app.js"
9 | },
10 | devtool: "source-map",
11 | resolve: {
12 | alias: {
13 | "openfl": path.resolve (__dirname, "node_modules/openfl/lib/openfl")
14 | }
15 | },
16 | module: {
17 | rules: [
18 | {
19 | test: /\.hxml$/,
20 | loader: 'haxe-loader',
21 | }
22 | ]
23 | },
24 | plugins: [
25 | new CopyWebpackPlugin({
26 | patterns: [
27 | "public"
28 | ]
29 | })
30 | ],
31 | performance: {
32 | hints: false
33 | }
34 | };
--------------------------------------------------------------------------------
/features/display/UsingBitmapData/webpack.config.js:
--------------------------------------------------------------------------------
1 | const path = require ("path");
2 | const CopyWebpackPlugin = require("copy-webpack-plugin");
3 |
4 | module.exports = {
5 | entry: "./build.hxml",
6 | output: {
7 | path: path.resolve (__dirname, "dist"),
8 | filename: "app.js"
9 | },
10 | devtool: "source-map",
11 | resolve: {
12 | alias: {
13 | "openfl": path.resolve (__dirname, "node_modules/openfl/lib/openfl")
14 | }
15 | },
16 | module: {
17 | rules: [
18 | {
19 | test: /\.hxml$/,
20 | loader: 'haxe-loader',
21 | }
22 | ]
23 | },
24 | plugins: [
25 | new CopyWebpackPlugin({
26 | patterns: [
27 | "public"
28 | ]
29 | })
30 | ],
31 | performance: {
32 | hints: false
33 | }
34 | };
--------------------------------------------------------------------------------
/features/display3D/HelloTriangle/webpack.config.js:
--------------------------------------------------------------------------------
1 | const path = require ("path");
2 | const CopyWebpackPlugin = require("copy-webpack-plugin");
3 |
4 | module.exports = {
5 | entry: "./build.hxml",
6 | output: {
7 | path: path.resolve (__dirname, "dist"),
8 | filename: "app.js"
9 | },
10 | devtool: "source-map",
11 | resolve: {
12 | alias: {
13 | "openfl": path.resolve (__dirname, "node_modules/openfl/lib/openfl")
14 | }
15 | },
16 | module: {
17 | rules: [
18 | {
19 | test: /\.hxml$/,
20 | loader: 'haxe-loader',
21 | }
22 | ]
23 | },
24 | plugins: [
25 | new CopyWebpackPlugin({
26 | patterns: [
27 | "public"
28 | ]
29 | })
30 | ],
31 | performance: {
32 | hints: false
33 | }
34 | };
--------------------------------------------------------------------------------
/features/display3D/Stage3DCamera/webpack.config.js:
--------------------------------------------------------------------------------
1 | const path = require ("path");
2 | const CopyWebpackPlugin = require("copy-webpack-plugin");
3 |
4 | module.exports = {
5 | entry: "./build.hxml",
6 | output: {
7 | path: path.resolve (__dirname, "dist"),
8 | filename: "app.js"
9 | },
10 | devtool: "source-map",
11 | resolve: {
12 | alias: {
13 | "openfl": path.resolve (__dirname, "node_modules/openfl/lib/openfl")
14 | }
15 | },
16 | module: {
17 | rules: [
18 | {
19 | test: /\.hxml$/,
20 | loader: 'haxe-loader',
21 | }
22 | ]
23 | },
24 | plugins: [
25 | new CopyWebpackPlugin({
26 | patterns: [
27 | "public"
28 | ]
29 | })
30 | ],
31 | performance: {
32 | hints: false
33 | }
34 | };
--------------------------------------------------------------------------------
/features/display3D/Stage3DMipmap/webpack.config.js:
--------------------------------------------------------------------------------
1 | const path = require ("path");
2 | const CopyWebpackPlugin = require("copy-webpack-plugin");
3 |
4 | module.exports = {
5 | entry: "./build.hxml",
6 | output: {
7 | path: path.resolve (__dirname, "dist"),
8 | filename: "app.js"
9 | },
10 | devtool: "source-map",
11 | resolve: {
12 | alias: {
13 | "openfl": path.resolve (__dirname, "node_modules/openfl/lib/openfl")
14 | }
15 | },
16 | module: {
17 | rules: [
18 | {
19 | test: /\.hxml$/,
20 | loader: 'haxe-loader',
21 | }
22 | ]
23 | },
24 | plugins: [
25 | new CopyWebpackPlugin({
26 | patterns: [
27 | "public"
28 | ]
29 | })
30 | ],
31 | performance: {
32 | hints: false
33 | }
34 | };
--------------------------------------------------------------------------------
/features/display/DisplayingABitmap/webpack.config.js:
--------------------------------------------------------------------------------
1 | const path = require ("path");
2 | const CopyWebpackPlugin = require("copy-webpack-plugin");
3 |
4 | module.exports = {
5 | entry: "./build.hxml",
6 | output: {
7 | path: path.resolve (__dirname, "dist"),
8 | filename: "app.js"
9 | },
10 | devtool: "source-map",
11 | resolve: {
12 | alias: {
13 | "openfl": path.resolve (__dirname, "node_modules/openfl/lib/openfl")
14 | }
15 | },
16 | module: {
17 | rules: [
18 | {
19 | test: /\.hxml$/,
20 | loader: 'haxe-loader',
21 | }
22 | ]
23 | },
24 | plugins: [
25 | new CopyWebpackPlugin({
26 | patterns: [
27 | "public"
28 | ]
29 | })
30 | ],
31 | performance: {
32 | hints: false
33 | }
34 | };
--------------------------------------------------------------------------------
/features/events/CreatingAMainLoop/webpack.config.js:
--------------------------------------------------------------------------------
1 | const path = require ("path");
2 | const CopyWebpackPlugin = require("copy-webpack-plugin");
3 |
4 | module.exports = {
5 | entry: "./build.hxml",
6 | output: {
7 | path: path.resolve (__dirname, "dist"),
8 | filename: "app.js"
9 | },
10 | devtool: "source-map",
11 | resolve: {
12 | alias: {
13 | "openfl": path.resolve (__dirname, "node_modules/openfl/lib/openfl")
14 | }
15 | },
16 | module: {
17 | rules: [
18 | {
19 | test: /\.hxml$/,
20 | loader: 'haxe-loader',
21 | }
22 | ]
23 | },
24 | plugins: [
25 | new CopyWebpackPlugin({
26 | patterns: [
27 | "public"
28 | ]
29 | })
30 | ],
31 | performance: {
32 | hints: false
33 | }
34 | };
--------------------------------------------------------------------------------
/features/events/CreatingCustomEvents/webpack.config.js:
--------------------------------------------------------------------------------
1 | const path = require ("path");
2 | const CopyWebpackPlugin = require("copy-webpack-plugin");
3 |
4 | module.exports = {
5 | entry: "./build.hxml",
6 | output: {
7 | path: path.resolve (__dirname, "dist"),
8 | filename: "app.js"
9 | },
10 | devtool: "source-map",
11 | resolve: {
12 | alias: {
13 | "openfl": path.resolve (__dirname, "node_modules/openfl/lib/openfl")
14 | }
15 | },
16 | module: {
17 | rules: [
18 | {
19 | test: /\.hxml$/,
20 | loader: 'haxe-loader',
21 | }
22 | ]
23 | },
24 | plugins: [
25 | new CopyWebpackPlugin({
26 | patterns: [
27 | "public"
28 | ]
29 | })
30 | ],
31 | performance: {
32 | hints: false
33 | }
34 | };
--------------------------------------------------------------------------------
/features/events/HandlingKeyboardEvents/webpack.config.js:
--------------------------------------------------------------------------------
1 | const path = require ("path");
2 | const CopyWebpackPlugin = require("copy-webpack-plugin");
3 |
4 | module.exports = {
5 | entry: "./build.hxml",
6 | output: {
7 | path: path.resolve (__dirname, "dist"),
8 | filename: "app.js"
9 | },
10 | devtool: "source-map",
11 | resolve: {
12 | alias: {
13 | "openfl": path.resolve (__dirname, "node_modules/openfl/lib/openfl")
14 | }
15 | },
16 | module: {
17 | rules: [
18 | {
19 | test: /\.hxml$/,
20 | loader: 'haxe-loader',
21 | }
22 | ]
23 | },
24 | plugins: [
25 | new CopyWebpackPlugin({
26 | patterns: [
27 | "public"
28 | ]
29 | })
30 | ],
31 | performance: {
32 | hints: false
33 | }
34 | };
--------------------------------------------------------------------------------
/demos/HerokuShaders/public/assets/6284.1.frag:
--------------------------------------------------------------------------------
1 | //http://glsl.heroku.com/e#6284.1
2 |
3 |
4 | uniform float time;
5 | uniform vec2 mouse;
6 | uniform vec2 resolution;
7 |
8 | void main( void ) {
9 |
10 | vec2 position = ( gl_FragCoord.xy / resolution.xy ) + mouse / 1.0;
11 |
12 | float color = 0.0;
13 | color += sin( position.x * cos( time / 15.0 ) * 80.0 ) + cos( position.y * cos( time / 15.0 ) * 10.0 );
14 | color += sin( position.y * sin( time / 10.0 ) * 40.0 ) + cos( position.x * sin( time / 25.0 ) * 40.0 );
15 | color += sin( position.x * sin( time / 5.0 ) * 10.0 ) + sin( position.y * sin( time / 35.0 ) * 80.0 );
16 | color *= sin( time / 10.0 ) * 0.5;
17 |
18 | gl_FragColor = vec4( vec3( color, color * 0.1, sin( color + time / 9.0 ) * 0.75 ), 1.0 );
19 |
20 | }
--------------------------------------------------------------------------------
/demos/NyanCat/webpack.config.js:
--------------------------------------------------------------------------------
1 | const path = require ("path");
2 | const CopyWebpackPlugin = require("copy-webpack-plugin");
3 |
4 | module.exports = {
5 | entry: "./build.hxml",
6 | output: {
7 | path: path.resolve (__dirname, "dist"),
8 | filename: "app.js"
9 | },
10 | devtool: "source-map",
11 | resolve: {
12 | alias: {
13 | "openfl": path.resolve (__dirname, "node_modules/openfl/lib/openfl")
14 | }
15 | },
16 | module: {
17 | rules: [
18 | {
19 | test: /\.hxml$/,
20 | loader: 'haxe-loader',
21 | },
22 | {
23 | test: /\.swf$/,
24 | loader: 'swf-loader'
25 | }
26 | ]
27 | },
28 | plugins: [
29 | new CopyWebpackPlugin({
30 | patterns: [
31 | "public"
32 | ]
33 | })
34 | ],
35 | performance: {
36 | hints: false
37 | }
38 | };
--------------------------------------------------------------------------------
/demos/PiratePig/webpack.config.js:
--------------------------------------------------------------------------------
1 | const path = require ("path");
2 | const CopyWebpackPlugin = require("copy-webpack-plugin");
3 |
4 | module.exports = {
5 | entry: "./build.hxml",
6 | output: {
7 | path: path.resolve (__dirname, "dist"),
8 | filename: "app.js"
9 | },
10 | devtool: "source-map",
11 | resolve: {
12 | alias: {
13 | "openfl": path.resolve (__dirname, "node_modules/openfl/lib/openfl"),
14 | "motion": path.resolve (__dirname, "node_modules/actuate/lib/motion")
15 | }
16 | },
17 | module: {
18 | rules: [
19 | {
20 | test: /\.hxml$/,
21 | loader: 'haxe-loader',
22 | }
23 | ]
24 | },
25 | plugins: [
26 | new CopyWebpackPlugin({
27 | patterns: [
28 | "public"
29 | ]
30 | })
31 | ],
32 | performance: {
33 | hints: false
34 | }
35 | };
--------------------------------------------------------------------------------
/features/display/UsingSWFAssets/webpack.config.js:
--------------------------------------------------------------------------------
1 | const path = require ("path");
2 | const CopyWebpackPlugin = require("copy-webpack-plugin");
3 |
4 | module.exports = {
5 | entry: "./build.hxml",
6 | output: {
7 | path: path.resolve (__dirname, "dist"),
8 | filename: "app.js"
9 | },
10 | devtool: "source-map",
11 | resolve: {
12 | alias: {
13 | "openfl": path.resolve (__dirname, "node_modules/openfl/lib/openfl")
14 | }
15 | },
16 | module: {
17 | rules: [
18 | {
19 | test: /\.hxml$/,
20 | loader: 'haxe-loader',
21 | },
22 | {
23 | test: /\.swf$/,
24 | loader: 'swf-loader'
25 | }
26 | ]
27 | },
28 | plugins: [
29 | new CopyWebpackPlugin({
30 | patterns: [
31 | "public"
32 | ]
33 | })
34 | ],
35 | performance: {
36 | hints: false
37 | }
38 | };
--------------------------------------------------------------------------------
/features/media/PlayingSound/webpack.config.js:
--------------------------------------------------------------------------------
1 | const path = require ("path");
2 | const CopyWebpackPlugin = require("copy-webpack-plugin");
3 |
4 | module.exports = {
5 | entry: "./build.hxml",
6 | output: {
7 | path: path.resolve (__dirname, "dist"),
8 | filename: "app.js"
9 | },
10 | devtool: "source-map",
11 | resolve: {
12 | alias: {
13 | "openfl": path.resolve (__dirname, "node_modules/openfl/lib/openfl"),
14 | "motion": path.resolve (__dirname, "node_modules/actuate/lib/motion")
15 | }
16 | },
17 | module: {
18 | rules: [
19 | {
20 | test: /\.hxml$/,
21 | loader: 'haxe-loader',
22 | }
23 | ]
24 | },
25 | plugins: [
26 | new CopyWebpackPlugin({
27 | patterns: [
28 | "public"
29 | ]
30 | })
31 | ],
32 | performance: {
33 | hints: false
34 | }
35 | };
--------------------------------------------------------------------------------
/features/media/PlayingVideo/webpack.config.js:
--------------------------------------------------------------------------------
1 | const path = require ("path");
2 | const CopyWebpackPlugin = require("copy-webpack-plugin");
3 |
4 | module.exports = {
5 | entry: "./build.hxml",
6 | output: {
7 | path: path.resolve (__dirname, "dist"),
8 | filename: "app.js"
9 | },
10 | devtool: "source-map",
11 | resolve: {
12 | alias: {
13 | "openfl": path.resolve (__dirname, "node_modules/openfl/lib/openfl"),
14 | "motion": path.resolve (__dirname, "node_modules/actuate/lib/motion")
15 | }
16 | },
17 | module: {
18 | rules: [
19 | {
20 | test: /\.hxml$/,
21 | loader: 'haxe-loader',
22 | }
23 | ]
24 | },
25 | plugins: [
26 | new CopyWebpackPlugin({
27 | patterns: [
28 | "public"
29 | ]
30 | })
31 | ],
32 | performance: {
33 | hints: false
34 | }
35 | };
--------------------------------------------------------------------------------
/features/display/AddingAnimation/webpack.config.js:
--------------------------------------------------------------------------------
1 | const path = require ("path");
2 | const CopyWebpackPlugin = require("copy-webpack-plugin");
3 |
4 | module.exports = {
5 | entry: "./build.hxml",
6 | output: {
7 | path: path.resolve (__dirname, "dist"),
8 | filename: "app.js"
9 | },
10 | devtool: "source-map",
11 | resolve: {
12 | alias: {
13 | "openfl": path.resolve (__dirname, "node_modules/openfl/lib/openfl"),
14 | "motion": path.resolve (__dirname, "node_modules/actuate/lib/motion")
15 | }
16 | },
17 | module: {
18 | rules: [
19 | {
20 | test: /\.hxml$/,
21 | loader: 'haxe-loader',
22 | }
23 | ]
24 | },
25 | plugins: [
26 | new CopyWebpackPlugin({
27 | patterns: [
28 | "public"
29 | ]
30 | })
31 | ],
32 | performance: {
33 | hints: false
34 | }
35 | };
--------------------------------------------------------------------------------
/demos/BunnyMark/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "org.openfl.samples.bunnymark-haxe",
3 | "version": "1.0.0",
4 | "private": true,
5 | "devDependencies": {
6 | "copy-webpack-plugin": "^13.0.0",
7 | "haxe": "^5.2.1",
8 | "haxe-loader": "^0.10.0",
9 | "openfl": "^9.4.1",
10 | "webpack": "^5.99.8",
11 | "webpack-cli": "^6.0.1",
12 | "webpack-dev-server": "^5.2.1"
13 | },
14 | "haxeDependencies": {
15 | "haxe": "4.0.5"
16 | },
17 | "scripts": {
18 | "build": "npm run build:prod",
19 | "build:dev": "webpack --mode=development",
20 | "build:prod": "webpack --mode=production",
21 | "start": "npm run start:dev",
22 | "start:dev": "webpack serve --mode=development",
23 | "start:prod": "webpack serve --mode=production"
24 | },
25 | "dependencies": {}
26 | }
27 |
--------------------------------------------------------------------------------
/demos/NyanCat/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "org.openfl.samples.nyancat-haxe",
3 | "version": "1.0.0",
4 | "private": true,
5 | "devDependencies": {
6 | "copy-webpack-plugin": "^13.0.0",
7 | "haxe": "^5.2.1",
8 | "haxe-loader": "^0.10.0",
9 | "openfl": "^9.4.1",
10 | "swf-loader": "^1.0.2",
11 | "webpack": "^5.99.8",
12 | "webpack-cli": "^6.0.1",
13 | "webpack-dev-server": "^5.2.1"
14 | },
15 | "haxeDependencies": {
16 | "haxe": "4.0.5"
17 | },
18 | "scripts": {
19 | "build": "npm run build:prod",
20 | "build:dev": "webpack --mode=development",
21 | "build:prod": "webpack --mode=production",
22 | "start": "npm run start:dev",
23 | "start:dev": "webpack serve --mode=development",
24 | "start:prod": "webpack serve --mode=production"
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/features/events/HandlingMouseEvents/webpack.config.js:
--------------------------------------------------------------------------------
1 | const path = require ("path");
2 | const CopyWebpackPlugin = require("copy-webpack-plugin");
3 |
4 | module.exports = {
5 | entry: "./build.hxml",
6 | output: {
7 | path: path.resolve (__dirname, "dist"),
8 | filename: "app.js"
9 | },
10 | devtool: "source-map",
11 | resolve: {
12 | alias: {
13 | "openfl": path.resolve (__dirname, "node_modules/openfl/lib/openfl"),
14 | "motion": path.resolve (__dirname, "node_modules/actuate/lib/motion")
15 | }
16 | },
17 | module: {
18 | rules: [
19 | {
20 | test: /\.hxml$/,
21 | loader: 'haxe-loader',
22 | }
23 | ]
24 | },
25 | plugins: [
26 | new CopyWebpackPlugin({
27 | patterns: [
28 | "public"
29 | ]
30 | })
31 | ],
32 | performance: {
33 | hints: false
34 | }
35 | };
--------------------------------------------------------------------------------
/demos/PiratePig/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "org.openfl.samples.piratepig-haxe",
3 | "version": "1.0.0",
4 | "private": true,
5 | "devDependencies": {
6 | "actuate": "^1.9.0",
7 | "copy-webpack-plugin": "^13.0.0",
8 | "haxe": "^5.2.1",
9 | "haxe-loader": "^0.10.0",
10 | "openfl": "^9.4.1",
11 | "webpack": "^5.99.8",
12 | "webpack-cli": "^6.0.1",
13 | "webpack-dev-server": "^5.2.1"
14 | },
15 | "haxeDependencies": {
16 | "haxe": "4.0.5"
17 | },
18 | "scripts": {
19 | "build": "npm run build:prod",
20 | "build:dev": "webpack --mode=development",
21 | "build:prod": "webpack --mode=production",
22 | "start": "npm run start:dev",
23 | "start:dev": "webpack serve --mode=development",
24 | "start:prod": "webpack serve --mode=production"
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/features/events/CreatingCustomEvents/src/CustomEvent.hx:
--------------------------------------------------------------------------------
1 | import openfl.events.Event;
2 |
3 | class CustomEvent extends Event
4 | {
5 | public static var TYPED_CUSTOM_EVENT = "typedCustomEvent";
6 |
7 | public var customData:Int;
8 |
9 | public function new(type:String, customData:Int, bubbles:Bool = false, cancelable:Bool = false)
10 | {
11 | this.customData = customData;
12 |
13 | super(type, bubbles, cancelable);
14 | }
15 |
16 | public override function clone():CustomEvent
17 | {
18 | return new CustomEvent(type, customData, bubbles, cancelable);
19 | }
20 |
21 | public override function toString():String
22 | {
23 | return "[CustomEvent type=\"" + type + "\" bubbles=" + bubbles + " cancelable=" + cancelable + " eventPhase=" + eventPhase + " customData="
24 | + customData + "]";
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](LICENSE.md) [](https://github.com/openfl/openfl-samples-haxe/actions)
2 |
3 | OpenFL npm Samples (Haxe)
4 | =========================
5 |
6 | These samples demonstrate how to use the [OpenFL npm module](https://www.openfl.org/learn/npm/getting-started/) with Haxe.
7 |
8 | ## Get Started
9 |
10 | ### Clone the repository
11 |
12 | ```bash
13 | git clone https://github.com/openfl/openfl-samples-haxe
14 | ```
15 |
16 | ### Choose a sample
17 |
18 | ```bash
19 | cd openfl-samples-haxe/features/display/DisplayingABitmap
20 | ```
21 |
22 | ### Install and start
23 |
24 | ```bash
25 | npm install
26 | npm start
27 | ```
28 |
--------------------------------------------------------------------------------
/demos/HerokuShaders/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "org.openfl.samples.herokushaders-haxe",
3 | "version": "1.0.0",
4 | "private": true,
5 | "devDependencies": {
6 | "copy-webpack-plugin": "^13.0.0",
7 | "haxe": "^5.2.1",
8 | "haxe-loader": "^0.10.0",
9 | "openfl": "^9.4.1",
10 | "webpack": "^5.99.8",
11 | "webpack-cli": "^6.0.1",
12 | "webpack-dev-server": "^5.2.1"
13 | },
14 | "haxeDependencies": {
15 | "haxe": "4.0.5"
16 | },
17 | "scripts": {
18 | "build": "npm run build:prod",
19 | "build:dev": "webpack --mode=development",
20 | "build:prod": "webpack --mode=production",
21 | "start": "npm run start:dev",
22 | "start:dev": "webpack serve --mode=development",
23 | "start:prod": "webpack serve --mode=production"
24 | },
25 | "dependencies": {}
26 | }
27 |
--------------------------------------------------------------------------------
/features/text/AddingText/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "org.openfl.samples.addingtext-haxe",
3 | "version": "1.0.0",
4 | "private": true,
5 | "devDependencies": {
6 | "copy-webpack-plugin": "^13.0.0",
7 | "haxe": "^5.2.1",
8 | "haxe-loader": "^0.10.0",
9 | "openfl": "^9.4.1",
10 | "webpack": "^5.99.8",
11 | "webpack-cli": "^6.0.1",
12 | "webpack-dev-server": "^5.2.1"
13 | },
14 | "haxeDependencies": {
15 | "haxe": "4.0.5"
16 | },
17 | "scripts": {
18 | "build": "npm run build:prod",
19 | "build:dev": "webpack --mode=development",
20 | "build:prod": "webpack --mode=production",
21 | "start": "npm run start:dev",
22 | "start:dev": "webpack serve --mode=development",
23 | "start:prod": "webpack serve --mode=production"
24 | },
25 | "dependencies": {}
26 | }
27 |
--------------------------------------------------------------------------------
/features/display/DrawingShapes/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "org.openfl.samples.drawingshapes-haxe",
3 | "version": "1.0.0",
4 | "private": true,
5 | "devDependencies": {
6 | "copy-webpack-plugin": "^13.0.0",
7 | "haxe": "^5.2.1",
8 | "haxe-loader": "^0.10.0",
9 | "openfl": "^9.4.1",
10 | "webpack": "^5.99.8",
11 | "webpack-cli": "^6.0.1",
12 | "webpack-dev-server": "^5.2.1"
13 | },
14 | "haxeDependencies": {
15 | "haxe": "4.0.5"
16 | },
17 | "scripts": {
18 | "build": "npm run build:prod",
19 | "build:dev": "webpack --mode=development",
20 | "build:prod": "webpack --mode=production",
21 | "start": "npm run start:dev",
22 | "start:dev": "webpack serve --mode=development",
23 | "start:prod": "webpack serve --mode=production"
24 | },
25 | "dependencies": {}
26 | }
27 |
--------------------------------------------------------------------------------
/features/display3D/HelloTriangle/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "org.openfl.samples.hellotriangle-haxe",
3 | "version": "1.0.0",
4 | "private": true,
5 | "devDependencies": {
6 | "copy-webpack-plugin": "^13.0.0",
7 | "haxe": "^5.2.1",
8 | "haxe-loader": "^0.10.0",
9 | "openfl": "^9.4.1",
10 | "webpack": "^5.99.8",
11 | "webpack-cli": "^6.0.1",
12 | "webpack-dev-server": "^5.2.1"
13 | },
14 | "haxeDependencies": {
15 | "haxe": "4.0.5"
16 | },
17 | "scripts": {
18 | "build": "npm run build:prod",
19 | "build:dev": "webpack --mode=development",
20 | "build:prod": "webpack --mode=production",
21 | "start": "npm run start:dev",
22 | "start:dev": "webpack serve --mode=development",
23 | "start:prod": "webpack serve --mode=production"
24 | },
25 | "dependencies": {}
26 | }
27 |
--------------------------------------------------------------------------------
/features/display3D/Stage3DCamera/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "org.openfl.samples.stage3dcamera-haxe",
3 | "version": "1.0.0",
4 | "private": true,
5 | "devDependencies": {
6 | "copy-webpack-plugin": "^13.0.0",
7 | "haxe": "^5.2.1",
8 | "haxe-loader": "^0.10.0",
9 | "openfl": "^9.4.1",
10 | "webpack": "^5.99.8",
11 | "webpack-cli": "^6.0.1",
12 | "webpack-dev-server": "^5.2.1"
13 | },
14 | "haxeDependencies": {
15 | "haxe": "4.0.5"
16 | },
17 | "scripts": {
18 | "build": "npm run build:prod",
19 | "build:dev": "webpack --mode=development",
20 | "build:prod": "webpack --mode=production",
21 | "start": "npm run start:dev",
22 | "start:dev": "webpack serve --mode=development",
23 | "start:prod": "webpack serve --mode=production"
24 | },
25 | "dependencies": {}
26 | }
27 |
--------------------------------------------------------------------------------
/features/display3D/Stage3DMipmap/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "org.openfl.samples.stage3dmipmap-haxe",
3 | "version": "1.0.0",
4 | "private": true,
5 | "devDependencies": {
6 | "copy-webpack-plugin": "^13.0.0",
7 | "haxe": "^5.2.1",
8 | "haxe-loader": "^0.10.0",
9 | "openfl": "^9.4.1",
10 | "webpack": "^5.99.8",
11 | "webpack-cli": "^6.0.1",
12 | "webpack-dev-server": "^5.2.1"
13 | },
14 | "haxeDependencies": {
15 | "haxe": "4.0.5"
16 | },
17 | "scripts": {
18 | "build": "npm run build:prod",
19 | "build:dev": "webpack --mode=development",
20 | "build:prod": "webpack --mode=production",
21 | "start": "npm run start:dev",
22 | "start:dev": "webpack serve --mode=development",
23 | "start:prod": "webpack serve --mode=production"
24 | },
25 | "dependencies": {}
26 | }
27 |
--------------------------------------------------------------------------------
/features/display/CustomRendering/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "org.openfl.samples.customrendering-haxe",
3 | "version": "1.0.0",
4 | "private": true,
5 | "devDependencies": {
6 | "copy-webpack-plugin": "^13.0.0",
7 | "haxe": "^5.2.1",
8 | "haxe-loader": "^0.10.0",
9 | "openfl": "^9.4.1",
10 | "webpack": "^5.99.8",
11 | "webpack-cli": "^6.0.1",
12 | "webpack-dev-server": "^5.2.1"
13 | },
14 | "haxeDependencies": {
15 | "haxe": "4.0.5"
16 | },
17 | "scripts": {
18 | "build": "npm run build:prod",
19 | "build:dev": "webpack --mode=development",
20 | "build:prod": "webpack --mode=production",
21 | "start": "npm run start:dev",
22 | "start:dev": "webpack serve --mode=development",
23 | "start:prod": "webpack serve --mode=production"
24 | },
25 | "dependencies": {}
26 | }
27 |
--------------------------------------------------------------------------------
/features/display/DisplayingABitmap/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "org.openfl.samples.displayingabitmap-haxe",
3 | "version": "1.0.0",
4 | "private": true,
5 | "devDependencies": {
6 | "copy-webpack-plugin": "^13.0.0",
7 | "haxe": "^5.2.1",
8 | "haxe-loader": "^0.10.0",
9 | "openfl": "^9.4.1",
10 | "webpack": "^5.99.8",
11 | "webpack-cli": "^6.0.1",
12 | "webpack-dev-server": "^5.2.1"
13 | },
14 | "haxeDependencies": {
15 | "haxe": "4.0.5"
16 | },
17 | "scripts": {
18 | "build": "npm run build:prod",
19 | "build:dev": "webpack --mode=development",
20 | "build:prod": "webpack --mode=production",
21 | "start": "npm run start:dev",
22 | "start:dev": "webpack serve --mode=development",
23 | "start:prod": "webpack serve --mode=production"
24 | },
25 | "dependencies": {}
26 | }
27 |
--------------------------------------------------------------------------------
/features/display/UsingBitmapData/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "org.openfl.samples.usingbitmapdata-haxe",
3 | "version": "1.0.0",
4 | "private": true,
5 | "devDependencies": {
6 | "copy-webpack-plugin": "^13.0.0",
7 | "haxe": "^5.2.1",
8 | "haxe-loader": "^0.10.0",
9 | "openfl": "^9.4.1",
10 | "webpack": "^5.99.8",
11 | "webpack-cli": "^6.0.1",
12 | "webpack-dev-server": "^5.2.1"
13 | },
14 | "haxeDependencies": {
15 | "haxe": "4.0.5"
16 | },
17 | "scripts": {
18 | "build": "npm run build:prod",
19 | "build:dev": "webpack --mode=development",
20 | "build:prod": "webpack --mode=production",
21 | "start": "npm run start:dev",
22 | "start:dev": "webpack serve --mode=development",
23 | "start:prod": "webpack serve --mode=production"
24 | },
25 | "dependencies": {}
26 | }
27 |
--------------------------------------------------------------------------------
/features/events/CreatingAMainLoop/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "org.openfl.samples.creatingamainloop-haxe",
3 | "version": "1.0.0",
4 | "private": true,
5 | "devDependencies": {
6 | "copy-webpack-plugin": "^13.0.0",
7 | "haxe": "^5.2.1",
8 | "haxe-loader": "^0.10.0",
9 | "openfl": "^9.4.1",
10 | "webpack": "^5.99.8",
11 | "webpack-cli": "^6.0.1",
12 | "webpack-dev-server": "^5.2.1"
13 | },
14 | "haxeDependencies": {
15 | "haxe": "4.0.5"
16 | },
17 | "scripts": {
18 | "build": "npm run build:prod",
19 | "build:dev": "webpack --mode=development",
20 | "build:prod": "webpack --mode=production",
21 | "start": "npm run start:dev",
22 | "start:dev": "webpack serve --mode=development",
23 | "start:prod": "webpack serve --mode=production"
24 | },
25 | "dependencies": {}
26 | }
27 |
--------------------------------------------------------------------------------
/features/events/CreatingCustomEvents/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "org.openfl.samples.creatingcustomevents-haxe",
3 | "version": "1.0.0",
4 | "private": true,
5 | "devDependencies": {
6 | "copy-webpack-plugin": "^13.0.0",
7 | "haxe": "^5.2.1",
8 | "haxe-loader": "^0.10.0",
9 | "openfl": "^9.4.1",
10 | "webpack": "^5.99.8",
11 | "webpack-cli": "^6.0.1",
12 | "webpack-dev-server": "^5.2.1"
13 | },
14 | "haxeDependencies": {
15 | "haxe": "4.0.5"
16 | },
17 | "scripts": {
18 | "build": "npm run build:prod",
19 | "build:dev": "webpack --mode=development",
20 | "build:prod": "webpack --mode=production",
21 | "start": "npm run start:dev",
22 | "start:dev": "webpack serve --mode=development",
23 | "start:prod": "webpack serve --mode=production"
24 | },
25 | "dependencies": {}
26 | }
27 |
--------------------------------------------------------------------------------
/features/events/HandlingKeyboardEvents/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "org.openfl.samples.handlingkeyboardevents-haxe",
3 | "version": "1.0.0",
4 | "private": true,
5 | "devDependencies": {
6 | "copy-webpack-plugin": "^13.0.0",
7 | "haxe": "^5.2.1",
8 | "haxe-loader": "^0.10.0",
9 | "openfl": "^9.4.1",
10 | "webpack": "^5.99.8",
11 | "webpack-cli": "^6.0.1",
12 | "webpack-dev-server": "^5.2.1"
13 | },
14 | "haxeDependencies": {
15 | "haxe": "4.0.5"
16 | },
17 | "scripts": {
18 | "build": "npm run build:prod",
19 | "build:dev": "webpack --mode=development",
20 | "build:prod": "webpack --mode=production",
21 | "start": "npm run start:dev",
22 | "start:dev": "webpack serve --mode=development",
23 | "start:prod": "webpack serve --mode=production"
24 | },
25 | "dependencies": {}
26 | }
27 |
--------------------------------------------------------------------------------
/demos/HerokuShaders/public/assets/5398.8.frag:
--------------------------------------------------------------------------------
1 | //http://glsl.heroku.com/e#5398.8
2 |
3 |
4 | uniform float time;
5 | uniform vec2 mouse;
6 | uniform vec2 resolution;
7 |
8 | void main( void ) {
9 |
10 | float scale = resolution.y / 100.0;
11 | float ring = 50.0;
12 | float radius = resolution.x*1.0;
13 | float gap = scale*.5;
14 | vec2 pos = gl_FragCoord.xy - resolution.xy*.5;
15 |
16 | float d = length(pos);
17 |
18 | // Create the wiggle
19 | d += (sin(pos.y*0.25/scale+time)*sin(pos.x*0.25/scale+time*.5))*scale*2.0;
20 |
21 | // Compute the distance to the closest ring
22 | float v = mod(d + radius/(ring*2.0), radius/ring);
23 | v = abs(v - radius/(ring*2.0));
24 |
25 | v = clamp(v-gap, 0.0, 1.0);
26 |
27 | d /= radius;
28 | vec3 m = fract((d-1.0)*vec3(ring*-.5, -ring, ring*.25)*0.5);
29 |
30 | gl_FragColor = vec4( m*v, 1.0 );
31 | }
--------------------------------------------------------------------------------
/demos/HerokuShaders/public/assets/6288.1.frag:
--------------------------------------------------------------------------------
1 | //http://glsl.heroku.com/e#6288.1
2 |
3 |
4 | uniform float time;
5 | uniform vec2 mouse;
6 | uniform vec2 resolution;
7 |
8 |
9 | void main( void )
10 | {
11 |
12 | vec2 uPos = ( gl_FragCoord.xy / resolution.xy );//normalize wrt y axis
13 | //suPos -= vec2((resolution.x/resolution.y)/2.0, 0.0);//shift origin to center
14 |
15 | uPos.x -= 1.0;
16 | uPos.y -= 0.5;
17 |
18 | vec3 color = vec3(0.0);
19 | float vertColor = 0.0;
20 | for( float i = 0.0; i < 15.0; ++i )
21 | {
22 | float t = time * (0.9);
23 |
24 | uPos.y += sin( uPos.x*i + t+i/2.0 ) * 0.1;
25 | float fTemp = abs(1.0 / uPos.y / 100.0);
26 | vertColor += fTemp;
27 | color += vec3( fTemp*(10.0-i)/10.0, fTemp*i/10.0, pow(fTemp,1.5)*1.5 );
28 | }
29 |
30 | vec4 color_final = vec4(color, 1.0);
31 | gl_FragColor = color_final;
32 | }
--------------------------------------------------------------------------------
/features/media/PlayingSound/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "org.openfl.samples.playingsound-haxe",
3 | "version": "1.0.0",
4 | "private": true,
5 | "devDependencies": {
6 | "actuate": "^1.9.0",
7 | "copy-webpack-plugin": "^13.0.0",
8 | "haxe": "^5.2.1",
9 | "haxe-loader": "^0.10.0",
10 | "openfl": "^9.4.1",
11 | "webpack": "^5.99.8",
12 | "webpack-cli": "^6.0.1",
13 | "webpack-dev-server": "^5.2.1"
14 | },
15 | "haxeDependencies": {
16 | "haxe": "4.0.5"
17 | },
18 | "scripts": {
19 | "build": "npm run build:prod",
20 | "build:dev": "webpack --mode=development",
21 | "build:prod": "webpack --mode=production",
22 | "start": "npm run start:dev",
23 | "start:dev": "webpack serve --mode=development",
24 | "start:prod": "webpack serve --mode=production"
25 | },
26 | "dependencies": {}
27 | }
28 |
--------------------------------------------------------------------------------
/features/media/PlayingVideo/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "org.openfl.samples.playingvideo-haxe",
3 | "version": "1.0.0",
4 | "private": true,
5 | "devDependencies": {
6 | "actuate": "^1.9.0",
7 | "copy-webpack-plugin": "^13.0.0",
8 | "haxe": "^5.2.1",
9 | "haxe-loader": "^0.10.0",
10 | "openfl": "^9.4.1",
11 | "webpack": "^5.99.8",
12 | "webpack-cli": "^6.0.1",
13 | "webpack-dev-server": "^5.2.1"
14 | },
15 | "haxeDependencies": {
16 | "haxe": "4.0.5"
17 | },
18 | "scripts": {
19 | "build": "npm run build:prod",
20 | "build:dev": "webpack --mode=development",
21 | "build:prod": "webpack --mode=production",
22 | "start": "npm run start:dev",
23 | "start:dev": "webpack serve --mode=development",
24 | "start:prod": "webpack serve --mode=production"
25 | },
26 | "dependencies": {}
27 | }
28 |
--------------------------------------------------------------------------------
/features/display/AddingAnimation/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "org.openfl.samples.addinganimation-haxe",
3 | "version": "1.0.0",
4 | "private": true,
5 | "devDependencies": {
6 | "actuate": "^1.9.0",
7 | "copy-webpack-plugin": "^13.0.0",
8 | "haxe": "^5.2.1",
9 | "haxe-loader": "^0.10.0",
10 | "openfl": "^9.4.1",
11 | "webpack": "^5.99.8",
12 | "webpack-cli": "^6.0.1",
13 | "webpack-dev-server": "^5.2.1"
14 | },
15 | "haxeDependencies": {
16 | "haxe": "4.0.5"
17 | },
18 | "scripts": {
19 | "build": "npm run build:prod",
20 | "build:dev": "webpack --mode=development",
21 | "build:prod": "webpack --mode=production",
22 | "start": "npm run start:dev",
23 | "start:dev": "webpack serve --mode=development",
24 | "start:prod": "webpack serve --mode=production"
25 | },
26 | "dependencies": {}
27 | }
28 |
--------------------------------------------------------------------------------
/features/display/UsingSWFAssets/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "org.openfl.samples.usingswfassets-haxe",
3 | "version": "1.0.0",
4 | "private": true,
5 | "devDependencies": {
6 | "copy-webpack-plugin": "^13.0.0",
7 | "haxe": "^5.2.1",
8 | "haxe-loader": "^0.10.0",
9 | "openfl": "^9.4.1",
10 | "swf-loader": "^1.0.2",
11 | "webpack": "^5.99.8",
12 | "webpack-cli": "^6.0.1",
13 | "webpack-dev-server": "^5.2.1"
14 | },
15 | "haxeDependencies": {
16 | "haxe": "4.0.5"
17 | },
18 | "scripts": {
19 | "build": "npm run build:prod",
20 | "build:dev": "webpack --mode=development",
21 | "build:prod": "webpack --mode=production",
22 | "start": "npm run start:dev",
23 | "start:dev": "webpack serve --mode=development",
24 | "start:prod": "webpack serve --mode=production"
25 | },
26 | "dependencies": {}
27 | }
28 |
--------------------------------------------------------------------------------
/features/events/HandlingMouseEvents/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "org.openfl.samples.handlingmouseevents-haxe",
3 | "version": "1.0.0",
4 | "private": true,
5 | "devDependencies": {
6 | "actuate": "^1.9.0",
7 | "copy-webpack-plugin": "^13.0.0",
8 | "haxe": "^5.2.1",
9 | "haxe-loader": "^0.10.0",
10 | "openfl": "^9.4.1",
11 | "webpack": "^5.99.8",
12 | "webpack-cli": "^6.0.1",
13 | "webpack-dev-server": "^5.2.1"
14 | },
15 | "haxeDependencies": {
16 | "haxe": "4.0.5"
17 | },
18 | "scripts": {
19 | "build": "npm run build:prod",
20 | "build:dev": "webpack --mode=development",
21 | "build:prod": "webpack --mode=production",
22 | "start": "npm run start:dev",
23 | "start:dev": "webpack serve --mode=development",
24 | "start:prod": "webpack serve --mode=production"
25 | },
26 | "dependencies": {}
27 | }
28 |
--------------------------------------------------------------------------------
/demos/PiratePig/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | OpenFL | PiratePig
5 |
6 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/features/events/CreatingCustomEvents/src/App.hx:
--------------------------------------------------------------------------------
1 | import openfl.display.Sprite;
2 | import openfl.display.Stage;
3 | import openfl.events.Event;
4 |
5 | class App extends Sprite
6 | {
7 | public function new()
8 | {
9 | super();
10 |
11 | addEventListener("simpleCustomEvent", this_onSimpleCustomEvent);
12 | addEventListener(CustomEvent.TYPED_CUSTOM_EVENT, this_onTypedCustomEvent);
13 |
14 | dispatchEvent(new Event("simpleCustomEvent"));
15 | dispatchEvent(new CustomEvent(CustomEvent.TYPED_CUSTOM_EVENT, 100));
16 | }
17 |
18 | // Event Handlers
19 |
20 | private function this_onSimpleCustomEvent(event:Event):Void
21 | {
22 | trace(event);
23 | }
24 |
25 | private function this_onTypedCustomEvent(event:CustomEvent)
26 | {
27 | trace(event);
28 | }
29 |
30 | // Entry Point
31 |
32 | static function main()
33 | {
34 | var stage = new Stage(550, 400, 0xFFFFFF, App);
35 | js.Browser.document.body.appendChild(stage.element);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/demos/HerokuShaders/public/assets/5891.5.frag:
--------------------------------------------------------------------------------
1 | //http://glsl.heroku.com/e#5891.5
2 |
3 |
4 | uniform float time;
5 | uniform vec2 mouse;
6 | uniform vec2 resolution;
7 |
8 | const float Tau = 6.2832;
9 | const float speed = .02;
10 | const float density = .04;
11 | const float shape = .04;
12 |
13 | float random( vec2 seed ) {
14 | return fract(sin(seed.x+seed.y*1e3)*1e5);
15 | }
16 |
17 | float Cell(vec2 coord) {
18 | vec2 cell = fract(coord) * vec2(.5,2.) - vec2(.0,.5);
19 | return (1.-length(cell*2.-1.))*step(random(floor(coord)),density)*2.;
20 | }
21 |
22 | void main( void ) {
23 |
24 | vec2 p = gl_FragCoord.xy / resolution - mouse;
25 |
26 | float a = fract(atan(p.x, p.y) / Tau);
27 | float d = length(p);
28 |
29 | vec2 coord = vec2(pow(d, shape), a)*256.;
30 | vec2 delta = vec2(-time*speed*256., .5);
31 |
32 | float c = 0.;
33 | for(int i=0; i<3; i++) {
34 | coord += delta;
35 | c = max(c, Cell(coord));
36 | }
37 |
38 | gl_FragColor = vec4(c * d);
39 |
40 | }
--------------------------------------------------------------------------------
/features/display/DisplayingABitmap/src/Main.hx:
--------------------------------------------------------------------------------
1 | import openfl.display.Bitmap;
2 | import openfl.display.Loader;
3 | import openfl.display.Sprite;
4 | import openfl.display.Stage;
5 | import openfl.events.Event;
6 | import openfl.net.URLRequest;
7 |
8 | class Main extends Sprite
9 | {
10 | public function new()
11 | {
12 | super();
13 |
14 | var loader = new Loader();
15 | loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loader_onComplete);
16 | loader.load(new URLRequest("openfl.png"));
17 | }
18 |
19 | // Event Handlers
20 |
21 | private function loader_onComplete(event:Event):Void
22 | {
23 | var bitmap = cast(event.target.loader.content, Bitmap);
24 | bitmap.x = (stage.stageWidth - bitmap.width) / 2;
25 | bitmap.y = (stage.stageHeight - bitmap.height) / 2;
26 | addChild(bitmap);
27 | }
28 |
29 | // Entry point
30 |
31 | static function main()
32 | {
33 | var stage = new Stage(550, 400, 0xFFFFFF, Main);
34 | js.Browser.document.body.appendChild(stage.element);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/demos/HerokuShaders/public/assets/6238.frag:
--------------------------------------------------------------------------------
1 | //http://glsl.heroku.com/e#6238.0
2 |
3 |
4 | uniform float time;
5 | uniform vec2 mouse;
6 | uniform vec2 resolution;
7 |
8 | void main( void ) {
9 |
10 | vec3 color1 = vec3(1.7, 0.25, 0.5);
11 | vec3 color2 = vec3(0.5, 0.7, 0.25);
12 | vec3 color3 = vec3(0.25, 0.5, 0.7);
13 |
14 | vec2 point1 = resolution/2.0 + vec2(sin(time*2.0) * 10.0, cos(time*2.0) * 5.0);
15 | vec2 point2 = resolution/2.0 + vec2(sin(time)*75.0, cos(time)*50.0);
16 | vec2 point3 = resolution/2.0 + vec2(sin(time)*25.0, sin(time*2.0)*50.0)*2.0;
17 |
18 | vec2 dist1 = gl_FragCoord.xy - point1;
19 | float intensity1 = pow(32.0/(0.01+length(dist1)), 2.0);
20 |
21 | vec2 dist2 = gl_FragCoord.xy - point2;
22 | float intensity2 = pow(3.0/(0.01+length(dist2)), 2.0);
23 |
24 | vec2 dist3 = gl_FragCoord.xy - point3;
25 | float intensity3 = pow(62.0/(0.01+length(dist3)), 1.0);
26 |
27 | gl_FragColor = vec4((color1*intensity1 + color2*intensity2 + color3*intensity3)*mod(gl_FragCoord.y, 2.0),1.0);
28 | }
--------------------------------------------------------------------------------
/demos/HerokuShaders/public/assets/6223.2.frag:
--------------------------------------------------------------------------------
1 | //http://glsl.heroku.com/e#6223.2
2 |
3 |
4 | uniform float time;
5 | uniform vec2 mouse;
6 | uniform vec2 resolution;
7 |
8 | // a raymarching experiment by kabuto
9 | //fork by tigrou ind (2013.01.22)
10 | //optimized
11 |
12 | #define MAXITER 90
13 | #define MAXITER_SQR MAXITER*MAXITER
14 |
15 | vec3 field(vec3 p) {
16 | p = abs(fract(p)-.5);
17 | p *= p;
18 | return sqrt(p+p.yzx*p.zzy)-.015;
19 | }
20 |
21 | void main( void ) {
22 | vec3 dir = normalize(vec3((gl_FragCoord.xy-resolution*.5)/resolution.x,1.));
23 | float a = time * 0.4;
24 | vec3 pos = vec3(time*0.6 + sin(time)*0.2,sin(time)*0.25,-3.0);
25 |
26 | vec3 color = vec3(0);
27 | for (int i = 0; i < MAXITER; i++) {
28 | vec3 f2 = field(pos);
29 | vec3 rep = vec3(1.0,0.7+sin(time)*0.7, 1.3);
30 | float f = min(min(min(f2.x,f2.y),f2.z), length(mod(pos-vec3(0.1),rep)-0.5*rep)-0.10);
31 | pos += dir*f;
32 | color += float(MAXITER-i)/(f2+.01);
33 | }
34 | vec3 color3 = vec3(1.-1./(1.+color*(.09/float(MAXITER_SQR))));
35 | color3 *= color3;
36 | gl_FragColor = vec4(vec3(color3.r+color3.g+color3.b),1.);
37 | }
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | MIT License
2 | ===========
3 |
4 | Copyright (c) 2013-2025 Joshua Granick and other OpenFL contributors
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 |
--------------------------------------------------------------------------------
/features/text/AddingText/src/App.hx:
--------------------------------------------------------------------------------
1 | import openfl.display.Sprite;
2 | import openfl.display.Stage;
3 | import openfl.text.Font;
4 | import openfl.text.TextField;
5 | import openfl.text.TextFormat;
6 | import openfl.utils.AssetLibrary;
7 | import openfl.utils.AssetManifest;
8 |
9 | class App extends Sprite
10 | {
11 | public function new()
12 | {
13 | super();
14 |
15 | var format = new TextFormat("Katamotz Ikasi", 30, 0x7A0026);
16 | var textField = new TextField();
17 |
18 | textField.defaultTextFormat = format;
19 | textField.embedFonts = true;
20 | textField.selectable = false;
21 |
22 | textField.x = 50;
23 | textField.y = 50;
24 | textField.width = 200;
25 |
26 | textField.text = "Hello World";
27 |
28 | addChild(textField);
29 | }
30 |
31 | static function main()
32 | {
33 | var manifest = new AssetManifest();
34 | manifest.addFont("Katamotz Ikasi");
35 |
36 | AssetLibrary.loadFromManifest(manifest).onComplete(function(library)
37 | {
38 | // Assets.registerLibrary ("default", library);
39 |
40 | var stage = new Stage(550, 400, 0xFFFFFF, App);
41 | js.Browser.document.body.appendChild(stage.element);
42 | }).onError(function(e)
43 | {
44 | trace(e);
45 | });
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/features/events/CreatingAMainLoop/src/App.hx:
--------------------------------------------------------------------------------
1 | import openfl.display.Sprite;
2 | import openfl.display.Stage;
3 | import openfl.events.Event;
4 | import openfl.Lib;
5 |
6 | class App extends Sprite
7 | {
8 | private var cacheTime:Int;
9 | private var speed:Float;
10 | private var sprite:Sprite;
11 |
12 | public function new()
13 | {
14 | super();
15 |
16 | sprite = new Sprite();
17 | sprite.graphics.beginFill(0x24AFC4);
18 | sprite.graphics.drawRect(0, 0, 100, 100);
19 | sprite.y = 50;
20 | addChild(sprite);
21 |
22 | speed = 0.3;
23 | cacheTime = Lib.getTimer();
24 |
25 | addEventListener(Event.ENTER_FRAME, this_onEnterFrame);
26 | }
27 |
28 | private function update(deltaTime:Int):Void
29 | {
30 | if (sprite.x + sprite.width >= stage.stageWidth || sprite.x < 0)
31 | {
32 | speed *= -1;
33 | }
34 |
35 | sprite.x += speed * deltaTime;
36 | }
37 |
38 | // Event Handlers
39 |
40 | private function this_onEnterFrame(event:Event):Void
41 | {
42 | var currentTime = Lib.getTimer();
43 | update(currentTime - cacheTime);
44 | cacheTime = currentTime;
45 | }
46 |
47 | // Entry point
48 |
49 | static function main()
50 | {
51 | var stage = new Stage(550, 400, 0xFFFFFF, App);
52 | js.Browser.document.body.appendChild(stage.element);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/demos/HerokuShaders/public/assets/5812.frag:
--------------------------------------------------------------------------------
1 | //http://glsl.heroku.com/e#5812
2 |
3 |
4 | uniform float time;
5 | uniform vec2 mouse;
6 | uniform vec2 resolution;
7 |
8 | float random(vec2 v)
9 | {
10 | return fract(sin(dot(v ,vec2(13.9898,78.233))) * (10000.0+time*0.05));
11 | }
12 |
13 | void main( void )
14 | {
15 | const int numColors = 3;
16 | vec3 colors[numColors];
17 | colors[0] = vec3( 0.3, 0.8, 0.8);
18 | colors[1] = vec3( 0.8, 0.9, 0.4);
19 | colors[2] = vec3( 0.4, 0.4, 0.5);
20 |
21 | vec2 screenPos = gl_FragCoord.xy;
22 | vec2 screenPosNorm = gl_FragCoord.xy / resolution.xy;
23 | vec2 position = screenPosNorm + mouse / 4.0;
24 |
25 | // calc block
26 | vec2 screenBlock0 = floor(screenPos*0.16 + vec2(time,0) + mouse*3.0);
27 | vec2 screenBlock1 = floor(screenPos*0.08 + vec2(time*1.5,0) + mouse*5.0);
28 | vec2 screenBlock2 = floor(screenPos*0.02 + vec2(time*2.0,0)+mouse*10.0);
29 | float rand0 = random(screenBlock0);
30 | float rand1 = random(screenBlock1);
31 | float rand2 = random(screenBlock2);
32 |
33 | float rand = rand1;
34 | if ( rand2 < 0.05 ) { rand = rand2; }
35 |
36 | // block color
37 | vec3 color = mix( colors[0], colors[1], pow(rand,5.0) );
38 | if ( rand < 0.05 ) { color=colors[2]; }
39 |
40 | float vignette = 1.6-length(screenPosNorm*2.0-1.0);
41 | vec4 finalColor = vec4(color*vignette, 1.0);
42 |
43 | gl_FragColor = finalColor;
44 | }
--------------------------------------------------------------------------------
/features/display/AddingAnimation/src/App.hx:
--------------------------------------------------------------------------------
1 | import motion.easing.Elastic;
2 | import motion.Actuate;
3 | import openfl.display.Bitmap;
4 | import openfl.display.BitmapData;
5 | import openfl.display.Sprite;
6 | import openfl.display.Stage;
7 | import openfl.utils.AssetLibrary;
8 | import openfl.utils.AssetManifest;
9 | import openfl.utils.Assets;
10 |
11 | class App extends Sprite
12 | {
13 | public function new()
14 | {
15 | super();
16 |
17 | var bitmap = new Bitmap(Assets.getBitmapData("assets/openfl.png"));
18 | bitmap.x = -bitmap.width / 2;
19 | bitmap.y = -bitmap.height / 2;
20 | bitmap.smoothing = true;
21 |
22 | var container = new Sprite();
23 | container.addChild(bitmap);
24 | container.alpha = 0;
25 | container.scaleX = 0;
26 | container.scaleY = 0;
27 | container.x = stage.stageWidth / 2;
28 | container.y = stage.stageHeight / 2;
29 |
30 | addChild(container);
31 |
32 | Actuate.tween(container, 3, {alpha: 1});
33 | Actuate.tween(container, 6, {scaleX: 1, scaleY: 1}).delay(0.4).ease(Elastic.easeOut);
34 | }
35 |
36 | static function main()
37 | {
38 | var manifest = new AssetManifest();
39 | manifest.addBitmapData("assets/openfl.png");
40 |
41 | AssetLibrary.loadFromManifest(manifest).onComplete(function(library)
42 | {
43 | Assets.registerLibrary("default", library);
44 |
45 | var stage = new Stage(550, 400, 0xFFFFFF, App);
46 | js.Browser.document.body.appendChild(stage.element);
47 | }).onError(function(e)
48 | {
49 | trace(e);
50 | });
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/demos/PiratePig/src/piratepig/Main.hx:
--------------------------------------------------------------------------------
1 | package piratepig;
2 |
3 | import openfl.display.BitmapData;
4 | import openfl.display.Sprite;
5 | import openfl.display.Stage;
6 | import openfl.media.Sound;
7 | import openfl.text.Font;
8 | import openfl.utils.AssetLibrary;
9 | import openfl.utils.AssetManifest;
10 | import openfl.utils.Assets;
11 | import piratepig.PiratePig;
12 |
13 | class Main extends Sprite
14 | {
15 | static function main()
16 | {
17 | var manifest = new AssetManifest();
18 |
19 | for (image in [
20 | "background_tile.png", "center_bottom.png", "cursor_highlight.png", "cursor.png", "game_bear.png", "game_bunny_02.png", "game_carrot.png",
21 | "game_lemon.png", "game_panda.png", "game_piratePig.png", "logo.png"
22 | ])
23 | {
24 | manifest.addBitmapData("images/" + image);
25 | }
26 |
27 | for (sound in ["3", "4", "5", "theme"])
28 | {
29 | var id = "sound" + sound.charAt(0).toUpperCase() + sound.substr(1);
30 | manifest.addSound(["sounds/" + sound + ".ogg", "sounds/" + sound + ".mp3", "sounds/" + sound + ".wav"], id);
31 | }
32 |
33 | manifest.addFont("Freebooter", "fonts/FreebooterUpdated.ttf");
34 |
35 | AssetLibrary.loadFromManifest(manifest).onComplete(function(library)
36 | {
37 | Assets.registerLibrary("default", library);
38 |
39 | var stage = new Stage();
40 | js.Browser.document.getElementById("openfl-content").appendChild(stage.element);
41 | stage.addChild(new PiratePig());
42 | }).onError(function(e)
43 | {
44 | trace(e);
45 | });
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/features/display/UsingSWFAssets/src/App.hx:
--------------------------------------------------------------------------------
1 | import openfl.display.MovieClip;
2 | import openfl.display.Sprite;
3 | import openfl.display.Stage;
4 | import openfl.events.Event;
5 | import openfl.utils.AssetLibrary;
6 | import js.Lib.require;
7 |
8 | class App extends Sprite
9 | {
10 | private var columnOffsetHeight:Float;
11 | private var headerOffsetWidth:Float;
12 | private var layout:MovieClip;
13 |
14 | public function new()
15 | {
16 | super();
17 |
18 | AssetLibrary.loadFromFile(require("./assets/layout.swf")).onComplete(function(library:AssetLibrary)
19 | {
20 | layout = library.getMovieClip("Layout");
21 | addChild(layout);
22 |
23 | columnOffsetHeight = (layout.Column.height - layout.height);
24 | headerOffsetWidth = (layout.Header.width - layout.width);
25 |
26 | resize();
27 | stage.addEventListener(Event.RESIZE, resize);
28 | });
29 | }
30 |
31 | private function resize(event:Event = null):Void
32 | {
33 | var background = cast(layout.Background, MovieClip);
34 | var column = cast(layout.Column, MovieClip);
35 | var header = cast(layout.Header, MovieClip);
36 |
37 | background.width = stage.stageWidth;
38 | background.height = stage.stageHeight;
39 |
40 | var columnHeight = stage.stageHeight + columnOffsetHeight;
41 | column.height = (columnHeight > 0 ? columnHeight : 0);
42 |
43 | var headerWidth = stage.stageWidth + headerOffsetWidth;
44 | header.width = (headerWidth > 0 ? headerWidth : 0);
45 | }
46 |
47 | static function main()
48 | {
49 | var stage = new Stage(0, 0, 0xFFFFFF, App);
50 | js.Browser.document.body.appendChild(stage.element);
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/demos/HerokuShaders/public/assets/6147.1.frag:
--------------------------------------------------------------------------------
1 | //http://glsl.heroku.com/e#6147.1
2 |
3 |
4 | #define PI 3.14159265
5 | uniform float time;
6 | uniform vec2 mouse, resolution;
7 |
8 | vec3 sim(vec3 p,float s); //.h
9 | vec2 rot(vec2 p,float r);
10 | vec2 rotsim(vec2 p,float s);
11 |
12 | vec2 makeSymmetry(vec2 p){ //nice stuff :)
13 | vec2 ret=p;
14 | ret=rotsim(p, 6.0);
15 | ret.x=abs(ret.x);
16 | return ret;
17 | }
18 |
19 | float makePoint(float x,float y,float fx,float fy,float sx,float sy,float t){
20 |
21 | float xx=x+tan(t * fx)*sy;
22 | float yy=y-tan(t * fx)*sy;
23 | return 0.8/sqrt(abs(x*xx+yy*yy));
24 | }
25 |
26 | vec2 sim(vec2 p,float s){
27 | vec2 ret=p;
28 | ret=p+s/2.0;
29 | ret=fract(ret/s)*s-s/2.0;
30 | return ret;
31 | }
32 |
33 | vec2 rot(vec2 p,float r){
34 | vec2 ret;
35 | ret.x=p.x*cos(r)-p.y*sin(r);
36 | ret.y=p.x*sin(r)+p.y*cos(r);
37 | return ret;
38 | }
39 |
40 | vec2 rotsim(vec2 p,float s){
41 | float k = atan(p.x, p.y);
42 | vec2 ret=rot(p,floor((k + PI/(s*2.0)) / PI*s)*(PI/s));
43 | return ret;
44 | }
45 |
46 | void main( void ) {
47 | vec2 p=(gl_FragCoord.xy/resolution.x)*2.0-vec2(1.0,resolution.y/resolution.x);
48 | p=makeSymmetry(p);
49 | float x=p.x;
50 | float y=p.y;
51 | float t=time*0.2;
52 | float a= makePoint(x,y,3.3,2.9,0.3,0.3,t);
53 | // a=a+makePoint(x,y,1.8,1.7,0.5,0.4,t);
54 | float b=makePoint(x,y,1.2,1.9,0.3,0.3,t);
55 | // b=b+makePoint(x,y,0.7,2.7,0.4,0.4,t);
56 | float c=makePoint(x,y,3.7,0.3,0.3,0.3,t);
57 | // c=c+makePoint(x,y,0.8,0.9,0.4,0.5,t);
58 | gl_FragColor = vec4(a/5.,b/5.,c/5.,1.0);
59 | }
--------------------------------------------------------------------------------
/demos/HerokuShaders/public/assets/5805.18.frag:
--------------------------------------------------------------------------------
1 | //http://glsl.heroku.com/e#5805.18
2 |
3 |
4 | uniform float time;
5 | uniform vec2 mouse;
6 | uniform vec2 resolution;
7 |
8 | float function_f (float x) {
9 | return + mouse.y * 0.5 * 2.0 * resolution.y / 4.0 / (1.0 + exp((x+200.0)*0.1))
10 | - mouse.y * 0.5 * 2.0 * resolution.y / 4.0 / (1.0 + exp((x+100.0)*0.1))
11 | + mouse.y * 0.5 * 2.0 * resolution.y / 4.0 / (1.0 + exp(x*0.1))
12 | - mouse.y * 0.5 * 2.0 * resolution.y / 4.0 / (1.0 + exp((x-100.0)*0.1))
13 | + mouse.y * 0.5 * 2.0 * resolution.y / 4.0 / (1.0 + exp((x-200.0)*0.1))
14 | + sin(x*0.1 - time*10.0 + mouse.x * 10.0)*50.0;
15 | }
16 |
17 | float function_g (float x) {
18 | return - mouse.y * 0.5 * 2.0 * resolution.y / 4.0 / (1.0 + exp((x+200.0)*0.1))
19 | + mouse.y * 0.5 * 2.0 * resolution.y / 4.0 / (1.0 + exp((x+100.0)*0.1))
20 | - mouse.y * 0.5 * 2.0 * resolution.y / 4.0 / (1.0 + exp(x*0.1))
21 | + mouse.y * 0.5 * 2.0 * resolution.y / 4.0 / (1.0 + exp((x-100.0)*0.1))
22 | - mouse.y * 0.5 * 2.0 * resolution.y / 4.0 / (1.0 + exp((x-200.0)*0.1))
23 | + sin(x*0.1 + time*5.0 - mouse.x * 10.0)*50.0;
24 | }
25 |
26 |
27 | void main( void ) {
28 |
29 | vec3 color_1 = vec3(0.25, sin(time), cos(time));
30 | vec3 color_2 = vec3(0.5, 0.25, cos(time));
31 |
32 | vec2 pos = gl_FragCoord.xy;
33 |
34 | pos.y -= resolution.y / 2.0;
35 | pos.x -= resolution.x / 2.0;
36 |
37 | float intensity_f = 16.0 / abs(pos.y - function_f(pos.x));
38 | intensity_f = pow(intensity_f, 0.5);
39 |
40 | float intensity_g = 16.0 / abs(pos.y - function_g(pos.x));
41 | intensity_g += pow(intensity_g, 0.5);
42 |
43 | gl_FragColor = vec4((color_1 * intensity_f + color_2 * intensity_g)*mod(gl_FragCoord.y, 2.0), 1);
44 | }
--------------------------------------------------------------------------------
/demos/PiratePig/src/piratepig/PiratePig.hx:
--------------------------------------------------------------------------------
1 | package piratepig;
2 |
3 | import openfl.display.Bitmap;
4 | import openfl.display.BitmapData;
5 | import openfl.display.Sprite;
6 | import openfl.events.Event;
7 | import openfl.events.KeyboardEvent;
8 | import openfl.system.Capabilities;
9 | import openfl.utils.Assets;
10 | import openfl.Lib;
11 |
12 | class PiratePig extends Sprite
13 | {
14 | private var Background:Bitmap;
15 | private var Footer:Bitmap;
16 | private var Game:PiratePigGame;
17 |
18 | public function new()
19 | {
20 | super();
21 |
22 | addEventListener(Event.ADDED_TO_STAGE, function(_)
23 | {
24 | initialize();
25 | construct();
26 |
27 | resize(stage.stageWidth, stage.stageHeight);
28 | stage.addEventListener(Event.RESIZE, stage_onResize);
29 | });
30 | }
31 |
32 | private function construct():Void
33 | {
34 | Footer.smoothing = true;
35 |
36 | addChild(Background);
37 | addChild(Footer);
38 | addChild(Game);
39 | }
40 |
41 | private function initialize():Void
42 | {
43 | Background = new Bitmap(Assets.getBitmapData("images/background_tile.png"));
44 | Footer = new Bitmap(Assets.getBitmapData("images/center_bottom.png"));
45 | Game = new PiratePigGame();
46 | }
47 |
48 | private function resize(newWidth:Int, newHeight:Int):Void
49 | {
50 | Background.width = newWidth;
51 | Background.height = newHeight;
52 |
53 | Game.resize(newWidth, newHeight);
54 |
55 | Footer.scaleX = Game.currentScale;
56 | Footer.scaleY = Game.currentScale;
57 | Footer.x = newWidth / 2 - Footer.width / 2;
58 | Footer.y = newHeight - Footer.height;
59 | }
60 |
61 | private function stage_onResize(event:Event):Void
62 | {
63 | resize(stage.stageWidth, stage.stageHeight);
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/demos/PiratePig/src/piratepig/Tile.hx:
--------------------------------------------------------------------------------
1 | package piratepig;
2 |
3 | import motion.easing.Quad;
4 | import motion.Actuate;
5 | import openfl.display.Bitmap;
6 | import openfl.display.Sprite;
7 | import openfl.utils.Assets;
8 |
9 | class Tile extends Sprite
10 | {
11 | public var column:Int;
12 | public var moving:Bool;
13 | public var removed:Bool;
14 | public var row:Int;
15 | public var type:Int;
16 |
17 | public function new(imagePath:String)
18 | {
19 | super();
20 |
21 | var image = new Bitmap(Assets.getBitmapData(imagePath));
22 | image.smoothing = true;
23 | addChild(image);
24 |
25 | mouseChildren = false;
26 | buttonMode = true;
27 |
28 | graphics.beginFill(0x000000, 0);
29 | graphics.drawRect(-5, -5, 66, 66);
30 | }
31 |
32 | public function initialize():Void
33 | {
34 | moving = false;
35 | removed = false;
36 |
37 | mouseEnabled = true;
38 | buttonMode = true;
39 |
40 | scaleX = 1;
41 | scaleY = 1;
42 | alpha = 1;
43 | }
44 |
45 | public function moveTo(duration:Float, targetX:Float, targetY:Float):Void
46 | {
47 | moving = true;
48 |
49 | Actuate.tween(this, duration, {x: targetX, y: targetY}).ease(Quad.easeOut).onComplete(this_onMoveToComplete);
50 | }
51 |
52 | public function remove(animate:Bool = true):Void
53 | {
54 | if (!removed)
55 | {
56 | if (animate)
57 | {
58 | mouseEnabled = false;
59 | buttonMode = false;
60 |
61 | parent.addChildAt(this, 0);
62 | Actuate.tween(this, 0.6,
63 | {
64 | alpha: 0,
65 | scaleX: 2,
66 | scaleY: 2,
67 | x: x - width / 2,
68 | y: y - height / 2
69 | }).onComplete(this_onRemoveComplete);
70 | }
71 | else
72 | {
73 | this_onRemoveComplete();
74 | }
75 | }
76 |
77 | removed = true;
78 | }
79 |
80 | // Event Handlers
81 |
82 | private function this_onMoveToComplete():Void
83 | {
84 | moving = false;
85 | }
86 |
87 | private function this_onRemoveComplete():Void
88 | {
89 | parent.removeChild(this);
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/features/media/PlayingVideo/src/App.hx:
--------------------------------------------------------------------------------
1 | import motion.Actuate;
2 | import openfl.display.Sprite;
3 | import openfl.display.Stage;
4 | import openfl.events.AsyncErrorEvent;
5 | import openfl.events.MouseEvent;
6 | import openfl.events.NetStatusEvent;
7 | import openfl.media.Video;
8 | import openfl.net.NetConnection;
9 | import openfl.net.NetStream;
10 |
11 | class App extends Sprite
12 | {
13 | private var netStream:NetStream;
14 | private var overlay:Sprite;
15 | private var video:Video;
16 |
17 | public function new()
18 | {
19 | super();
20 |
21 | video = new Video();
22 | addChild(video);
23 |
24 | var netConnection = new NetConnection();
25 | netConnection.connect(null);
26 |
27 | netStream = new NetStream(netConnection);
28 | netStream.client = {onMetaData: client_onMetaData};
29 | netStream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, netStream_onAsyncError);
30 |
31 | overlay = new Sprite();
32 | overlay.graphics.beginFill(0, 0.5);
33 | overlay.graphics.drawRect(0, 0, 560, 320);
34 | overlay.addEventListener(MouseEvent.MOUSE_DOWN, overlay_onMouseDown);
35 | addChild(overlay);
36 |
37 | netConnection.addEventListener(NetStatusEvent.NET_STATUS, netConnection_onNetStatus);
38 | }
39 |
40 | private function client_onMetaData(metaData:Dynamic)
41 | {
42 | video.attachNetStream(netStream);
43 |
44 | video.width = video.videoWidth;
45 | video.height = video.videoHeight;
46 | }
47 |
48 | private function netStream_onAsyncError(event:AsyncErrorEvent):Void
49 | {
50 | trace("Error loading video");
51 | }
52 |
53 | private function netConnection_onNetStatus(event:NetStatusEvent):Void
54 | {
55 | if (event.info.code == "NetStream.Play.Complete")
56 | {
57 | Actuate.tween(overlay, 1, {alpha: 1});
58 | }
59 | }
60 |
61 | private function overlay_onMouseDown(event:MouseEvent):Void
62 | {
63 | Actuate.tween(overlay, 2, {alpha: 0});
64 | netStream.play("assets/example.mp4");
65 | }
66 |
67 | // Entry Point
68 |
69 | static function main()
70 | {
71 | var stage = new Stage(550, 400, 0xFFFFFF, App);
72 | js.Browser.document.body.appendChild(stage.element);
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/demos/HerokuShaders/public/assets/6022.frag:
--------------------------------------------------------------------------------
1 | //http://glsl.heroku.com/e#6022.0
2 |
3 |
4 | uniform float time;
5 | uniform vec2 mouse;
6 | uniform vec2 resolution;
7 | varying vec2 surfacePosition;
8 |
9 | float rand(vec2 co){
10 | return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43748.5453);
11 | }
12 | float cerp(float a, float b, float i)
13 | {
14 | if(i<0.)
15 | i += 1.;
16 | i *= 3.14159265;
17 | i = (1.-cos(i))/2.;
18 | return a*(1.-i)+b*i;
19 | }
20 | float lerp(float a, float b, float i)
21 | {
22 | if(i<0.)
23 | i+=1.;
24 | return a*(1.-i)+b*i;
25 | }
26 | vec3 lerp(vec3 a, vec3 b, float i)
27 | {
28 | if(i<0.)
29 | i+=1.;
30 | return a*(1.-i)+b*i;
31 | }
32 | float posrand(vec2 pos, float width, float height)
33 | {
34 | return rand(vec2(int(pos.x*width),int(pos.y*height)));
35 | }
36 | float tdposrand(vec2 pos, float width, float height)
37 | {
38 | float n1, n2, n3, n4, n5, n6;
39 | n1 = posrand(pos,width,height);
40 | n2 = posrand(vec2(pos.x+1./width,pos.y),width,height);
41 | n3 = posrand(vec2(pos.x,pos.y+1./height),width,height);
42 | n4 = posrand(vec2(pos.x+1./width,pos.y+1./height),width,height);
43 | n5 = cerp(n1,n2,pos.x*width-float(int(pos.x*width)));
44 | n6 = cerp(n3,n4,pos.x*width-float(int(pos.x*width)));
45 | return cerp(n5,n6,pos.y*height-float(int(pos.y*height)));
46 | }
47 |
48 | vec3 readcolpath(vec3 one, vec3 two, vec3 thr, vec3 fou, float i)
49 | {
50 | int num = int(i*3.);
51 | if(num==0)
52 | return lerp(one,two,i*3.-float(num));
53 | if(num==1)
54 | return lerp(two,thr,i*3.-float(num));
55 | if(num==2)
56 | return lerp(thr,fou,i*3.-float(num));
57 | return fou;
58 | }
59 | void main( void ) {
60 |
61 | vec2 position = surfacePosition+.5;
62 | vec2 odd = vec2(0,time/5.);
63 | vec3 col1 = vec3(1.,0.25,0.);
64 | vec3 col2 = vec3(.45,0.2,0.);
65 | vec3 col3 = vec3(0.2,.1,0.);
66 | vec3 col4 = vec3(.4,.3,.25);
67 | float color = 0.0;
68 | position = position*(1.+1./12.)+vec2(length(vec2(tdposrand(position-odd,2.,2.),tdposrand(position*4.3-odd,2.,2.))))/12.;
69 | if(position.y>0.)
70 | {
71 | //color += tdposrand(position-odd,1000.,1000.)/5.;
72 | color += tdposrand(position-odd,50.,50.)/8.;
73 | color += tdposrand(position-odd,20.,20.)/3.;
74 | color += tdposrand(position-odd,10.,10.)/2.;
75 | color += tdposrand(position-odd,5.,5.);
76 | color /= position.y*1.;
77 | }
78 | else
79 | {
80 | color = 16.0;
81 | }
82 | gl_FragColor = vec4( vec3( color/2. )*readcolpath(col1,col2,col3,col4,color/16.), 1.0 );
83 |
84 | }
--------------------------------------------------------------------------------
/demos/HerokuShaders/public/assets/4278.1.frag:
--------------------------------------------------------------------------------
1 | //http://glsl.heroku.com/e#4278.1
2 |
3 |
4 | uniform float time;
5 | uniform vec2 resolution;
6 | uniform vec2 mouse;
7 |
8 | mat3 genRotMat(float a0,float x,float y,float z){
9 | float a=a0*3.1415926535897932384626433832795/180.0;
10 | return mat3(
11 | 1.0+(1.0-cos(a))*(x*x-1.0),
12 | -z*sin(a)+(1.0-cos(a))*x*y,
13 | y*sin(a)+(1.0-cos(a))*x*z,
14 | z*sin(a)+(1.0-cos(a))*x*y,
15 | 1.0+(1.0-cos(a))*(y*y-1.0),
16 | -x*sin(a)+(1.0-cos(a))*y*z,
17 | -y*sin(a)+(1.0-cos(a))*x*z,
18 | x*sin(a)+(1.0-cos(a))*y*z,
19 | 1.0+(1.0-cos(a))*(z*z-1.0)
20 | );
21 | }
22 |
23 | float cubeDist(vec3 p){
24 | return max(abs(p.x),max(abs(p.y),abs(p.z)));
25 | }
26 |
27 | void main(){
28 | float spread=1.0;
29 | float total=0.0;
30 | float delta=0.01;
31 | float cameraZ=-1.75;
32 | float nearZ=-1.0;
33 | float farZ=1.0;
34 | float gs=0.0;
35 | int iter=0;
36 | vec3 col=vec3(0.0,0.0,0.0);
37 | vec3 ray=vec3(0.0,0.0,0.0);
38 | mat3 rot=genRotMat(sin(time/4.13)*360.0,1.0,0.0,0.0);
39 | rot=rot*genRotMat(sin(time/4.64)*360.0,0.0,1.0,0.0);
40 | rot=rot*genRotMat(sin(time/4.24)*360.0,0.0,0.0,1.0);
41 | vec2 p=vec2(0.0,0.0);
42 | p.x=gl_FragCoord.x/resolution.y-0.5*resolution.x/resolution.y;
43 | p.y=gl_FragCoord.y/resolution.y-0.5;
44 | ray.xy+=p.xy*spread*(nearZ-cameraZ);
45 | vec3 rayDir=vec3(spread*p.xy*delta,delta);
46 | vec3 tempDir=rayDir*rot;
47 | vec3 norm;
48 | ray.z=nearZ;
49 | bool refracted=false;
50 | for(int i=0;i<250;i++){
51 | vec3 temp;
52 | vec3 tempc;
53 | float val;
54 | temp=ray.xyz*rot;
55 | tempc=temp;
56 | float thres=0.5;
57 | if(tempc.x<0.0)tempc.x=abs(tempc.x);
58 | if(tempc.x=farZ)break;
80 | }
81 | col.x=col.x/float(iter);
82 | col.y=col.y/float(iter);
83 | col.z=col.z/float(iter);
84 | gl_FragColor=vec4(col,1.0);
85 | }
--------------------------------------------------------------------------------
/features/events/HandlingMouseEvents/src/App.hx:
--------------------------------------------------------------------------------
1 | import motion.Actuate;
2 | import openfl.display.Bitmap;
3 | import openfl.display.Sprite;
4 | import openfl.display.Stage;
5 | import openfl.events.MouseEvent;
6 | import openfl.utils.AssetLibrary;
7 | import openfl.utils.AssetManifest;
8 | import openfl.utils.Assets;
9 |
10 | class App extends Sprite
11 | {
12 | private var Logo:Sprite;
13 | private var Destination:Sprite;
14 | private var cacheOffsetX:Float;
15 | private var cacheOffsetY:Float;
16 |
17 | public function new()
18 | {
19 | super();
20 |
21 | Logo = new Sprite();
22 | Logo.addChild(new Bitmap(Assets.getBitmapData("assets/openfl.png")));
23 | Logo.x = 100;
24 | Logo.y = 100;
25 | Logo.buttonMode = true;
26 |
27 | Destination = new Sprite();
28 | Destination.graphics.beginFill(0xF5F5F5);
29 | Destination.graphics.lineStyle(1, 0xCCCCCC);
30 | Destination.graphics.drawRect(0, 0, Logo.width + 10, Logo.height + 10);
31 | Destination.x = 300;
32 | Destination.y = 95;
33 |
34 | addChild(Destination);
35 | addChild(Logo);
36 |
37 | Logo.addEventListener(MouseEvent.MOUSE_DOWN, Logo_onMouseDown);
38 | }
39 |
40 | // Event Handlers
41 |
42 | private function Logo_onMouseDown(event:MouseEvent):Void
43 | {
44 | cacheOffsetX = Logo.x - event.stageX;
45 | cacheOffsetY = Logo.y - event.stageY;
46 |
47 | stage.addEventListener(MouseEvent.MOUSE_MOVE, stage_onMouseMove);
48 | stage.addEventListener(MouseEvent.MOUSE_UP, stage_onMouseUp);
49 | }
50 |
51 | private function stage_onMouseMove(event:MouseEvent):Void
52 | {
53 | Logo.x = event.stageX + cacheOffsetX;
54 | Logo.y = event.stageY + cacheOffsetY;
55 | }
56 |
57 | private function stage_onMouseUp(event:MouseEvent):Void
58 | {
59 | if (Destination.hitTestPoint(event.stageX, event.stageY))
60 | {
61 | Actuate.tween(Logo, 1, {x: Destination.x + 5, y: Destination.y + 5});
62 | }
63 |
64 | stage.removeEventListener(MouseEvent.MOUSE_MOVE, stage_onMouseMove);
65 | stage.removeEventListener(MouseEvent.MOUSE_UP, stage_onMouseUp);
66 | }
67 |
68 | // Entry Point
69 |
70 | static function main()
71 | {
72 | var manifest = new AssetManifest();
73 | manifest.addBitmapData("assets/openfl.png");
74 |
75 | AssetLibrary.loadFromManifest(manifest).onComplete(function(library)
76 | {
77 | Assets.registerLibrary("default", library);
78 |
79 | var stage = new Stage(550, 400, 0xFFFFFF, App);
80 | js.Browser.document.body.appendChild(stage.element);
81 | }).onError(function(e)
82 | {
83 | trace(e);
84 | });
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/demos/HerokuShaders/public/assets/6162.frag:
--------------------------------------------------------------------------------
1 | //http://glsl.heroku.com/e#6162.0
2 |
3 |
4 | #define PI 3.141592653589793
5 |
6 | #define ZOOM (4. - sin(time/2.)*3.)
7 |
8 | #define MAX_ITERATION 6
9 | #define ITERATION_BAIL sqrt(PI/2.)
10 |
11 | #define MAX_MARCH 50
12 | #define MAX_DISTANCE 2.3
13 |
14 | uniform float time;
15 | uniform vec2 mouse;
16 | uniform vec2 resolution;
17 |
18 | float DE(vec3 p)
19 | {
20 | vec3 w = p;
21 | float dr = 1.;
22 | float r = 0.;
23 | for (int i=0; iITERATION_BAIL) break;
27 |
28 | dr*=pow(r, 7.)*8.+1.;
29 |
30 | float x = w.x; float x2 = x*x; float x4 = x2*x2;
31 | float y = w.y; float y2 = y*y; float y4 = y2*y2;
32 | float z = w.z; float z2 = z*z; float z4 = z2*z2;
33 |
34 | float k3 = x2 + z2;
35 | float k2 = inversesqrt( pow(k3, 7.) );
36 | float k1 = x4 + y4 + z4 - 6.0*y2*z2 - 6.0*x2*y2 + 2.0*z2*x2;
37 | float k4 = x2 - y2 + z2;
38 |
39 | w = vec3(64.0*x*y*z*(x2-z2)*k4*(x4-6.0*x2*z2+z4)*k1*k2,
40 | -16.0*y2*k3*k4*k4 + k1*k1,
41 | -8.0*y*k4*(x4*x4 - 28.0*x4*x2*z2 + 70.0*x4*z4 - 28.0*x2*z2*z4 + z4*z4)*k1*k2);
42 | w+=p;
43 | }
44 | return .5*log(r)*r/dr;
45 | }
46 |
47 | bool inCircle(vec3 p, vec3 d)
48 | {
49 | float rdt = dot(p, d);
50 | float rdr = dot(p, p) - 1.253314137315501; // sqrt(PI/2)
51 | return (rdt*rdt)-rdr>0.;
52 | }
53 |
54 |
55 | void main( void )
56 | {
57 | vec2 pos = (gl_FragCoord.xy*2.0 - resolution.xy) / resolution.y;
58 |
59 | vec2 m = vec2(sin(time), cos(time))/ZOOM;
60 | //m = ((.5-mouse)*PI*2.)/ZOOM;
61 | m.y = clamp(m.y, -PI/2.+.01, PI/2.-.01);
62 |
63 | vec3 camOrigin = vec3(cos(m.x)*cos(m.y), sin(m.y), cos(m.y)*sin(m.x))*2.0;
64 | vec3 camTarget = vec3(0.0, 0.0, 0.0);
65 | vec3 camDir = normalize(camTarget - camOrigin);
66 | vec3 camUp = normalize(vec3(0.0, 1.0, 0.0));
67 | vec3 camSide = normalize(cross(camDir, camUp));
68 | vec3 camCDS = cross(camDir, camSide);
69 |
70 | vec3 ray = normalize(camSide*pos.x + camCDS*pos.y + camDir*ZOOM);
71 |
72 | float col = 0., col2 = 0., col3 = 0.;
73 | if (inCircle(camOrigin, ray))
74 | {
75 | float m = 1.0, dist = 0.0, total_dist = 0.0;
76 |
77 | for(int i=0; iMAX_DISTANCE) break;
83 | }
84 |
85 | col = m;
86 | col2 = m*2.5-total_dist;
87 | col3 = m*1.5-total_dist;
88 | if (total_dist>MAX_DISTANCE) col = 0.;
89 | }
90 |
91 | gl_FragColor = vec4(col, col2/2., col3*2., 1.0);
92 | }
--------------------------------------------------------------------------------
/demos/PiratePig/src/piratepig/GamepadWrapper.hx:
--------------------------------------------------------------------------------
1 | package piratepig;
2 |
3 | import openfl.ui.GameInputControl;
4 | import openfl.ui.GameInputDevice;
5 |
6 | class GamepadWrapper
7 | {
8 | public var a:ButtonState;
9 | public var b:ButtonState;
10 | public var down:ButtonState;
11 | public var device:GameInputDevice;
12 | public var left:ButtonState;
13 | public var right:ButtonState;
14 | public var up:ButtonState;
15 | public var x:ButtonState;
16 | public var y:ButtonState;
17 |
18 | public function new(device:GameInputDevice)
19 | {
20 | this.device = device;
21 |
22 | up = new ButtonState();
23 | down = new ButtonState();
24 | left = new ButtonState();
25 | right = new ButtonState();
26 |
27 | a = new ButtonState();
28 | b = new ButtonState();
29 | x = new ButtonState();
30 | y = new ButtonState();
31 | }
32 |
33 | public function destroy():Void
34 | {
35 | device = null;
36 | }
37 |
38 | public function update():Void
39 | {
40 | for (i in 0...device.numControls)
41 | {
42 | var control:GameInputControl = device.getControlAt(i);
43 |
44 | var state:ButtonState = switch (control.id)
45 | {
46 | case "BUTTON_11": up;
47 | case "BUTTON_12": down;
48 | case "BUTTON_13": left;
49 | case "BUTTON_14": right;
50 | case "BUTTON_0": a;
51 | case "BUTTON_1": b;
52 | case "BUTTON_2": x;
53 | case "BUTTON_3": y;
54 | default: null;
55 | }
56 |
57 | if (state != null)
58 | {
59 | if (control.value <= 0)
60 | {
61 | state.release();
62 | }
63 | else
64 | {
65 | state.press();
66 | }
67 | }
68 | }
69 | }
70 | }
71 |
72 | class ButtonState
73 | {
74 | public var pressed(default, null):Bool;
75 | public var justPressed(default, null):Bool;
76 | public var justReleased(default, null):Bool;
77 |
78 | public function new():Void
79 | {
80 | pressed = false;
81 | justPressed = false;
82 | justReleased = false;
83 | }
84 |
85 | public function press():Void
86 | {
87 | if (!pressed)
88 | {
89 | justPressed = true;
90 | }
91 | else
92 | {
93 | justPressed = false;
94 | }
95 |
96 | pressed = true;
97 | justReleased = false;
98 | }
99 |
100 | public function release():Void
101 | {
102 | if (pressed)
103 | {
104 | justReleased = true;
105 | }
106 | else
107 | {
108 | justReleased = false;
109 | }
110 |
111 | pressed = false;
112 | justPressed = false;
113 | }
114 |
115 | public function update():Void
116 | {
117 | justPressed = false;
118 | justReleased = false;
119 | }
120 | }
121 |
--------------------------------------------------------------------------------
/features/events/HandlingKeyboardEvents/src/App.hx:
--------------------------------------------------------------------------------
1 | import openfl.display.Bitmap;
2 | import openfl.display.Sprite;
3 | import openfl.display.Stage;
4 | import openfl.events.Event;
5 | import openfl.events.KeyboardEvent;
6 | import openfl.ui.Keyboard;
7 | import openfl.utils.AssetLibrary;
8 | import openfl.utils.AssetManifest;
9 | import openfl.utils.Assets;
10 |
11 | class App extends Sprite
12 | {
13 | private var Logo:Sprite;
14 | private var movingDown:Bool;
15 | private var movingLeft:Bool;
16 | private var movingRight:Bool;
17 | private var movingUp:Bool;
18 |
19 | public function new()
20 | {
21 | super();
22 |
23 | Logo = new Sprite();
24 | Logo.addChild(new Bitmap(Assets.getBitmapData("assets/openfl.png")));
25 | Logo.x = 100;
26 | Logo.y = 100;
27 | Logo.buttonMode = true;
28 | addChild(Logo);
29 |
30 | stage.addEventListener(KeyboardEvent.KEY_DOWN, stage_onKeyDown);
31 | stage.addEventListener(KeyboardEvent.KEY_UP, stage_onKeyUp);
32 | stage.addEventListener(Event.ENTER_FRAME, this_onEnterFrame);
33 | }
34 |
35 | // Event Handlers
36 |
37 | private function stage_onKeyDown(event:KeyboardEvent):Void
38 | {
39 | var preventDefault = true;
40 |
41 | switch (event.keyCode)
42 | {
43 | case Keyboard.DOWN:
44 | movingDown = true;
45 | case Keyboard.LEFT:
46 | movingLeft = true;
47 | case Keyboard.RIGHT:
48 | movingRight = true;
49 | case Keyboard.UP:
50 | movingUp = true;
51 | default:
52 | preventDefault = false;
53 | }
54 |
55 | if (preventDefault) event.preventDefault();
56 | }
57 |
58 | private function stage_onKeyUp(event:KeyboardEvent):Void
59 | {
60 | var preventDefault = true;
61 |
62 | switch (event.keyCode)
63 | {
64 | case Keyboard.DOWN:
65 | movingDown = false;
66 | case Keyboard.LEFT:
67 | movingLeft = false;
68 | case Keyboard.RIGHT:
69 | movingRight = false;
70 | case Keyboard.UP:
71 | movingUp = false;
72 | default:
73 | preventDefault = false;
74 | }
75 |
76 | if (preventDefault) event.preventDefault();
77 | }
78 |
79 | private function this_onEnterFrame(event:Event):Void
80 | {
81 | if (movingDown)
82 | {
83 | Logo.y += 5;
84 | }
85 |
86 | if (movingLeft)
87 | {
88 | Logo.x -= 5;
89 | }
90 |
91 | if (movingRight)
92 | {
93 | Logo.x += 5;
94 | }
95 |
96 | if (movingUp)
97 | {
98 | Logo.y -= 5;
99 | }
100 | }
101 |
102 | // Entry Point
103 |
104 | static function main()
105 | {
106 | var manifest = new AssetManifest();
107 | manifest.addBitmapData("assets/openfl.png");
108 |
109 | AssetLibrary.loadFromManifest(manifest).onComplete(function(library)
110 | {
111 | Assets.registerLibrary("default", library);
112 |
113 | var stage = new Stage(550, 400, 0xFFFFFF, App);
114 | js.Browser.document.body.appendChild(stage.element);
115 | }).onError(function(e)
116 | {
117 | trace(e);
118 | });
119 | }
120 | }
121 |
--------------------------------------------------------------------------------
/features/display3D/HelloTriangle/src/App.hx:
--------------------------------------------------------------------------------
1 | import openfl.display.Sprite;
2 | import openfl.display.Stage;
3 | import openfl.display3D.Context3D;
4 | import openfl.display3D.Context3DBlendFactor;
5 | import openfl.display3D.Context3DProgramType;
6 | import openfl.display3D.Context3DVertexBufferFormat;
7 | import openfl.display3D.IndexBuffer3D;
8 | import openfl.display3D.Program3D;
9 | import openfl.display3D.VertexBuffer3D;
10 | import openfl.events.Event;
11 | import openfl.geom.Matrix3D;
12 | import openfl.geom.Rectangle;
13 | import openfl.geom.Vector3D;
14 | import openfl.utils.AGALMiniAssembler;
15 | import openfl.Lib;
16 | import openfl.Vector;
17 |
18 | class App extends Sprite
19 | {
20 | private var context3D:Context3D;
21 | private var program:Program3D;
22 | private var vertexBuffer:VertexBuffer3D;
23 | private var indexBuffer:IndexBuffer3D;
24 |
25 | public function new()
26 | {
27 | super();
28 |
29 | stage.stage3Ds[0].addEventListener(Event.CONTEXT3D_CREATE, init);
30 | stage.stage3Ds[0].requestContext3D();
31 | }
32 |
33 | private function init(_):Void
34 | {
35 | context3D = stage.stage3Ds[0].context3D;
36 | context3D.configureBackBuffer(stage.stageWidth, stage.stageHeight, 1, true);
37 |
38 | context3D.setBlendFactors(Context3DBlendFactor.ONE, Context3DBlendFactor.ONE_MINUS_SOURCE_ALPHA);
39 |
40 | var vertices = Vector.ofArray([-0.3, -0.3, 0, 1, 0, 0, -0.3, 0.3, 0, 0, 1, 0, 0.3, 0.3, 0, 0, 0, 1]);
41 |
42 | vertexBuffer = context3D.createVertexBuffer(3, 6);
43 | vertexBuffer.uploadFromVector(vertices, 0, 3);
44 |
45 | var indices = Vector.ofArray([0, 1, 2]);
46 |
47 | indexBuffer = context3D.createIndexBuffer(3);
48 | indexBuffer.uploadFromVector(indices, 0, 3);
49 |
50 | var assembler = new AGALMiniAssembler();
51 |
52 | var vertexShader = assembler.assemble(Context3DProgramType.VERTEX, "m44 op, va0, vc0\n" + "mov v0, va1");
53 |
54 | var fragmentShader = assembler.assemble(Context3DProgramType.FRAGMENT, "mov oc, v0");
55 |
56 | program = context3D.createProgram();
57 | program.upload(vertexShader, fragmentShader);
58 |
59 | addEventListener(Event.ENTER_FRAME, this_onEnterFrame);
60 | }
61 |
62 | // Event Handlers
63 |
64 | private function this_onEnterFrame(event:Event):Void
65 | {
66 | if (context3D == null)
67 | {
68 | return;
69 | }
70 |
71 | context3D.clear(1, 1, 1, 1);
72 |
73 | context3D.setProgram(program);
74 | context3D.setVertexBufferAt(0, vertexBuffer, 0, Context3DVertexBufferFormat.FLOAT_3);
75 | context3D.setVertexBufferAt(1, vertexBuffer, 3, Context3DVertexBufferFormat.FLOAT_3);
76 |
77 | var m = new Matrix3D();
78 | m.appendRotation(Lib.getTimer() / 40, Vector3D.Z_AXIS);
79 | context3D.setProgramConstantsFromMatrix(Context3DProgramType.VERTEX, 0, m, true);
80 |
81 | context3D.drawTriangles(indexBuffer);
82 |
83 | context3D.present();
84 | }
85 |
86 | // Entry Point
87 |
88 | static function main()
89 | {
90 | var stage = new Stage(550, 400, 0xFFFFFF, App);
91 | js.Browser.document.body.appendChild(stage.element);
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/features/media/PlayingSound/src/App.hx:
--------------------------------------------------------------------------------
1 | import motion.easing.Quad;
2 | import motion.Actuate;
3 | import openfl.display.Sprite;
4 | import openfl.display.Stage;
5 | import openfl.events.Event;
6 | import openfl.events.MouseEvent;
7 | import openfl.media.Sound;
8 | import openfl.media.SoundChannel;
9 | import openfl.media.SoundTransform;
10 | import openfl.utils.AssetLibrary;
11 | import openfl.utils.AssetManifest;
12 | import openfl.utils.Assets;
13 |
14 | class App extends Sprite
15 | {
16 | private var background:Sprite;
17 | private var channel:SoundChannel;
18 | private var playing:Bool;
19 | private var position:Float;
20 | private var sound:Sound;
21 |
22 | public function new()
23 | {
24 | super();
25 |
26 | Actuate.defaultEase = Quad.easeOut;
27 |
28 | background = new Sprite();
29 | background.alpha = 0.1;
30 | background.buttonMode = true;
31 | background.addEventListener(MouseEvent.MOUSE_DOWN, this_onMouseDown);
32 | addChild(background);
33 |
34 | sound = Assets.getSound("assets/stars.ogg");
35 | position = 0;
36 |
37 | resize();
38 | stage.addEventListener(Event.RESIZE, stage_onResize);
39 |
40 | play();
41 | }
42 |
43 | private function pause(fadeOut:Float = 1.2):Void
44 | {
45 | if (playing)
46 | {
47 | playing = false;
48 |
49 | Actuate.transform(channel, fadeOut).sound(0, 0).onComplete(stop);
50 | Actuate.tween(background, fadeOut, {alpha: 0.1});
51 | }
52 | }
53 |
54 | private function play(fadeIn:Float = 3):Void
55 | {
56 | stop();
57 |
58 | playing = true;
59 |
60 | if (fadeIn <= 0)
61 | {
62 | channel = sound.play(position);
63 | }
64 | else
65 | {
66 | channel = sound.play(position, 0, new SoundTransform(0, 0));
67 | Actuate.transform(channel, fadeIn).sound(1, 0);
68 | }
69 |
70 | channel.addEventListener(Event.SOUND_COMPLETE, channel_onSoundComplete);
71 | Actuate.tween(background, fadeIn, {alpha: 1});
72 | }
73 |
74 | private function resize():Void
75 | {
76 | background.graphics.clear();
77 | background.graphics.beginFill(0x24afc4);
78 | background.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
79 | }
80 |
81 | private function stop():Void
82 | {
83 | playing = false;
84 |
85 | Actuate.stop(channel);
86 |
87 | if (channel != null)
88 | {
89 | position = channel.position;
90 | channel.removeEventListener(Event.SOUND_COMPLETE, channel_onSoundComplete);
91 | channel.stop();
92 | channel = null;
93 | }
94 | }
95 |
96 | // Event Handlers
97 |
98 | private function channel_onSoundComplete(event:Event):Void
99 | {
100 | pause();
101 | position = 0;
102 | }
103 |
104 | private function stage_onResize(event:Event):Void
105 | {
106 | resize();
107 | }
108 |
109 | private function this_onMouseDown(event:MouseEvent):Void
110 | {
111 | if (!playing)
112 | {
113 | play();
114 | }
115 | else
116 | {
117 | pause();
118 | }
119 | }
120 |
121 | // Entry Point
122 |
123 | static function main()
124 | {
125 | var manifest = new AssetManifest();
126 | manifest.addSound(["assets/stars.ogg", "assets/stars.mp3"]);
127 |
128 | AssetLibrary.loadFromManifest(manifest).onComplete(function(library)
129 | {
130 | Assets.registerLibrary("default", library);
131 |
132 | var stage = new Stage(550, 400, 0xFFFFFF, App);
133 | js.Browser.document.body.appendChild(stage.element);
134 | }).onError(function(e)
135 | {
136 | trace(e);
137 | });
138 | }
139 | }
140 |
--------------------------------------------------------------------------------
/demos/BunnyMark/src/Main.hx:
--------------------------------------------------------------------------------
1 | import openfl.display.Bitmap;
2 | import openfl.display.BitmapData;
3 | import openfl.display.Loader;
4 | import openfl.display.Sprite;
5 | import openfl.display.Stage;
6 | import openfl.display.Tilemap;
7 | import openfl.display.Tileset;
8 | import openfl.events.Event;
9 | import openfl.events.MouseEvent;
10 | import openfl.net.URLRequest;
11 |
12 | class Main extends Sprite
13 | {
14 | private var addingBunnies:Bool;
15 | private var bunnies:Array;
16 | // private var fps:FPS;
17 | private var gravity:Float;
18 | private var minX:Float;
19 | private var minY:Float;
20 | private var maxX:Float;
21 | private var maxY:Float;
22 | private var tilemap:Tilemap;
23 | private var tileset:Tileset;
24 |
25 | public function new()
26 | {
27 | super();
28 |
29 | bunnies = [];
30 |
31 | var loader = new Loader();
32 | loader.contentLoaderInfo.addEventListener(Event.COMPLETE, function(event)
33 | {
34 | start(cast(loader.content, Bitmap).bitmapData);
35 | });
36 | loader.load(new URLRequest("wabbit_alpha.png"));
37 | }
38 |
39 | private function start(bitmapData:BitmapData):Void
40 | {
41 | minX = 0;
42 | maxX = stage.stageWidth;
43 | minY = 0;
44 | maxY = stage.stageHeight;
45 | gravity = 0.5;
46 |
47 | tileset = new Tileset(bitmapData);
48 | tileset.addRect(bitmapData.rect);
49 |
50 | tilemap = new Tilemap(stage.stageWidth, stage.stageHeight, tileset);
51 | // tilemap = new Tilemap (100, 100, tileset);
52 | addChild(tilemap);
53 |
54 | // fps = new FPS ();
55 | // addChild (fps);
56 |
57 | stage.addEventListener(MouseEvent.MOUSE_DOWN, stage_onMouseDown);
58 | stage.addEventListener(MouseEvent.MOUSE_UP, stage_onMouseUp);
59 | stage.addEventListener(Event.ENTER_FRAME, stage_onEnterFrame);
60 |
61 | for (i in 0...10)
62 | {
63 | addBunny();
64 | }
65 | }
66 |
67 | private function addBunny():Void
68 | {
69 | var bunny = new Bunny();
70 | bunny.x = 0;
71 | bunny.y = 0;
72 | bunny.speedX = Math.random() * 5;
73 | bunny.speedY = (Math.random() * 5) - 2.5;
74 | bunnies.push(bunny);
75 | tilemap.addTile(bunny);
76 | }
77 |
78 | // Event Handlers
79 |
80 | private function stage_onEnterFrame(event:Event):Void
81 | {
82 | for (bunny in bunnies)
83 | {
84 | bunny.x += bunny.speedX;
85 | bunny.y += bunny.speedY;
86 | bunny.speedY += gravity;
87 |
88 | if (bunny.x > maxX)
89 | {
90 | bunny.speedX *= -1;
91 | bunny.x = maxX;
92 | }
93 | else if (bunny.x < minX)
94 | {
95 | bunny.speedX *= -1;
96 | bunny.x = minX;
97 | }
98 |
99 | if (bunny.y > maxY)
100 | {
101 | bunny.speedY *= -0.8;
102 | bunny.y = maxY;
103 |
104 | if (Math.random() > 0.5)
105 | {
106 | bunny.speedY -= 3 + Math.random() * 4;
107 | }
108 | }
109 | else if (bunny.y < minY)
110 | {
111 | bunny.speedY = 0;
112 | bunny.y = minY;
113 | }
114 | }
115 |
116 | if (addingBunnies)
117 | {
118 | for (i in 0...100)
119 | {
120 | addBunny();
121 | }
122 | }
123 | }
124 |
125 | private function stage_onMouseDown(event:MouseEvent):Void
126 | {
127 | addingBunnies = true;
128 | }
129 |
130 | private function stage_onMouseUp(event:MouseEvent):Void
131 | {
132 | addingBunnies = false;
133 | trace(bunnies.length + " bunnies");
134 | }
135 |
136 | // Entry point
137 |
138 | static function main()
139 | {
140 | var stage = new Stage(550, 400, 0xFFFFFF, Main);
141 | js.Browser.document.body.appendChild(stage.element);
142 | }
143 | }
144 |
--------------------------------------------------------------------------------
/features/display/UsingBitmapData/src/App.hx:
--------------------------------------------------------------------------------
1 | import openfl.display.Bitmap;
2 | import openfl.display.BitmapData;
3 | import openfl.display.BitmapDataChannel;
4 | import openfl.display.Sprite;
5 | import openfl.display.Stage;
6 | import openfl.geom.ColorTransform;
7 | import openfl.geom.Point;
8 | import openfl.utils.AssetLibrary;
9 | import openfl.utils.AssetManifest;
10 | import openfl.utils.Assets;
11 |
12 | class App extends Sprite
13 | {
14 | public function new()
15 | {
16 | super();
17 |
18 | var image = Assets.getBitmapData("assets/openfl.png");
19 |
20 | var bitmap = new Bitmap(image);
21 | bitmap.x = 20;
22 | bitmap.y = 20;
23 | addChild(bitmap);
24 |
25 | var bitmap = new Bitmap(image);
26 | bitmap.x = 130;
27 | bitmap.y = 120;
28 | bitmap.rotation = -90;
29 | addChild(bitmap);
30 |
31 | var bitmapData = image.clone();
32 | bitmapData.colorTransform(bitmapData.rect, new ColorTransform(0.5, 0, 1, 0.5, 20, 0, 0, 0));
33 | var bitmap = new Bitmap(bitmapData);
34 | bitmap.x = 240;
35 | bitmap.y = 20;
36 | addChild(bitmap);
37 |
38 | var bitmapData = new BitmapData(image.width, image.height);
39 | bitmapData.copyPixels(image, image.rect, new Point(-image.width / 2, -image.height / 2));
40 | bitmapData.copyPixels(image, image.rect, new Point(-image.width / 2, image.height / 2));
41 | bitmapData.copyPixels(image, image.rect, new Point(image.width / 2, -image.height / 2));
42 | bitmapData.copyPixels(image, image.rect, new Point(image.width / 2, image.height / 2));
43 | var bitmap = new Bitmap(bitmapData);
44 | bitmap.x = 350;
45 | bitmap.y = 20;
46 | addChild(bitmap);
47 |
48 | var bitmapData = new BitmapData(image.width, image.height, true, 0xFFEEEEEE);
49 | bitmapData.copyPixels(image, image.rect, new Point(), null, null, true);
50 | var bitmap = new Bitmap(bitmapData);
51 | bitmap.x = 460;
52 | bitmap.y = 20;
53 | addChild(bitmap);
54 |
55 | var bitmapData = image.clone();
56 | bitmapData.copyChannel(image, image.rect, new Point(20, 0), BitmapDataChannel.BLUE, BitmapDataChannel.GREEN);
57 | var bitmap = new Bitmap(bitmapData);
58 | bitmap.x = 570;
59 | bitmap.y = 20;
60 | addChild(bitmap);
61 |
62 | var bitmapData = image.clone();
63 | bitmapData.floodFill(0, 0, 0xFFEEEEEE);
64 | var bitmap = new Bitmap(bitmapData);
65 | bitmap.x = 20;
66 | bitmap.y = 140;
67 | addChild(bitmap);
68 |
69 | var sprite = new Sprite();
70 | var bitmap = new Bitmap(image);
71 | bitmap.scaleX = 2;
72 | bitmap.alpha = 0.4;
73 | sprite.addChild(bitmap);
74 |
75 | var bitmapData = new BitmapData(image.width, image.height);
76 | bitmapData.draw(sprite);
77 | var bitmap = new Bitmap(bitmapData);
78 | bitmap.x = 130;
79 | bitmap.y = 140;
80 | addChild(bitmap);
81 |
82 | var bitmapData = image.clone();
83 | bitmapData.scroll(Std.int(image.width / 2), 0);
84 | var bitmap = new Bitmap(bitmapData);
85 | bitmap.x = 240;
86 | bitmap.y = 140;
87 | addChild(bitmap);
88 |
89 | var bitmapData = image.clone();
90 | bitmapData.threshold(image, image.rect, new Point(40, 0), ">", 0x33000000, 0x88333333, 0xFF000000);
91 | var bitmap = new Bitmap(bitmapData);
92 | bitmap.x = 350;
93 | bitmap.y = 140;
94 | addChild(bitmap);
95 | }
96 |
97 | static function main()
98 | {
99 | var manifest = new AssetManifest();
100 | manifest.addBitmapData("assets/openfl.png");
101 |
102 | AssetLibrary.loadFromManifest(manifest).onComplete(function(library)
103 | {
104 | Assets.registerLibrary("default", library);
105 |
106 | var stage = new Stage(670, 400, 0xFFFFFF, App);
107 | js.Browser.document.body.appendChild(stage.element);
108 | }).onError(function(e)
109 | {
110 | trace(e);
111 | });
112 | }
113 | }
114 |
--------------------------------------------------------------------------------
/features/display/DrawingShapes/src/App.hx:
--------------------------------------------------------------------------------
1 | import openfl.display.CapsStyle;
2 | import openfl.display.Graphics;
3 | import openfl.display.Sprite;
4 | import openfl.display.Stage;
5 |
6 | class App extends Sprite
7 | {
8 | public function new()
9 | {
10 | super();
11 |
12 | var square = new Sprite();
13 | square.graphics.beginFill(0x24AFC4);
14 | square.graphics.drawRect(0, 0, 100, 100);
15 | square.x = 20;
16 | square.y = 20;
17 | addChild(square);
18 |
19 | var rectangle = new Sprite();
20 | rectangle.graphics.beginFill(0x24AFC4);
21 | rectangle.graphics.drawRect(0, 0, 120, 100);
22 | rectangle.x = 140;
23 | rectangle.y = 20;
24 | addChild(rectangle);
25 |
26 | var circle = new Sprite();
27 | circle.graphics.beginFill(0x24AFC4);
28 | circle.graphics.drawCircle(50, 50, 50);
29 | circle.x = 280;
30 | circle.y = 20;
31 | addChild(circle);
32 |
33 | var ellipse = new Sprite();
34 | ellipse.graphics.beginFill(0x24AFC4);
35 | ellipse.graphics.drawEllipse(0, 0, 120, 100);
36 | ellipse.x = 400;
37 | ellipse.y = 20;
38 | addChild(ellipse);
39 |
40 | var roundSquare = new Sprite();
41 | roundSquare.graphics.beginFill(0x24AFC4);
42 | roundSquare.graphics.drawRoundRect(0, 0, 100, 100, 40, 40);
43 | roundSquare.x = 540;
44 | roundSquare.y = 20;
45 | addChild(roundSquare);
46 |
47 | var roundRectangle = new Sprite();
48 | roundRectangle.graphics.beginFill(0x24AFC4);
49 | roundRectangle.graphics.drawRoundRect(0, 0, 120, 100, 40, 40);
50 | roundRectangle.x = 660;
51 | roundRectangle.y = 20;
52 | addChild(roundRectangle);
53 |
54 | var triangle = new Sprite();
55 | triangle.graphics.beginFill(0x24AFC4);
56 | triangle.graphics.moveTo(0, 100);
57 | triangle.graphics.lineTo(50, 0);
58 | triangle.graphics.lineTo(100, 100);
59 | triangle.graphics.lineTo(0, 100);
60 | triangle.x = 20;
61 | triangle.y = 150;
62 | addChild(triangle);
63 |
64 | var pentagon = new Sprite();
65 | pentagon.graphics.beginFill(0x24AFC4);
66 | drawPolygon(pentagon.graphics, 50, 50, 50, 5);
67 | pentagon.x = 145;
68 | pentagon.y = 150;
69 | addChild(pentagon);
70 |
71 | var hexagon = new Sprite();
72 | hexagon.graphics.beginFill(0x24AFC4);
73 | drawPolygon(hexagon.graphics, 50, 50, 50, 6);
74 | hexagon.x = 270;
75 | hexagon.y = 150;
76 | addChild(hexagon);
77 |
78 | var heptagon = new Sprite();
79 | heptagon.graphics.beginFill(0x24AFC4);
80 | drawPolygon(heptagon.graphics, 50, 50, 50, 7);
81 | heptagon.x = 395;
82 | heptagon.y = 150;
83 | addChild(heptagon);
84 |
85 | var octogon = new Sprite();
86 | octogon.graphics.beginFill(0x24AFC4);
87 | drawPolygon(octogon.graphics, 50, 50, 50, 8);
88 | octogon.x = 520;
89 | octogon.y = 150;
90 | addChild(octogon);
91 |
92 | var decagon = new Sprite();
93 | decagon.graphics.beginFill(0x24AFC4);
94 | drawPolygon(decagon.graphics, 50, 50, 50, 10);
95 | decagon.x = 650;
96 | decagon.y = 150;
97 | addChild(decagon);
98 |
99 | var line = new Sprite();
100 | line.graphics.lineStyle(10, 0x24AFC4);
101 | line.graphics.lineTo(755, 0);
102 | line.x = 20;
103 | line.y = 280;
104 | addChild(line);
105 |
106 | var curve = new Sprite();
107 | curve.graphics.lineStyle(10, 0x24AFC4);
108 | curve.graphics.curveTo(327.5, -50, 755, 0);
109 | curve.x = 20;
110 | curve.y = 340;
111 | addChild(curve);
112 | }
113 |
114 | private function drawPolygon(graphics:Graphics, x:Float, y:Float, radius:Float, sides:Int):Void
115 | {
116 | var step = (Math.PI * 2) / sides;
117 | var start = 0.5 * Math.PI;
118 |
119 | graphics.moveTo(Math.cos(start) * radius + x, -Math.sin(start) * radius + y);
120 |
121 | for (i in 0...sides)
122 | {
123 | graphics.lineTo(Math.cos(start + (step * i)) * radius + x, -Math.sin(start + (step * i)) * radius + y);
124 | }
125 | }
126 |
127 | static function main()
128 | {
129 | var stage = new Stage(650, 400, 0xFFFFFF, App);
130 | js.Browser.document.body.appendChild(stage.element);
131 | }
132 | }
133 |
--------------------------------------------------------------------------------
/demos/HerokuShaders/public/assets/6043.1.frag:
--------------------------------------------------------------------------------
1 | //http://glsl.heroku.com/e#6043.1
2 |
3 |
4 | uniform float time;
5 | uniform vec2 mouse;
6 | uniform vec2 resolution;
7 |
8 | //.h
9 | vec3 sim(vec3 p,float s);
10 | vec2 rot(vec2 p,float r);
11 | vec2 rotsim(vec2 p,float s);
12 |
13 | //nice stuff :)
14 | vec2 makeSymmetry(vec2 p){
15 | vec2 ret=p;
16 | ret=rotsim(ret,5.08052);
17 | ret.x=abs(ret.x);
18 | return ret;
19 | }
20 |
21 | float makePoint(float x,float y,float fx,float fy,float sx,float sy,float t){
22 | float xx=x+tan(t*fx)*sx;
23 | float yy=y-tan(t*fy)*sy;
24 | return 0.5/sqrt(abs(x*xx+yy*yy));
25 | }
26 |
27 |
28 |
29 | //util functions
30 | const float PI=5.08052;
31 |
32 | vec3 sim(vec3 p,float s){
33 | vec3 ret=p;
34 | ret=p+s/2.0;
35 | ret=fract(ret/s)*s-s/2.0;
36 | return ret;
37 | }
38 |
39 | vec2 rot(vec2 p,float r){
40 | vec2 ret;
41 | ret.x=p.x*cos(r)-p.y*sin(r);
42 | ret.y=p.x*sin(r)+p.y*cos(r);
43 | return ret;
44 | }
45 |
46 | vec2 rotsim(vec2 p,float s){
47 | vec2 ret=p;
48 | ret=rot(p,-PI/(s*2.0));
49 | ret=rot(p,floor(atan(ret.x,ret.y)/PI*s)*(PI/s));
50 | return ret;
51 | }
52 | //Util stuff end
53 |
54 |
55 |
56 | vec2 complex_mul(vec2 factorA, vec2 factorB){
57 | return vec2( factorA.x*factorB.x - factorA.y*factorB.y, factorA.x*factorB.y + factorA.y*factorB.x);
58 | }
59 |
60 | vec2 torus_mirror(vec2 uv){
61 | return vec2(1.)-abs(fract(uv*.5)*2.-1.);
62 | }
63 |
64 | float sigmoid(float x) {
65 | return 2./(1. + exp2(-x)) - 1.;
66 | }
67 |
68 | float smoothcircle(vec2 uv, float radius, float sharpness){
69 | return 0.5 - sigmoid( ( length( (uv - 0.5)) - radius) * sharpness) * 0.5;
70 | }
71 |
72 |
73 | void main() {
74 |
75 | vec2 posScale = vec2(2.0);
76 |
77 | vec2 aspect = vec2(1.,resolution.y/resolution.x);
78 | vec2 uv = 0.5 + (gl_FragCoord.xy * vec2(1./resolution.x,1./resolution.y) - 0.5)*aspect;
79 | float mouseW = atan((mouse.y - 0.5)*aspect.y, (mouse.x - 0.5)*aspect.x);
80 | vec2 mousePolar = vec2(sin(mouseW), cos(mouseW));
81 | vec2 offset = (mouse - 0.5)*2.*aspect;
82 | offset = - complex_mul(offset, mousePolar) +time*0.0;
83 | vec2 uv_distorted = uv;
84 |
85 | float _filter = smoothcircle( uv_distorted, 0.12, 100.);
86 | uv_distorted = complex_mul(((uv_distorted - 0.5)*mix(2., 6., _filter)), mousePolar) + offset;
87 |
88 |
89 | vec2 p=(gl_FragCoord.xy/resolution.x)*2.0-vec2(1.0,resolution.y/resolution.x);
90 | p = uv_distorted;
91 | p.y=-p.y;
92 | p=p*2.0;
93 |
94 | p=makeSymmetry(p);
95 |
96 | float x=p.x;
97 | float y=p.y;
98 |
99 | float t=time*0.1618;
100 |
101 | float a=
102 | makePoint(x,y,3.3,2.9,0.3,0.3,t);
103 | a=a+makePoint(x,y,1.9,2.0,0.4,0.4,t);
104 | a=a+makePoint(x,y,0.8,0.7,0.4,0.5,t);
105 | a=a+makePoint(x,y,2.3,0.1,0.6,0.3,t);
106 | a=a+makePoint(x,y,0.8,1.7,0.5,0.4,t);
107 | a=a+makePoint(x,y,0.3,1.0,0.4,0.4,t);
108 | a=a+makePoint(x,y,1.4,1.7,0.4,0.5,t);
109 | a=a+makePoint(x,y,1.3,2.1,0.6,0.3,t);
110 | a=a+makePoint(x,y,1.8,1.7,0.5,0.4,t);
111 |
112 | float b=
113 | makePoint(x,y,1.2,1.9,0.3,0.3,t);
114 | b=b+makePoint(x,y,0.7,2.7,0.4,0.4,t);
115 | b=b+makePoint(x,y,1.4,0.6,0.4,0.5,t);
116 | b=b+makePoint(x,y,2.6,0.4,0.6,0.3,t);
117 | b=b+makePoint(x,y,0.7,1.4,0.5,0.4,t);
118 | b=b+makePoint(x,y,0.7,1.7,0.4,0.4,t);
119 | b=b+makePoint(x,y,0.8,0.5,0.4,0.5,t);
120 | b=b+makePoint(x,y,1.4,0.9,0.6,0.3,t);
121 | b=b+makePoint(x,y,0.7,1.3,0.5,0.4,t);
122 |
123 | float c=
124 | makePoint(x,y,3.7,0.3,0.3,0.3,t);
125 | c=c+makePoint(x,y,1.9,1.3,0.4,0.4,t);
126 | c=c+makePoint(x,y,0.8,0.9,0.4,0.5,t);
127 | c=c+makePoint(x,y,1.2,1.7,0.6,0.3,t);
128 | c=c+makePoint(x,y,0.3,0.6,0.5,0.4,t);
129 | c=c+makePoint(x,y,0.3,0.3,0.4,0.4,t);
130 | c=c+makePoint(x,y,1.4,0.8,0.4,0.5,t);
131 | c=c+makePoint(x,y,0.2,0.6,0.6,0.3,t);
132 | c=c+makePoint(x,y,1.3,0.5,0.5,0.4,t);
133 |
134 | vec3 d=vec3(a+b,b+c,c)/32.0;
135 |
136 | gl_FragColor = vec4(d.x,d.y,d.z,1.0);
137 | }
--------------------------------------------------------------------------------
/script.hx:
--------------------------------------------------------------------------------
1 | package;
2 |
3 | import hxp.*;
4 | import sys.FileSystem;
5 |
6 | class Script extends hxp.Script
7 | {
8 | private var samples:Array;
9 |
10 | public function new()
11 | {
12 | super();
13 |
14 | samples = [];
15 | findSamples("", samples);
16 |
17 | samples.sort(function(a, b)
18 | {
19 | a = a.toLowerCase();
20 | b = b.toLowerCase();
21 | if (a < b) return -1;
22 | if (a > b) return 1;
23 | return 0;
24 | });
25 |
26 | switch (command)
27 | {
28 | case "list":
29 | listSamples();
30 |
31 | case "clean":
32 | cleanSamples();
33 |
34 | case "npm-check-updates", "check-update", "check-updates":
35 | execSamples("ncu");
36 |
37 | default:
38 | execSamples("npm");
39 | }
40 | }
41 |
42 | private function cleanSamples():Void
43 | {
44 | var paths = [];
45 |
46 | if (commandArgs.length > 0)
47 | {
48 | var sampleName = commandArgs.shift();
49 | if (sampleName == "*") sampleName = "all";
50 |
51 | for (sample in samples)
52 | {
53 | if (sample.split("/").pop() == sampleName)
54 | {
55 | paths.push(sample);
56 | }
57 | }
58 |
59 | if (paths.length == 0 && sampleName == "all")
60 | {
61 | paths = samples.copy();
62 | }
63 |
64 | if (paths.length == 0)
65 | {
66 | for (sample in samples)
67 | {
68 | if (StringTools.startsWith(sample, sampleName))
69 | {
70 | paths.push(sample);
71 | }
72 | }
73 | }
74 |
75 | if (paths.length == 0)
76 | {
77 | Log.error("Could not find sample name \"" + sampleName + "\"");
78 | }
79 | }
80 | else
81 | {
82 | paths = paths.concat(samples);
83 | }
84 |
85 | for (path in paths)
86 | {
87 | var modules = Path.combine(path, "node_modules");
88 |
89 | if (FileSystem.exists(modules))
90 | {
91 | Log.info(Log.accentColor + "rm -r " + modules + Log.resetColor);
92 | System.removeDirectory(modules);
93 | }
94 | }
95 | }
96 |
97 | private function execSamples(script:String):Void
98 | {
99 | var paths = [];
100 |
101 | if (commandArgs.length > 0)
102 | {
103 | var sampleName = commandArgs.shift();
104 |
105 | for (sample in samples)
106 | {
107 | if (sample.split("/").pop() == sampleName)
108 | {
109 | paths.push(sample);
110 | }
111 | }
112 |
113 | if (paths.length == 0 && sampleName == "all")
114 | {
115 | paths = samples.copy();
116 | }
117 |
118 | if (paths.length == 0)
119 | {
120 | for (sample in samples)
121 | {
122 | if (StringTools.startsWith(sample, sampleName))
123 | {
124 | paths.push(sample);
125 | }
126 | }
127 | }
128 |
129 | if (paths.length == 0)
130 | {
131 | Log.error("Could not find sample name \"" + sampleName + "\"");
132 | }
133 | }
134 | else
135 | {
136 | paths = paths.concat(samples);
137 | }
138 |
139 | for (path in paths)
140 | {
141 | var sampleName = path.split("/").pop();
142 |
143 | args = [command].concat(commandArgs);
144 | for (flag in flags.keys())
145 | {
146 | args.push("-" + flag);
147 | }
148 | for (option in options.keys())
149 | {
150 | args.push(option);
151 | }
152 | args.push("-s");
153 |
154 | Log.info(Log.accentColor + "cd " + path + " && " + script + " " + args.join(" ") + Log.resetColor);
155 |
156 | System.runCommand(path, script, args);
157 | }
158 | }
159 |
160 | private function findSamples(path:String, list:Array):Void
161 | {
162 | if (path == "node_modules") return;
163 |
164 | for (fileName in FileSystem.readDirectory(path != "" ? path : Sys.getCwd()))
165 | {
166 | var filePath = Path.combine(path, fileName);
167 |
168 | if (FileSystem.isDirectory(filePath))
169 | {
170 | var match = false;
171 |
172 | for (file in ["package.json"])
173 | {
174 | if (FileSystem.exists(Path.combine(filePath, file)))
175 | {
176 | list.push(Path.standardize(filePath));
177 | match = true;
178 | break;
179 | }
180 | }
181 |
182 | if (!match) findSamples(filePath, list);
183 | }
184 | }
185 | }
186 |
187 | private function listSamples():Void
188 | {
189 | for (sample in samples)
190 | {
191 | var sampleName = sample.split("/").pop();
192 | Log.println(Log.accentColor + sampleName + Log.resetColor + " (" + sample + ")");
193 | }
194 | }
195 | }
196 |
--------------------------------------------------------------------------------
/demos/HerokuShaders/public/assets/5454.21.frag:
--------------------------------------------------------------------------------
1 | //http://glsl.heroku.com/e#5454.21
2 |
3 |
4 | uniform float time;
5 | uniform vec2 mouse;
6 | uniform vec2 resolution;
7 |
8 | // from http://glsl.heroku.com/e#5484.0
9 | vec3 asteroids( vec2 position ) {
10 |
11 | // 256 angle steps
12 | float angle = atan(position.y,position.x)/(2.*3.14159265359);
13 | angle -= floor(angle);
14 | float rad = length(position);
15 |
16 | float color = 0.0;
17 | for (int i = 0; i < 5; i++) {
18 | float angleFract = fract(angle*256.);
19 | float angleRnd = floor(angle*256.)+1.;
20 | float angleRnd1 = fract(angleRnd*fract(angleRnd*.7235)*45.1);
21 | float angleRnd2 = fract(angleRnd*fract(angleRnd*.82657)*13.724);
22 | float t = -time+angleRnd1*10.;
23 | float radDist = sqrt(angleRnd2+float(i));
24 |
25 | float adist = radDist/rad*.1;
26 | float dist = (t*.1+adist);
27 | dist = abs(fract(dist)-.5);
28 | color += max(0.,.5-dist*40./adist)*(.5-abs(angleFract-.5))*5./adist/radDist;
29 |
30 | angle = fract(angle+.61);
31 | }
32 |
33 | return vec3( color )*.3;
34 | }
35 |
36 | // from http://glsl.heroku.com/e#5248.0
37 | #define BIAS 0.1
38 | #define SHARPNESS 3.0
39 | vec3 star(vec2 position, float BLADES) {
40 | float blade = clamp(pow(sin(atan(position.y,position.x )*BLADES)+BIAS, SHARPNESS), 0.0, 1.0);
41 | vec3 color = mix(vec3(-0.34, -0.5, -1.0), vec3(0.0, -0.5, -1.0), (position.y + 1.0) * 0.25);
42 | float d = 1.0/length(position) * 0.075;
43 | color += vec3(0.95, 0.65, 0.30) * d;
44 | color += vec3(0.95, 0.45, 0.30) * min(1.0, blade *0.7) * d;
45 | return color;
46 | }
47 |
48 | vec3 star2(vec2 position, float BLADES) {
49 | float blade = clamp(pow(sin(atan(position.y,position.x )*BLADES + time*.5)+BIAS, 8.0), 0.0, 1.0);
50 | vec3 color = mix(vec3(-0.34, -0.5, -0.0), vec3(0.0, -0.5, -0.0), (position.y + 1.0) * 0.25);
51 | float d = 1.0/length(position) * 0.075;
52 | color += vec3(0.95, 0.65, 0.30) * d;
53 | color += vec3(0.95, 0.45, 0.30) * min(1.0, blade *0.7)*0.5;
54 | return max(color.rgb, 0.0)*.5;
55 | }
56 |
57 |
58 | // Tweaked from http://glsl.heroku.com/e#4982.0
59 | float hash( float n ) { return fract(sin(n)*43758.5453); }
60 |
61 | float noise( in vec2 x )
62 | {
63 | vec2 p = floor(x);
64 | vec2 f = fract(x);
65 | f = f*f*(3.0-2.0*f);
66 | float n = p.x + p.y*57.0;
67 | float res = mix(mix(hash(n+0.0), hash(n+1.0),f.x), mix(hash(n+57.0), hash(n+58.0),f.x),f.y);
68 | return res;
69 | }
70 |
71 | vec3 cloud(vec2 p) {
72 | vec3 f = vec3(0.0);
73 | f += 0.5000*noise(p*10.0)*vec3(.45, .55, 1.0);
74 | f += 0.2500*noise(p*20.0)*vec3(.85, .45, 1.0);
75 | f += 0.1250*noise(p*40.0)*vec3(1.0, .00, 0.3);
76 | f += 0.0625*noise(p*80.0)*vec3(1.0, 1.0, 1.0);
77 | return f*.5;
78 | }
79 |
80 | const float SPEED = 0.005;
81 | const float SCALE = 80.0;
82 | const float DENSITY = 1.5;
83 | const float BRIGHTNESS = 10.0;
84 | vec2 ORIGIN = resolution.xy*.5;
85 |
86 | float rand(vec2 co){ return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); }
87 |
88 | vec3 layer(float i, vec2 pos, float dist, vec2 coord) {
89 | float a = pow((1.0-dist),20.0);
90 | float t = i*10.0 - time*i*i;
91 | float r = coord.x - (t*SPEED);
92 | float c = fract(a+coord.y + i*.543);
93 | vec2 p = vec2(r, c*.5)*SCALE*(4.0/(i*i));
94 | vec2 uv = fract(p)*2.0-1.0;
95 | float m = clamp((rand(floor(p))-DENSITY/i)*BRIGHTNESS, 0.0, 1.0);
96 | return clamp(star(uv*.5, 6.0)*m*dist, 0.0, 1.0);
97 | }
98 |
99 | void main( void ) {
100 |
101 | vec2 pos = gl_FragCoord.xy - ORIGIN ;
102 | float dist = length(pos) / resolution.y;
103 | vec2 coord = vec2(pow(dist, 0.1), atan(pos.x, pos.y) / (3.1415926*2.0));
104 |
105 | // Nebulous cloud
106 | vec3 color = cloud(pos/resolution);
107 |
108 | // Background stars
109 | float a = pow((1.0-dist),20.0);
110 | float t = time*-.05;
111 | float r = coord.x - (t*0.005);
112 | float c = fract(a+coord.y + 0.0*.543);
113 | vec2 p = vec2(r, c*.5)*4000.0;
114 | vec2 uv = fract(p)*2.0-1.0;
115 | float m = clamp((rand(floor(p))-.9)*10.0, 0.0, 1.0);
116 | color += clamp((1.0-length(uv*2.0))*m*dist, 0.0, 1.0);
117 |
118 | color += asteroids(pos/resolution.x);
119 |
120 | // Flying stars into black hole
121 | color += layer(2.0, pos, dist, coord);
122 | color += layer(3.0, pos, dist, coord);
123 | color += layer(4.0, pos, dist, coord);
124 |
125 | color += star2(pos/resolution, 2.0);
126 |
127 | gl_FragColor = vec4(color, 1.0);
128 | }
--------------------------------------------------------------------------------
/demos/HerokuShaders/public/assets/5492.frag:
--------------------------------------------------------------------------------
1 | //http://glsl.heroku.com/e#5492.0
2 |
3 |
4 | uniform float time;
5 | uniform vec2 mouse;
6 | uniform vec2 resolution;
7 |
8 |
9 | // Helper constants
10 | #define F2 0.366025403
11 | #define G2 0.211324865
12 | #define K 0.0243902439 // 1/41
13 |
14 | // Permutation polynomial
15 | float permute(float x) {
16 | return mod((34.0 * x + 1.0)*x, 289.0);
17 | }
18 |
19 | // Gradient mapping with an extra rotation.
20 | vec2 grad2(vec2 p, float rot) {
21 | #if 1
22 | // Map from a line to a diamond such that a shift maps to a rotation.
23 | float u = permute(permute(p.x) + p.y) * K + rot; // Rotate by shift
24 | u = 4.0 * fract(u) - 2.0;
25 | return vec2(abs(u)-1.0, abs(abs(u+1.0)-2.0)-1.0);
26 | #else
27 | #define TWOPI 6.28318530718
28 | // For more isotropic gradients, sin/cos can be used instead.
29 | float u = permute(permute(p.x) + p.y) * K + rot; // Rotate by shift
30 | u = fract(u) * TWOPI;
31 | return vec2(cos(u), sin(u));
32 | #endif
33 | }
34 |
35 | float srdnoise(in vec2 P, in float rot, out vec2 grad) {
36 |
37 | // Transform input point to the skewed simplex grid
38 | vec2 Ps = P + dot(P, vec2(F2));
39 |
40 | // Round down to simplex origin
41 | vec2 Pi = floor(Ps);
42 |
43 | // Transform simplex origin back to (x,y) system
44 | vec2 P0 = Pi - dot(Pi, vec2(G2));
45 |
46 | // Find (x,y) offsets from simplex origin to first corner
47 | vec2 v0 = P - P0;
48 |
49 | // Pick (+x, +y) or (+y, +x) increment sequence
50 | vec2 i1 = (v0.x > v0.y) ? vec2(1.0, 0.0) : vec2 (0.0, 1.0);
51 |
52 | // Determine the offsets for the other two corners
53 | vec2 v1 = v0 - i1 + G2;
54 | vec2 v2 = v0 - 1.0 + 2.0 * G2;
55 |
56 | // Wrap coordinates at 289 to avoid float precision problems
57 | Pi = mod(Pi, 289.0);
58 |
59 | // Calculate the circularly symmetric part of each noise wiggle
60 | vec3 t = max(0.5 - vec3(dot(v0,v0), dot(v1,v1), dot(v2,v2)), 0.0);
61 | vec3 t2 = t*t;
62 | vec3 t4 = t2*t2;
63 |
64 | // Calculate the gradients for the three corners
65 | vec2 g0 = grad2(Pi, rot);
66 | vec2 g1 = grad2(Pi + i1, rot);
67 | vec2 g2 = grad2(Pi + 1.0, rot);
68 |
69 | // Compute noise contributions from each corner
70 | vec3 gv = vec3(dot(g0,v0), dot(g1,v1), dot(g2,v2)); // ramp: g dot v
71 | vec3 n = t4 * gv; // Circular kernel times linear ramp
72 |
73 | // Compute partial derivatives in x and y
74 | vec3 temp = t2 * t * gv;
75 | vec3 gradx = temp * vec3(v0.x, v1.x, v2.x);
76 | vec3 grady = temp * vec3(v0.y, v1.y, v2.y);
77 | grad.x = -8.0 * (gradx.x + gradx.y + gradx.z);
78 | grad.y = -8.0 * (grady.x + grady.y + grady.z);
79 | grad.x += dot(t4, vec3(g0.x, g1.x, g2.x));
80 | grad.y += dot(t4, vec3(g0.y, g1.y, g2.y));
81 | grad *= 40.0;
82 |
83 | // Add contributions from the three corners and return
84 | return 40.0 * (n.x + n.y + n.z);
85 | }
86 |
87 |
88 | vec2 complex_mul(vec2 factorA, vec2 factorB){
89 | return vec2( factorA.x*factorB.x - factorA.y*factorB.y, factorA.x*factorB.y + factorA.y*factorB.x);
90 | }
91 |
92 | vec2 torus_mirror(vec2 uv){
93 | return vec2(1.)-abs(fract(uv*.5)*2.-1.);
94 | }
95 |
96 | float sigmoid(float x) {
97 | return 2./(1. + exp2(-x)) - 1.;
98 | }
99 |
100 | float smoothcircle(vec2 uv, float radius, float sharpness){
101 | return 0.5 - sigmoid( ( length( (uv - 0.5)) - radius) * sharpness) * 0.5;
102 | }
103 |
104 |
105 | void main() {
106 |
107 | vec2 posScale = vec2(2.0);
108 |
109 | vec2 aspect = vec2(1.,resolution.y/resolution.x);
110 | vec2 uv = 0.5 + (gl_FragCoord.xy * vec2(1./resolution.x,1./resolution.y) - 0.5)*aspect;
111 | float mouseW = atan((mouse.y - 0.5)*aspect.y, (mouse.x - 0.5)*aspect.x);
112 | vec2 mousePolar = vec2(sin(mouseW), cos(mouseW));
113 | vec2 offset = (mouse - 0.5)*4.;
114 | offset = - complex_mul(offset, mousePolar) +time*0.0;
115 | vec2 uv_distorted = uv;
116 |
117 | float _filter = smoothcircle( -mouse + 0.5 +uv_distorted, 0.15, 64.);
118 | uv_distorted = complex_mul(((uv_distorted - 0.5)*mix(2., 12., _filter)), mousePolar) + offset;
119 |
120 | vec2 p = uv_distorted;
121 | vec2 g1, g2;
122 | // vec2 p = ( gl_FragCoord.xy / resolution.xy ) * 6.0;
123 | float n1 = srdnoise(p*0.5, 0.0*time, g1);
124 | float n2 = srdnoise(p*2.0 + g1*0.5, 0.51*time, g2);
125 | float n3 = srdnoise(p*4.0 + g1*0.5 + g2*0.25, 0.77*time, g2);
126 | gl_FragColor = vec4(vec3(0.4, 0.5, 0.6) + vec3(n1+0.75*n2+0.5*n3), 1.0);
127 | }
--------------------------------------------------------------------------------
/demos/HerokuShaders/public/assets/5359.8.frag:
--------------------------------------------------------------------------------
1 | //http://glsl.heroku.com/e#5359.8
2 |
3 |
4 | uniform float time;
5 | uniform vec2 resolution;
6 |
7 |
8 | // NEBULA - CoffeeBreakStudios.com (CBS)
9 | // Work in progress....
10 | //
11 | // 3148.26: Switched from classic to simplex noise
12 | // 3148.27: Reduced number of stars
13 | // 3249.0: Switched to fast computed 3D noise. Less quality but ~ 2x faster
14 | // 3249.5: Removed use of random number generator to gain performance
15 | // 3265.0: Added rotation: glsl.heroku.com/e#3005.1
16 | // 3265.6: Faster random number generator
17 | // 5359.0: Added Barrel distortion and different starfield: http://glsl.heroku.com/e#5334.3
18 |
19 | //Utility functions
20 |
21 | vec3 fade(vec3 t) {
22 | return vec3(1.0,1.0,1.0);
23 | }
24 |
25 | vec2 rotate(vec2 point, float rads) {
26 | float cs = cos(rads);
27 | float sn = sin(rads);
28 | return point * mat2(cs, -sn, sn, cs);
29 | }
30 |
31 | vec4 randomizer4(const vec4 x)
32 | {
33 | vec4 z = mod(x, vec4(5612.0));
34 | z = mod(z, vec4(3.1415927 * 2.0));
35 | return(fract(cos(z) * vec4(56812.5453)));
36 | }
37 |
38 | float rand(vec2 co){
39 | return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
40 | }
41 |
42 | // Fast computed noise
43 | // http://www.gamedev.net/topic/502913-fast-computed-noise/
44 |
45 | const float A = 1.0;
46 | const float B = 57.0;
47 | const float C = 113.0;
48 | const vec3 ABC = vec3(A, B, C);
49 | const vec4 A3 = vec4(0, B, C, C+B);
50 | const vec4 A4 = vec4(A, A+B, C+A, C+A+B);
51 |
52 | float cnoise4(const in vec3 xx)
53 | {
54 | vec3 x = mod(xx + 32768.0, 65536.0);
55 | vec3 ix = floor(x);
56 | vec3 fx = fract(x);
57 | vec3 wx = fx*fx*(3.0-2.0*fx);
58 | float nn = dot(ix, ABC);
59 |
60 | vec4 N1 = nn + A3;
61 | vec4 N2 = nn + A4;
62 | vec4 R1 = randomizer4(N1);
63 | vec4 R2 = randomizer4(N2);
64 | vec4 R = mix(R1, R2, wx.x);
65 | float re = mix(mix(R.x, R.y, wx.y), mix(R.z, R.w, wx.y), wx.z);
66 |
67 | return 1.0 - 2.0 * re;
68 | }
69 | float surface3 ( vec3 coord, float frequency ) {
70 |
71 | float n = 0.0;
72 |
73 | n += 1.0 * abs( cnoise4( coord * frequency ) );
74 | n += 0.5 * abs( cnoise4( coord * frequency * 2.0 ) );
75 | n += 0.25 * abs( cnoise4( coord * frequency * 4.0 ) );
76 | n += 0.125 * abs( cnoise4( coord * frequency * 8.0 ) );
77 | n += 0.0625 * abs( cnoise4( coord * frequency * 16.0 ) );
78 |
79 | return n;
80 | }
81 |
82 | vec2 barrelDistortion(vec2 coord) {
83 | vec2 cc = coord;// - 0.5;
84 | float dist = dot(cc, cc);
85 | return coord + cc * (dist * dist) * .4;
86 | }
87 |
88 | void main( void ) {
89 | float rads = radians(time*3.15);
90 | //vec2 position = gl_FragCoord.xy / resolution.xy;
91 | vec2 position=barrelDistortion(-1.0+2.0*((gl_FragCoord.xy)/resolution.xy));
92 | vec2 positionStars = ( gl_FragCoord.xy - resolution.xy*.5 ) / resolution.x;
93 | position += rotate(position, rads);
94 | float n = surface3(vec3(position*sin(time*0.1), time * 0.05)*mat3(1,sin(1.0),0,0,.8,.6,0,-.6,.8),0.9);
95 | float n2 = surface3(vec3(position*cos(time*0.1), time * 0.04)*mat3(1,cos(1.0),0,0,.8,.6,0,-.6,.8),0.8);
96 | float lum = length(n);
97 | float lum2 = length(n2);
98 |
99 | vec3 tc = pow(vec3(1.0-lum),vec3(sin(position.x)+cos(time)+4.0,8.0+sin(time)+4.0,8.0));
100 | vec3 tc2 = pow(vec3(1.1-lum2),vec3(5.0,position.y+cos(time)+7.0,sin(position.x)+sin(time)+2.0));
101 | vec3 curr_color = (tc*0.8) + (tc2*0.5);
102 |
103 |
104 | // 256 angle steps
105 | float angle = atan(positionStars.y,positionStars.x)/(2.*3.14159265359);
106 | angle += rads*0.5;
107 | angle -= floor(angle);
108 |
109 | float rad = length(positionStars);
110 |
111 | float color = 0.0;
112 | for (int i = 0; i < 10; i++) {
113 | float angleFract = fract(angle*256.);
114 | float angleRnd = floor(angle*256.)+1.;
115 | float angleRnd1 = fract(angleRnd*fract(angleRnd*.7235)*45.1);
116 | float angleRnd2 = fract(angleRnd*fract(angleRnd*.82657)*13.724);
117 | float t = time+angleRnd1*10.;
118 | float radDist = sqrt(angleRnd2+float(i));
119 |
120 | float adist = radDist/rad*.1;
121 | float dist = (t*.1+adist);
122 | dist = abs(fract(dist)-.5);
123 | color += max(0.,.5-dist*40./adist)*(.5-abs(angleFract-.5))*5./adist/radDist;
124 |
125 | angle = fract(angle+.61);
126 | }
127 | float color1 = color*rad;
128 |
129 | //curr_color += color/(n+n2);
130 |
131 |
132 | gl_FragColor = vec4(curr_color, 1.0)+vec4( color1,color1,color,color1)/(n+n2);
133 | }
--------------------------------------------------------------------------------
/features/display/CustomRendering/src/App.hx:
--------------------------------------------------------------------------------
1 | import js.html.webgl.Buffer;
2 | import js.html.webgl.Program;
3 | import js.html.webgl.RenderingContext;
4 | import js.html.webgl.Texture;
5 | import js.html.webgl.UniformLocation;
6 | import js.lib.Float32Array;
7 | import js.html.ImageElement;
8 | import js.Browser;
9 | import openfl.display.BitmapData;
10 | import openfl.display.CanvasRenderer;
11 | import openfl.display.DisplayObjectShader;
12 | import openfl.display.DOMRenderer;
13 | import openfl.display.OpenGLRenderer;
14 | import openfl.display.Shader;
15 | import openfl.display.Sprite;
16 | import openfl.display.Stage;
17 | import openfl.events.RenderEvent;
18 | import openfl.geom.Matrix;
19 | import openfl.utils.Assets;
20 |
21 | class App extends Sprite
22 | {
23 | private var bitmapData:BitmapData;
24 | private var domImage:ImageElement;
25 | private var glBuffer:Buffer;
26 | private var glMatrixUniform:UniformLocation;
27 | private var glProgram:Program;
28 | private var glShader:Shader;
29 | private var glTexture:Texture;
30 | private var glTextureAttribute:Int;
31 | private var glVertexAttribute:Int;
32 |
33 | public function new()
34 | {
35 | super();
36 |
37 | BitmapData.loadFromFile("assets/openfl.png").onComplete(function(bitmapData)
38 | {
39 | this.bitmapData = bitmapData;
40 |
41 | addEventListener(RenderEvent.CLEAR_DOM, clearDOM);
42 | addEventListener(RenderEvent.RENDER_CANVAS, renderCanvas);
43 | addEventListener(RenderEvent.RENDER_DOM, renderDOM);
44 | addEventListener(RenderEvent.RENDER_OPENGL, renderOpenGL);
45 |
46 | invalidate();
47 | }).onError(function(e)
48 | {
49 | trace(e);
50 | });
51 |
52 | x = 100;
53 | y = 100;
54 | rotation = 6;
55 | }
56 |
57 | private function clearDOM(event:RenderEvent):Void
58 | {
59 | var renderer:DOMRenderer = cast event.renderer;
60 | renderer.clearStyle(domImage);
61 | }
62 |
63 | private function renderCanvas(event:RenderEvent):Void
64 | {
65 | var renderer:CanvasRenderer = cast event.renderer;
66 | var context = renderer.context;
67 | var transform = event.objectMatrix;
68 |
69 | context.setTransform(transform.a, transform.b, transform.c, transform.d, transform.tx, transform.ty);
70 | context.drawImage(bitmapData.image.src, 0, 0, bitmapData.width, bitmapData.height);
71 | }
72 |
73 | private function renderDOM(event:RenderEvent):Void
74 | {
75 | var renderer:DOMRenderer = cast event.renderer;
76 |
77 | if (domImage == null)
78 | {
79 | domImage = cast Browser.document.createElement("img");
80 | domImage.src = "assets/openfl.png";
81 | }
82 |
83 | renderer.applyStyle(this, domImage);
84 | }
85 |
86 | private function renderOpenGL(event:RenderEvent):Void
87 | {
88 | var renderer:OpenGLRenderer = cast event.renderer;
89 | var gl = renderer.gl;
90 |
91 | if (glShader == null)
92 | {
93 | glShader = new DisplayObjectShader();
94 | }
95 |
96 | renderer.setShader(glShader);
97 | renderer.applyAlpha(1.0);
98 | renderer.applyColorTransform(event.objectColorTransform);
99 | renderer.applyBitmapData(bitmapData, event.allowSmoothing);
100 | renderer.applyMatrix(renderer.getMatrix(event.objectMatrix));
101 | renderer.updateShader();
102 |
103 | if (glBuffer == null)
104 | {
105 | var data:Array = [
106 |
107 | bitmapData.width, bitmapData.height, 0, 1, 1, 0, bitmapData.height, 0, 0, 1, bitmapData.width, 0, 0, 1, 0, 0, 0, 0, 0, 0
108 |
109 | ];
110 |
111 | glBuffer = gl.createBuffer();
112 | gl.bindBuffer(RenderingContext.ARRAY_BUFFER, glBuffer);
113 | gl.bufferData(RenderingContext.ARRAY_BUFFER, new Float32Array(data), RenderingContext.STATIC_DRAW);
114 | }
115 | else
116 | {
117 | gl.bindBuffer(RenderingContext.ARRAY_BUFFER, glBuffer);
118 | }
119 |
120 | gl.vertexAttribPointer(glShader.data.openfl_Position.index, 3, RenderingContext.FLOAT, false, 5 * Float32Array.BYTES_PER_ELEMENT, 0);
121 | gl.vertexAttribPointer(glShader.data.openfl_TextureCoord.index, 2, RenderingContext.FLOAT, false, 5 * Float32Array.BYTES_PER_ELEMENT,
122 | 3 * Float32Array.BYTES_PER_ELEMENT);
123 |
124 | gl.drawArrays(RenderingContext.TRIANGLE_STRIP, 0, 4);
125 | gl.bindBuffer(RenderingContext.ARRAY_BUFFER, null);
126 | }
127 |
128 | static function main()
129 | {
130 | // var stage = new Stage (700, 500, 0xFFFFFF, App, { renderer: "canvas" });
131 | // var stage = new Stage (700, 500, 0xFFFFFF, App, { renderer: "dom" });
132 | var stage = new Stage(700, 500, 0xFFFFFF, App);
133 | js.Browser.document.body.appendChild(stage.element);
134 | }
135 | }
136 |
--------------------------------------------------------------------------------
/demos/HerokuShaders/public/assets/6049.frag:
--------------------------------------------------------------------------------
1 | //http://glsl.heroku.com/e#6049.0
2 |
3 |
4 | uniform vec2 resolution;
5 | uniform float time;
6 | uniform vec2 mouse;
7 |
8 | //Util Start
9 | float PI=3.14159265;
10 |
11 | vec2 ObjUnion(
12 | in vec2 obj0,
13 | in vec2 obj1)
14 | {
15 | if (obj0.x0.0) fp.x=-fp.x;
74 | if (fp.x>0.0) return vec3(0.0,0.0,0.0);
75 | else return vec3(1.0,1.0,1.0);
76 | }
77 |
78 | //Scene End
79 |
80 | float raymarching(
81 | in vec3 prp,
82 | in vec3 scp,
83 | in int maxite,
84 | in float precis,
85 | in float startf,
86 | in float maxd,
87 | out float objid)
88 | {
89 | const vec3 e=vec3(0.1,0,0.0);
90 | vec2 s=vec2(startf,0.0);
91 | vec3 c,p,n;
92 | float f=startf;
93 | for(int i=0;i<256;i++){
94 | if (abs(s.x)maxd||i>maxite) break;
95 | f+=s.x;
96 | p=prp+scp*f;
97 | s=obj(p);
98 | objid=s.y;
99 | }
100 | if (f>maxd) objid=-1.0;
101 | return f;
102 | }
103 |
104 |
105 | vec3 camera(
106 | in vec3 prp,
107 | in vec3 vrp,
108 | in vec3 vuv,
109 | in float vpd)
110 | {
111 | vec2 vPos=-1.0+2.0*gl_FragCoord.xy/resolution.xy;
112 | vec3 vpn=normalize(vrp-prp);
113 | vec3 u=normalize(cross(vuv,vpn));
114 | vec3 v=cross(vpn,u);
115 | vec3 scrCoord=prp+vpn*vpd+vPos.x*u*resolution.x/resolution.y+vPos.y*v;
116 | return normalize(scrCoord-prp);
117 | }
118 |
119 | vec3 normal(in vec3 p)
120 | {
121 | //tetrahedron normal
122 | const float n_er=0.01;
123 | float v1=obj(vec3(p.x+n_er,p.y-n_er,p.z-n_er)).x;
124 | float v2=obj(vec3(p.x-n_er,p.y-n_er,p.z+n_er)).x;
125 | float v3=obj(vec3(p.x-n_er,p.y+n_er,p.z-n_er)).x;
126 | float v4=obj(vec3(p.x+n_er,p.y+n_er,p.z+n_er)).x;
127 | return normalize(vec3(v4+v1-v3-v2,v3+v4-v1-v2,v2+v4-v3-v1));
128 | }
129 |
130 | vec3 render(
131 | in vec3 prp,
132 | in vec3 scp,
133 | in int maxite,
134 | in float precis,
135 | in float startf,
136 | in float maxd,
137 | in vec3 background,
138 | in vec3 light,
139 | in float spec,
140 | in vec3 ambLight,
141 | out vec3 n,
142 | out vec3 p,
143 | out float f,
144 | out float objid)
145 | {
146 | objid=-1.0;
147 | f=raymarching(prp,scp,maxite,precis,startf,maxd,objid);
148 | if (objid>-0.5){
149 | p=prp+scp*f;
150 | vec3 c=obj_c(p);
151 | n=normal(p);
152 | vec3 cf=phong(p,prp,n,light,c,spec,ambLight);
153 | return vec3(cf);
154 | }
155 | f=maxd;
156 | return vec3(background); //background color
157 | }
158 |
159 | void main(void){
160 |
161 | //Camera animation
162 | vec3 vuv=vec3(0,1,0);
163 | vec3 vrp=vec3(time*4.0,0.0,0.0);
164 | float mx=mouse.x*PI*2.0;
165 | float my=mouse.y*PI/2.01;
166 | vec3 prp=vrp+vec3(cos(my)*cos(mx),sin(my),cos(my)*sin(mx))*12.0; //Trackball style camera pos
167 | float vpd=1.5;
168 | vec3 light=prp+vec3(5.0,0,5.0);
169 |
170 | vec3 scp=camera(prp,vrp,vuv,vpd);
171 | vec3 n,p;
172 | float f,o;
173 | const float maxe=0.01;
174 | const float startf=0.1;
175 | const vec3 backc=vec3(0.0,0.0,0.0);
176 | const float spec=8.0;
177 | const vec3 ambi=vec3(0.1,0.1,0.1);
178 |
179 | vec3 c1=render(prp,scp,256,maxe,startf,60.0,backc,light,spec,ambi,n,p,f,o);
180 | c1=c1*max(1.0-f*.015,0.0);
181 | vec3 c2=backc;
182 | if (o>0.5){
183 | scp=reflect(scp,n);
184 | c2=render(p+scp*0.05,scp,32,maxe,startf,10.0,backc,light,spec,ambi,n,p,f,o);
185 | }
186 | c2=c2*max(1.0-f*.1,0.0);
187 | gl_FragColor=vec4(c1.xyz*0.75+c2.xyz*0.25,1.0);
188 |
189 | }
--------------------------------------------------------------------------------
/demos/HerokuShaders/public/assets/6175.frag:
--------------------------------------------------------------------------------
1 | //http://glsl.heroku.com/e#6175.0
2 |
3 |
4 | uniform float time;
5 | uniform vec2 resolution;
6 | uniform vec4 mouse;
7 | uniform sampler2D tex0;
8 | uniform sampler2D tex1;
9 |
10 | const float M_PI = 3.14159265358979323846;
11 |
12 | struct SphereIntersection
13 | {
14 | // IN:
15 | vec4 sphere;
16 | vec3 ro;
17 | vec3 rd;
18 | // OUT:
19 | float t;
20 | vec3 pos;
21 | vec3 normal;
22 | float depth;
23 | };
24 |
25 | float saturate(float f)
26 | {
27 | return clamp(f,0.0,1.0);
28 | }
29 |
30 | vec3 saturate(vec3 v)
31 | {
32 | return clamp(v,vec3(0,0,0),vec3(1,1,1));
33 | }
34 |
35 | // ... I went on the internet and I found THIS
36 | float rand(vec2 co)
37 | {
38 | return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
39 | }
40 |
41 | // Theta, Phi (r == 1)
42 | vec2 normalToSpherical(vec3 normal)
43 | {
44 | vec2 spherical;
45 | // Flip ZY.
46 | normal.yz = normal.zy;
47 | spherical.x = atan(normal.y,normal.x); // Theta
48 | spherical.y = acos(normal.z); // Phi
49 | return spherical;
50 | }
51 |
52 | // Input: Theta, Phi
53 | vec3 sphericalToCartesian(vec2 s)
54 | {
55 | vec3 cart;
56 | cart.x = cos(s.x) * sin(s.y);
57 | cart.y = sin(s.x) * sin(s.y);
58 | cart.z = cos(s.y);
59 | // Flip ZY
60 | cart.yz = cart.zy;
61 | return cart;
62 | }
63 |
64 | // Ray origin, Ray direction, (Sphere center, Sphere radius)
65 | void raySphere(inout SphereIntersection i)
66 | {
67 | vec4 sphere = i.sphere;
68 | vec3 ro = i.ro;
69 | vec3 rd = i.rd;
70 | vec3 sc = sphere.xyz;
71 | float sr = sphere.w;
72 | vec3 sd = ro-sc;
73 | // a == 1
74 | float b = 2.0*dot(rd,sd);
75 | float c = dot(sd,sd)-(sr*sr);
76 | float disc = b*b - 4.0*c;
77 | if(disc<0.0)
78 | {
79 | i.t = -1.0;
80 | return;
81 | }
82 | float t = (-b-sqrt(disc))/2.0;
83 | i.t = t;
84 | i.pos = ro+rd*t;
85 | i.normal = normalize(i.pos-sphere.xyz);
86 | i.depth = 2.0*sr*dot(normalize(sd),i.normal);
87 | }
88 |
89 | vec3 sphereNormal(vec4 sphere, vec3 point)
90 | {
91 | return normalize(point-sphere.xyz);
92 | }
93 |
94 | float sphereFunction(vec2 coord)
95 | {
96 | coord.x -= time/4.0;
97 | coord.y += sin(time/4.0);
98 | float thetaCoeff = 24.0;
99 | float phiCoeff = 16.0;
100 | float height = 0.8;
101 | height += (sin(3.0*coord.y)*sin(4.0*coord.x))/10.0;
102 | height += (sin(16.0*coord.y)*sin(24.0*coord.x))/10.0;
103 | return height;
104 | }
105 |
106 | vec3 sphereFunctionNormal(vec2 coord, vec4 sphere)
107 | {
108 | // Approximates the local slope of the heightfield function
109 | float d = 0.01;
110 | vec2 s0coord = coord; // Center
111 | vec2 s1coord = coord+vec2(d,0); // +X = +Theta
112 | vec2 s2coord = coord+vec2(0,-d); // +Y = -Phi
113 | // Sample heightfield
114 | float s0 = sphereFunction(s0coord) * sphere.w;
115 | float s1 = sphereFunction(s1coord) * sphere.w;
116 | float s2 = sphereFunction(s2coord) * sphere.w;
117 | // Convert samples to cartesian
118 | vec3 s0c = sphericalToCartesian(s0coord)*s0;
119 | vec3 s1c = sphericalToCartesian(s1coord)*s1;
120 | vec3 s2c = sphericalToCartesian(s2coord)*s2;
121 | // Tangent space
122 | vec3 x = s1c-s0c;
123 | vec3 y = s2c-s0c;
124 | vec3 normal = normalize(cross(y,x));
125 | return normal;
126 | }
127 |
128 | void rayMarchSphere(inout SphereIntersection i)
129 | {
130 | const float NUM_SAMPLES = 50.0;
131 | vec3 pos = i.pos;
132 | vec3 dir = i.rd;
133 | float stepSize = i.depth/NUM_SAMPLES;
134 |
135 | // No hit
136 | i.t = -1.0;
137 |
138 | for(float s = 0.0; s < NUM_SAMPLES; s++)
139 | {
140 | if(s == 0.0)
141 | {
142 | pos += dir*stepSize*rand(gl_FragCoord.xy);
143 | }
144 | vec3 v = pos-i.sphere.xyz;
145 | float height = length(v);
146 | vec3 n = v/height;
147 | vec2 sCoord = normalToSpherical(n);
148 | float testHeight = sphereFunction(sCoord)*i.sphere.w;
149 | testHeight += 0.000001; // Prevent floating point error
150 | if(height<=testHeight)
151 | {
152 | i.t = length(pos-i.ro);
153 | i.pos = pos;
154 | i.normal = n;
155 | i.normal = sphereFunctionNormal(sCoord,i.sphere);
156 | return;
157 | }
158 | pos += dir*stepSize;
159 | }
160 | return;
161 | }
162 |
163 | vec3 lighting(vec3 point, vec3 N, vec3 light, vec3 color)
164 | {
165 | vec3 toLight = light-point;
166 | vec3 L = normalize(toLight);
167 | return color*saturate(dot(N,L));
168 | }
169 |
170 | void rayMarchedSphereIntersection(inout SphereIntersection i)
171 | {
172 | // First intersect the sphere
173 | raySphere(i);
174 | // Then raymarch the heightfield
175 | if(i.t > 0.0)
176 | {
177 | rayMarchSphere(i);
178 | }
179 | }
180 |
181 | void main(void)
182 | {
183 | vec2 screenPos = -1.0 + 2.0 * gl_FragCoord.xy / resolution.xy;
184 | vec2 screenPosAR = vec2(screenPos.x*(resolution.x/resolution.y),screenPos.y);
185 |
186 | vec3 rayDir = normalize(vec3(screenPosAR.x,screenPosAR.y,1.0));
187 | vec3 light = vec3(sin(time/4.0)*3.0,cos(time/5.0)*3.0,-2.0);
188 | vec4 sphere = vec4(0.0,0.0,3.0,2.2);
189 |
190 | SphereIntersection inter;
191 | inter.ro = vec3(0,0,0);
192 | inter.rd = rayDir;
193 | inter.sphere = sphere;
194 | rayMarchedSphereIntersection(inter);
195 | //raySphere(inter);
196 |
197 | vec3 color;
198 | if(inter.t > 0.0)
199 | {
200 | float shadowFactor = 1.0;
201 | SphereIntersection shadowInter;
202 | vec3 lightDir = normalize(light-inter.pos);
203 | shadowInter.ro = inter.pos;
204 | shadowInter.rd = lightDir;
205 | shadowInter.pos = inter.pos+lightDir*0.1;
206 | shadowInter.sphere = sphere;
207 | shadowInter.depth = sphere.w;
208 | rayMarchSphere(shadowInter);
209 | if(shadowInter.t > 0.0)
210 | {
211 | //shadowFactor = 0.0;
212 | }
213 | // Some crazy colors
214 | vec3 diffuse = normalize(normalize(inter.pos-sphere.xyz)+vec3(abs(sin(time/4.0)),abs(cos(time/5.0)),abs(sin(time/5.0)*2.0)));
215 | color.xyz = lighting(inter.pos, inter.normal, light, diffuse) * shadowFactor;
216 | color.xyz += saturate(inter.normal.zzz+0.50)*diffuse; // Some fake backlighting
217 | }
218 | else
219 | {
220 | color.xyz = vec3(0,0,0);
221 | }
222 |
223 | gl_FragColor.xyz = color;
224 | gl_FragColor.w = 1.0;
225 | }
--------------------------------------------------------------------------------
/demos/NyanCat/public/favicon.png:
--------------------------------------------------------------------------------
1 | �PNG
2 |
3 |
IHDR � � R�l IDATx��yt]U�ǿ�}n�6m�-(s�)�*����6i���!C�"�O&qx,�g��]>ѧ �O,b�I������U��L�\�TjK�$�������R�>g�{on�g��Ѯ����{�9{��o))))))))))))))))))))))))))))))))))))))))))))c�:���G7���.���vR`X+q���"��T��lkB#��ˠ `���3��Tox��6�����'�XR��m��)��. �#ڃ%�'r��~�3
?) ���⚐�>!��ژ;in��3�x"������fHs�����>ɷ"����>�&������ K�i���naw�I
�>�R������}s3,[!4��k��6�Ť^���&7�Ӏ� ��=7�g��G%�
4 | `{zz2u���4��ō�������ḣ#�!
�f�TX2�ܤ�S1��T �Pם�c,�t4�)q�I� �=>r����F�F����@s�*��uƵ [��j�S[Γՙx�W��H+$��pE� �<� $<Ā������i���ƥ f^�3�jj�� >pz1= �n/��f�z�=�z����z_����Qƌ+��X9}(S�����d,IOA��g��$���kGH�]]SȜ�`�\/�c�q!��t�L�9�������-FLI!�ȋ3��>�KF�֏f\�!�����]Q0ۙ;o�L�q��,�� Sd���GE� @���١�d�k��Q�Ɋ��]+�R���*+]L���.4<�OF�}�:w��/Y Rq�qcnZ�.��N"(e.��l̽ fix����!�J�)� �x����K��o*J u����t��K��$�/RzƂW�ڕ6�vs`��j�A ����m�Lm8��L�p�d&��c��#"�$4���!���~��m��%��3!��]=S�P�kHGw|H��
5 | V�,��lȯ=���$��q���5��e�v�C@�YTQH y��|�@�Q�7!Ƽ �[�;* ��{1� zw��T=ҵ���+F��߲;wc8�J�XG��V��Z��in��8�a�
6 | @2ٮ����@�Ֆ7�g��B��X��;���};W.0?F�hoI4�T���շ}��Dc%Ę�̞�wϬ���;�=R����~�`�Ĩ�6�~�S �0!�@ҟG�U�����X��s�չ�_-7歉����k7�׃G];��o�u�����c wK"��u���m;����cJ ��+��_��T��FX��Z/9&��7��#�7{�� �P�۽��I{Z_˂��}'Ř@}���!~���} ���NK�� ��w93�s�iV��i��W�R4_�k��]�~bL {]�"8��r�����n����`�~�y����'(�'�z�*�BW��?͛τ(w��+�e�|9蘌¹�[�^��w,sВܴ���ĉ��K���u~�xf-_H�v�%��ͥ�C&�|�����}��$��Ø��A��i�����A���U ���_c�v�d5��m
�����v.�
7 | ���a�V��@k�I(Ù�,P�4w�1��_�������^����g��t�߇?+^9�:�� ��<@�+w���/Y�ښ�kH�;}���y� J��b?�
uj}W�2����f���+�ih�w�G����G[~�)�qM�3��r�;�r$���hk�����S6�^�� -��
8 | !�gLu�{{�=�!_�� t.߿ ��}��d |����j_�š,��~�;Q����t��n=�_�������
��wD�,I��̑���+y�Dɿfܘ�����֚�k礃?9�?�q}��¿���8~Hֆ��t��ܢRZH�j�7� ִ
9 | ���Z�����aO��숦�B[�q�<��{���FH%�%
��Zq�w��!����5��+���1�2�L��:I�w�w��+�H9�*p�kE3e;��K>RxE�3|��F�;�3
10 | ��A����NY���`f�=S3z�ј'�:�Z>�-���d;s�"yrT{A�Px��%��*�+P/_g��J����x�"�A%��+}�4Z�.����?D(N�����{���R�0���6�wF�'yl}g��9�*n1�17�j����5����5́=~���%^)����o��I/��Y�l�[��zWE��`P�N�r�ɍ�3�/(R_$�Ӈ��/<���M �K�p�c��J����GO<�>�i�x摖��[kϔ�
��oY�(�y�b �b�Q�4
11 | �h�uޯ}'��k�,tI4k2u�ߌvLQ����琘�V�C-
��SJ�>%�H�4o�v潜y3@��7��|5���acuRŶ)�d�fj�%D�ݞ�bttT�Nk{���vZ`�(���^o[�j���G>0�~?�dL�1+�g��[���mg���8�]�_�����aꎎ��j��o�
%�qR�)ny��h�~T�Cl�kk�k�?[w~JA�t�m�Js�8�qT�"��+�:�E%�[�0s�}Nb]�m*���oE��/`��Iv��<9�!^�����,���c�����t��m�n���G�'S���-�V�G�Ҵ�wg .[~Jb�*7[�����d�K�h�=�L���������|�h��i�.
Ys�����x�>���'�ƾ� �s�9���l�)�K"����XT�Zy�LڂOAr�u�������V���D��`���{jw������y�����C�#S�lS�ID �K�'���j'i����f9�E,G�-u>�>�uk#�Θյ�C�BB�ѿG����t�Y#����گ�9x��� �[QL-�Hc���.�Y]=�<��Pzz��!��yeBp�����n��d�q�#8g�
�C|��] ���嘣ċ}�2��o�S���Ŗ�P'D2�������j&h���/�^��P�
12 | �
13 | [�uߏ�"D�X�]$�:��ٽ��tW;W�=+��u�29 x��}3�k\�HN���No����0u��3�7|�QA쳠�'�����`1 �Ya��X��#\�$��{�ܧ��QA����� {�:�$�=n���;J
[ǚ�9�?$�r���
/�C��p;9���1B����%� x��
�)u�� ���&