Обновлены примеры

This commit is contained in:
Victor 2019-10-17 14:39:53 +03:00
parent 651bc3a3a3
commit 36ea7b25b5
6 changed files with 70 additions and 10 deletions

View File

@ -8,7 +8,7 @@ OwnLang - dynamic functional programming language inspired by Scala and Python.
| Free | Pro | Desktop | | Free | Pro | Desktop |
| :--: | :-: | :-----: | | :--: | :-: | :-----: |
| [![Free](https://developer.android.com/images/brand/en_generic_rgb_wo_45.png)](https://play.google.com/store/apps/details?id=com.annimon.ownlang.free) | [![Pro](https://developer.android.com/images/brand/en_generic_rgb_wo_45.png)](https://play.google.com/store/apps/details?id=com.annimon.ownlang) | [v1.4.0](https://github.com/aNNiMON/Own-Programming-Language-Tutorial/releases/tag/1.4.0) | [![Free](https://developer.android.com/images/brand/en_generic_rgb_wo_45.png)](https://play.google.com/store/apps/details?id=com.annimon.ownlang.free) | [![Pro](https://developer.android.com/images/brand/en_generic_rgb_wo_45.png)](https://play.google.com/store/apps/details?id=com.annimon.ownlang) | [v1.5.0](https://github.com/aNNiMON/Own-Programming-Language-Tutorial/releases/tag/1.5.0)
Also available as AUR package: Also available as AUR package:

21
examples/formats/gzip.own Normal file
View File

@ -0,0 +1,21 @@
use ["std", "gzip"]
// println "Gzip single file"
// gzip("absolute path to file", "example.gz")
println "Gzip bytes"
text = trim("
Lorem ipsum dolor sit amet, consectetur adipiscing elit. In leo dui, venenatis eu eleifend ut, volutpat vitae risus. Vivamus sed massa consectetur, fermentum est ac, semper ligula. Donec vel facilisis urna. Cras scelerisque libero a pulvinar mollis. Maecenas elementum, lectus vitae ullamcorper viverra, odio justo interdum lacus, a dictum mauris lacus id neque. Donec ante nibh, ornare ac lacus at, rutrum vulputate lacus. Quisque aliquet sem sit amet nisl semper faucibus. Aenean finibus sodales est, eget efficitur nibh. Donec ut tortor ut ex auctor fringilla id sed neque. Aenean id placerat ipsum.
Etiam enim ligula, vulputate ac velit nec, accumsan blandit velit. Aenean tortor neque, ornare eu quam vel, viverra condimentum erat. In vitae mattis augue. Sed nec auctor est. Aenean in auctor lorem. Etiam non accumsan arcu. Vivamus purus massa, finibus at ultrices feugiat, congue vitae quam.
Vestibulum porttitor finibus nulla, vel mollis elit luctus vel. Phasellus ut erat ante. Praesent consectetur vulputate sem eget bibendum. Etiam porttitor magna et egestas viverra. Praesent urna eros, porttitor vitae lorem sodales, luctus sagittis velit. Donec sed aliquet nulla, ac gravida urna. Mauris at quam eros. Nam dolor lacus, laoreet vel consequat non, semper sed quam. Nunc semper interdum arcu eget iaculis. Vivamus at turpis et urna pellentesque suscipit in nec tellus. Nam sed sem ut ipsum semper imperdiet in et est. Praesent vestibulum augue a dolor consequat feugiat. Nam massa tortor, feugiat quis orci ut, blandit varius tellus. Quisque et blandit erat.
Fusce ultricies, odio scelerisque venenatis pellentesque, nisl mi vehicula mi, eu ultrices dui nisi ac elit. Nullam laoreet et lacus ac fringilla. Morbi pretium, eros non facilisis bibendum, nisl ex ultricies ipsum, sed sodales est felis vel eros. Suspendisse lobortis lectus scelerisque turpis dapibus, et tristique neque faucibus. Donec sed tellus id augue molestie tempus ac in urna. Morbi accumsan velit in erat ultricies, vitae ultricies nulla viverra. Pellentesque non euismod purus. Pellentesque vitae consequat orci. Pellentesque in nulla pulvinar, blandit leo sed, vehicula quam. Cras finibus libero ut diam aliquam efficitur. Vestibulum rutrum tincidunt posuere. Integer ultricies rutrum libero vitae pellentesque. Nulla blandit ipsum sit amet aliquet venenatis. Maecenas cursus massa quis massa posuere eleifend. Morbi vel lorem luctus, efficitur nibh id, sagittis tortor. Maecenas tristique suscipit dui vel congue.
")
bytesOriginal = getBytes(text)
bytesGzipped = gzipBytes(bytesOriginal)
println "Original bytes count: " + bytesOriginal.length
println "Gzipped bytes count: " + bytesGzipped.length
println "Ungzip"
ungzippedBytes = ungzipBytes(bytesGzipped)
println stringFromBytes(ungzippedBytes)

16
examples/formats/json.own Normal file
View File

@ -0,0 +1,16 @@
use "json"
data = {
"name": "Json Example",
"version": 1,
"arrayData": [
1, 2, 3, 4
],
"objectData": {
"key": "value",
10: "1000"
}
}
println "Json encode"
println "Minified: " + jsonencode(data)
println "Pretty-print: " + jsonencode(data, 2)

View File

@ -1,7 +1,6 @@
use "yaml" use "yaml"
println "Yaml encode" data = {
println yamlencode({
"name": "Yaml Example", "name": "Yaml Example",
"version": 1, "version": 1,
"arrayData": [ "arrayData": [
@ -11,6 +10,14 @@ println yamlencode({
"key": "value", "key": "value",
10: "1000" 10: "1000"
} }
}
println "Yaml encode"
println yamlencode(data)
println "Yaml encode with options"
println yamlencode(data, {
"indent": 6,
"prettyFlow": true,
"defaultFlowStyle": "BLOCK"
}) })
println "\nYaml decode" println "\nYaml decode"

16
examples/formats/zip.own Normal file
View File

@ -0,0 +1,16 @@
use "zip"
// println "Zip single file"
// zip("absolute path to file", "example.zip")
println "Zip files"
zipFiles(["json.own", "yaml.own", "zip.own"], "example1.zip")
println "Zip files"
zipFiles({
"json.own": "json.txt",
"yaml.own": "yaml/yaml.own",
"zip.own": "readme.md"}, "example2.zip")
println "List zip entries"
println listZipEntries("example2.zip").joinToString(", ")

View File

@ -7,11 +7,11 @@ use "canvasfx"
CELL_NONE = -100 CELL_NONE = -100
CELL_MINE = -200 CELL_MINE = -200
// Colors // Colors
BACKGROUND_COLOR = Color.new(#FF283593) BACKGROUND_COLOR = Color.`new`(#FF283593)
OPENED_CELL_COLOR = Color.new(0xFF9FA8DA) OPENED_CELL_COLOR = Color.`new`(0xFF9FA8DA)
DEFAULT_CELL_COLOR = Color.new(#FF5C6BC0) DEFAULT_CELL_COLOR = Color.`new`(#FF5C6BC0)
MINE_CELL_COLOR = Color.new(#FF1A237E) MINE_CELL_COLOR = Color.`new`(#FF1A237E)
FLAG_COLOR = Color.new(#FF7A231E) FLAG_COLOR = Color.`new`(#FF7A231E)
// Parameters // Parameters
WIDTH = 400 HEIGHT = 400 WIDTH = 400 HEIGHT = 400
@ -73,7 +73,7 @@ def drawGameTable(showBombs = false) {
def drawWin() { def drawWin() {
drawGameTable(true) drawGameTable(true)
g.setFill(Color.new(#60FFFFFF)) g.setFill(Color.`new`(#60FFFFFF))
g.fillRect(0, 0, WIDTH, HEIGHT) g.fillRect(0, 0, WIDTH, HEIGHT)
g.setFill(Color.DARKGREEN) g.setFill(Color.DARKGREEN)
g.fillText("YOU WIN", WIDTH / 2, HEIGHT / 2) g.fillText("YOU WIN", WIDTH / 2, HEIGHT / 2)
@ -81,7 +81,7 @@ def drawWin() {
def drawGameOver() { def drawGameOver() {
drawGameTable(true) drawGameTable(true)
g.setFill(Color.new(#60000000)) g.setFill(Color.`new`(#60000000))
g.fillRect(0, 0, WIDTH, HEIGHT) g.fillRect(0, 0, WIDTH, HEIGHT)
g.setFill(Color.PINK) g.setFill(Color.PINK)
g.fillText("Game Over", WIDTH / 2, HEIGHT / 2) g.fillText("Game Over", WIDTH / 2, HEIGHT / 2)