在线编辑
参考代码
代码: 全选
function init() {
scene.backgroundImage().fillRect(0, 0, scene.screenWidth(), scene.screenHeight(), 15)
x = 1
y = 1
z = 1
a = Math.randomRange(50, 200) / 10
b = Math.randomRange(150, 300) / 10
c = Math.randomRange(10, 30) / 10
scene.backgroundImage().print(a.toString(), 0, 0)
scene.backgroundImage().print(b.toString(), 0, 10)
scene.backgroundImage().print(c.toString(), 0, 20)
}
function calc() {
x1 = x - a * x * dt + a * y * dt
y1 = y + b * x * dt - y * dt - x * z * dt
z1 = z - c * z * dt + x * y * dt
color = Math.abs(x1 - x) + Math.abs(y1 - y) + Math.abs(z1 - z)
console.logValue("L", color)
color = Math.round(color * 4) % 14 + 1
console.logValue("C", color)
draw((x + y) / 2, z, (x1 + y1) / 2, z1)
x = x1
y = y1
z = z1
}
function draw(x1: number, y1: number, x2: number, y2: number) {
// color = Math.abs(x1 - x2) + Math.abs(y1 - y2)
// console.logValue("L", color)
// color = Math.round(color * 4) % 14 + 1
// console.logValue("C", color)
scene.backgroundImage().drawLine(x1 * 3 + scene.screenWidth() / 2, scene.screenHeight() - y1 * 3, x2 * 3 + scene.screenWidth() / 2, scene.screenHeight() - y2 * 3, color)
}
controller.anyButton.onEvent(ControllerButtonEvent.Pressed, function () {
init()
})
let color = 0
let z1 = 0
let y1 = 0
let x1 = 0
let x = 0
let y = 0
let z = 0
let dt = 0
let a = 0
let b = 0
let c = 0
c = 2
b = 15
a = 5
dt = 0.02
z = 1
y = 1
x = 1
forever(function () {
calc()
if (x > 100) {
music.playTone(262, music.beat(BeatFraction.Eighth))
init()
}
})