{"version":3,"file":"ImageTruchet.ClP9ZXd7.mjs","names":[],"sources":["https:/framerusercontent.com/modules/4AgdJw4Hj3LBnpuQwe7I/jm6rI2BjFBEhJShMl6Dq/ImageTruchet.js"],"sourcesContent":["import{defineShader,ControlType}from\"framer\";export default defineShader({title:\"Truchet\",fragment:`\nfloat arcSDF(vec2 p, vec2 center) {\n    return abs(length(p - center) - 1.0);\n}\n\nfloat tileSDF(vec2 p, float luma, float th) {\n    vec2 c = p * 2.0 - 1.0;\n    float d = 1e9;\n    float idx = clamp(floor(luma * 4.0), 0.0, 3.0);\n\n    if (u_reverseSymbols > 0.5) idx = 3.0 - idx;\n\n    if (idx < 0.5) {                          // 4 corner dots\n        d = min(d, length(c - vec2(1, 1)) - th);\n        d = min(d, length(c - vec2(-1, 1)) - th);\n        d = min(d, length(c - vec2(1, -1)) - th);\n        d = min(d, length(c - vec2(-1, -1)) - th);\n    } else if (idx < 1.5) {                   // 1 arc\n        d = arcSDF(c, vec2(1, 1)) - th;\n    } else if (idx < 2.5) {                   // 2 diagonal arcs\n        d = min(d, arcSDF(c, vec2(1, 1)) - th);\n        d = min(d, arcSDF(c, vec2(-1, -1)) - th);\n    } else {                                   // 4 arcs + center dot\n        d = min(d, arcSDF(c, vec2(1, 1)) - th);\n        d = min(d, arcSDF(c, vec2(-1, 1)) - th);\n        d = min(d, arcSDF(c, vec2(1, -1)) - th);\n        d = min(d, arcSDF(c, vec2(-1, -1)) - th);\n        d = min(d, length(c) - th);\n    }\n\n    return d;\n}\n\nvoid main() {\n    float aspect = u_resolution.x / u_resolution.y;\n\n    ivec2 texSizeI = textureSize(u_texture, 0);\n    vec2 texSize = vec2(texSizeI);\n    float textureAspect = texSize.x / texSize.y;\n\n    vec2 coverScale = vec2(1.0);\n    vec2 coverOffset = vec2(0.0);\n    if (aspect > textureAspect) {\n        float s = aspect / textureAspect;\n        coverScale = vec2(1.0, 1.0 / s);\n        coverOffset = vec2(0.0, (1.0 - coverScale.y) * 0.5);\n    } else {\n        float s = textureAspect / aspect;\n        coverScale = vec2(1.0 / s, 1.0);\n        coverOffset = vec2((1.0 - coverScale.x) * 0.5, 0.0);\n    }\n\n    float cellsY = u_cells;\n    vec2 cellCount = vec2(cellsY * aspect, cellsY);\n\n    vec2 gridUV = v_uv * cellCount;\n    vec2 cellID = floor(gridUV);\n    vec2 cellUV = fract(gridUV);\n\n    // Random rotation per cell\n    float h = fract(sin(dot(cellID, vec2(127.1, 311.7))) * 43758.5453);\n    float rot = floor(h * 4.0);\n    for (float i = 0.0; i < 4.0; i++) {\n        if (i >= rot) break;\n        vec2 tmp = cellUV;\n        cellUV = vec2(1.0 - tmp.y, tmp.x);\n    }\n\n    // Sample texture at cell center\n    vec2 texCoord = (cellID + 0.5) / cellCount;\n    texCoord = texCoord * coverScale + coverOffset;\n    texCoord.y = 1.0 - texCoord.y;\n    texCoord = clamp(texCoord, vec2(0.0), vec2(1.0));\n\n    ivec2 texel = clamp(ivec2(texCoord * texSize), ivec2(0), texSizeI - 1);\n    vec4 sampled = texelFetch(u_texture, texel, 0);\n\n    float luma = dot(sampled.rgb, vec3(0.2126, 0.7152, 0.0722));\n    if (u_invert > 0.5) luma = 1.0 - luma;\n\n    float d = tileSDF(cellUV, luma, u_thickness);\n\n    float aa = 2.0 / u_resolution.y * cellsY;\n    float mask = smoothstep(aa, -aa, d);\n\n    // Foreground color: sampled or solid\n    vec3 bg = u_background.rgb;\n    vec3 fg;\n    if (u_colorMode < 0.5) {\n        fg = sampled.rgb;\n    } else {\n        fg = u_foreground.rgb;\n    }\n\n    // 4-stage luma compositing:\n    // empty → normal truchet → inverted truchet → solid\n    vec3 col;\n    if (luma < 0.2) {\n        col = fg;\n    } else if (luma < 0.75) {\n        col = mix(fg, bg, mask);\n    } else if (luma < 0.99) {\n        col = mix(fg, bg, mask);\n    } else {\n        col = fg;\n    }\n\n    fragColor = vec4(col, 1.0);\n}\n`,propertyControls:{texture:{type:ControlType.ResponsiveImage,title:\"Image\",defaultValue:\"data:framer/asset-reference,Mko7GJNnwvpfOd4otfZJbjRag.png?originalFilename=Fire.png&width=2560&height=1440\"},cells:{type:ControlType.Number,title:\"Cells\",defaultValue:53,min:8,max:128,step:1},thickness:{type:ControlType.Number,title:\"Thickness\",defaultValue:.05,min:.05,max:.5,step:.01},invert:{type:ControlType.Boolean,title:\"Invert\",defaultValue:true},reverseSymbols:{type:ControlType.Boolean,title:\"Reverse Symbols\",defaultValue:false,hidden:true},colorMode:{type:ControlType.Enum,title:\"Color Mode\",options:[0,1],optionTitles:[\"Sampled\",\"Solid\"],defaultValue:0,hidden:true},foreground:{type:ControlType.Color,title:\"Foreground\",defaultValue:\"#004FEE\",hidden:props=>props.colorMode===0},background:{type:ControlType.Color,title:\"Background\",defaultValue:\"#FFFFFF\"}}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"shader\",\"name\":null,\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./ImageTruchet.map"],"mappings":"8HAA4C,IAAgB,EAAa,CAAC,MAAM,UAAU,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA6GjG,iBAAiB,CAAC,QAAQ,CAAC,KAAK,EAAY,gBAAgB,MAAM,QAAQ,aAAa,4GAA4G,EAAE,MAAM,CAAC,KAAK,EAAY,OAAO,MAAM,QAAQ,aAAa,GAAG,IAAI,EAAE,IAAI,IAAI,KAAK,CAAC,EAAE,UAAU,CAAC,KAAK,EAAY,OAAO,MAAM,YAAY,aAAa,IAAI,IAAI,IAAI,IAAI,GAAG,KAAK,GAAG,EAAE,OAAO,CAAC,KAAK,EAAY,QAAQ,MAAM,SAAS,aAAa,EAAI,EAAE,eAAe,CAAC,KAAK,EAAY,QAAQ,MAAM,kBAAkB,aAAa,GAAM,OAAO,EAAI,EAAE,UAAU,CAAC,KAAK,EAAY,KAAK,MAAM,aAAa,QAAQ,CAAC,EAAE,CAAC,EAAE,aAAa,CAAC,UAAU,OAAO,EAAE,aAAa,EAAE,OAAO,EAAI,EAAE,WAAW,CAAC,KAAK,EAAY,MAAM,MAAM,aAAa,aAAa,UAAU,OAAO,GAAO,EAAM,YAAY,CAAC,EAAE,WAAW,CAAC,KAAK,EAAY,MAAM,MAAM,aAAa,aAAa,SAAS,CAAC,CAAC,CAAC"}