All Projects → prostory → AndroidZdog

prostory / AndroidZdog

Licence: MIT License
Porting Zdog(Round, flat, designer-friendly pseudo-3D engine for canvas) to Android with kotlin

Programming Languages

kotlin
9241 projects
java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to AndroidZdog

Exokit
Native VR/AR/XR engine for JavaScript 🦖
Stars: ✭ 809 (+3577.27%)
Mutual labels:  canvas, engine
drawing-board
canvas-drawing-board
Stars: ✭ 23 (+4.55%)
Mutual labels:  canvas
uSource
uSource is a plugin for importing MDL / BSP / VMT / VTF and etc... resources to Unity!
Stars: ✭ 44 (+100%)
Mutual labels:  engine
xamboo
The CMS Framework and web server to build full applications and APIs for Go
Stars: ✭ 14 (-36.36%)
Mutual labels:  engine
NightSky
A way to avoid paying 50 bucks by using some js to generate an image of the night sky at specific time and location. 🌑
Stars: ✭ 49 (+122.73%)
Mutual labels:  canvas
auther
Enhances Rails with multi-account, form-based, database-less, application-wide authentication.
Stars: ✭ 22 (+0%)
Mutual labels:  engine
radiaSlider
circular/linear knob-style slider
Stars: ✭ 18 (-18.18%)
Mutual labels:  canvas
incubator-linkis
Linkis helps easily connect to various back-end computation/storage engines(Spark, Python, TiDB...), exposes various interfaces(REST, JDBC, Java ...), with multi-tenancy, high performance, and resource control.
Stars: ✭ 2,459 (+11077.27%)
Mutual labels:  engine
phalanx
Phalanx is a cloud-native distributed search engine that provides endpoints through gRPC and traditional RESTful API.
Stars: ✭ 192 (+772.73%)
Mutual labels:  engine
canvas-merge-video-in-vue
canvas+vue 实现视频碎片合并 比较粗陋,欢迎fork 升级++
Stars: ✭ 21 (-4.55%)
Mutual labels:  canvas
MonoGame.Forms
MonoGame.Forms is the easiest way of integrating a MonoGame render window into your Windows Forms project. It should make your life much easier, when you want to create your own editor environment.
Stars: ✭ 183 (+731.82%)
Mutual labels:  engine
snake-game-p5
The Snake Game made with p5.js 🐍🎮.
Stars: ✭ 18 (-18.18%)
Mutual labels:  canvas
idraw
A simple JavaScript framework for Drawing on the web.(一个面向Web绘图的JavaScript框架)
Stars: ✭ 436 (+1881.82%)
Mutual labels:  canvas
canvas-cast
Cast any <canvas> element to an LED Matrix over WebSockets with an Arduino/ESP8266.
Stars: ✭ 39 (+77.27%)
Mutual labels:  canvas
empathy-map
チームでお互いのことを知り、ゴールや目的を共有する。
Stars: ✭ 15 (-31.82%)
Mutual labels:  canvas
shoot game
🎮 It is a game using HTML5 Canvas and Vanilla JavaScript.
Stars: ✭ 35 (+59.09%)
Mutual labels:  canvas
jitterphysics
A cross-platform, realtime physics engine for all .NET apps.
Stars: ✭ 327 (+1386.36%)
Mutual labels:  engine
SubmiBot
Plugin do Eclipse para automatização do processo de submissão de tarefas na disciplina de LP2 - Computação@UFCG
Stars: ✭ 16 (-27.27%)
Mutual labels:  canvas
lottery-rotate
适配移动端rem布局的canvas大转盘抽奖插件
Stars: ✭ 15 (-31.82%)
Mutual labels:  canvas
turkeyvisited
Mark the cities you have visited in Turkey and share the map!
Stars: ✭ 82 (+272.73%)
Mutual labels:  canvas

AndroidZdog

Porting Zdog(Round, flat, designer-friendly pseudo-3D engine for canvas) to Android with kotlin

Table of content

Getting started

Gradle

Step 1. Add the JitPack repository to your build file

Add it in your root build.gradle at the end of repositories:

	allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}

Step 2. Add the dependency

	dependencies {
	        implementation 'com.github.prostory:AndroidZdog:v1.0.0'
	}

Maven

Step 1. Add the JitPack repository to your build file

	<repositories>
		<repository>
		    <id>jitpack.io</id>
		    <url>https://jitpack.io</url>
		</repository>
	</repositories>

Step 2. Add the dependency

	<dependency>
	    <groupId>com.github.prostory</groupId>
	    <artifactId>AndroidZdog</artifactId>
	    <version>v1.0.0</version>
	</dependency>

What can it do?

Simple graphics and animation

Basic Shapes Extended Features Dynamic icons
basic shapes extended features dynamic icons

More complex graphics and animations

Day Night Rotate
day night rotate

Usage

Contrast with Zdog

  • Line

    • For Zdog

      // line
      new Zdog.Shape({
        addTo: illo,
        path: [
          { x: -40 }, // start at 1st point
          { x:  40 }, // line to 2nd point
        ],
        stroke: 20,
        color: '#636',
      });
      // z-shape
      new Zdog.Shape({
        addTo: illo,
        path: [
          { x: -32, y: -40 }, // start at top left
          { x:  32, y: -40 }, // line to top right
          { x: -32, y:  40 }, // line to bottom left
          { x:  32, y:  40 }, // line to bottom right
        ],
        closed: false,
        stroke: 20,
        color: '#636',
      });
      // 3D shape
      new Zdog.Shape({
        addTo: illo,
        path: [
          { x: -32, y: -40, z:  40 },
          { x:  32, y: -40 },
          { x:  32, y:  40, z:  40 },
          { x:  32, y:  40, z: -40 },
        ],
        closed: false,
        stroke: 20,
        color: '#636',
      });
    • For AndroidZdog

      // line
      shape {
          addTo = illo
          path(
              move(x = -40f), // start at 1st point
              line(x = 40f)   // line to 2nd point
          )
          stroke = 20f
          color = "#636"
      }
      // z-shape
      shape {
          addTo = illo
          path(
              move(x = -32f, y = -40f), // start at top left
              line(x = 32f, y = -40f),  // line to top right
              line(x = -32f, y = 40f),  // line to bottom left
              line(x = 32f, y = 40f)    // line to bottom right
          )
          closed = false
          stroke = 20f
          color = "#636"
      }
      // 3D shape
      shape {
          addTo = illo
          path(
              move(x = -32f, y = -40f, z = 40f),
              line(x = 32f, y = -40f),
              line(x = 32f, y = 40f, z = 40f),
              line(x = 32f, y = 40f, z = -40f)
          )
          closed = false
          stroke = 20f
          color = "#636"
      }
    • Shapes

      line z-shape 3D shape
      line line line
  • Arc

    • For Zdog

      new Zdog.Shape({
        addTo: illo,
        path: [
          { x: -60, y: -60 },   // start
          { arc: [
            { x:  20, y: -60 }, // corner
            { x:  20, y:  20 }, // end point
          ]},
          { arc: [ // start next arc from last end point
            { x:  20, y:  60 }, // corner
            { x:  60, y:  60 }, // end point
          ]},
        ],
        closed: false,
        stroke: 20,
        color: '#636'
      });
    • For AndroidZdog

      shape {
          addTo = illo
          path(
              move(x = -60f, y = -60f),		// start
              arc(
                  vector(x = 20f, y = -60f),	// corner
                  vector(x = 20f, y = 20f)	// end point
              ),
              arc(				// start next arc from last end point
                  vector(x = 20f, y = 60f),	// corner
                  vector(x = 60f, y = 60f)	// end point
              )
          )
          closed = false
          stroke = 20f
          color = "#636"
      }
    • Shapes

      arc

  • Bezier

    • For Zdog

      new Zdog.Shape({
        addTo: illo,
        path: [
          { x: -60, y: -60 },   // start
          { bezier: [
            { x:  20, y: -60 }, // start control point
            { x:  20, y:  60 }, // end control point
            { x:  60, y:  60 }, // end point
          ]},
        ],
        closed: false,
        stroke: 20,
        color: '#636'
      });
    • For AndroidZdog

      shape {
          addTo = illo
          path(
              move(x = -60f, y = -60f),		// start
              bezier(
                  vector(x = 20f, y = -60f),	// start control point
                  vector(x = 20f, y = 60f),	// end control point
                  vector(x = 60f, y = 60f)	// end point
              )
          )
          closed = false
          stroke = 20f
          color = "#636"
      }
    • Shapes

      bezier

  • Closed

    • For Zdog

      // Closed
      new Zdog.Shape({
        addTo: illo,
        path: [ // triangle
          { x:   0, y: -40 },
          { x:  40, y:  40 },
          { x: -40, y:  40 },
        ],
        // closed by default
        stroke: 20,
        color: '#636'
      });
      // Unclosed
      new Zdog.Shape({
        addTo: illo,
        path: [
          { x:   0, y: -40 },
          { x:  40, y:  40 },
          { x: -40, y:  40 },
        ],
        closed: false, // unclosed
        stroke: 20,
        color: '#636'
      });
    • For AndroidZdog

      // Closed
      shape {
          addTo = illo
          path( // triangle
              move(x = 0f, y = -40f),
              line(x = 40f, y = 40f),
              line(x = -40f, y = 40f)
          )
          // closed by default
          stroke = 20f
          color = "#636"
      }
      // Unclosed
      shape {
          addTo = illo
          path( // triangle
              move(x = 0f, y = -40f),
              line(x = 40f, y = 40f),
              line(x = -40f, y = 40f)
          )
          closed = false // unclosed
          stroke = 20f
          color = "#636"
      }
    • Shapes

      Closed Unclosed
      closed unclosed
  • Hemisphere

    • For Zdog

      let dome = new Zdog.Hemisphere({
        addTo: illo,
        diameter: 120,
        // fill enabled by default
        // disable stroke for crisp edge
        stroke: false,
        color: '#C25',
        backface: '#EA0',
      });
    • For AndroidZdog

      val demo = hemisphere {
          addTo = illo
          diameter = 120f
          // fill enabled by default
        	// disable stroke for crisp edge
          stroke = 0f // zero for no stroke
          color = "#C25"
          backface = "#EA0"
      }
    • Shapes

      hemisphere

  • Cone

    • For Zdog

      let partyHat = new Zdog.Cone({
        addTo: illo,
        diameter: 70,
        length: 90,
        stroke: false,
        color: '#636',
        backface: '#C25',
      });
    • For AndroidZdog

      val partyHat = cone {
          addTo = illo
          diameter = 70f
          length = 90f
          stroke = 0f // zero for no stroke
          color = "#636"
          backface = "#C25"
      }
    • Shapes

      cone

  • Cylinder

    • For Zdog

      let can = new Zdog.Cylinder({
        addTo: illo,
        diameter: 80,
        length: 120,
        stroke: false,
        color: '#C25',
        frontFace: '#EA0',
        backface: '#636',
      });
    • For AndroidZdog

      val can = cylinder {
          addTo = illo
          diameter = 80f
          length = 120f
          stroke = 0f // zero for no stroke
          color = "#C25"
          frontFace = "#EA0"
          backface = "#636"
      }
    • Shapes

      cylinder

  • Box

    • For Zdog

      let box = new Zdog.Box({
        addTo: illo,
        width: 120,
        height: 100,
        depth: 80,
        stroke: false,
        color: '#C25', // default face color
        leftFace: '#EA0',
        rightFace: '#E62',
        topFace: '#ED0',
        bottomFace: '#636',
      });
    • For AndroidZdog

      val box = box {
          addTo = illo
          width = 120f
          height = 100f
          depth = 80f
          stroke = 0f
          color = "#C25" // default face color
          leftFace = "#EA0"
          rightFace = "#E62"
          topFace = "#ED0"
          bottomFace = "#636"
      }
    • Shapes

      box

  • Z-fighting

    • For Zdog

      const distance = 40;
      
      let dot = new Zdog.Shape({
        addTo: illo,
        translate: { y: -distance },
        stroke: 80,
        color: '#636',
      });
      dot.copy({
        translate: { x: -distance },
        color: '#EA0',
      });
      dot.copy({
        translate: { z: distance },
        color: '#C25',
      });
      dot.copy({
        translate: { x: distance },
        color: '#E62',
      });
      dot.copy({
        translate: { z: -distance },
        color: '#C25',
      });
      dot.copy({
        translate: { y: distance },
      });
    • For AndroidZdog

      val distance = 40f
      
      val dot = shape {
          addTo = illo
          translate(y = -distance)
          stroke = 80f
          color = "#636"
      }
      dot.copy {
          translate(x = -distance)
          color = "#EA0"
      }
      dot.copy {
          translate(z = distance)
          color = "#C25"
      }
      dot.copy {
          translate(x = distance)
          color = "#E62"
      }
      dot.copy {
          translate(z = -distance)
          color = "#C25"
      }
      dot.copy {
          translate(y = distance)
      }
    • Shapes

      z-fighting

Display shapes in ImageView

It's very simple to display Shapes in ImageView. You just need to create shapes, add shapes to ZdogDrawable, and then call the setImageDrawable method of ImageView to display ZdogDrawable.

// Attach shapes to ZdogDrawable and set animations
val drawable = ZdogDrawable().apply { 
    // Create a shape 
    shape {
        addTo = illo // add to ZdogDrawable
        path(
            move(x = -32f, y = -40f),
            line(x = 32f, y = -40f),
            line(x = -32f, y = 40f),
            line(x = 32f, y = 40f)
        )
        closed = false
        stroke = 20f
        color = "#636"
    }
    // Set animations, rotate the Illustration
    play(illo.rotateTo(y = TAU.toFloat()).duration(3000).repeat())
}

// Attach ZdogDrawable to ImageView
imageView.setImageDrawable(drawable)

// Start animation
drawable.start()

Final display effect:

z shape

Extended features

We can also use the powerful features of Android Canvas to achieve some cool effects that can't be achieved in Zdog. Here I extend the following features. Through the combination of these features, you can achieve many cool effects.

Segment

It allows shapes to display only part of the image.

ZdogDrawable().apply {
    illo.alpha(0f) // Set background transparent
    val line = shape { // Create a shape
        addTo = illo // Add to drawable
        path(
            move(x = -32f, y = -40f),
            line(x = 32f, y = -40f),
            line(x = -32f, y = 40f),
            line(x = 32f, y = 40f)
        )
        closed = false
        stroke = 20f
        color = "#636"
        updateSegment(0f, 0f) // Set segement 0
    }

    play(line.animate {
        onReset {
            line.updateSegment(0f, 1f) // Set segement 0-1, When the animation ends
        }

        update {
            line.updateSegment(0f, it) // Update segment by fraction
        }
    }.duration(1500).interpolator(FastOutSlowInInterpolator()).toReverse())
}

segment

Path Effect

It allows lines to be displayed in different effects, such as dashed lines.

ZdogDrawable().apply {
    illo.alpha(0f)
    shape { // A dot at (-90, 0, 0)
        addTo = illo
        path(
            move(-90f),
            line(-90f)
        )
        color = "#FD4"
        stroke = 16f
    }

    shape { // A dot at (90, 0, 0)
        addTo = illo
        path(
            move(90f),
            line(90f)
        )
        color = "#FD4"
        stroke = 16f
    }

    shape { // Create a half circle
        addTo = illo
        path(
            move(-90f, 0f),
            arc(
                vector(-90f, -90f),
                vector(0f, -90f)
            ),
            arc(
                vector(90f, -90f),
                vector(90f, 0f)
            )
        )
        translate { z = -8f }
        color = "#636"
        effect = DashPathEffect(floatArrayOf(20f, 10f), 0f) // Set dotted line effect
        stroke = 4f
        closed = false
    }

    illo.rotate { z = -(TAU / 8).toFloat() }
    play(
        illo.rotateBy(z = (TAU / 4).toFloat()).duration(1500)
            .interpolator(OvershootInterpolator()).toReverse()
    )
}

path effect

Gradient

It can fill shapes with gradient colors.

ZdogDrawable().apply {
    illo.alpha(0f)
    shape {
        addTo = illo
        path(
            move(-90f, 0f),
            arc(
                vector(-90f, 90f),
                vector(0f, 90f)
            ),
            arc(
                vector(90f, 90f),
                vector(90f, 0f)
            )
        )
        // Set a Vertical Linear Gradient from (0, 90) to (0, 0)
        shader = LinearGradient(
            0f, 90f, 0f, 0f,
            "#636".color, Color.TRANSPARENT, Shader.TileMode.CLAMP
        ) 
        fill = true
        stroke = 0f
        closed = false
    }

    illo.rotate { z = (TAU / 8).toFloat() }
    play(
        illo.rotateBy(z = -(TAU / 4).toFloat()).duration(1500)
            .interpolator(OvershootInterpolator()).toReverse()
    )
}

gradient

Shadow

It adds shadows to shapes.

ZdogDrawable().apply {
    illo.alpha(0f)
    shape {
        addTo = illo
        path(
            move(-90f, 0f),
            arc(
                vector(-90f, 90f),
                vector(0f, 90f)
            ),
            arc(
                vector(90f, 90f),
                vector(90f, 0f)
            )
        )
        color = "#fff"
        // Set a Shader Layer witch radius is 16
        layer = ShaderLayer(
            16f, 0f, 0f,
            Colors.shader.colour
        )
        stroke = 8f
        closed = false
    }

    illo.rotate { z = (TAU / 8).toFloat() }
    play(
        illo.rotateBy(z = -(TAU / 4).toFloat()).duration(1500)
            .interpolator(OvershootInterpolator()).toReverse()
    )
}

shadow

Path Animation

It allows the shape to move along a path.

ZdogDrawable().apply {
    illo.alpha(0f)
    val dotted = shape {
        addTo = illo
        path(
            move(-90f, 0f),
            arc(
                vector(-90f, -90f),
                vector(0f, -90f)
            ),
            arc(
                vector(90f, -90f),
                vector(90f, 0f)
            )
        )
        translate { z = -8f }
        color = "#636"
        effect = DashPathEffect(floatArrayOf(20f, 10f), 0f)
        stroke = 4f
        closed = false
    }

    // Get dotted path
    val keyframes =
        PathKeyframes(illo.renderToPath(dotted))
    val xFrames = keyframes.createXFloatKeyframes()
    val yFrames = keyframes.createYFloatKeyframes()

    val dot = shape {
        addTo = illo
        color = "#FD4"
        stroke = 16f

        translate {
            x = xFrames.getFloatValue(0f)
            y = yFrames.getFloatValue(0f)
        }
    }

    play(
        // Let the dot move along the dotted line
        dot.animate {
            onReset {
                dot.translate {
                    x = xFrames.getFloatValue(0f)
                    y = yFrames.getFloatValue(0f)
                }
            }

            update {
                dot.translate {
                    x = xFrames.getFloatValue(it)
                    y = yFrames.getFloatValue(it)
                }
            }
        }.duration(1500).interpolator(FastOutSlowInInterpolator())
            .toReverse()
    )
}

path_animation

Real-time update path

It can update the path to change the shape in animations.

ZdogDrawable().apply {
    illo.alpha(0f)
    val arrow = shape {
        addTo = illo
        path(
            move(-80f, 40f),
            line(0f, -40f),
            line(80f, 40f)
        )
        color = "#fff"
        stroke = 10f
        layer = ShaderLayer(
            16f, 0f, 0f,
            Colors.shader.colour
        )
        closed = false
    }

    // Update the path to change the shape of the arrow
    fun updatePath(shape: Shape, top: Float) {
        shape.apply {
            path[0].point().y = -top
            path[1].point().y = top
            path[2].point().y = -top
        }
    }

    play(arrow.animate {
        onReset {
            updatePath(arrow, 40f)
        }

        update {
            updatePath(arrow, -40f + it * 80f)
        }
    }.duration(1500).toReverse())
}

update path

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].