Code Monkey home page Code Monkey logo

scalagraphics's Introduction

Scala Graphics

This library makes it easier and more fun to write functional, lazy and composeable graphics operations for the Java Graphics api.

It can be used like this:

import com.github.jarlah.scalagraphics.GraphicsOp
import com.github.jarlah.scalagraphics.Java2DGraphics
import com.github.jarlah.scalagraphics.GraphicsOp.*

def renderHello: GraphicsOp[Unit] = for {
  _ <- clearRect(0, 0, 800, 600)
  _ <- setColor(Black)
  _ <- drawString("Hello", 100, 100)
} yield ()

val g: java.awt.Graphics = // somehow get graphics object
Java2DGraphics(g).run(renderHello) match {
  case Left(error) => println(s"Error while rendering: $error")
  case Right(_) =>
}

The library is using the Cats Free Monad to create a DSL for graphics operations. The operations are then interpreted to Java Graphics operations. The library also provides a way to interpret the operations to OpenGL operations.

To see how it can be used in an actual Java 2D game, see https://github.com/jarlah/scalagraphics-demo, or to see how it can be used in a OpenGL game, see https://github.com/jarlah/scalagraphics-demo-opengl.

scalagraphics's People

Contributors

jarlah avatar

Stargazers

Øyvind Raddum Berg avatar Vegard Fjellbo avatar

Watchers

 avatar  avatar

scalagraphics's Issues

Remove unneeded methods from GraphicsIO

Currently i have all methods from Java Graphics api in GraphicsIO trait. I want to trim this list down severely by only including stuff thats useable and (hopefully) possible to implement in OpenGL and Vulkan

Consider moving nanovg init inside OpenGL impl

I suppose if the OpenGL impl is to be useable without too much work it should be as self contained as possible. It should initialise shader program and rectangle stuff and nanovg in an init method. But should it also allow for not running the init method and override the identifiers if the program wants to control all of it ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.