3/26/2023 0 Comments P5js mousexIf you are trying to do other kinds of zooming, such as zooming on whatever the current mouse location is, then the basics are the same but it gets a bit more complex. 2.1: Variables in p5.js (mouseX, mouseY) - p5.js Tutorial The Coding Train 1. 0,0 is the top left of the canvas and x,y is the bottom right. This approach works the same in both p5.js and Processing (Java). We will let the text position co-ordinates equal (cx,cy) and the mouse pointer co-ordinates equal (mx,my). draw things based on 0,0 at the middle of the screen. The system variable mouseY always contains the current vertical position. and here is a slightly more complex setup in which mouseWheel() controls the zoom variable: var zoom = 1.00 Depending on what you are trying to do, you might approach zooming by: centering on the sketch / canvas using translate (width/2, height/2) use scale (zoom) to set the zoom level, with 1.0 being normal. The system variable mouseX always contains the current horizontal position of the mouse, relative to (0, 0) of the canvas. There is no user input - it just keeps zooming every time the screen redraws: var zoom = 1.00 Here is a simple example of a zooming sketch in p5.js - it is almost identical to the Processing(Java) equivalent. This example can be found in the Processing examples package that comes with the Processing PDE. The changes made are shown in the comments, all the other lines remained the same. This approach works the same in both p5.js and Processing(Java). Here are two examples of sketches that have been converted from p5.js to Processing. draw things based on 0,0 at the middle of the screen.use scale(zoom) to set the zoom level, with 1.0 being normal.centering on the sketch / canvas using translate(width/2, height/2).Depending on what you are trying to do, you might approach zooming by:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |