Example #1
0
// geoPlusSigns build the plus_signs SVG pattern
func (p *Pattern) geoPlusSigns() {
	squareSize := utils.Map(utils.HexVal(p.Hash, 0, 1), 0, 15, 10, 25)
	plusSize := squareSize * 3
	plusShape := shapes.BuildPlus(squareSize)

	p.Svg.SetHeight(int(squareSize * 12))
	p.Svg.SetWidth(int(squareSize * 12))

	i := 0
	for y := 0; y <= 5; y++ {
		for x := 0; x <= 5; x++ {

			val := utils.HexVal(p.Hash, i, 1)
			opacity := utils.Opacity(val)
			fill := utils.FillColor(val)

			var dx float64
			if y%2 != 0 {
				dx = 1
			}

			styles := make(map[string]interface{})
			styles["fill"] = fill
			styles["stroke"] = utils.StrokeColor
			styles["stroke-opacity"] = utils.StrokeOpacity
			styles["style"] = map[string]string{"fill-opacity": fmt.Sprintf("%v", opacity)}

			style := make(map[string]interface{})

			style["transform"] = fmt.Sprintf("translate(%v,%v)", float64(x)*(plusSize-squareSize)+dx*squareSize-squareSize, float64(y)*(plusSize-squareSize)-plusSize/2)
			p.Svg.Group(plusShape, utils.Merge(styles, style))

			if x == 0 {
				style["transform"] = fmt.Sprintf("translate(%v,%v)", 4*plusSize-float64(x)*squareSize+dx*squareSize-squareSize, float64(y)*(plusSize-squareSize)-plusSize/2)
				p.Svg.Group(plusShape, utils.Merge(styles, style))
			}

			if y == 0 {
				style["transform"] = fmt.Sprintf("translate(%v,%v)", float64(x)*(plusSize-squareSize)+dx*squareSize-squareSize, 4*(plusSize)-float64(y)*squareSize-plusSize/2)
				p.Svg.Group(plusShape, utils.Merge(styles, style))
			}

			if x == 0 && y == 0 {
				style["transform"] = fmt.Sprintf("translate(%v,%v)", 4*plusSize-float64(x)*squareSize+dx*squareSize-squareSize, 4*plusSize-float64(y)*squareSize-plusSize/2)
				p.Svg.Group(plusShape, utils.Merge(styles, style))
			}

			i = i + 1
		}
	}
}
Example #2
0
// geoXes build the xes SVG pattern
func (p *Pattern) geoXes() {
	squareSize := utils.Map(utils.HexVal(p.Hash, 0, 1), 0, 15, 10, 25)
	xShape := shapes.BuildPlus(squareSize)
	xSize := squareSize * 3 * 0.943

	p.Svg.SetHeight(int(xSize * 3))
	p.Svg.SetWidth(int(xSize * 3))

	i := 0
	for y := 0; y <= 5; y++ {
		for x := 0; x <= 5; x++ {

			val := utils.HexVal(p.Hash, i, 1)
			opacity := utils.Opacity(val)
			fill := utils.FillColor(val)

			var dy float64
			if x%2 == 0 {
				dy = float64(y)*xSize - xSize*0.5
			} else {
				dy = float64(y)*xSize - xSize*0.5 + xSize/4
			}

			styles := make(map[string]interface{})
			styles["fill"] = fill
			styles["style"] = map[string]string{"opacity": fmt.Sprintf("%v", opacity)}

			style := make(map[string]interface{})

			style["transform"] = fmt.Sprintf("translate(%v, %v) rotate(45, %v, %v)", float64(x)*xSize/2-xSize/2, dy-float64(y)*xSize/2, xSize/2, xSize/2)
			p.Svg.Group(xShape, utils.Merge(styles, style))

			if x == 0 {
				style["transform"] = fmt.Sprintf("translate(%v, %v) rotate(45, %v, %v)", 6*xSize/2-xSize/2, dy-float64(y)*xSize/2, xSize/2, xSize/2)
				p.Svg.Group(xShape, utils.Merge(styles, style))
			}

			if y == 0 {
				if x%2 == 0 {
					dy = 6*xSize - xSize/2
				} else {
					dy = 6*xSize - xSize/2 + xSize/4
				}

				style["transform"] = fmt.Sprintf("translate(%v, %v) rotate(45, %v, %v)", float64(x)*xSize/2-xSize/2, dy-float64(y)*xSize/2, xSize/2, xSize/2)
				p.Svg.Group(xShape, utils.Merge(styles, style))
			}

			if y == 5 {
				style["transform"] = fmt.Sprintf("translate(%v, %v) rotate(45, %v, %v)", float64(x)*xSize/2-xSize/2, dy-11*xSize/2, xSize/2, xSize/2)
				p.Svg.Group(xShape, utils.Merge(styles, style))
			}

			if x == 0 && y == 0 {
				style["transform"] = fmt.Sprintf("translate(%v, %v) rotate(45, %v, %v)", 6*xSize/2-xSize/2, dy-6*xSize/2, xSize/2, xSize/2)
				p.Svg.Group(xShape, utils.Merge(styles, style))
			}

			i = i + 1
		}
	}
}