|
|
@ -2,6 +2,7 @@ package com.example.acapendulum20.canvas |
|
|
|
|
|
|
|
import android.content.Context |
|
|
|
import android.graphics.Canvas |
|
|
|
import android.graphics.Color |
|
|
|
import android.graphics.Paint |
|
|
|
import android.util.AttributeSet |
|
|
|
import android.view.View |
|
|
@ -11,32 +12,48 @@ class CanvasPendulum @JvmOverloads constructor( |
|
|
|
) : View(context, attrs, defStyleAttr) { |
|
|
|
|
|
|
|
|
|
|
|
val paint: Paint = Paint() |
|
|
|
lateinit var canvas: Canvas |
|
|
|
private val paint: Paint = Paint() |
|
|
|
private lateinit var canvas: Canvas |
|
|
|
private var pendulumLineStopX = 200f |
|
|
|
private var pendulumLineStopY = 600f |
|
|
|
//var pendulumOnMove = false |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onDraw(canvas: Canvas?) { |
|
|
|
super.onDraw(canvas) |
|
|
|
|
|
|
|
paint.style = Paint.Style.STROKE |
|
|
|
//paint.strokeWidth = 10f |
|
|
|
//canvas?.drawCircle(500f, 700f, 70f, paint) |
|
|
|
paint.strokeWidth = 9f |
|
|
|
canvas?.drawLine(455f,0f,500f, 630f,paint) |
|
|
|
|
|
|
|
//if canvas not NULL then this canvas = it |
|
|
|
canvas?.let { |
|
|
|
this.canvas = it |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
fun drawPendulum() { |
|
|
|
fun startPendulum() { |
|
|
|
//pendulumOnMove = false |
|
|
|
paint.style = Paint.Style.STROKE |
|
|
|
paint.strokeWidth = 10f |
|
|
|
canvas.drawCircle(500f, 700f, 70f, paint) |
|
|
|
//paint.strokeWidth = 10f |
|
|
|
//canvas.drawCircle(200f, 700f, 70f, paint)// cx&cy -> Variable |
|
|
|
paint.strokeWidth = 9f |
|
|
|
canvas.drawLine(455f,0f,500f, 630f,paint) |
|
|
|
canvas.drawColor(Color.WHITE) |
|
|
|
canvas.drawLine(455f,0f,pendulumLineStopX, pendulumLineStopY,paint) //stopX&stopY -> Variable |
|
|
|
println("excess to startPendulum function") |
|
|
|
} |
|
|
|
|
|
|
|
fun stopDrawingPendulum() { |
|
|
|
canvas.drawCircle(400f, 300f, 70f, paint) |
|
|
|
//canvas.drawCircle(400f, 300f, 70f, paint) |
|
|
|
//pendulumOnMove = false |
|
|
|
//canvas.drawColor(Color.WHITE) |
|
|
|
//canvas.drawLine(455f,0f,500f, 630f,paint) //stopX&stopY -> Variable |
|
|
|
println("excess to stopDrawingPendulum function") |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|