Code Sketch
Bixuu02 Robot
Category: Programming
import java.awt._
import java.awt.event._
import java.awt.geom._
import java.awt.datatransfer.StringSelection
import java.nio.charset.StandardCharsets
import java.nio.file.Files
import javax.swing._
import javax.swing.border._
import javax.swing.event.{ChangeEvent, ChangeListener}
import javax.swing.filechooser.FileNameExtensionFilter
import scala.util.Try
/**
* BIXUU Robot Code Creator
* One-file Scala desktop app; uses Java Swing/AWT only (no external libraries).
* Script-runner edition: includes a final explicit launch call at the bottom.
* Use the regular BixuuRobotCodeCreator.scala file for normal Scala CLI / IDE builds.
*/
object BixuuRobotCodeCreator {
/** Explicit launcher. Call this from main() or from a script-style Scala editor. */
def launch(): Unit = {
if (GraphicsEnvironment.isHeadless) {
System.err.println("BIXUU Robot Code Creator needs a desktop session to display its window. Run it on your Windows desktop, not in a headless/console-only runner.")
} else {
val showWindow = new Runnable {
override def run(): Unit = {
try {
try UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName) catch { case _: Throwable => () }
val frame = new CreatorFrame()
frame.setVisible(true)
frame.setState(Frame.NORMAL)
frame.toFront()
frame.requestFocus()
} catch {
case ex: Throwable =>
ex.printStackTrace()
JOptionPane.showMessageDialog(
null,
"The BIXUU window could not be opened.\n" + Option(ex.getMessage).getOrElse(ex.getClass.getName) +
"\n\nRun this as a desktop Scala Swing application, then check the console if it still fails.",
"BIXUU Robot Code Creator - Startup Error",
JOptionPane.ERROR_MESSAGE
)
}
}
}
if (SwingUtilities.isEventDispatchThread) showWindow.run()
else SwingUtilities.invokeLater(showWindow)
}
}
def main(args: Array[String]): Unit = launch()
private val appBg = new Color(5, 9, 25)
private val panelBg = new Color(11, 18, 43)
private val accent = new Color(0, 225, 255)
private val purple = new Color(185, 72, 255)
private val whiteBlue = new Color(215, 240, 255)
case class Theme(name: String, primary: Color, secondary: Color, background: Color)
val themes: Vector[Theme] = Vector(
Theme("Cyber Cyan + Violet", new Color(0, 225, 255), new Color(190, 65, 255), new Color(3, 7, 25)),
Theme("Disco Pink + Blue", new Color(255, 55, 175), new Color(0, 190, 255), new Color(17, 3, 26)),
Theme("Solar Gold", new Color(255, 190, 45), new Color(255, 75, 60), new Color(22, 9, 5)),
Theme("Matrix Green", new Color(60, 255, 145), new Color(0, 190, 180), new Color(2, 19, 14)),
Theme("Ice Blue", new Color(135, 210, 255), new Color(170, 130, 255), new Color(3, 12, 30))
)
case class RobotConfig(
title: String,
description: String,
theme: Theme,
dancing: Boolean,
disco: Boolean,
wings: Boolean,
hologram: Boolean,
particles: Boolean,
speed: Int
)
private def colorWithAlpha(c: Color, a: Int): Color =
new Color(c.getRed, c.getGreen, c.getBlue, math.max(0, math.min(255, a)))
private def scalaString(s: String): String = {
val clean = Option(s).getOrElse("")
"\"" + clean.flatMap {
case '\\' => "\\\\"
case '"' => "\\\""
case '\n' => "\\n"
case '\r' => "\\r"
case '\t' => "\\t"
case c if c < ' ' => " "
case c => c.toString
} + "\""
}
private def rgb(c: Color): String =
"new Color(" + c.getRed + ", " + c.getGreen + ", " + c.getBlue + ")"
private def standaloneSource(cfg: RobotConfig): String = {
val raw = """import java.awt._
import java.awt.event._
import java.awt.geom._
import javax.swing._
/** Generated by BIXUU Robot Code Creator. Run this file as a normal Scala app. */
object GeneratedBixuuRobot extends App {
val robotTitle = __TITLE__
val robotDescription = __DESC__
val primary = __PRIMARY__
val secondary = __SECONDARY__
val backgroundColor = __BACKGROUND__
val useDance = __DANCE__
val useDiscoLights = __DISCO__
val useWings = __WINGS__
val useHologram = __HOLOGRAM__
val useParticles = __PARTICLES__
val animationSpeed = __SPEED__
SwingUtilities.invokeLater(new Runnable {
override def run(): Unit = {
val frame = new JFrame("BIXUU ROBOT | " + robotTitle)
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE)
frame.setSize(1100, 760)
frame.setMinimumSize(new Dimension(800, 560))
frame.setLocationRelativeTo(null)
frame.setContentPane(new RobotCanvas)
frame.setVisible(true)
}
})
class RobotCanvas extends JPanel {
private var tick = 0.0
setBackground(backgroundColor)
val timer = new Timer(30, new ActionListener {
override def actionPerformed(e: ActionEvent): Unit = {
tick += 0.025 + animationSpeed * 0.009
repaint()
}
})
timer.start()
private def alpha(c: Color, a: Int): Color = new Color(c.getRed, c.getGreen, c.getBlue, math.max(0, math.min(255, a)))
private def fillOval(g: Graphics2D, x: Double, y: Double, w: Double, h: Double, c: Color): Unit = {
g.setColor(c); g.fill(new Ellipse2D.Double(x, y, w, h))
}
private def outlineOval(g: Graphics2D, x: Double, y: Double, w: Double, h: Double, c: Color, sw: Float): Unit = {
g.setColor(c); g.setStroke(new BasicStroke(sw)); g.draw(new Ellipse2D.Double(x, y, w, h))
}
private def fillRound(g: Graphics2D, x: Double, y: Double, w: Double, h: Double, arc: Double, c: Color): Unit = {
g.setColor(c); g.fill(new RoundRectangle2D.Double(x, y, w, h, arc, arc))
}
private def outlineRound(g: Graphics2D, x: Double, y: Double, w: Double, h: Double, arc: Double, c: Color, sw: Float): Unit = {
g.setColor(c); g.setStroke(new BasicStroke(sw)); g.draw(new RoundRectangle2D.Double(x, y, w, h, arc, arc))
}
private def line(g: Graphics2D, x1: Double, y1: Double, x2: Double, y2: Double, c: Color, sw: Float): Unit = {
g.setColor(c); g.setStroke(new BasicStroke(sw, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); g.draw(new Line2D.Double(x1, y1, x2, y2))
}
override protected def paintComponent(graphics: Graphics): Unit = {
super.paintComponent(graphics)
val g = graphics.create().asInstanceOf[Graphics2D]
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON)
g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY)
val w = getWidth.toDouble; val h = getHeight.toDouble
g.setPaint(new GradientPaint(0f, 0f, backgroundColor, w.toFloat, h.toFloat, new Color(15, 10, 42)))
g.fillRect(0, 0, getWidth, getHeight)
val cx = w * 0.43
val cy = h * 0.56
val s = math.max(0.56, math.min(w / 850.0, h / 590.0))
val active = if (useDiscoLights) Color.getHSBColor(((tick * 0.12) % 1.0).toFloat, 0.88f, 1.0f) else primary
val bob = if (useDance) math.sin(tick * 2.2) * 5.0 * s else 0.0
val y = cy + bob
// Nebula rings and stars
for (i <- 0 until 8) {
val pulse = math.sin(tick + i * 0.42) * 11.0
outlineOval(g, cx - (112 + i * 15 + pulse) * s, cy - (112 + i * 15 + pulse) * s,
(224 + i * 30 + pulse * 2) * s, (224 + i * 30 + pulse * 2) * s,
alpha(if (i % 2 == 0) active else secondary, 20 + i * 3), 1.4f)
}
for (i <- 0 until 150) {
val sx = ((i * 137 + 31) % math.max(1, getWidth)).toDouble
val sy = ((i * 83 + 17) % math.max(1, getHeight)).toDouble
val tw = 1.0 + math.abs(math.sin(tick * 2 + i * 0.3)) * 2.0
fillOval(g, sx, sy, tw, tw, alpha(if (i % 8 == 0) secondary else new Color(175, 225, 255), 70 + (math.abs(math.sin(tick + i)) * 180).toInt))
}
// Neon floor and HUD corners
for (i <- 0 until 12) line(g, 0, h * 0.79 + i * 8, w, h * 0.79 + i * 8, alpha(active, 45), 1f)
line(g, 0, h * 0.79, w, h * 0.79, alpha(secondary, 170), 2f)
line(g, 12, 18, 48, 18, active, 2f); line(g, 12, 18, 12, 48, active, 2f)
line(g, w - 12, 18, w - 48, 18, active, 2f); line(g, w - 12, 18, w - 12, 48, active, 2f)
// Energy wings
if (useWings) {
val flap = math.sin(tick * 2.4) * 13 * s
val left = new Path2D.Double(); left.moveTo(cx - 28*s, y - 30*s); left.lineTo(cx - 104*s, y - 75*s - flap); left.lineTo(cx - 80*s, y + 32*s - flap); left.closePath()
g.setColor(alpha(active, 28)); g.fill(left); g.setColor(alpha(active, 235)); g.setStroke(new BasicStroke(2.8f)); g.draw(left)
line(g, cx - 36*s, y - 23*s, cx - 88*s, y - 34*s - flap, alpha(new Color(205,245,255), 220), 1.8f)
val right = new Path2D.Double(); right.moveTo(cx + 28*s, y - 30*s); right.lineTo(cx + 104*s, y - 75*s + flap); right.lineTo(cx + 80*s, y + 32*s + flap); right.closePath()
g.setColor(alpha(secondary, 28)); g.fill(right); g.setColor(alpha(secondary, 240)); g.setStroke(new BasicStroke(2.8f)); g.draw(right)
line(g, cx + 36*s, y - 23*s, cx + 88*s, y - 34*s + flap, alpha(new Color(220,240,255), 220), 1.8f)
fillOval(g, cx - 92*s, y - 16*s - flap, 10*s, 10*s, Color.WHITE)
fillOval(g, cx + 82*s, y - 16*s + flap, 10*s, 10*s, Color.WHITE)
}
// Energy orbit
for (i <- 0 until 4) outlineOval(g, cx - (76 + i*12)*s, y - (13 + i*3)*s,
(152 + i*24)*s, (26 + i*6)*s, alpha(if(i%2==0) active else secondary, 75 + (math.abs(math.sin(tick+i))*130).toInt), 1.8f)
// Arms and shoulders
val armSwing = if (useDance) math.sin(tick * 3.0) * 16 * s else 0.0
line(g, cx - 32*s, y - 27*s, cx - 55*s, y + 9*s + armSwing, new Color(30,55,95), 17*s.toFloat)
line(g, cx + 32*s, y - 27*s, cx + 55*s, y + 9*s - armSwing, new Color(30,55,95), 17*s.toFloat)
line(g, cx - 32*s, y - 27*s, cx - 55*s, y + 9*s + armSwing, new Color(175,205,230), 9*s.toFloat)
line(g, cx + 32*s, y - 27*s, cx + 55*s, y + 9*s - armSwing, new Color(175,205,230), 9*s.toFloat)
line(g, cx - 33*s, y - 27*s, cx - 55*s, y + 9*s + armSwing, active, 2*s.toFloat)
line(g, cx + 33*s, y - 27*s, cx + 55*s, y + 9*s - armSwing, active, 2*s.toFloat)
fillOval(g, cx - 65*s, y + 1*s + armSwing, 20*s, 20*s, new Color(160,195,225)); outlineOval(g, cx - 65*s, y + 1*s + armSwing, 20*s, 20*s, active, 2f)
fillOval(g, cx + 45*s, y + 1*s - armSwing, 20*s, 20*s, new Color(160,195,225)); outlineOval(g, cx + 45*s, y + 1*s - armSwing, 20*s, 20*s, active, 2f)
// Legs and boots
fillRound(g, cx - 25*s, y + 39*s, 18*s, 50*s, 8*s, new Color(110,145,185)); outlineRound(g, cx - 25*s, y + 39*s, 18*s, 50*s, 8*s, active, 2f)
fillRound(g, cx + 7*s, y + 39*s, 18*s, 50*s, 8*s, new Color(110,145,185)); outlineRound(g, cx + 7*s, y + 39*s, 18*s, 50*s, 8*s, active, 2f)
fillOval(g, cx - 31*s, y + 79*s, 34*s, 20*s, new Color(20,36,75)); outlineOval(g, cx - 31*s, y + 79*s, 34*s, 20*s, active, 2.2f)
fillOval(g, cx + 1*s, y + 79*s, 34*s, 20*s, new Color(20,36,75)); outlineOval(g, cx + 1*s, y + 79*s, 34*s, 20*s, active, 2.2f)
line(g, cx - 23*s, y + 91*s, cx - 7*s, y + 91*s, active, 3f); line(g, cx + 9*s, y + 91*s, cx + 25*s, y + 91*s, active, 3f)
// Torso armour
fillOval(g, cx - 43*s, y - 43*s, 29*s, 29*s, new Color(45,82,135)); outlineOval(g, cx - 43*s, y - 43*s, 29*s, 29*s, active, 2.4f)
fillOval(g, cx + 14*s, y - 43*s, 29*s, 29*s, new Color(45,82,135)); outlineOval(g, cx + 14*s, y - 43*s, 29*s, 29*s, active, 2.4f)
fillRound(g, cx - 37*s, y - 50*s, 74*s, 91*s, 22*s, new Color(95,130,175)); outlineRound(g, cx - 37*s, y - 50*s, 74*s, 91*s, 22*s, new Color(205,230,250), 2.6f)
fillRound(g, cx - 28*s, y - 37*s, 56*s, 54*s, 12*s, new Color(5,13,40)); outlineRound(g, cx - 28*s, y - 37*s, 56*s, 54*s, 10*s, active, 2.5f)
fillOval(g, cx - 22*s, y - 31*s, 44*s, 44*s, alpha(active, 60)); outlineOval(g, cx - 18*s, y - 27*s, 36*s, 36*s, active, 2.5f)
outlineOval(g, cx - 12*s, y - 21*s, 24*s, 24*s, secondary, 2f)
fillOval(g, cx - 7*s, y - 16*s, 14*s, 14*s, active); fillOval(g, cx - 3*s, y - 12*s, 6*s, 6*s, Color.WHITE)
fillRound(g, cx - 24*s, y + 38*s, 48*s, 13*s, 5*s, new Color(30,62,108)); outlineRound(g, cx - 24*s, y + 38*s, 48*s, 13*s, 5*s, active, 2f)
// Helmet and neon visor
fillRound(g, cx - 34*s, y - 126*s, 68*s, 57*s, 17*s, new Color(150,185,215)); outlineRound(g, cx - 34*s, y - 126*s, 68*s, 57*s, 17*s, new Color(225,245,255), 3f)
fillRound(g, cx - 27*s, y - 113*s, 54*s, 28*s, 8*s, new Color(2,8,28)); outlineRound(g, cx - 27*s, y - 113*s, 54*s, 28*s, 8*s, active, 2.3f)
val eyeGlow = 170 + (math.abs(math.sin(tick * 3.0)) * 85).toInt
fillOval(g, cx - 19*s, y - 105*s, 13*s, 8*s, alpha(active, eyeGlow)); fillOval(g, cx + 6*s, y - 105*s, 13*s, 8*s, alpha(active, eyeGlow))
fillOval(g, cx - 15*s, y - 104*s, 4*s, 4*s, Color.WHITE); fillOval(g, cx + 10*s, y - 104*s, 4*s, 4*s, Color.WHITE)
line(g, cx - 9*s, y - 82*s, cx + 9*s, y - 82*s, active, 2f)
fillRound(g, cx - 16*s, y - 132*s, 32*s, 8*s, 5*s, new Color(35,70,120)); fillOval(g, cx - 7*s, y - 140*s, 14*s, 14*s, active); fillOval(g, cx - 3*s, y - 136*s, 6*s, 6*s, Color.WHITE)
// Particles around the robot
if (useParticles) for (i <- 0 until 34) {
val a = tick * 0.7 + i * math.Pi / 17
val r = (88 + (i % 5) * 9) * s
val px = cx + math.cos(a) * r
val py = y - 22*s + math.sin(a * 1.25) * 75*s
fillOval(g, px, py, (2.5 + (i % 3)) * s, (2.5 + (i % 3)) * s, alpha(if (i % 2 == 0) active else secondary, 100 + (math.abs(math.sin(tick+i))*140).toInt))
}
// Hologram console
if (useHologram) {
val hx = cx + 118*s; val hy = y - 22*s + math.sin(tick) * 4*s
fillRound(g, hx, hy, 144*s, 83*s, 9*s, alpha(new Color(4,12,37), 235))
outlineRound(g, hx, hy, 144*s, 83*s, 9*s, active, 2f)
line(g, hx + 8*s, hy + 21*s, hx + 136*s, hy + 21*s, secondary, 2f)
g.setFont(new Font("Monospaced", Font.BOLD, math.max(9, (11*s).toInt))); g.setColor(active); g.drawString("BIXUU CORE", (hx+9*s).toInt, (hy+15*s).toInt)
g.setFont(new Font("Monospaced", Font.PLAIN, math.max(8, (9*s).toInt))); g.setColor(new Color(210,235,255)); g.drawString("SYSTEM ONLINE", (hx+9*s).toInt, (hy+39*s).toInt)
g.setColor(new Color(80,255,155)); g.drawString("DANCE: ACTIVE", (hx+9*s).toInt, (hy+53*s).toInt)
for (i <- 0 until 8) { val bh = (5 + math.abs(math.sin(tick*3+i*0.7))*17)*s; g.setColor(active); g.fill(new Rectangle2D.Double(hx+(9+i*16)*s, hy+65*s-bh, 6*s, bh)) }
}
// Title and footer
g.setFont(new Font("SansSerif", Font.BOLD, 17)); g.setColor(active); g.drawString(robotTitle.take(32), 23, 32)
g.setFont(new Font("Monospaced", Font.PLAIN, 11)); g.setColor(new Color(190,220,255)); g.drawString("BIXUU ROBOT SYSTEM | SCALA SWING", 23, 50)
g.setColor(new Color(0,255,150)); g.drawString("ONLINE", 23, getHeight - 18)
g.setColor(secondary); g.drawString("POWER " + (80 + (math.abs(math.sin(tick))*20).toInt) + "%", getWidth - 95, getHeight - 18)
g.dispose()
}
}
}
"""
raw
.replace("__TITLE__", scalaString(cfg.title))
.replace("__DESC__", scalaString(cfg.description))
.replace("__PRIMARY__", rgb(cfg.theme.primary))
.replace("__SECONDARY__", rgb(cfg.theme.secondary))
.replace("__BACKGROUND__", rgb(cfg.theme.background))
.replace("__DANCE__", cfg.dancing.toString)
.replace("__DISCO__", cfg.disco.toString)
.replace("__WINGS__", cfg.wings.toString)
.replace("__HOLOGRAM__", cfg.hologram.toString)
.replace("__PARTICLES__", cfg.particles.toString)
.replace("__SPEED__", cfg.speed.toString)
}
class CreatorFrame extends JFrame("BIXUU | ROBOT CODE CREATOR") {
private val titleField = new JTextField("NEXUS X", 22)
private val descriptionArea = new JTextArea("Cyber robot, disco lighting, dancing, energy wings and hologram.", 4, 22)
private val themeBox = new JComboBox[String](themes.map(_.name).toArray)
private val danceBox = new JCheckBox("Dance animation", true)
private val discoBox = new JCheckBox("Disco / colour-changing lights", true)
private val wingsBox = new JCheckBox("Energy wings", true)
private val hologramBox = new JCheckBox("Hologram screen", true)
private val particlesBox = new JCheckBox("Energy particles", true)
private val speedSlider = new JSlider(1, 10, 6)
private val speedText = new JLabel("Animation speed: 6")
private val statusLabel = new JLabel("Ready ? create your robot!")
private val preview = new RobotPreview(readConfig())
private val codeArea = new JTextArea("Press GENERATE CODE to create a standalone Scala Swing animation.")
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE)
// Fit the window to the current screen; a 1400x900 fixed window can start partly off-screen
// on smaller laptop displays and make it look as if no window opened.
private val screenSize = Toolkit.getDefaultToolkit.getScreenSize
private val initialWidth = math.max(800, math.min(1400, screenSize.width - 40))
private val initialHeight = math.max(600, math.min(900, screenSize.height - 70))
setMinimumSize(new Dimension(math.min(900, initialWidth), math.min(600, initialHeight)))
setSize(initialWidth, initialHeight)
setLocationRelativeTo(null)
private def styleButton(b: JButton, bg: Color): JButton = {
b.setBackground(bg); b.setForeground(Color.WHITE); b.setFocusPainted(false)
b.setFont(new Font("SansSerif", Font.BOLD, 12)); b.setBorder(new CompoundBorder(new LineBorder(colorWithAlpha(accent, 170), 1, true), new EmptyBorder(9, 10, 9, 10)))
b.setAlignmentX(Component.LEFT_ALIGNMENT); b
}
private def styleCheck(c: JCheckBox): Unit = {
c.setOpaque(false); c.setForeground(whiteBlue); c.setFont(new Font("SansSerif", Font.PLAIN, 13)); c.setFocusPainted(false)
}
private def label(text: String): JLabel = {
val l = new JLabel(text); l.setForeground(accent); l.setFont(new Font("SansSerif", Font.BOLD, 12)); l.setAlignmentX(Component.LEFT_ALIGNMENT); l
}
private def readConfig(): RobotConfig = {
val selected = Option(themeBox.getSelectedItem).map(_.toString).getOrElse(themes.head.name)
val theme = themes.find(_.name == selected).getOrElse(themes.head)
RobotConfig(
Option(titleField.getText).getOrElse("").trim match { case "" => "BIXUU ROBOT"; case x => x },
Option(descriptionArea.getText).getOrElse(""), theme,
danceBox.isSelected, discoBox.isSelected, wingsBox.isSelected,
hologramBox.isSelected, particlesBox.isSelected, speedSlider.getValue
)
}
private val controls = new JPanel()
controls.setBackground(panelBg)
controls.setBorder(new EmptyBorder(15, 15, 15, 15))
controls.setLayout(new BoxLayout(controls, BoxLayout.Y_AXIS))
controls.setPreferredSize(new Dimension(300, 700))
controls.add(label("ROBOT TITLE")); controls.add(Box.createVerticalStrut(6))
titleField.setBackground(new Color(5, 12, 32)); titleField.setForeground(Color.WHITE); titleField.setCaretColor(accent)
titleField.setBorder(new CompoundBorder(new LineBorder(new Color(0, 125, 180), 1, true), new EmptyBorder(8, 8, 8, 8)))
titleField.setMaximumSize(new Dimension(Short.MaxValue, 38)); controls.add(titleField)
controls.add(Box.createVerticalStrut(14)); controls.add(label("ROBOT DESCRIPTION")); controls.add(Box.createVerticalStrut(6))
descriptionArea.setLineWrap(true); descriptionArea.setWrapStyleWord(true); descriptionArea.setBackground(new Color(5, 12, 32)); descriptionArea.setForeground(whiteBlue); descriptionArea.setCaretColor(accent)
descriptionArea.setBorder(new EmptyBorder(8, 8, 8, 8))
val descScroll = new JScrollPane(descriptionArea); descScroll.setBorder(new LineBorder(new Color(0, 125, 180), 1, true)); descScroll.setMaximumSize(new Dimension(Short.MaxValue, 105)); controls.add(descScroll)
controls.add(Box.createVerticalStrut(14)); controls.add(label("LIGHTING STYLE")); controls.add(Box.createVerticalStrut(6))
themeBox.setBackground(new Color(5, 12, 32)); themeBox.setForeground(whiteBlue); themeBox.setMaximumSize(new Dimension(Short.MaxValue, 35)); controls.add(themeBox)
controls.add(Box.createVerticalStrut(14)); controls.add(label("ANIMATION FEATURES")); controls.add(Box.createVerticalStrut(6))
Vector(danceBox, discoBox, wingsBox, hologramBox, particlesBox).foreach { cb => styleCheck(cb); controls.add(cb); controls.add(Box.createVerticalStrut(5)) }
controls.add(Box.createVerticalStrut(12)); controls.add(label("ANIMATION SPEED"))
speedSlider.setOpaque(false); speedSlider.setForeground(accent); speedSlider.setMajorTickSpacing(3); speedSlider.setPaintTicks(true); speedSlider.setPaintLabels(true); speedSlider.setMaximumSize(new Dimension(Short.MaxValue, 55))
controls.add(speedSlider); controls.add(speedText)
controls.add(Box.createVerticalStrut(14))
val createButton = styleButton(new JButton("? CREATE / UPDATE ROBOT"), new Color(0, 100, 145))
val generateButton = styleButton(new JButton("? GENERATE CODE"), new Color(95, 35, 160))
val copyButton = styleButton(new JButton("? COPY CODE"), new Color(0, 105, 95))
val saveButton = styleButton(new JButton("? SAVE .SCALA FILE"), new Color(40, 70, 120))
Vector(createButton, generateButton, copyButton, saveButton).foreach { b => controls.add(b); controls.add(Box.createVerticalStrut(8)) }
controls.add(Box.createVerticalStrut(8))
statusLabel.setForeground(new Color(150, 220, 255)); statusLabel.setFont(new Font("SansSerif", Font.PLAIN, 11)); statusLabel.setAlignmentX(Component.LEFT_ALIGNMENT); controls.add(statusLabel)
controls.add(Box.createVerticalGlue())
preview.setBackground(appBg)
codeArea.setBackground(new Color(3, 8, 23)); codeArea.setForeground(new Color(180, 245, 220)); codeArea.setCaretColor(Color.WHITE)
codeArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); codeArea.setTabSize(2); codeArea.setLineWrap(false)
val codeScroll = new JScrollPane(codeArea); codeScroll.setBorder(new LineBorder(new Color(0, 135, 175), 1))
val previewTitle = new JLabel(" LIVE ROBOT PREVIEW ? CYBER DISCO MODE")
previewTitle.setOpaque(true); previewTitle.setBackground(new Color(7, 17, 42)); previewTitle.setForeground(accent); previewTitle.setFont(new Font("SansSerif", Font.BOLD, 12)); previewTitle.setBorder(new EmptyBorder(9, 8, 9, 8))
val codeTitle = new JLabel(" GENERATED SCALA SWING CODE")
codeTitle.setOpaque(true); codeTitle.setBackground(new Color(7, 17, 42)); codeTitle.setForeground(new Color(135, 255, 190)); codeTitle.setFont(new Font("SansSerif", Font.BOLD, 12)); codeTitle.setBorder(new EmptyBorder(9, 8, 9, 8))
val previewWrap = new JPanel(new BorderLayout()); previewWrap.setBackground(appBg); previewWrap.add(previewTitle, BorderLayout.NORTH); previewWrap.add(preview, BorderLayout.CENTER)
val codeWrap = new JPanel(new BorderLayout()); codeWrap.setBackground(appBg); codeWrap.add(codeTitle, BorderLayout.NORTH); codeWrap.add(codeScroll, BorderLayout.CENTER)
val verticalSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT, previewWrap, codeWrap); verticalSplit.setResizeWeight(0.53); verticalSplit.setDividerSize(7); verticalSplit.setBorder(null); verticalSplit.setBackground(appBg)
val mainSplit = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(controls), verticalSplit); mainSplit.setResizeWeight(0.23); mainSplit.setDividerLocation(315); mainSplit.setDividerSize(7); mainSplit.setBorder(null)
val header = new JPanel(new BorderLayout()); header.setBackground(new Color(4, 8, 25)); header.setBorder(new EmptyBorder(12, 18, 12, 18))
val brand = new JLabel("B I X U U | ROBOT CODE CREATOR")
brand.setForeground(accent); brand.setFont(new Font("SansSerif", Font.BOLD, 22))
val subtitle = new JLabel("SCALA SWING ? ANIMATION LAB ? CREATE / GENERATE / COPY")
subtitle.setForeground(new Color(185, 205, 235)); subtitle.setFont(new Font("Monospaced", Font.PLAIN, 11))
val brandPanel = new JPanel(); brandPanel.setOpaque(false); brandPanel.setLayout(new BoxLayout(brandPanel, BoxLayout.Y_AXIS)); brandPanel.add(brand); brandPanel.add(Box.createVerticalStrut(4)); brandPanel.add(subtitle)
header.add(brandPanel, BorderLayout.WEST)
val badge = new JLabel(" LIVE PREVIEW "); badge.setForeground(Color.WHITE); badge.setOpaque(true); badge.setBackground(new Color(0, 105, 120)); badge.setBorder(new EmptyBorder(8, 10, 8, 10)); header.add(badge, BorderLayout.EAST)
getContentPane.setLayout(new BorderLayout()); getContentPane.setBackground(appBg); getContentPane.add(header, BorderLayout.NORTH); getContentPane.add(mainSplit, BorderLayout.CENTER)
private def applyPromptHints(): Unit = {
// Small offline keyword helper: the prompt can switch common features/themes.
// The feature checkboxes remain editable, so users can fine-tune the result.
val p = Option(descriptionArea.getText).getOrElse("").toLowerCase
def has(words: String*): Boolean = words.exists(p.contains)
if (has("pink", "??????", "magenta")) themeBox.setSelectedItem("Disco Pink + Blue")
else if (has("gold", "golden", "??????", "????????")) themeBox.setSelectedItem("Solar Gold")
else if (has("green", "matrix", "?????", "?????")) themeBox.setSelectedItem("Matrix Green")
else if (has("ice blue", "icy", "??????????", "?????")) themeBox.setSelectedItem("Ice Blue")
else if (has("cyan", "violet", "purple", "??????", "????")) themeBox.setSelectedItem("Cyber Cyan + Violet")
if (has("no wings", "without wings", "wings off", "??? ???", "?????? ???")) wingsBox.setSelected(false)
else if (has("wings", "wing", "???", "??????")) wingsBox.setSelected(true)
if (has("no disco", "without disco", "disco off", "?????? ???", "??????? ???")) discoBox.setSelected(false)
else if (has("disco", "rainbow", "neon", "lighting", "lights", "???????", "???????", "????", "????")) discoBox.setSelected(true)
if (has("no dance", "without dance", "dance off", "????? ???", "??? ???")) danceBox.setSelected(false)
else if (has("dance", "dancing", "?????", "???????", "???????")) danceBox.setSelected(true)
if (has("no hologram", "without hologram", "????????? ???")) hologramBox.setSelected(false)
else if (has("hologram", "?????????")) hologramBox.setSelected(true)
if (has("no particles", "without particles", "particles off", "?? ???")) particlesBox.setSelected(false)
else if (has("particles", "sparks", "energy particles", "??", "???????")) particlesBox.setSelected(true)
if (has("very fast", "super fast", "??? ??????", "?????")) speedSlider.setValue(9)
else if (has("slow dance", "slow motion", "???")) speedSlider.setValue(3)
}
private def refreshPreview(): Unit = {
preview.setConfig(readConfig())
previewTitle.setText(" LIVE ROBOT PREVIEW ? " + readConfig().title.take(38))
speedText.setText("Animation speed: " + speedSlider.getValue)
statusLabel.setText("Preview updated ? " + readConfig().theme.name)
}
private def showError(msg: String): Unit = JOptionPane.showMessageDialog(this, msg, "BIXUU Robot Code Creator", JOptionPane.ERROR_MESSAGE)
createButton.addActionListener(new ActionListener { override def actionPerformed(e: ActionEvent): Unit = { applyPromptHints(); refreshPreview() } })
themeBox.addActionListener(new ActionListener { override def actionPerformed(e: ActionEvent): Unit = refreshPreview() })
speedSlider.addChangeListener(new ChangeListener {
override def stateChanged(e: ChangeEvent): Unit = {
speedText.setText("Animation speed: " + speedSlider.getValue)
refreshPreview()
}
})
Vector(danceBox, discoBox, wingsBox, hologramBox, particlesBox).foreach(_.addActionListener(new ActionListener { override def actionPerformed(e: ActionEvent): Unit = refreshPreview() }))
generateButton.addActionListener(new ActionListener {
override def actionPerformed(e: ActionEvent): Unit = {
applyPromptHints()
refreshPreview()
val cfg = readConfig()
val generated = standaloneSource(cfg)
codeArea.setText(generated); codeArea.setCaretPosition(0)
statusLabel.setText("Generated Scala source for: " + cfg.title.take(30))
codeTitle.setText(" GENERATED SCALA SWING CODE ? " + generated.split("\\n", -1).length + " LINES")
}
})
copyButton.addActionListener(new ActionListener {
override def actionPerformed(e: ActionEvent): Unit = {
val text = codeArea.getText
if (text.trim.isEmpty || text.startsWith("Press GENERATE")) showError("First press GENERATE CODE.")
else Try { Toolkit.getDefaultToolkit.getSystemClipboard.setContents(new StringSelection(text), null) } match {
case scala.util.Success(_) => statusLabel.setText("Code copied to clipboard ? paste it into your Scala editor.")
case scala.util.Failure(_) => showError("Clipboard access failed. Select the code and copy it manually.")
}
}
})
saveButton.addActionListener(new ActionListener {
override def actionPerformed(e: ActionEvent): Unit = {
val text = codeArea.getText
if (text.trim.isEmpty || text.startsWith("Press GENERATE")) showError("First press GENERATE CODE.")
else {
val chooser = new JFileChooser(); chooser.setDialogTitle("Save generated Scala source")
chooser.setSelectedFile(new java.io.File("GeneratedBixuuRobot.scala")); chooser.setFileFilter(new FileNameExtensionFilter("Scala source (*.scala)", "scala"))
if (chooser.showSaveDialog(CreatorFrame.this) == JFileChooser.APPROVE_OPTION) {
var file = chooser.getSelectedFile
if (!file.getName.toLowerCase.endsWith(".scala")) file = new java.io.File(file.getParentFile, file.getName + ".scala")
Try { Files.write(file.toPath, text.getBytes(StandardCharsets.UTF_8)) } match {
case scala.util.Success(_) => statusLabel.setText("Saved: " + file.getName)
case scala.util.Failure(ex) => showError("Could not save file: " + ex.getMessage)
}
}
}
}
})
// Generate a useful first version so the code pane is not empty at launch.
codeArea.setText(standaloneSource(readConfig())); codeArea.setCaretPosition(0)
codeTitle.setText(" GENERATED SCALA SWING CODE")
refreshPreview()
}
class RobotPreview(initialConfig: RobotConfig) extends JPanel {
private var cfg = initialConfig
private var t = 0.0
setDoubleBuffered(true)
private val timer = new Timer(30, new ActionListener {
override def actionPerformed(e: ActionEvent): Unit = { t += 0.025 + cfg.speed * 0.009; repaint() }
})
timer.start()
def setConfig(c: RobotConfig): Unit = { cfg = c; repaint() }
private def alpha(c: Color, a: Int): Color = colorWithAlpha(c, a)
private def fillOval(g: Graphics2D, x: Double, y: Double, w: Double, h: Double, c: Color): Unit = { g.setColor(c); g.fill(new Ellipse2D.Double(x, y, w, h)) }
private def outlineOval(g: Graphics2D, x: Double, y: Double, w: Double, h: Double, c: Color, sw: Float): Unit = { g.setColor(c); g.setStroke(new BasicStroke(sw)); g.draw(new Ellipse2D.Double(x, y, w, h)) }
private def fillRound(g: Graphics2D, x: Double, y: Double, w: Double, h: Double, arc: Double, c: Color): Unit = { g.setColor(c); g.fill(new RoundRectangle2D.Double(x, y, w, h, arc, arc)) }
private def outlineRound(g: Graphics2D, x: Double, y: Double, w: Double, h: Double, arc: Double, c: Color, sw: Float): Unit = { g.setColor(c); g.setStroke(new BasicStroke(sw)); g.draw(new RoundRectangle2D.Double(x, y, w, h, arc, arc)) }
private def line(g: Graphics2D, x1: Double, y1: Double, x2: Double, y2: Double, c: Color, sw: Float): Unit = { g.setColor(c); g.setStroke(new BasicStroke(sw, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); g.draw(new Line2D.Double(x1, y1, x2, y2)) }
override protected def paintComponent(graphics: Graphics): Unit = {
super.paintComponent(graphics)
val g = graphics.create().asInstanceOf[Graphics2D]
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON)
g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY)
val w = getWidth.toDouble; val h = getHeight.toDouble
g.setPaint(new GradientPaint(0f, 0f, cfg.theme.background, w.toFloat, h.toFloat, new Color(15, 10, 42)))
g.fillRect(0, 0, getWidth, getHeight)
val cx = w * 0.43; val cy = h * 0.56
val s = math.max(0.48, math.min(w / 850.0, h / 590.0))
val active = if (cfg.disco) Color.getHSBColor(((t * 0.12) % 1.0).toFloat, 0.88f, 1.0f) else cfg.theme.primary
val bob = if (cfg.dancing) math.sin(t * 2.2) * 5.0 * s else 0.0
val y = cy + bob
for (i <- 0 until 8) {
val pulse = math.sin(t + i * 0.42) * 11.0
outlineOval(g, cx - (112 + i * 15 + pulse) * s, cy - (112 + i * 15 + pulse) * s,
(224 + i * 30 + pulse * 2) * s, (224 + i * 30 + pulse * 2) * s,
alpha(if (i % 2 == 0) active else cfg.theme.secondary, 20 + i * 3), 1.4f)
}
for (i <- 0 until 150) {
val sx = ((i * 137 + 31) % math.max(1, getWidth)).toDouble
val sy = ((i * 83 + 17) % math.max(1, getHeight)).toDouble
val tw = 1.0 + math.abs(math.sin(t * 2 + i * 0.3)) * 2.0
fillOval(g, sx, sy, tw, tw, alpha(if (i % 8 == 0) cfg.theme.secondary else new Color(175, 225, 255), 70 + (math.abs(math.sin(t + i)) * 180).toInt))
}
for (i <- 0 until 12) line(g, 0, h * 0.79 + i * 8, w, h * 0.79 + i * 8, alpha(active, 45), 1f)
line(g, 0, h * 0.79, w, h * 0.79, alpha(cfg.theme.secondary, 170), 2f)
line(g, 12, 18, 48, 18, active, 2f); line(g, 12, 18, 12, 48, active, 2f)
line(g, w - 12, 18, w - 48, 18, active, 2f); line(g, w - 12, 18, w - 12, 48, active, 2f)
if (cfg.wings) {
val flap = math.sin(t * 2.4) * 13 * s
val left = new Path2D.Double(); left.moveTo(cx - 28*s, y - 30*s); left.lineTo(cx - 104*s, y - 75*s - flap); left.lineTo(cx - 80*s, y + 32*s - flap); left.closePath()
g.setColor(alpha(active, 28)); g.fill(left); g.setColor(alpha(active, 235)); g.setStroke(new BasicStroke(2.8f)); g.draw(left)
line(g, cx - 36*s, y - 23*s, cx - 88*s, y - 34*s - flap, alpha(whiteBlue, 220), 1.8f)
val right = new Path2D.Double(); right.moveTo(cx + 28*s, y - 30*s); right.lineTo(cx + 104*s, y - 75*s + flap); right.lineTo(cx + 80*s, y + 32*s + flap); right.closePath()
g.setColor(alpha(cfg.theme.secondary, 28)); g.fill(right); g.setColor(alpha(cfg.theme.secondary, 240)); g.setStroke(new BasicStroke(2.8f)); g.draw(right)
line(g, cx + 36*s, y - 23*s, cx + 88*s, y - 34*s + flap, alpha(whiteBlue, 220), 1.8f)
fillOval(g, cx - 92*s, y - 16*s - flap, 10*s, 10*s, Color.WHITE); fillOval(g, cx + 82*s, y - 16*s + flap, 10*s, 10*s, Color.WHITE)
}
for (i <- 0 until 4) outlineOval(g, cx - (76 + i*12)*s, y - (13 + i*3)*s, (152 + i*24)*s, (26 + i*6)*s,
alpha(if (i % 2 == 0) active else cfg.theme.secondary, 75 + (math.abs(math.sin(t+i))*130).toInt), 1.8f)
val armSwing = if (cfg.dancing) math.sin(t * 3.0) * 16 * s else 0.0
line(g, cx - 32*s, y - 27*s, cx - 55*s, y + 9*s + armSwing, new Color(30,55,95), 17*s.toFloat)
line(g, cx + 32*s, y - 27*s, cx + 55*s, y + 9*s - armSwing, new Color(30,55,95), 17*s.toFloat)
line(g, cx - 32*s, y - 27*s, cx - 55*s, y + 9*s + armSwing, new Color(175,205,230), 9*s.toFloat)
line(g, cx + 32*s, y - 27*s, cx + 55*s, y + 9*s - armSwing, new Color(175,205,230), 9*s.toFloat)
line(g, cx - 33*s, y - 27*s, cx - 55*s, y + 9*s + armSwing, active, 2*s.toFloat)
line(g, cx + 33*s, y - 27*s, cx + 55*s, y + 9*s - armSwing, active, 2*s.toFloat)
fillOval(g, cx - 65*s, y + 1*s + armSwing, 20*s, 20*s, new Color(160,195,225)); outlineOval(g, cx - 65*s, y + 1*s + armSwing, 20*s, 20*s, active, 2f)
fillOval(g, cx + 45*s, y + 1*s - armSwing, 20*s, 20*s, new Color(160,195,225)); outlineOval(g, cx + 45*s, y + 1*s - armSwing, 20*s, 20*s, active, 2f)
fillRound(g, cx - 25*s, y + 39*s, 18*s, 50*s, 8*s, new Color(110,145,185)); outlineRound(g, cx - 25*s, y + 39*s, 18*s, 50*s, 8*s, active, 2f)
fillRound(g, cx + 7*s, y + 39*s, 18*s, 50*s, 8*s, new Color(110,145,185)); outlineRound(g, cx + 7*s, y + 39*s, 18*s, 50*s, 8*s, active, 2f)
fillOval(g, cx - 31*s, y + 79*s, 34*s, 20*s, new Color(20,36,75)); outlineOval(g, cx - 31*s, y + 79*s, 34*s, 20*s, active, 2.2f)
fillOval(g, cx + 1*s, y + 79*s, 34*s, 20*s, new Color(20,36,75)); outlineOval(g, cx + 1*s, y + 79*s, 34*s, 20*s, active, 2.2f)
line(g, cx - 23*s, y + 91*s, cx - 7*s, y + 91*s, active, 3f); line(g, cx + 9*s, y + 91*s, cx + 25*s, y + 91*s, active, 3f)
fillOval(g, cx - 43*s, y - 43*s, 29*s, 29*s, new Color(45,82,135)); outlineOval(g, cx - 43*s, y - 43*s, 29*s, 29*s, active, 2.4f)
fillOval(g, cx + 14*s, y - 43*s, 29*s, 29*s, new Color(45,82,135)); outlineOval(g, cx + 14*s, y - 43*s, 29*s, 29*s, active, 2.4f)
fillRound(g, cx - 37*s, y - 50*s, 74*s, 91*s, 22*s, new Color(95,130,175)); outlineRound(g, cx - 37*s, y - 50*s, 74*s, 91*s, 22*s, new Color(205,230,250), 2.6f)
fillRound(g, cx - 28*s, y - 37*s, 56*s, 54*s, 12*s, new Color(5,13,40)); outlineRound(g, cx - 28*s, y - 37*s, 56*s, 54*s, 10*s, active, 2.5f)
fillOval(g, cx - 22*s, y - 31*s, 44*s, 44*s, alpha(active, 60)); outlineOval(g, cx - 18*s, y - 27*s, 36*s, 36*s, active, 2.5f)
outlineOval(g, cx - 12*s, y - 21*s, 24*s, 24*s, cfg.theme.secondary, 2f)
fillOval(g, cx - 7*s, y - 16*s, 14*s, 14*s, active); fillOval(g, cx - 3*s, y - 12*s, 6*s, 6*s, Color.WHITE)
fillRound(g, cx - 24*s, y + 38*s, 48*s, 13*s, 5*s, new Color(30,62,108)); outlineRound(g, cx - 24*s, y + 38*s, 48*s, 13*s, 5*s, active, 2f)
fillRound(g, cx - 34*s, y - 126*s, 68*s, 57*s, 17*s, new Color(150,185,215)); outlineRound(g, cx - 34*s, y - 126*s, 68*s, 57*s, 17*s, new Color(225,245,255), 3f)
fillRound(g, cx - 27*s, y - 113*s, 54*s, 28*s, 8*s, new Color(2,8,28)); outlineRound(g, cx - 27*s, y - 113*s, 54*s, 28*s, 8*s, active, 2.3f)
val eyeGlow = 170 + (math.abs(math.sin(t * 3.0)) * 85).toInt
fillOval(g, cx - 19*s, y - 105*s, 13*s, 8*s, alpha(active, eyeGlow)); fillOval(g, cx + 6*s, y - 105*s, 13*s, 8*s, alpha(active, eyeGlow))
fillOval(g, cx - 15*s, y - 104*s, 4*s, 4*s, Color.WHITE); fillOval(g, cx + 10*s, y - 104*s, 4*s, 4*s, Color.WHITE)
line(g, cx - 9*s, y - 82*s, cx + 9*s, y - 82*s, active, 2f)
fillRound(g, cx - 16*s, y - 132*s, 32*s, 8*s, 5*s, new Color(35,70,120)); fillOval(g, cx - 7*s, y - 140*s, 14*s, 14*s, active); fillOval(g, cx - 3*s, y - 136*s, 6*s, 6*s, Color.WHITE)
if (cfg.particles) for (i <- 0 until 34) {
val a = t * 0.7 + i * math.Pi / 17; val r = (88 + (i % 5) * 9) * s
val px = cx + math.cos(a) * r; val py = y - 22*s + math.sin(a * 1.25) * 75*s
fillOval(g, px, py, (2.5 + (i % 3))*s, (2.5 + (i % 3))*s, alpha(if (i % 2 == 0) active else cfg.theme.secondary, 100 + (math.abs(math.sin(t+i))*140).toInt))
}
if (cfg.hologram) {
val hx = cx + 118*s; val hy = y - 22*s + math.sin(t)*4*s
fillRound(g, hx, hy, 144*s, 83*s, 9*s, alpha(new Color(4,12,37), 235)); outlineRound(g, hx, hy, 144*s, 83*s, 9*s, active, 2f)
line(g, hx + 8*s, hy + 21*s, hx + 136*s, hy + 21*s, cfg.theme.secondary, 2f)
g.setFont(new Font("Monospaced", Font.BOLD, math.max(9, (11*s).toInt))); g.setColor(active); g.drawString("BIXUU CORE", (hx+9*s).toInt, (hy+15*s).toInt)
g.setFont(new Font("Monospaced", Font.PLAIN, math.max(8, (9*s).toInt))); g.setColor(whiteBlue); g.drawString("SYSTEM ONLINE", (hx+9*s).toInt, (hy+39*s).toInt)
g.setColor(new Color(80,255,155)); g.drawString("DANCE: ACTIVE", (hx+9*s).toInt, (hy+53*s).toInt)
for (i <- 0 until 8) { val bh = (5 + math.abs(math.sin(t*3+i*0.7))*17)*s; g.setColor(active); g.fill(new Rectangle2D.Double(hx+(9+i*16)*s, hy+65*s-bh, 6*s, bh)) }
}
g.setFont(new Font("SansSerif", Font.BOLD, 17)); g.setColor(active); g.drawString(cfg.title.take(32), 23, 32)
g.setFont(new Font("Monospaced", Font.PLAIN, 11)); g.setColor(whiteBlue); g.drawString("BIXUU ROBOT SYSTEM | SCALA SWING", 23, 50)
g.setColor(new Color(0,255,150)); g.drawString("ONLINE", 23, getHeight - 18)
g.setColor(cfg.theme.secondary); g.drawString("POWER " + (80 + (math.abs(math.sin(t))*20).toInt) + "%", getWidth - 95, getHeight - 18)
g.dispose()
}
}
}
// Explicitly launch the GUI when this file is executed as a Scala script.
BixuuRobotCodeCreator.launch()