|
@ -26,7 +26,6 @@ class CanvasPendulum @JvmOverloads constructor( |
|
|
this.canvas = it |
|
|
this.canvas = it |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//println("ONDRAW") |
|
|
|
|
|
//draw line |
|
|
//draw line |
|
|
mPendulum.startPosition.x = (width / 2).toFloat() |
|
|
mPendulum.startPosition.x = (width / 2).toFloat() |
|
|
paint.isAntiAlias = true |
|
|
paint.isAntiAlias = true |
|
@ -84,25 +83,26 @@ class CanvasPendulum @JvmOverloads constructor( |
|
|
|
|
|
|
|
|
fun startPendulum() { |
|
|
fun startPendulum() { |
|
|
|
|
|
|
|
|
|
|
|
//when active button is pushed |
|
|
if (mPendulum.magneticField) { |
|
|
if (mPendulum.magneticField) { |
|
|
|
|
|
|
|
|
var gravity = 0.981f |
|
|
var gravity = 0.981f |
|
|
var damping = 0.996f |
|
|
var damping = 0.996f |
|
|
|
|
|
|
|
|
|
|
|
//Pendulum positioning inside magnetic field close to Sensor left and right |
|
|
if (mPendulum.stopPosition.x > canvas.width / 4f && mPendulum.stopPosition.x <= canvas.width * 0.75f) { |
|
|
if (mPendulum.stopPosition.x > canvas.width / 4f && mPendulum.stopPosition.x <= canvas.width * 0.75f) { |
|
|
gravity = 1.981f |
|
|
gravity = 1.981f |
|
|
|
|
|
|
|
|
|
|
|
//Pendulum positioning inside magnetic field at Sensor left and right |
|
|
if (mPendulum.stopPosition.x > canvas.width / 3.toFloat() && mPendulum.stopPosition.x <= canvas.width / 1.5.toFloat()) { |
|
|
if (mPendulum.stopPosition.x > canvas.width / 3.toFloat() && mPendulum.stopPosition.x <= canvas.width / 1.5.toFloat()) { |
|
|
gravity = 2.981f |
|
|
gravity = 2.981f |
|
|
|
|
|
|
|
|
|
|
|
//Pendulum positioning inside magnetic field close to magnet |
|
|
if (mPendulum.stopPosition.x >= canvas.width / 2.toFloat() - 3 && mPendulum.stopPosition.x <= canvas.width / 2.toFloat() + 3) { |
|
|
if (mPendulum.stopPosition.x >= canvas.width / 2.toFloat() - 3 && mPendulum.stopPosition.x <= canvas.width / 2.toFloat() + 3) { |
|
|
damping = 0.3f |
|
|
damping = 0.3f |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
mPendulum.angleAcceleration = |
|
|
|
|
|
((-1 * gravity / mPendulum.r) * (mPendulum.angle)).toFloat() |
|
|
|
|
|
|
|
|
mPendulum.angleAcceleration = ((-1 * gravity / mPendulum.r) * (mPendulum.angle)).toFloat() |
|
|
mPendulum.angleVelocity += mPendulum.angleAcceleration |
|
|
mPendulum.angleVelocity += mPendulum.angleAcceleration |
|
|
mPendulum.angleVelocity *= damping |
|
|
mPendulum.angleVelocity *= damping |
|
|
mPendulum.angle += mPendulum.angleVelocity |
|
|
mPendulum.angle += mPendulum.angleVelocity |
|
@ -113,12 +113,12 @@ class CanvasPendulum @JvmOverloads constructor( |
|
|
mPendulum.stopPosition.x += mPendulum.startPosition.x |
|
|
mPendulum.stopPosition.x += mPendulum.startPosition.x |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//when active button released |
|
|
if (!mPendulum.magneticField) { |
|
|
if (!mPendulum.magneticField) { |
|
|
val gravity = 0.981f |
|
|
val gravity = 0.981f |
|
|
val damping = 0.996f |
|
|
val damping = 0.996f |
|
|
|
|
|
|
|
|
mPendulum.angleAcceleration = |
|
|
|
|
|
((-1 * gravity / mPendulum.r) * (mPendulum.angle)).toFloat() |
|
|
|
|
|
|
|
|
mPendulum.angleAcceleration = ((-1 * gravity / mPendulum.r) * (mPendulum.angle)).toFloat() |
|
|
mPendulum.angleVelocity += mPendulum.angleAcceleration |
|
|
mPendulum.angleVelocity += mPendulum.angleAcceleration |
|
|
mPendulum.angleVelocity *= damping |
|
|
mPendulum.angleVelocity *= damping |
|
|
mPendulum.angle += mPendulum.angleVelocity |
|
|
mPendulum.angle += mPendulum.angleVelocity |
|
@ -156,10 +156,9 @@ class Pendulum { |
|
|
var stopPosition: Position = Position(0f, 0f) |
|
|
var stopPosition: Position = Position(0f, 0f) |
|
|
var r = 800f |
|
|
var r = 800f |
|
|
|
|
|
|
|
|
//PI/6 Max ausschwingen |
|
|
|
|
|
var angle: Double = Math.PI / 12 |
|
|
var angle: Double = Math.PI / 12 |
|
|
var angleVelocity: Float = 0.0f // |
|
|
|
|
|
var angleAcceleration: Float = 0.0f // |
|
|
|
|
|
var ballr: Float = 70.0f // |
|
|
|
|
|
|
|
|
var angleVelocity: Float = 0.0f |
|
|
|
|
|
var angleAcceleration: Float = 0.0f |
|
|
|
|
|
var ballr: Float = 70.0f |
|
|
var magneticField: Boolean = false |
|
|
var magneticField: Boolean = false |
|
|
} |
|
|
} |