Skip to content

Commit

Permalink
Few changes and example setup
Browse files Browse the repository at this point in the history
  • Loading branch information
VOSID8 committed Aug 20, 2024
1 parent ced2f8e commit 24bc8c5
Showing 1 changed file with 36 additions and 36 deletions.
72 changes: 36 additions & 36 deletions canvas/src/main/scala/doodle/canvas/algebra/Immediate.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ trait Immediate {
def arc(
x: Int,
y: Int,
radius: Int,
diameter: Int,
startAngle: Double,
endAngle: Double,
counterclockwise: Boolean = false,
Expand All @@ -40,7 +40,7 @@ trait Immediate {
y1: Int,
x2: Int,
y2: Int,
radius: Int,
diameter: Int,
counterclockwise: Boolean = false,
closedPath: Boolean = false,
segments: Array[Double] = Array.empty[Double]
Expand All @@ -60,7 +60,7 @@ trait Immediate {
def clipArc(
x: Int,
y: Int,
radius: Int,
diameter: Int,
startAngle: Double = 0,
endAngle: Double = 2 * Math.PI,
counterclockwise: Boolean = false
Expand All @@ -70,7 +70,7 @@ trait Immediate {
def circle(
x: Double,
y: Double,
radius: Double,
diameter: Double,
segments: Array[Double] = Array.empty[Double]
): Unit
def dashLine(
Expand All @@ -90,8 +90,8 @@ trait Immediate {
def ellipseWithRotation(
x: Double,
y: Double,
radiusX: Double,
radiusY: Double,
diameterX: Double,
diameterY: Double,
rotation: Double,
startAngle: Double,
endAngle: Double,
Expand All @@ -105,7 +105,7 @@ trait Immediate {
def pentagon(
x: Double,
y: Double,
radius: Double,
diameter: Double,
segments: Array[Double] = Array.empty[Double]
): Unit
def quadraticCurveTo(cpx: Double, cpy: Double, x: Double, y: Double): Unit
Expand All @@ -122,13 +122,13 @@ trait Immediate {
y: Int,
width: Int,
height: Int,
radius: Int,
diameter: Int,
segments: Array[Double] = Array.empty[Double]
): Unit
def star(
x: Double,
y: Double,
radius: Double,
diameter: Double,
segments: Array[Double] = Array.empty[Double]
): Unit
def stroke(color: Color): Unit
Expand Down Expand Up @@ -175,7 +175,7 @@ class ImmediateImpl(
def arc(
x: Int,
y: Int,
radius: Int,
diameter: Int,
startAngle: Double,
endAngle: Double,
counterclockwise: Boolean = false,
Expand All @@ -185,7 +185,7 @@ class ImmediateImpl(
val x0 = x - rasterWidth / 2
val y0 = y - rasterHeight / 2
ctx.beginPath()
ctx.arc(x0, y0, radius, startAngle, endAngle, counterclockwise)
ctx.arc(x0, y0, diameter / 2, startAngle, endAngle, counterclockwise)
if closedPath then ctx.closePath();
ctx.stroke()
}
Expand All @@ -195,13 +195,13 @@ class ImmediateImpl(
y1: Int,
x2: Int,
y2: Int,
radius: Int,
diameter: Int,
counterclockwise: Boolean = false,
closedPath: Boolean = false,
segments: Array[Double] = Array.empty[Double]
): Unit = {
ctx.beginPath()
ctx.arcTo(x1, y1, x2, y2, radius)
ctx.arcTo(x1, y1, x2, y2, diameter / 2)
ctx.stroke()
}

Expand Down Expand Up @@ -237,14 +237,14 @@ class ImmediateImpl(
def clipArc(
x: Int,
y: Int,
radius: Int,
diameter: Int,
startAngle: Double = 0,
endAngle: Double = 2 * Math.PI,
counterclockwise: Boolean = false
): Unit = {
val x0 = x - rasterWidth / 2
val y0 = y - rasterHeight / 2
region.arc(x0, y0, radius, startAngle, endAngle, counterclockwise)
region.arc(x0, y0, diameter / 2, startAngle, endAngle, counterclockwise)
}

def clipRect(x: Int, y: Int, width: Int, height: Int): Unit = {
Expand All @@ -260,14 +260,14 @@ class ImmediateImpl(
def circle(
x: Double,
y: Double,
radius: Double,
diameter: Double,
segments: Array[Double] = Array.empty[Double]
): Unit = {
val x0 = x - rasterWidth / 2.0
val y0 = y - rasterHeight / 2.0
ctx.beginPath()
ctx.setLineDash(segments.toJSArray)
ctx.arc(x0, y0, radius, 0, 2 * Math.PI)
ctx.arc(x0, y0, diameter / 2, 0, 2 * Math.PI)
ctx.stroke()
}

Expand Down Expand Up @@ -306,8 +306,8 @@ class ImmediateImpl(
def ellipseWithRotation(
x: Double,
y: Double,
radiusX: Double,
radiusY: Double,
diameterX: Double,
diameterY: Double,
rotation: Double,
startAngle: Double,
endAngle: Double,
Expand All @@ -320,8 +320,8 @@ class ImmediateImpl(
ctx.ellipse(
x0,
y0,
radiusX,
radiusY,
diameterX,
diameterY,
rotation,
startAngle,
endAngle,
Expand Down Expand Up @@ -380,24 +380,24 @@ class ImmediateImpl(
def pentagon(
x: Double,
y: Double,
radius: Double,
diameter: Double,
segments: Array[Double] = Array.empty[Double]
): Unit = {
val x0 = x - radius / 2
val y0 = y - radius / 2
val x0 = x - rasterWidth / 2
val y0 = y - rasterHeight / 2

@tailrec
def drawSide(i: Int): Unit = {
if i <= 5 then {
val angle = 2 * Math.PI * i / 5
val x1 = x0 + radius * Math.cos(angle)
val y1 = y0 + radius * Math.sin(angle)
val x1 = x0 + (diameter / 2) * Math.cos(angle)
val y1 = y0 + (diameter / 2) * Math.sin(angle)
ctx.lineTo(x1, y1)
drawSide(i + 1)
}
}
ctx.beginPath()
ctx.moveTo(x0 + radius, y0)
ctx.moveTo(x0 + (diameter / 2), y0)
drawSide(1)
}

Expand Down Expand Up @@ -429,28 +429,28 @@ class ImmediateImpl(
y: Int,
width: Int,
height: Int,
radius: Int,
diameter: Int,
segments: Array[Double] = Array.empty[Double]
): Unit = {
val x0 = x - rasterWidth / 2
val y0 = y - rasterHeight / 2
ctx.beginPath()
ctx.moveTo(x0 + radius, y0)
ctx.arcTo(x0 + width, y0, x0 + width, y0 + height, radius)
ctx.arcTo(x0 + width, y0 + height, x0, y0 + height, radius)
ctx.arcTo(x0, y0 + height, x0, y0, radius)
ctx.arcTo(x0, y0, x0 + width, y0, radius)
ctx.moveTo(x0 + (diameter / 2), y0)
ctx.arcTo(x0 + width, y0, x0 + width, y0 + height, diameter / 2)
ctx.arcTo(x0 + width, y0 + height, x0, y0 + height, diameter / 2)
ctx.arcTo(x0, y0 + height, x0, y0, diameter / 2)
ctx.arcTo(x0, y0, x0 + width, y0, diameter / 2)
ctx.fill()
}

def star(
x1: Double,
y1: Double,
radius: Double,
diameter: Double,
segments: Array[Double] = Array.empty[Double]
): Unit = {
val outerRadius = radius
val innerRadius = radius / 2
val outerRadius = diameter / 2
val innerRadius = diameter / 4
val angle = Math.PI / 5
val x = x1 - rasterWidth / 2
val y = y1 - rasterHeight / 2
Expand Down

0 comments on commit 24bc8c5

Please sign in to comment.