"Hello, Kotlin" example working with the new library

This commit is contained in:
pTalanov
2012-05-31 18:07:22 +04:00
parent 527c4585a3
commit f07523df1d
@@ -1,15 +1,33 @@
/* /*
This example is just simple text floating around. If u are using chrome, there is a bug that spoil the visuals. This shows simple text floating around.
*/ */
package hello package hello
import js.* import js.dom.html5.*
import html5.* import js.dom.html.window
import jquery.* import js.jquery.*
val canvas: HTMLCanvasElement
get() {
return window.document.getElementsByTagName("canvas").item(0)!! as HTMLCanvasElement
}
val context: CanvasContext
get() {
return canvas.getContext("2d")!!
}
val width: Double
get() {
return canvas.width
}
val height: Double
get() {
return canvas.height
}
val context = getContext()
val height = getCanvas().height
val width = getCanvas().width
// class representing a floating text // class representing a floating text
class HelloKotlin() { class HelloKotlin() {
@@ -30,7 +48,7 @@ class HelloKotlin() {
{ {
context.font = "bold ${textHeightInPixels}px Georgia, serif" context.font = "bold ${textHeightInPixels}px Georgia, serif"
} }
val textWidthInPixels = context.measureText(message).width val textWidthInPixels = context.measureText(message)!!.width
fun draw() { fun draw() {
context.save() context.save()
@@ -73,12 +91,13 @@ fun renderBackground() {
} }
fun main(args: Array<String>) { fun main(args: Array<String>) {
jq {
val interval = 50 val interval = 50
// we pass a literal that constructs a new HelloKotlin object // we pass a literal that constructs a new HelloKotlin object
val logos = Array(3) { val logos = Array(3) {
HelloKotlin() HelloKotlin()
} }
jq {
setInterval({ setInterval({
renderBackground() renderBackground()
for (logo in logos) { for (logo in logos) {