// 使用三目运算符的示例 height := 10; width := 5; // 三目运算符判断矩形是横长还是竖长 isTall := height > width ? {true} : {false}; // 输出结果 Scene.addText({ text := isTall ? {"矩形是竖长的"} : {"矩形是横长的"}; pos := [0, 2]; size := 0.5; }); // 使用alloc关键字实例化类 Person := { p := alloc; p.name := "默认名称"; p.age := 0; p.greet := null; p -> { greet := (message) => { return p.name + "说: " + message; }; }; p; }; // 创建人类实例 student := Person; student.name := "小明"; student.age := 15; // 调用方法并使用三目运算符决定消息 message := student.age >= 18 ? {"我是成年人"} : {"我是未成年人"}; result := student.greet(message); // 在场景中显示结果 Scene.addText({ text := result; pos := [0, 0]; size := 0.5; }); // 使用for循环和三目运算符创建彩色物体 for(5, (i) => { color := i % 2 == 0 ? {[1, 0, 0, 1]} : {[0, 0, 1, 1]}; Scene.addCircle({ pos := [i - 2, -2]; radius := 0.3; color := color; restitution := 0.8; }); });