Last active
July 17, 2021 10:53
-
-
Save Simarjot-sk/d15a278839aac249a2e86f1ea0eec725 to your computer and use it in GitHub Desktop.
Creates a circle shaped android vector drawable of given radius.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.simarjot | |
import java.util.* | |
class Vector(val x: Float, val y: Float){ | |
override fun toString() :String{ | |
return "$x,$y" | |
} | |
} | |
fun main(){ | |
val scanner = Scanner(System.`in`) | |
print("enter the radius of the circle") | |
val radius = scanner.nextFloat() | |
print("enter the x and y coordinates of the circle") | |
val x = scanner.nextFloat() | |
val y = scanner.nextFloat() | |
val curve = Bezier(radius, Vector(x,y)) | |
curve.draw() | |
} | |
class Bezier(val radius:Float, val center: Vector){ | |
companion object{ | |
const val m = 0.5544f | |
} | |
fun draw(){ | |
var result = firstArc() | |
result += secondArc() | |
result += thirdArc() | |
result += fourthArc() | |
print(result) | |
} | |
private fun firstArc(): String{ | |
var output = "" | |
val o = Vector(center.x, center.y - radius) | |
output += "M $o " | |
val p1 = Vector(o.x + (m * radius), o.y) | |
val p2 = Vector(o.x + radius, o.y + (radius - (m * radius))) | |
val end = Vector(center.x + radius, center.y) | |
output += "C $p1 $p2 $end" | |
return output | |
} | |
private fun secondArc() : String{ | |
var output = "" | |
//we are at this point after drawing the first arc. | |
val o = Vector(center.x + radius, center.y) | |
val p1 = Vector(o.x , o.y + (m * radius)) | |
val p2 = Vector(center.x + (m*radius), center.y + radius) | |
val end = Vector(center.x, center.y + radius) | |
output += " C $p1 $p2 $end" | |
return output | |
} | |
private fun thirdArc() : String{ | |
var output = "" | |
//we are at this point after drawing the first arc. | |
val o = Vector(center.x, center.y + radius) | |
val p1 = Vector(o.x - (m*radius), o.y) | |
val p2 = Vector(center.x - radius, center.y + (m * radius)) | |
val end = Vector(center.x - radius, center.y) | |
output += " C $p1 $p2 $end" | |
return output | |
} | |
private fun fourthArc() : String{ | |
var output = "" | |
//we are at this point after drawing the first arc. | |
val o = Vector(center.x - radius, center.y) | |
val p1 = Vector(o.x , o.y - (m*radius)) | |
val p2 = Vector(center.x - radius + (radius*m), center.y - radius ) | |
val end = Vector(center.x , center.y - radius) | |
output += " C $p1 $p2 $end" | |
return output | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment