kanvas-core

A Kotlin DSL for JavaFX Canvas

License

License

GroupId

GroupId

com.athaydes.kanvas
ArtifactId

ArtifactId

kanvas-core
Last Version

Last Version

1.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

kanvas-core
A Kotlin DSL for JavaFX Canvas
Project URL

Project URL

https://github.com/renatoathaydes/kanvas
Source Code Management

Source Code Management

https://github.com/renatoathaydes/kanvas

Download kanvas-core

How to add to project

<!-- https://jarcasting.com/artifacts/com.athaydes.kanvas/kanvas-core/ -->
<dependency>
    <groupId>com.athaydes.kanvas</groupId>
    <artifactId>kanvas-core</artifactId>
    <version>1.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.athaydes.kanvas/kanvas-core/
implementation 'com.athaydes.kanvas:kanvas-core:1.0.1'
// https://jarcasting.com/artifacts/com.athaydes.kanvas/kanvas-core/
implementation ("com.athaydes.kanvas:kanvas-core:1.0.1")
'com.athaydes.kanvas:kanvas-core:jar:1.0.1'
<dependency org="com.athaydes.kanvas" name="kanvas-core" rev="1.0.1">
  <artifact name="kanvas-core" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.athaydes.kanvas', module='kanvas-core', version='1.0.1')
)
libraryDependencies += "com.athaydes.kanvas" % "kanvas-core" % "1.0.1"
[com.athaydes.kanvas/kanvas-core "1.0.1"]

Dependencies

compile (1)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-stdlib-jdk8 jar 1.3.72

test (1)

Group / Artifact Type Version
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

Kanvas

This project contains a few libraries to make it easy to draw on a JavaFX Canvas using either a Kotlin or Groovy DSL.

Libraries

Diagram produced by Kanvas itself!

Kanvas Project Diagram

kanvas-core

Maven coordinates: com.athaydes.kanvas:kanvas-core:<version>

The basic functionality of Kanvas. It's written in Kotlin and provides the basic API for drawing on a canvas via the com.athaydes.kanvas.Kanvas class.

This library also provides an abstract class, com.athaydes.kanvas.KanvasApp, to make it easy to create a javafx.application.Application implementation that displays a Kanvas and nothing else:

import com.athaydes.kanvas.Kanvas
import com.athaydes.kanvas.KanvasApp
import javafx.application.Application
import javafx.scene.paint.Color

fun main() {
    Application.launch(KanvasDemo::class.java)
}

class KanvasDemo : KanvasApp() {
    override fun draw(): Kanvas {
        return Kanvas(300.0, 250.0).apply {
            // draw your shapes here!
            background(Color.BLACK).fill(Color.BLUE)
            at(50.0, 30.0).circle(radius = 100.0, fill = true)
        }
    }
}

Result:

Kotlin Basic Screenshot

kanvas-groovy

Maven coordinates: com.athaydes.kanvas:kanvas-groovy:<version>

A Groovy DSL based on kanvas-core.

It provides a base class for Groovy scripts exposing a nice DSL for Kanvas:

import com.athaydes.kanvas.gr.KanvasScript
import groovy.transform.BaseScript
import javafx.scene.paint.Color

@BaseScript KanvasScript baseScript

title 'Groovy Kanvas Demo'
width 300
height 250

background Color.BLACK
fill Color.BLUE
at 50, 30 circle 100, true

This example is equivalent to the Kotlin example shown earlier.

Hot reloading Groovy scripts

This library also provides a JavaFX application class, com.athaydes.kanvas.gr.GroovyKanvasApp, that can launch a Groovy script and hot-reload it as it changes.

All files under the same directory tree as the Groovy script are watched.

For details on how to run Kanvas Groovy scripts, see the Groovy Demo.

Demos

Kotlin Demo

Groovy Demo

Kanvas-Reactive (shown below)

Kanvas Reactive Demo

Kanvas-To-Image

Showcase from demo/groovy/src/showcase.groovy:

Showcase

Development

To install the current version of the library in your local maven cache, use

./gradlew install

since this library uses JavaFX, make sure that you use a jdk with JavaFX, eg.

sdk install java 11.0.8.fx-zulu

Versions

Version
1.0.1