-
Notifications
You must be signed in to change notification settings - Fork 8
/
P41_a.kt
50 lines (41 loc) · 1.22 KB
/
P41_a.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.example.cse225_one
import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.view.MotionEvent
import android.view.View
class CustomDrawing(context: Context?) : View(context) {
lateinit var p: Paint
var x: Int = 0
fun init() {
p = Paint()
}
override fun onDraw(canvas: Canvas) {
canvas.drawColor(Color.BLUE)
p.color = Color.YELLOW
canvas.drawRect(100f, 100f, 500f, 500f, p)
p.color = Color.GREEN
canvas.drawRect(105f, 100f, 500f, 500f, p)
canvas.drawArc(500f, 500f, 800f, 800f, x.toFloat(), 30f, true, p)
canvas.drawArc(500f, 500f, 800f, 800f, (x + 120).toFloat(), 30f, true, p)
canvas.drawArc(500f, 500f, 800f, 800f, (x + 240).toFloat(), 30f, true, p)
}
override fun onTouchEvent(event: MotionEvent?): Boolean {
for (i in 0..50000) {
when (event?.action) {
MotionEvent.ACTION_MOVE -> startFan()
MotionEvent.ACTION_UP -> stopFan()
}
}
return true
}
fun stopFan() {}
fun startFan() {
x = x + 5
invalidate()
}
init {
init()
}
}