Push Matrix
Hello there!
Is there anything in Micro Studio simiilar to pushMatrix() and popMatrix() in processing? The idea is to create a point where we start modifying some reference points to draw elements and efter close that matrix to keep drawing in the preset properties (coordinates, rotation...)
Thanks in advance!
Xavi
Do you want these functions to work like in P5?
If so:
- I saw something similar in one of the libraries, but I can't find it now. Maybe the author of this library will let me know in this thread.
https://microstudio.dev/i/osterberg/screentools/
- You can also extend the existing
Image
class with these methods or add these functions to existing objects.
initMatrix = function( image )
image.matrixCord = []
image.pushMatrix = pushMatrix
image.popMatrix = popMatrix
end
pushMatrix = function( x, y )
this.matrixCord.push( [ x, y ])
this.setTranslation( x, y )
end
popMatrix = function()
local cord = this.matrixCord.pop()
this.setTranslation( cord[0], cord[1] )
end
init = function()
initMatrix( screen )
image = new Image( 200, 200 )
initMatrix( image )
x = 0
y = 0
end
update = function()
end
draw = function()
screen.clear()
for i = 1 to 10
screen.pushMatrix( i*10, i* 10)
screen.drawRect( 0, 0, 5, 5, "orange" )
end
for i = 1 to 10
screen.popMatrix( )
screen.drawRect( 0, 0, 4, 4, "red" )
end
end
Exactly! I didn't remember that Processing and P5.js were so similar! Thanks!
Xavi