Demonstrates the use of the HTML Canvas, along with some minor cuteness involving destructuring.
To run the program, just press 'Run' above. Then check out the code in the other tabs.
Adapted from [this original code][original].
This little example application demonstrates the use of Ceylon as an alternative to client-side JavaScript. In particular, the example shows:
//$webrun_wrapped | |
shared void run() { | |
//Strings come in two forms, ordinary, single-quoted strings, | |
//where backslashes represent escapes: | |
print("Hello\nworld"); | |
//And "verbatim" strings, where quotes and backslashes are | |
//interpreted literally: |
{ | |
"sets": [ | |
{ | |
"title": "Try out a sample:", | |
"items": [ | |
{ | |
"title": "Hello World", | |
"gist": "1b5a174b7fda6eb0e3a6" | |
}, | |
{ |
import ceylon.collection { LinkedList } | |
void run() { | |
value list = LinkedList{"Test 1", "Test 2"}; | |
list.add("Test 3"); | |
print(list); | |
} |
import ceylon.language.meta.declaration { | |
ValueDeclaration | |
} | |
shared void run() { | |
for (dec in `class String`.memberDeclarations<ValueDeclaration>()) { | |
print(dec); | |
} | |
} |
//$webrun_wrapped | |
shared void run() { | |
// Game of Life 2.5 | |
value seed = system.milliseconds; | |
value density = 0.8; | |
value gwidth = 180; // Number of cells horizontally and vertically | |
value gheight = 80; // Number of cells horizontally and vertically |
//$webrun_wrapped | |
shared void run() { | |
"You can get the metamodel of a class like this" | |
value stringType = `String`; | |
print("class ``stringType``"); | |
for (st in stringType.satisfiedTypes) { | |
print(" satisfies ``st``"); | |
} |
//$webrun_wrapped | |
shared void run() { | |
// Operators are associated to specific interfaces. A type that | |
// satisfies such an interface can be used with the respective | |
// operators. | |
class Product(String name, Float price) | |
satisfies Comparable<Product> { | |
shared actual String string = name; | |
shared actual Comparison compare(Product other) | |
=> price <=> other.price; |