Dnes již programuji výhradně s pomocí AI. Nemáte-li zatím předplacenou poslední verzi, možná vás bude zajímat, jak se liší od verze bezplatné.

 

Společný dotaz zněl takto:
Zooming and panning on mobile device with gestures. Repair following code so it can zoom on mobile devices too. Limit panning to the left to left side of page. Limit panning to the right to right side of the page.
Za dotaz byl nefunkční kód.

 

Odpověď z ChatGPT 3.5

To enable zooming and panning on mobile devices with gestures, and to limit panning to the left and right sides of the page, you can make several modifications to your code. Here’s an updated version of your HTML and JavaScript:

Changes made to your code:

  1. Added a <meta> tag for the viewport to ensure proper scaling on mobile devices.
  2. Disabled selection for the entire canvas using selection: false in the fabric.Canvas initialization.
  3. Added an event listener for the touch:gesture event to handle zooming via gestures on mobile devices.
  4. Added an event listener for the touch:drag event to handle panning via gestures on mobile devices. This code also limits panning to the left and right sides of the page.

Make sure to include the Fabric.js library from a CDN as shown in the script tag for proper functionality.

 

Odpověď z ChatGPT 4

The code provided is primarily designed for desktop interactions. To extend the functionality to handle touch events for zooming and panning on mobile devices, you would need to listen for touch events such as touchstart, touchmove, and touchend. Additionally, to zoom on mobile devices, you can listen for the gesture event which is emitted during a pinch zoom gesture on touch devices.

Here is a modified version of your code that includes mobile gesture support for zooming and panning, as well as limits for panning:

In this code:

  • We use the touch:gesture event to handle zooming with pinch gestures.
  • The touch:drag event is for panning around the canvas.
  • allowTouchScrolling is set to false to prevent default touch scrolling behavior.
  • The panning limits are enforced by checking the new position against the viewport’s bounds and setting it to the bounds if it exceeds them.

Remember to test this on an actual device or a mobile emulator to ensure that the interactions work as expected.

 

Opravy kódu

Tak na tohle je čtyřka geniální. Když jsem požádal trojku, měla halucinace a vymýšlela si neexistující funkce.
Čtyřka však vymyslela hned napoprvé funkční kód.

Společný dotaz: repair exportCanvasAsPNG function. it gives blank png file.
exportCanvasAsPNG should generate picture from every object that is inside rect object.

 

Výstup ze trojky:

To export the canvas as a PNG with all the objects inside the clipping rectangle, you can follow these steps:

  1. Create a group that contains all the objects you want to export.
  2. Use the clipTo property of the group to apply the clipping rectangle to the group.
  3. Export the group as a PNG.

Here’s the modified code:

(byla to nefunkční halucinace)

 

Výstup ze čtyřky:

It appears that the exportCanvasAsPNG function is attempting to create a PNG of the area within the rectangle, but the objects are not properly added or positioned on the export canvas.

To fix this, you should first make sure that all the objects that need to be exported are correctly added to the export canvas and are within the area that corresponds to the rectangle on the main canvas. You also need to ensure that the objects are not clipped unless intended, and that the viewport transformation is set correctly.

Here’s an updated version of the exportCanvasAsPNG function that should export all objects within the rect area:

Please ensure you replace the previous exportCanvasAsPNG function with this updated one in your script. Also, note that object positions might need to be adjusted if they are not currently relative to the rect. The filter function above also assumes that objects are wholly contained within the rect and does not handle the case where they might be partially overlapping the edges of the rect. If objects can be partially inside the rect, you’d need to adjust the filter conditions and possibly use the clipPath property of objects to clip them according to the rect dimensions.

(dokonale funkční)

 

Závěr

Čtyřka dává úplně jiné rady. Ani od čtyřky však nečekejte geniální bezchybná řešení. Platí, že je vždy nutné dotazy postupně upřesňovat.
Na každý pád se jedná o velkého pomocníka ať už programujete v čemkoliv. Investice 500 Kč měsíčně se rozhodně vyplatí.
Když jsem se snažil řešení najít bez AI, strávil jsem nad tím dvě hodiny a stále to nefungovalo. Se zapojením čtyřky bylo řešení na světě za 2 sekundy.
Doporučuji učit se namísto názvů funkcí už jen koncepty, strategie, terminologii.