xxxxxxxxxx
110
// primitive Playfield drawer for normal rez Batari BASIC screens
//
//W and H are the width and height of Atari screen
//(i.e. H is # of scanlines...)
//
// PIXW and PIXH are how many pixels are used in canvas here
// to make it look roughly like the atari screen
//
const W = 32;
const H = 11;
const PIXW = 24;
const PIXH = 48;
const grid = Array();
let isDrawing = false;
let sx,sy,ex,ey;
function setup() {
for (let x = 0; x < W; x++) {
grid[x] = Array();
}
createCanvas(W * PIXW, H * PIXH);
}
function draw() {
background(40);
noStroke();
fill(255);
for (let x = 0; x < W; x++) {
for (let y = 0; y < H; y++) {
if (grid[x][y]) rect(x * PIXW, y * PIXH, PIXW, PIXH);
}
}
stroke(random(255));
strokeWeight(1);
let x = int(mouseX/PIXW);
let y = int(mouseY/PIXH);
noFill();
rect(x * PIXW, y * PIXH, PIXW, PIXH);
stroke(255,0,0);
}
function mousePressed() {
x = int(mouseX / PIXW);
y = int(mouseY / PIXH);
isDrawing = !grid[x][y];
grid[x][y] = isDrawing;
// loop();
}
function mouseDragged() {
// loop();
sx = pmouseX;
sy = pmouseY;
ex = mouseX;
ey = mouseY;
//catch all the spots in the line between the drag endpints
for(let i = 0; i < 100; i++){
const tx = map(i,1,100,sx,ex);
const ty = map(i,1,100,sy,ey);
const x = int(tx / PIXW);
const y = int(ty / PIXH);
if(x >= 0 && x < W && y >= 0 && y < H) {
grid[x][y] = isDrawing;
}
}
}
function keyPressed() {
let buf = ` set kernel_options no_blank_lines
startLoop
COLUPF = $0E
playfield:\n`;
for (let y = 0; y < H; y++) {
buf += ' ';
for (let x = 0; x < W; x++) {
buf += grid[x][y] ? 'X':'.';
}
buf += '\n';
}
buf += `end
drawscreen
goto startLoop`;
print(buf);
}