功能:
- A键,放大
- B键,缩小
- 上下左右,移动
代码
图形编程比较复杂,图形块比较多,所以只贴出了代码,可以将代码粘贴到Arcade的Javascript编辑器中,然后切换回图形方式。
代码: 全选
function calc (x: number, y: number) {
a = x
b = y
n = 0
for (let p = 0; p <= 220; p++) {
tx = x * x - y * y + a
ty = 2 * x * y + b
if (tx * tx + ty * ty > 4) {
n = p
return
}
x = tx
y = ty
}
}
function draw (cx: number, cy: number, zoom: number) {
music.playTone(784, music.beat(BeatFraction.Sixteenth))
for (let i = 0; i <= scene.screenWidth(); i++) {
for (let j = 0; j <= scene.screenHeight(); j++) {
calc(cx + 4 * (i - scene.screenWidth() / 2) / scene.screenWidth() / zoom, cy + 4 * (j - scene.screenHeight() / 2) / scene.screenHeight() / zoom)
scene.backgroundImage().setPixel(i, j, n)
}
}
music.playTone(880, music.beat(BeatFraction.Sixteenth))
}
controller.A.onEvent(ControllerButtonEvent.Pressed, function () {
zoom = zoom * 2
draw(cx, cy, zoom)
})
controller.B.onEvent(ControllerButtonEvent.Pressed, function () {
zoom = zoom / 2
draw(cx, cy, zoom)
})
controller.left.onEvent(ControllerButtonEvent.Pressed, function () {
cx = cx - 1 / 8 / zoom
draw(cx, cy, zoom)
})
controller.up.onEvent(ControllerButtonEvent.Pressed, function () {
cy = cy - 1 / 8 / zoom
draw(cx, cy, zoom)
})
controller.down.onEvent(ControllerButtonEvent.Pressed, function () {
cy = cy + 1 / 8 / zoom
draw(cx, cy, zoom)
})
controller.right.onEvent(ControllerButtonEvent.Pressed, function () {
cx = cx + 1 / 8 / zoom
draw(cx, cy, zoom)
})
let y = 0
let x = 0
let ty = 0
let tx = 0
let n = 0
let b = 0
let a = 0
let cy = 0
let cx = 0
let zoom = 0
zoom = 1
draw(cx, cy, zoom)
在线编辑