# Writing Processing in Kotlin

**URL:** <https://discourse.processing.org/t/writing-processing-in-kotlin/3957>\
**Category:** Processing\
**Created:** [September 29, 2018, 4:42pm UTC](https://discourse.processing.org/t/writing-processing-in-kotlin/3957 "2018-09-29T16:42:12Z")\
**Posts on this page:** 1\
**Showing post:** 24

<div class="post-metadata">

**Author:** ![hamoid](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hamoid/32/58_2.png) [@hamoid](https://discourse.processing.org/u/hamoid)\
**Post date:** [May 10, 2019, 5:32pm UTC](https://discourse.processing.org/t/writing-processing-in-kotlin/3957/24 "2019-05-10T17:32:31Z")

</div>

Thank you @cansik for posting your code! Very useful to learn this new approach 🙂

Question: I’m trying to inherit from PGraphics3D but apparently when I call LCircle.draw() the PGraphics has not been initialized (NPE at `clear()`). Any ideas?

```auto
package com.hamoid

import processing.core.PApplet
import processing.core.PConstants

class Basic : PApplet() {
    lateinit var layer : LCircle
    companion object Factory {
        fun run() {
            val art = Basic()
            //art.setSize(700, 500)
            art.runSketch()
        }
    }

    override fun settings() {
        size(700, 500, PConstants.P3D)
    }

    override fun setup() {
        background(70.0f, 20.0f, 200.0f)
        layer = LCircle(this, 500, 500)
    }

    override fun draw() {
        line(0.0f, 0.0f, width * 1.0f, height * 1.0f);
        layer.draw()
    }
}

fun main() {
    Basic.run()
}

```

This is an example “hello world” layer:

```auto
package com.hamoid

import processing.core.PApplet
import processing.opengl.PGraphics3D

class LCircle(p5: PApplet, w: Int, h: Int) : PGraphics3D() {
    init {
        setParent(p5)
        setPrimary(false)
        setSize(w, h)
    }

    fun draw() {
        clear()
        fill(255)
        circle(width* 0.5f, height * 0.5f, 100.0f)
    }
}

```

Update: the thing that was missing was a `beginDraw()` / `endDraw()` inside `fun draw()`. The clean syntax (without the `myPG.` prefix) made me forget I was inside a PGraphics.

---

_[View the full topic](https://discourse.processing.org/t/writing-processing-in-kotlin/3957)._
