minart-pure


License

License

Categories

Categories

MINA Net Networking
GroupId

GroupId

eu.joaocosta
ArtifactId

ArtifactId

minart-pure_sjs0.6_2.11
Last Version

Last Version

0.1.7
Release Date

Release Date

Type

Type

jar
Description

Description

minart-pure
minart-pure
Project URL

Project URL

https://github.com/JD557/minart
Project Organization

Project Organization

eu.joaocosta
Source Code Management

Source Code Management

https://github.com/JD557/minart

Download minart-pure_sjs0.6_2.11

How to add to project

<!-- https://jarcasting.com/artifacts/eu.joaocosta/minart-pure_sjs0.6_2.11/ -->
<dependency>
    <groupId>eu.joaocosta</groupId>
    <artifactId>minart-pure_sjs0.6_2.11</artifactId>
    <version>0.1.7</version>
</dependency>
// https://jarcasting.com/artifacts/eu.joaocosta/minart-pure_sjs0.6_2.11/
implementation 'eu.joaocosta:minart-pure_sjs0.6_2.11:0.1.7'
// https://jarcasting.com/artifacts/eu.joaocosta/minart-pure_sjs0.6_2.11/
implementation ("eu.joaocosta:minart-pure_sjs0.6_2.11:0.1.7")
'eu.joaocosta:minart-pure_sjs0.6_2.11:jar:0.1.7'
<dependency org="eu.joaocosta" name="minart-pure_sjs0.6_2.11" rev="0.1.7">
  <artifact name="minart-pure_sjs0.6_2.11" type="jar" />
</dependency>
@Grapes(
@Grab(group='eu.joaocosta', module='minart-pure_sjs0.6_2.11', version='0.1.7')
)
libraryDependencies += "eu.joaocosta" % "minart-pure_sjs0.6_2.11" % "0.1.7"
[eu.joaocosta/minart-pure_sjs0.6_2.11 "0.1.7"]

Dependencies

compile (4)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.11.12
eu.joaocosta : minart-core_sjs0.6_2.11 jar 0.1.7
org.scala-js : scalajs-library_2.11 jar 0.6.33
org.scala-js : scalajs-dom_sjs0.6_2.11 jar 1.0.0

test (2)

Group / Artifact Type Version
org.scala-js : scalajs-test-bridge_2.11 jar 0.6.33
org.specs2 : specs2-core_sjs0.6_2.11 jar 4.8.3

Project Modules

There are no modules declared in this project.

Minart

Sonatype Nexus (Releases)

Minart is a very minimalistic Scala library to put pixels in a canvas.

It's mostly useful for small toy projects or prototypes that deal with generative art or software rendering.

I wouldn't recommend using this in any serious production environment. The API is constantly changing and I'm not making any effort to maintain backwards compatibility.

Features

  • JVM, JS and Native support
  • Small footprint
  • Double buffered canvas
  • Integer scaling
  • Keyboard Input

Concepts

The 3 main concepts in Minart are:

The CanvasManager

The CanvasManager, provides init and destroy operations to create and delete a new window with a Canvas.

The Canvas

The Canvas, which provides the operations required to draw on the window and read inputs:

  • putPixel(x: Int, y: Int, color: Color): Unit
  • getBackbufferPixel(x: Int, y: Int): Color
  • getBackbufferPixel(): Vector[Vector[Color]]
  • clear(resources: Set[Canvas.Resource]): Unit
  • redraw(): Unit
  • getKeyboardInput(): KeyboardInput

The RenderLoop

The RenderLoop, which provides helpful operations to handle the render loops.

The provided methods take care of creating and destroying the window.

Note that clear/redraw still need to be called manually (since in some cases, it might be useful to not call those methods, especially clear)

  • finiteRenderLoop[S](initialState: S, renderFrame: S => S, terminateWhen: S => Boolean, frameRate: FrameRate): Unit
  • infiniteRenderLoop[S](initialState: S, renderFrame: S => S, frameRate: FrameRate): Unit
  • infiniteRenderLoop(renderFrame: Unit => Unit, frameRate: FrameRate): Unit
  • singleFrame(canvasManager: CanvasManager, renderFrame: Canvas => Unit)

Sample Usage

To include minart, simply add minart-core to your project:

libraryDependencies += "eu.joaocosta" %% "minart-core" % "0.2.0"

The examples folder contains some sample code.

The recommended way to use Minart is to use the RenderLoop, since it takes care of creating and destroying the window, while it also takes care of some low-level platform-specific details.

Here's a simple example that renders a color gradient to a screen:

import eu.joaocosta.minart.backend.defaults._
import eu.joaocosta.minart.core._

val canvasSettings = Canvas.Settings(
  width = 128,
  height = 128,
  scale = 4)


RenderLoop.default().singleFrame(CanvasManager.default(canvasSettings), c => {
  for {
    x <- (0 until c.settings.width)
    y <- (0 until c.settings.height)
  } {
    val color = Color((255 * x.toDouble / c.settings.width).toInt, (255 * y.toDouble / c.settings.height).toInt, 255)
    c.putPixel(x, y, color)
  }
  c.redraw()
})

Note that you can avoid this and use the LowLevelCanvas interface, which is just a Canvas with CanvasManager. You also can remove the eu.joaocosta.minart.defaults._ import, but then you need to manually create the platform-specific canvas.

import eu.joaocosta.minart.core._

val canvasSettings = Canvas.Settings(
  width = 128,
  height = 128,
  scale = 4)

val canvas = new AwtCanvas(canvasSettings)
canvas.init()
for {
  x <- (0 until canvasSettings.width)
  y <- (0 until canvasSettings.height)
} {
  val color = Color((255 * x.toDouble / canvas.width).toInt, (255 * y.toDouble / canvas.height).toInt, 255)
  canvas.putPixel(x, y, color)
}
canvas.redraw()

// ... eventually, call `canvas.destroy()`

Multiplatform support

To compile for different platforms, one needs to either use import eu.joaocosta.minart.backend.defaults._ package and use the default method or use the correct Canvas and RenderLoop (see the examples above).

The following canvas and render loops are available:

  • All: PpmCanvas
  • JVM: AwtCanvas and JavaRenderLoop
  • JS: HtmlCanvas and JsRenderLoop
  • Native: SdlCanvas and SdlRenderLoop

Versions

Version
0.1.7
0.1.6
0.1.5
0.1.4