- | - |
---|---|
Name | BRC721Cofound |
Description | A protocol enabling all Bitcoin users to collaboratively create a pixelated image on a public canvas, where each contribution is recorded on Bitcoin and represented by an inscription of the canvas's latest state. |
Discussion-to | [https://bitcointalk.org/index.php?topic=5462453] |
Category | Ordinals |
We propose a new standard for Ordinal NFTs that leverages Recursive Inscription, enabling all Bitcoin users to collaboratively and cost-effectively create a pixelated image on a public canvas, with each contribution being recorded on the Bitcoin blockchain and represented by an inscription reflecting the canvas's latest state.
Recursive Inscriptions allow us to generate a new inscription by referencing an existing one and making incremental modifications to it. This methodology is ideal for serial collaborative scenarios, such as collective coding, writing, and painting. In these scenarios, each contributor's effort can be tokenized through the creation of new inscriptions, which not only records these incremental efforts forever but also makes them tradable.
Leveraging this feature of Recursive Inscriptions, BRC721Cofound is designed as a standard for collectively creating pixelated images on Bitcoin. This allows anyone to freely express themselves on the public on-chain canvas and gain a tradable token in return. We believe this will be an exciting and Bitcoin-suited, fully on-chain game that has the potential to inspire crypto users from around the world, who may not know each other, to co-create magnificent digital artwork.
BRC721Cofound uses Recursive Inscriptions to record the entire process of everyone collectively creating a pixelated image. Each moment in this process is an inscription, which depicts what the jointly created pixelated image looks like at this moment. We call this inscription a Moment Inscription, which contains the pixels that are newly added or updated at this moment, and contains references to the previous Moment Inscription and the Code Inscription that processes the image changes between the two moments.
The Moment Inscription is defined as an HTML, which includes three parameters: newly added or updated pixels, the state of the canvas at the previous moment, and the code for handling pixel changes on the canvas. When ordinal browsers try to display this Moment Inscription, they will automatically execute the main() function in the Code Inscription. It first loads the state of the canvas at the previous moment, then parses the newly added or updated pixels at the current moment and draws them on the canvas of the previous moment, finally obtaining the latest canvas state at the current moment.
<!DOCTYPE html>
<html>
<head>
<script>
let p="[pixels such as 39630b3,38130b4,...]";
let c="[last pixel inscription ID]";</script>
<script src="/inscription/content/[code inscription ID]"></script>
</head>
</html>
As we mentioned in the Moment Inscription, the primary role of the Code Inscription is to add the newly added or updated pixels to the canvas of the previous moment to create the current moment's canvas.
async function getSnapshotData ( doc ) {
let base64 = doc.querySelector( "meta[name=snapshot]" )?.content;
if ( base64 == null ) return null;
const img = new Image();
img.src = base64;
let load = false;
img.onload = () => { load = true };
while ( load != true ) { await sl( 1 ) } const canvas = document.createElement( 'canvas' );
canvas.width = img.width;
canvas.height = img.height;
const context = canvas.getContext( '2d' );
context.drawImage( img, 0, 0 );
const imageData = context.getImageData( 0, 0, img.width, img.height );
const pixels = imageData.data;
let plist = [];
for ( let x = 0;
x < img.width;
x++ ) {
for ( let y = 0;
y < img.height;
y++ ) {
const pixelIndex = ( y * img.width + x ) * 4;
const red = pixels[ pixelIndex ];
const green = pixels[ pixelIndex + 1 ];
const blue = pixels[ pixelIndex + 2 ];
const alpha = pixels[ pixelIndex + 3 ];
if ( alpha == 0xff ) {
const p = ( ( x << ( 4 * 5 ) ) + ( y << ( 4 * 3 ) ) + ( red >> 4 << ( 4 * 2 ) ) + ( green >> 4 << ( 4 * 1 ) ) + ( blue >> 4 << ( 4 * 0 ) ) ).toString( 16 ).padStart( 7, "0" );
plist.push( p )
}
}
} return plist.join( ',' )
}
const css_b = "margin:0px; display: flex; justify-content: center; align-items: center; height: 100vh; background: #000";
let w = 256;
let h = 256;
let r = 1;
let sl = ( t ) => new Promise( ( r ) => setTimeout( r, t ) );
let td = ( s ) => ( { s: s, x: parseInt( s.substr( 0, 2 ), 16 ), y: parseInt( s.substr( 2, 2 ), 16 ), c: "#" + s.substr( 4, 3 ) } );
let tdl = ( l ) => l.split( ',' ).map( ( s ) => td( s ) );
let lh = async ( id ) => {
try {
let u = '/content/' + id;
let x = new XMLHttpRequest();
x.open( "GET", u, false );
x.send( null );
if ( x.status === 200 ) {
let d = x.responseText;
const doc = new DOMParser().parseFromString( d, 'text/html' );
const pstr = await getSnapshotData( doc );
if ( pstr != null ) return { p: pstr, c: null };
let _p = d.match( /(?<=let p=")[^"]+/g );
let _c = d.match( /(?<=let c=")[^"]+/g );
let dd = { p: ( _p != null ? _p[ 0 ] : null ), c: ( _c != null ? _c[ 0 ] : null ) };
return dd
}
} catch ( error ) { }
};
let dp = ( l, needCanvas = false ) => {
const c = document.createElement( 'canvas' );
const t = c.getContext( '2d' );
c.width = w * r;
c.height = h * r;
l.reverse().forEach( p => {
t.fillStyle = p.c;
t.fillRect( p.x * r, p.y * r, r, r )
} );
if ( needCanvas ) return c;
return c.toDataURL( 'image/png' )
};
const css_c = "max-height:100%; height: 100vw; image-rendering:pixelated";
window.addEventListener( 'DOMContentLoaded', async ( event ) => await main() );
let main = async () => {
let l = ( p || window.p ).split( "," ).map( ( e ) => td( e ) );
let _c = c || window.c;
let b = document.body;
b.style.cssText = css_b;
while ( _c?.length > 0 ) {
let g = await lh( _c );
if ( g?.p.length > 0 ) { l.push( ...tdl( g.p ) ) } _c = g?.c || null
} let cv = dp( l, true );
cv.style.cssText = css_c;
b.appendChild( cv );
let h = document.head;
let jl = h.querySelectorAll( "script" );
jl.forEach( ( js ) => h.removeChild( js ) );
let b64 = cv.toDataURL( 'image/png' );
var m = document.createElement( "meta" );
m.setAttribute( "name", "snapshot" );
m.setAttribute( "content", b64 );
h.appendChild( m );
const ij = document.createElement( "script" );
ij.text = `window.addEventListener('DOMContentLoaded',(event)=>{let img=new Image(); img.src=document.querySelector('meta[name=snapshot]')?.content; img.onload=()=>{let cv=document.querySelector('canvas'); let ctx=cv.getContext('2d'); ctx.drawImage(img,0,0)}});`;
h.appendChild( ij )
};
Given the potentially large number of contributors to the pixelated image, rendering the lastest canvas state might require a deep recursion to load pixels drawn by everyone. This process, however, could lead to prolonged loading times in the inscription browser due to excessive recursion.
To address this, the Code Inscription is designed to snapshot the latest canvas state once the current Moment Inscription is rendered. This snapshot is then stored within the current Moment Inscription's DOM tree. As a result, ordinal browsers can streamline the rendering process by caching the DOM tree of each rendered Moment Inscription, thereby reducing recursion levels.
An example of a rendered Moment Inscription's DOM tree is provided below, which includes a 'snapshot' tag.
<!DOCTYPE html>
<html>
<head>
<meta name="snapshot" content="data:image/png;base64,iVB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bTQap5bjjOoDKoSfWvwSiNwCGAQIxE8AAYlaf3qMn8D+16gH4LZT7PwAAAABJRU5ErkJggg==">
<script>window.addEventListener( 'DOMContentLoaded', ( event ) => { let img = new Image(); img.src = document.querySelector( 'meta[name=snapshot]' )?.content; img.onload = () => { let cv = document.querySelector( 'canvas' ); let ctx = cv.getContext( '2d' ); ctx.drawImage( img, 0, 0 ) } } );</script>
</head>
<body style="margin: 0px; display: flex; justify-content: center; align-items: center; height: 100vh; background: rgb(0, 0, 0);">
<canvas width="256" height="256" style="max-height: 100%; height: 100vw; image-rendering: pixelated;"></canvas>
</body>
</html>
All inscriptions produced by ERC721Cofound are standard Recursive Inscriptions that can be properly parsed by all ordinal browsers.
Copyright and related rights waived via MIT.