1
0
mirror of https://github.com/sharkdp/bat.git synced 2025-08-14 01:59:41 +01:00
Files
.github
assets
diagnostics
doc
examples
src
tests
benchmarks
examples
mocked-pagers
scripts
snapshots
syntax-tests
highlighted
source
ARM Assembly
ASP
AWK
ActionScript
Apache
AppleScript
AsciiDoc
Assembly (x86_64)
Bash
BatTestCustomAssets
Batch
BibTeX
C
C-Sharp
CMake
CSS
CSV
Cabal
Clojure
CoffeeScript
Cpp
CpuInfo
Crystal
D
Dart
Diff
Dockerfile
DotENV
Elixir
Elm
LICENSE.md
test.elm
Email
Erlang
EtcGroup
F#
Fish
Fortran (Fixed Form)
Fortran (Modern)
Fortran Namelist
Fstab
GLSL
Git Attributes
Git Config
Git Ignore
Go
GraphQL
Graphviz DOT
Groff
Groovy
HTML
Haskell
Hosts
INI
Ignored suffixes
JQ
JSON
Java
Java Server Page (JSP)
JavaScript
Jinja2
Julia
Kotlin
LLVM
Lean
Less
Lisp
Literate Haskell
LiveScript
Log
Lua
MATLAB
Makefile
Manpage
Markdown
MediaWiki
MemInfo
NAnt Build File
Ninja
OCaml
Objective-C
Objective-C++
PHP
Pascal
Passwd
Perl
Plaintext
PowerShell
Protocol Buffer
Puppet
PureScript
Python
QML
R
Racket
Rego
Regular Expression
Robot Framework
Ruby
Ruby Haml
Ruby On Rails
Rust
SCSS
SLS
SML
SQL
SSH Config
SSHD Config
Sass
Scala
Slim
Solidity
Strace
Stylus
Svelte
Swift
Syslog
SystemVerilog
TOML
Tcl
TeX
Terraform
Textile
TypeScript
TypeScriptReact
Verilog
VimL
Vue
Vyper
XAML
XML
YAML
Zig
dash
gnuplot
http-request-response
jsonnet
nginx
nim
nix
orgmode
reStructuredText
resolv.conf
varlink
BatTestCustomAssets.sublime-syntax
compare_highlighted_versions.py
create_highlighted_versions.py
regression_test.sh
test_custom_assets.sh
update.sh
utils
.gitattributes
assets.rs
integration_tests.rs
no_duplicate_extensions.rs
snapshot_tests.rs
tester.rs
.gitignore
.gitmodules
CHANGELOG.md
CONTRIBUTING.md
Cargo.lock
Cargo.toml
LICENSE-APACHE
LICENSE-MIT
NOTICE
README.md
build.rs
rustfmt.toml
bat/tests/syntax-tests/source/Elm/test.elm
2020-10-04 15:19:54 +02:00

138 lines
2.1 KiB
Elm
Vendored

-- elm install elm-explorations/linear-algebra
-- elm install elm-explorations/webgl
import Browser
import Browser.Events as E
import Html exposing (Html)
import Html.Attributes exposing (width, height, style)
import Math.Matrix4 as Mat4 exposing (Mat4)
import Math.Vector3 as Vec3 exposing (Vec3, vec3)
import WebGL
-- MAIN
main =
Browser.element
{ init = init
, view = view
, update = update
, subscriptions = subscriptions
}
-- MODEL
type alias Model =
Float
init : () -> (Model, Cmd Msg)
init () =
( 0, Cmd.none )
-- UPDATE
type Msg
= TimeDelta Float
update : Msg -> Model -> (Model, Cmd Msg)
update msg currentTime =
case msg of
TimeDelta delta ->
( delta + currentTime, Cmd.none )
-- SUBSCRIPTIONS
subscriptions : Model -> Sub Msg
subscriptions _ =
E.onAnimationFrameDelta TimeDelta
-- VIEW
view : Model -> Html msg
view t =
WebGL.toHtml
[ width 400, height 400, style "display" "block"
]
[ WebGL.entity vertexShader fragmentShader mesh { perspective = perspective (t / 1000) }
]
perspective : Float -> Mat4
perspective t =
Mat4.mul
(Mat4.makePerspective 45 1 0.01 100)
(Mat4.makeLookAt (vec3 (4 * cos t) 0 (4 * sin t)) (vec3 0 0 0) (vec3 0 1 0))
-- MESH
type alias Vertex =
{ position : Vec3
, color : Vec3
}
mesh : WebGL.Mesh Vertex
mesh =
WebGL.triangles
[ ( Vertex (vec3 0 0 0) (vec3 1 0 0)
, Vertex (vec3 1 1 0) (vec3 0 1 0)
, Vertex (vec3 1 -1 0) (vec3 0 0 1)
)
]
-- SHADERS
type alias Uniforms =
{ perspective : Mat4
}
vertexShader : WebGL.Shader Vertex Uniforms { vcolor : Vec3 }
vertexShader =
[glsl|
attribute vec3 position;
attribute vec3 color;
uniform mat4 perspective;
varying vec3 vcolor;
void main () {
gl_Position = perspective * vec4(position, 1.0);
vcolor = color;
}
|]
fragmentShader : WebGL.Shader {} Uniforms { vcolor : Vec3 }
fragmentShader =
[glsl|
precision mediump float;
varying vec3 vcolor;
void main () {
gl_FragColor = vec4(vcolor, 1.0);
}
|]