Skip to content

Instantly share code, notes, and snippets.

@jedypod
Last active December 17, 2018 12:37
Show Gist options
  • Save jedypod/f915f2928633c96020796f7e1bab1cdf to your computer and use it in GitHub Desktop.
Save jedypod/f915f2928633c96020796f7e1bab1cdf to your computer and use it in GitHub Desktop.
Generates a Hex Pattern
set cut_paste_input [stack 0]
version 5.2 v1
Group {
inputs 0
name HexGenerator
selected true
xpos -50
ypos -482
addUserKnob {20 HexGenerator}
addUserKnob {41 format T HexGenCalc.format}
addUserKnob {26 ""}
addUserKnob {7 size R 10 400}
size 180
addUserKnob {7 sharpness}
sharpness 1
addUserKnob {7 thickness R 0 0.2}
thickness 0.011
addUserKnob {6 invert +STARTLINE}
}
BlinkScript {
inputs 0
recompileCount 6
ProgramGroup 1
KernelDescription "2 \"HexKernel\" iterate pixelWise 1e7192b9cc9235ac98937c42230792ead33a4d63b46d36793e9ff1a13ff9b6d0 1 \"dst\" Write Point 3 \"size\" Float 1 AAAgQQ== \"smoothness\" Float 1 AACAPw== \"thickness\" Float 1 CtcjPA== 3 \"size\" 1 1 \"smoothness\" 1 1 \"thickness\" 1 1 0"
kernelSource "kernel HexKernel : ImageComputationKernel<ePixelWise>\n\{\n Image<eWrite> dst;\n\n param:\n float size;\n float smoothness;\n float thickness;\n\n void define() \{\n defineParam(size, \"size\", 10.0f);\n defineParam(smoothness, \"smoothness\", 1.0f);\n defineParam(thickness, \"thickness\", 0.01f);\n \}\n\n float2 mod(float2 v, float m) \{\n return float2( fmod(v.x, m), fmod(v.y, m) );\n \}\n\n float hexGrid(float2 p) \{\n p.x *= 2.0f*0.57735f;\n p.y += fmod(floor(p.x), 2.0f)*0.5f;\n p = fabs(mod(p, 1.0f) - 0.5f);\n return fabs(max(p.x*1.5f+p.y, p.y*2.0f)-1.0f);\n \}\n\n float smoothstep(float a, float b, float x) \{\n if (x < a)\n return 0.0f;\n if (x >= b)\n return 1.0f;\n x = (x - a) / (b - a);\n return x*x * (3.0f - 2.0f*x);\n \}\n\n void process(int2 xy) \{\n float2 pos = float2(float(xy.x)/size, float(xy.y)/size);\n float v = hexGrid(pos);\n v = smoothstep(thickness, thickness+smoothness, v);\n dst() = float4(1-v, 1-v, 1-v, 1.0f);\n \}\n\};"
rebuild ""
HexKernel_size {{parent.size}}
HexKernel_smoothness {{1-parent.sharpness+0.01}}
HexKernel_thickness {{parent.thickness}}
rebuild_finalise ""
name HexGenCalc
xpos 120
ypos 345
}
Invert {
channels rgb
name Invert
xpos 120
ypos 423
disable {{!parent.invert}}
}
Output {
name Output
xpos 120
ypos 495
}
end_group
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment