-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathALG_example01.txt
More file actions
4 lines (4 loc) · 2.77 KB
/
Copy pathALG_example01.txt
File metadata and controls
4 lines (4 loc) · 2.77 KB
1
2
3
4
{
"params": "section0a:{class:\"text\", type:\"H3\", value:\"Welcome to genartlayers!\"}\nsection0b:{class:\"text\", type:\"H5\", value:\"Mess with the controls below and see what happens :) Then, go to the 'Code' tab to edit the algorithm or code your own alg!\"}\nsection0c:{class:\"text\", type:\"H5\", value:\"Follow the 'Documentation' link above for more info.\"}\n\nsection1:{class:\"text\", type:\"H3\", value:\"Geometric Properties\"}\nseed:{class:\"number\", default:1, min:1, max:100, step:1}\nnRows:{class:\"slider\", default:5, min:1, max:100, step:1}\npadding:{class:\"slider\", default:0.75, min:0, max:0.99, step:0.01}\n\nsection2:{class:\"text\", type:\"H3\", value:\"Probability\"}\nrectProb: {class:\"slider\", default:50, min:0, max:100, step:1}\ndefectivity:{class:\"slider\", default:0, min:0, max:1, step:0.01}\n\nsection3:{class:\"text\", type:\"H3\", value:\"Color Properties\"}\nhueCenter:{class:\"slider-hue\", default:0, min:0, max:255, step:1}\nsatCenter:{class:\"slider-sat\", default:50, min:0, max:100, step:1}\nlitCenter:{class:\"slider-lit\", default:50, min:0, max:100, step:1}\ncolorVar:{class:\"slider\", default:10, min:0, max:100, step:1}\n\nsection4:{class:\"text\", type:\"H3\", value:\"Line/Fill Properties\"}\nfillMode:{class:\"on-off\"}\nlineWidthFraction:{ class:\"slider\", default:0.1, min:0.01, max:1, step:0.01}\n\n",
"drawFunction": "\n// constant parameters\nvar alpha1 = 255;\n\n// code variables\nvar y;\nvar x;\nvar lineWidth;\n\n// the height and width of the cells\nvar width = 1/nRows;\nvar height = 1/nRows;\n\n\n// for each cell (row and column location), draw either a rectangle or a circle in the middle of the cell.\nfor(let i=0; i<nRows; i++) {\n \n y = height * i;\n \n for(let j=0; j<nRows; j++) {\n \n hue = hueCenter;\n sat = vary(satCenter,colorVar);\n lit = vary(litCenter,colorVar);\n \n if(getRandomFloat(0,1) < defectivity) {alpha=0} else { alpha=alpha1 }\n \n lineWidth = lineWidthFraction * width;\n \n x = width * j;\n \n // with 50% probability draw a rectangle, otherwise draw a circle instead.\n if( getRandomFloat(0,1) < rectProb/100 ) { \n \n // some calculations for the rectangle\n var rectWidth = width*padding;\n var rectHeight = height*padding;\n var xTL = x + (width-rectWidth)/2;\n var yTL = y + (height-rectHeight)/2;\n\n // draw a rectangle\n drawRect(xTL, yTL, rectWidth, rectHeight, lineWidth, hue, sat, lit, alpha, fillMode);\n\n } else {\n \n // some calculations for the circle\n radCirc = width/2 * padding;\n var xCenter = x + width/2;\n var yCenter = y + height/2;\n\n // draw a circle\n drawCircle(xCenter, yCenter, radCirc, lineWidth, hue, sat, lit, alpha, fillMode);\n \n }\n \n }\n \n}\n"
}