// Simple Breakout Game macro created by // ChatGPT using the prompt: // "Create an ImageJ macro that implements a // version of the classic Atari breakout game." width = 400; height = 300; paddleWidth = 60; paddleHeight = 8; paddleY = height - 20; ballX = width/2; ballY = height/2; ballVX = 2; ballVY = -2; ballSize = 6; rows = 5; cols = 10; brickW = width/cols; brickH = 15; // Brick array (1 = alive, 0 = destroyed) bricks = newArray(rows * cols); Array.fill(bricks,1); // Create image call("ij.gui.ImageWindow.centerNextImage"); newImage("Breakout", "8-bit black", width, height, 1); function drawGame(paddleX) { setColor(0); fillRect(0,0,width,height); // Draw bricks brickCount = 0; setColor(200); for (r=0; r width - paddleWidth) paddleX = width - paddleWidth; // Move ball ballX += ballVX; ballY += ballVY; // Wall collisions if (ballX <= 0 || ballX >= width-ballSize) ballVX *= -1; if (ballY <= 0) ballVY *= -1; // Paddle collision if (ballY + ballSize >= paddleY && ballX + ballSize >= paddleX && ballX <= paddleX + paddleWidth) { ballVY *= -1; ballY = paddleY - ballSize; beep; } // Brick collision for (r=0; r bx && ballX < bx + brickW && ballY + ballSize > by && ballY < by + brickH) { bricks[idx] = 0; ballVY *= -1; beep; } } } } // Game over? if (ballY > height) { showMessage("Breakout"," Game Over "); close; exit; } // Game won? Array.getStatistics(bricks,min,max,mean,stdDev); if (max==0) { showMessage("Breakout"," Congratulations!! "); exit; } drawGame(paddleX); updateDisplay(); wait(15); }