inexorabletash / jslogo

Logo in JavaScript
https://calormen.com/jslogo
Other
368 stars 146 forks source link

Proposal: canvas copy and paste functions #142

Closed bojidar-bg closed 12 months ago

bojidar-bg commented 1 year ago

Other Logos have functions for copying and pasting images from the canvas. E.g. FMSLogo has BITCUT/BITPASTE, TerrapinLogo has SNAP/STAMP, and... HTML5 canvas context has getImageData/putImageData.

It should be relatively simple to implement wrappers around get/putImageData, but as noted in #141, writing tests might prove be a bit trickier.

Also, the exact interface would have to be decided on. I personally would enjoy some compatibility with FMSLogo, as I've used that in the past, but considering that its BITCUT command "cuts a rectangle starting at the turtle's position with a width of width pixels and a height of height pixels. The rectangle that is cut is always taken horizontally and vertically, regardless of the turtle's heading," I'm unconvinced its the best model to follow in this case, as it feels a bit inconvenient for the user. ..Though, then again, TerrapinLogo's SNAP is virtually identical in that it always sets the lower left corner to the turtle's coordinates... so yeah, maybe it makes sense to not reinvent the wheel's axle in this case.