program Tutorial11_Lines;
// The unit is accessible in the C64 Turbl Rascal Units project from the front page 

@use "gfx/gfx"

var
	i: byte=5;

	xp: array[3] of byte = (40, 70, 50);
	yp: array[3] of byte = (100, 40, 156);
	xp2: array[3] of byte = (40, 70, 50);
	yp2: array[3] of byte = (100, 40, 156);
	dxp: array[3] of byte = (1, 1, 255);
	dyp: array[3] of byte = (255, 1, 1);

/*
  switch between bank 0 and 1
*/


procedure SwitchDrawBank();
begin
	if Gfx::currbank=0 then begin
		Gfx::currbank := $40;
		SetBank(VIC_BANK0);
		clearbitmap(#Gfx::bank2, 26); // Clear a certain window only
	end
	
	else
	begin
		Gfx::currbank:=0;
		SetBank(VIC_BANK1);
		clearbitmap(#Gfx::bank1, 26);
	end;
	
end;


procedure UpdateRaster();
	
begin
	SwitchDrawBank();
	Gfx::Line(xp[0],yp[0],xp[1],yp[1],0);
	Gfx::Line(xp[1],yp[1],xp[2],yp[2],0);
	Gfx::Line(xp[2],yp[2],xp[0],yp[0],0);

	i:=8;
	Gfx::Line(xp[0]+i,yp[0]+i,xp[1]+i,yp[1]+i,0);
	Gfx::Line(xp[1]+i,yp[1]+i,xp[2]+i,yp[2]+i,0);
	Gfx::Line(xp[2]+i,yp[2]+i,xp[0]+i,yp[0]+i,0);

	Gfx::Line(xp[0]+i,yp[0]+i,xp[0],yp[0],0);
	Gfx::Line(xp[1]+i,yp[1]+i,xp[1],yp[1],0);
	Gfx::Line(xp[2]+i,yp[2]+i,xp[2],yp[2],0);
	

	for i:=0 to 3 do begin
		xp2[i] := xp[i];
		yp2[i] := yp[i];
		xp[i]:=xp[i]+dxp[i];
		yp[i]:=yp[i]+dyp[i];
		if xp[i]>=125 then dxp[i]:=255;
		if xp[i]<30 then dxp[i]:=1;
		if yp[i]>=150 then dyp[i]:=255;
		if yp[i]<30 then dyp[i]:=1;
		
	end;
	

end;

begin	
	screen_bg_col:=black;
	Gfx::currbank :=0; // Current bitmap bank (added to high bit of putpixel)
	//Gfx::InitBitmapGraphics(1, #Gfx::bank1);
	vic_data_loc:=$18;
	
	setmulticolormode();
	setbitmapmode();
	
	SCREEN_BG_COL:=BLUE;
	SCREEN_FG_COL:=RED;
	
	clearscreen(YELLOW,screen_col_loc);
	clearscreen(BLUE,screen_char_loc2);

	while (true) do UpdateRaster();
	
end.
