예제 #1
0
// geoSineWaves build the sine_waves SVG pattern
func (p *Pattern) geoSineWaves() {
	period := utils.Map(utils.HexVal(p.Hash, 0, 1), 0, 15, 100, 400)
	amplitude := utils.Map(utils.HexVal(p.Hash, 1, 1), 0, 15, 30, 100)
	waveWidth := utils.Map(utils.HexVal(p.Hash, 2, 1), 0, 15, 3, 30)

	p.Svg.SetHeight(int(waveWidth * 36))
	p.Svg.SetWidth(int(period))

	for i := 0; i <= 35; i++ {
		val := utils.HexVal(p.Hash, i, 1)
		opacity := utils.Opacity(val)
		fill := utils.FillColor(val)
		xOffset := (period / 4) * 0.7

		styles := make(map[string]interface{})
		styles["fill"] = "none"
		styles["stroke"] = fill
		styles["style"] = map[string]string{"opacity": fmt.Sprintf("%v", opacity), "stroke-width": fmt.Sprintf("%vpx", waveWidth)}

		str := fmt.Sprintf("M0 %v C %v 0, %v 0, %v %v S %v %v, %v %v S %v 0, %v, %v", amplitude, xOffset, period/2-xOffset, period/2, amplitude, period-xOffset, amplitude*2, period, amplitude, period*1.5-xOffset, period*1.5, amplitude)

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

		style["transform"] = fmt.Sprintf("translate(-%v, %v)", period/4, (waveWidth*float64(i))-(amplitude*1.5))
		p.Svg.Path(str, utils.Merge(styles, style))

		style["transform"] = fmt.Sprintf("translate(-%v, %v)", period/4, (waveWidth*float64(i))-(amplitude*1.5)+waveWidth*36)
		p.Svg.Path(str, utils.Merge(styles, style))
	}
}
예제 #2
0
// DrawInnerMosaicTile returns string representing an inner mosaic tile shape
func DrawInnerMosaicTile(s *svg.SVG, x, y, triangleSize float64, values [2]float64) {
	triangle := BuildRightTriangle(triangleSize)
	opacity := utils.Opacity(values[0])
	fill := utils.FillColor(values[0])

	styles := make(map[string]interface{})
	styles["fill"] = fill
	styles["fill-opacity"] = opacity
	styles["stroke"] = utils.StrokeColor
	styles["stroke-opacity"] = utils.StrokeOpacity

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

	style["transform"] = fmt.Sprintf("translate(%v, %v) scale(-1, 1)", x+triangleSize, y)
	s.Polyline(triangle, utils.Merge(styles, style))

	style["transform"] = fmt.Sprintf("translate(%v, %v) scale(1, -1)", x+triangleSize, y+triangleSize*2)
	s.Polyline(triangle, utils.Merge(styles, style))

	opacity = utils.Opacity(values[1])
	fill = utils.FillColor(values[1])

	styles["fill"] = fill
	styles["fill-opacity"] = opacity

	style["transform"] = fmt.Sprintf("translate(%v, %v) scale(-1, -1)", x+triangleSize, y+triangleSize*2)
	s.Polyline(triangle, utils.Merge(styles, style))

	style["transform"] = fmt.Sprintf("translate(%v, %v) scale(1, 1)", x+triangleSize, y)
	s.Polyline(triangle, utils.Merge(styles, style))
}
예제 #3
0
// geoHexagons build the hexagons SVG pattern
func (p *Pattern) geoHexagons() {
	scale := utils.HexVal(p.Hash, 0, 1)
	sideLength := utils.Map(scale, 0, 15, 8, 60)
	hexHeight := sideLength * math.Sqrt(3)
	hexWidth := sideLength * 2
	hex := shapes.BuildHexagon(sideLength)

	p.Svg.SetHeight(int(hexHeight * 6))
	p.Svg.SetWidth(int((hexWidth * 3) + (sideLength * 3)))

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

			val := utils.HexVal(p.Hash, i, 1)
			var dy float64
			if x%2 == 0 {
				dy = float64(y) * hexHeight
			} else {
				dy = float64(y)*hexHeight + hexHeight/2
			}
			opacity := utils.Opacity(val)
			fill := utils.FillColor(val)

			styles := make(map[string]interface{})
			styles["fill"] = fill
			styles["fill-opacity"] = opacity
			styles["stroke"] = utils.StrokeColor
			styles["stroke-opacity"] = utils.StrokeOpacity

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

			style["transform"] = fmt.Sprintf("translate(%v, %v)", float64(x)*sideLength*1.5-hexWidth/2, dy-hexHeight/2)
			p.Svg.Polyline(hex, utils.Merge(styles, style))

			if x == 0 {
				style["transform"] = fmt.Sprintf("translate(%v, %v)", 6*sideLength*1.5-hexWidth/2, dy-hexHeight/2)
				p.Svg.Polyline(hex, utils.Merge(styles, style))
			}

			if y == 0 {
				if x%2 == 0 {
					dy = 6 * hexHeight
				} else {
					dy = 6*hexHeight + hexHeight/2
				}
				style["transform"] = fmt.Sprintf("translate(%v, %v)", float64(x)*sideLength*1.5-hexWidth/2, dy-hexHeight/2)
				p.Svg.Polyline(hex, utils.Merge(styles, style))
			}

			if x == 0 && y == 0 {
				style["transform"] = fmt.Sprintf("translate(%v, %v)", 6*sideLength*1.5-hexWidth/2, 5*hexHeight+hexHeight/2)
				p.Svg.Polyline(hex, utils.Merge(styles, style))
			}

			i = i + 1
		}
	}
}
예제 #4
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
		}
	}
}
예제 #5
0
// geoDiamonds build the diamonds SVG pattern
func (p *Pattern) geoDiamonds() {
	diamondWidth := utils.Map(utils.HexVal(p.Hash, 0, 1), 0, 15, 10, 50)
	diamondHeight := utils.Map(utils.HexVal(p.Hash, 1, 1), 0, 15, 10, 50)
	diamond := shapes.BuildDiamond(diamondWidth, diamondHeight)

	p.Svg.SetHeight(int(diamondHeight * 3))
	p.Svg.SetWidth(int(diamondWidth * 6))

	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)

			styles := make(map[string]interface{})
			styles["fill"] = fill
			styles["fill-opacity"] = opacity
			styles["stroke"] = utils.StrokeColor
			styles["stroke-opacity"] = utils.StrokeOpacity

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

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

			style["transform"] = fmt.Sprintf("translate(%v, %v)", dx+float64(x)*diamondWidth-diamondWidth/2, diamondHeight/2*float64(y)-diamondHeight/2)
			p.Svg.Polyline(diamond, utils.Merge(styles, style))

			if x == 0 {
				style["transform"] = fmt.Sprintf("translate(%v, %v)", dx+6*diamondWidth-diamondWidth/2, diamondHeight/2*float64(y)-diamondHeight/2)
				p.Svg.Polyline(diamond, utils.Merge(styles, style))
			}

			if y == 0 {
				style["transform"] = fmt.Sprintf("translate(%v, %v)", dx+float64(x)*diamondWidth-diamondWidth/2, diamondHeight/2*6-diamondHeight/2)
				p.Svg.Polyline(diamond, utils.Merge(styles, style))
			}

			if x == 0 && y == 0 {
				style["transform"] = fmt.Sprintf("translate(%v, %v)", dx+6*diamondWidth-diamondWidth/2, diamondHeight/2*6-diamondHeight/2)
				p.Svg.Polyline(diamond, utils.Merge(styles, style))
			}

			i = i + 1
		}
	}
}
예제 #6
0
// geoTriangles build the triangles SVG pattern
func (p *Pattern) geoTriangles() {
	scale := utils.HexVal(p.Hash, 0, 1)
	sideLength := utils.Map(scale, 0, 15, 15, 80)
	triangleHeight := sideLength / 2 * math.Sqrt(3)
	triangle := shapes.BuildTriangle(sideLength, triangleHeight)

	p.Svg.SetHeight(int(triangleHeight * 6))
	p.Svg.SetWidth(int(sideLength * 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)

			styles := make(map[string]interface{})
			styles["fill"] = fill
			styles["fill-opacity"] = opacity
			styles["stroke"] = utils.StrokeColor
			styles["stroke-opacity"] = utils.StrokeOpacity

			var rotation int
			if y%2 == 0 {
				if x%2 == 0 {
					rotation = 180
				}
			} else {
				if x%2 != 0 {
					rotation = 180
				}
			}

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

			style["transform"] = fmt.Sprintf("translate(%v, %v) rotate(%v, %v, %v)", float64(x)*sideLength*0.5-sideLength/2, triangleHeight*float64(y), rotation, sideLength/2, triangleHeight/2)
			p.Svg.Polyline(triangle, utils.Merge(styles, style))

			if x == 0 {
				style["transform"] = fmt.Sprintf("translate(%v, %v) rotate(%v, %v, %v)", 6*sideLength*0.5-sideLength/2, triangleHeight*float64(y), rotation, sideLength/2, triangleHeight/2)
				p.Svg.Polyline(triangle, utils.Merge(styles, style))
			}

			i = i + 1
		}
	}
}
예제 #7
0
// geoChevrons build the chevrons SVG pattern
func (p *Pattern) geoChevrons() {
	chevronWidth := utils.Map(utils.HexVal(p.Hash, 0, 1), 0, 15, 30, 80)
	chevronHeight := chevronWidth
	chevron := shapes.BuildChevron(chevronWidth, chevronHeight)

	p.Svg.SetHeight(int(chevronHeight * 6 * 0.66))
	p.Svg.SetWidth(int(chevronWidth * 6))

	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)

			styles := make(map[string]interface{})
			styles["fill"] = fill
			styles["fill-opacity"] = opacity
			styles["stroke"] = utils.StrokeColor
			styles["stroke-opacity"] = utils.StrokeOpacity
			styles["stroke-width"] = 1

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

			style["transform"] = fmt.Sprintf("translate(%v, %v)", float64(x)*chevronWidth, float64(y)*chevronHeight*0.66-chevronHeight/2)
			p.Svg.Group(chevron, utils.Merge(styles, style))

			if y == 0 {
				style["transform"] = fmt.Sprintf("translate(%v, %v)", float64(x)*chevronWidth, 6*chevronHeight*0.66-chevronHeight/2)
				p.Svg.Group(chevron, utils.Merge(styles, style))
			}

			i = i + 1
		}
	}
}
예제 #8
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
		}
	}
}
예제 #9
0
// geoTessellation build the tessellation SVG pattern
func (p *Pattern) geoTessellation() {
	sideLength := utils.Map(utils.HexVal(p.Hash, 0, 1), 0, 15, 5, 40)
	hexHeight := sideLength * math.Sqrt(3)
	hexWidth := sideLength * 2
	triangleHeight := sideLength / 2 * math.Sqrt(3)
	triangle := shapes.BuildRotatedTriangle(sideLength, triangleHeight)
	tileWidth := sideLength*3 + triangleHeight*2
	tileHeight := (hexHeight * 2) + (sideLength * 2)

	p.Svg.SetHeight(int(tileHeight))
	p.Svg.SetWidth(int(tileWidth))

	for i := 0; i <= 19; i++ {
		val := utils.HexVal(p.Hash, i, 1)
		opacity := utils.Opacity(val)
		fill := utils.FillColor(val)

		styles := make(map[string]interface{})
		styles["fill"] = fill
		styles["fill-opacity"] = opacity
		styles["stroke"] = utils.StrokeColor
		styles["stroke-opacity"] = utils.StrokeOpacity
		styles["stroke-width"] = 1

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

		switch i {
		case 0:
			p.Svg.Rect(-sideLength/2, -sideLength/2, sideLength, sideLength, styles)
			p.Svg.Rect(tileWidth-sideLength/2, -sideLength/2, sideLength, sideLength, styles)
			p.Svg.Rect(-sideLength/2, tileHeight-sideLength/2, sideLength, sideLength, styles)
			p.Svg.Rect(tileWidth-sideLength/2, tileHeight-sideLength/2, sideLength, sideLength, styles)
		case 1:
			p.Svg.Rect(hexWidth/2+triangleHeight, hexHeight/2, sideLength, sideLength, styles)
		case 2:
			p.Svg.Rect(-sideLength/2, tileHeight/2-sideLength/2, sideLength, sideLength, styles)
			p.Svg.Rect(tileWidth-sideLength/2, tileHeight/2-sideLength/2, sideLength, sideLength, styles)
		case 3:
			p.Svg.Rect(hexWidth/2+triangleHeight, hexHeight*1.5+sideLength, sideLength, sideLength, styles)
		case 4:
			style["transform"] = fmt.Sprintf("translate(%v, %v) rotate(0, %v, %v)", sideLength/2, -sideLength/2, sideLength/2, triangleHeight/2)
			p.Svg.Polyline(triangle, utils.Merge(styles, style))
			style["transform"] = fmt.Sprintf("translate(%v, %v) rotate(0, %v, %v) scale(1, -1)", sideLength/2, tileHeight-(-sideLength/2), sideLength/2, triangleHeight/2)
			p.Svg.Polyline(triangle, utils.Merge(styles, style))
		case 5:
			style["transform"] = fmt.Sprintf("translate(%v, %v) rotate(0, %v, %v) scale(-1, 1)", tileWidth-sideLength/2, -sideLength/2, sideLength/2, triangleHeight/2)
			p.Svg.Polyline(triangle, utils.Merge(styles, style))
			style["transform"] = fmt.Sprintf("translate(%v, %v) rotate(0, %v, %v) scale(-1, -1)", tileWidth-sideLength/2, tileHeight+sideLength/2, sideLength/2, triangleHeight/2)
			p.Svg.Polyline(triangle, utils.Merge(styles, style))
		case 6:
			style["transform"] = fmt.Sprintf("translate(%v, %v)", tileWidth/2+sideLength/2, hexHeight/2)
			p.Svg.Polyline(triangle, utils.Merge(styles, style))
		case 7:
			style["transform"] = fmt.Sprintf("translate(%v, %v) scale(-1, 1)", tileWidth-tileWidth/2-sideLength/2, hexHeight/2)
			p.Svg.Polyline(triangle, utils.Merge(styles, style))
		case 8:
			style["transform"] = fmt.Sprintf("translate(%v, %v) scale(1, -1)", tileWidth/2+sideLength/2, tileHeight-hexHeight/2)
			p.Svg.Polyline(triangle, utils.Merge(styles, style))
		case 9:
			style["transform"] = fmt.Sprintf("translate(%v, %v) scale(-1, -1)", tileWidth-tileWidth/2-sideLength/2, tileHeight-hexHeight/2)
			p.Svg.Polyline(triangle, utils.Merge(styles, style))
		case 10:
			style["transform"] = fmt.Sprintf("translate(%v, %v)", sideLength/2, tileHeight/2-sideLength/2)
			p.Svg.Polyline(triangle, utils.Merge(styles, style))
		case 11:
			style["transform"] = fmt.Sprintf("translate(%v, %v) scale(-1, 1)", tileWidth-sideLength/2, tileHeight/2-sideLength/2)
			p.Svg.Polyline(triangle, utils.Merge(styles, style))
		case 12:
			style["transform"] = fmt.Sprintf("translate(%v, %v) rotate(-30, 0, 0)", sideLength/2, sideLength/2)
			p.Svg.Rect(0, 0, sideLength, sideLength, utils.Merge(styles, style))
		case 13:
			style["transform"] = fmt.Sprintf("scale(-1, 1) translate(%v, %v) rotate(-30, 0, 0)", -tileWidth+sideLength/2, sideLength/2)
			p.Svg.Rect(0, 0, sideLength, sideLength, utils.Merge(styles, style))
		case 14:
			style["transform"] = fmt.Sprintf("translate(%v, %v) rotate(30, 0, %v)", sideLength/2, tileHeight/2-sideLength/2-sideLength, sideLength)
			p.Svg.Rect(0, 0, sideLength, sideLength, utils.Merge(styles, style))
		case 15:
			style["transform"] = fmt.Sprintf("scale(-1, 1) translate(%v, %v) rotate(30, 0, %v)", -tileWidth+sideLength/2, tileHeight/2-sideLength/2-sideLength, sideLength)
			p.Svg.Rect(0, 0, sideLength, sideLength, utils.Merge(styles, style))
		case 16:
			style["transform"] = fmt.Sprintf("scale(1, -1) translate(%v, %v) rotate(30, 0, %v)", sideLength/2, -tileHeight+tileHeight/2-sideLength/2-sideLength, sideLength)
			p.Svg.Rect(0, 0, sideLength, sideLength, utils.Merge(styles, style))
		case 17:
			style["transform"] = fmt.Sprintf("scale(-1, -1) translate(%v, %v) rotate(30, 0, %v)", -tileWidth+sideLength/2, -tileHeight+tileHeight/2-sideLength/2-sideLength, sideLength)
			p.Svg.Rect(0, 0, sideLength, sideLength, utils.Merge(styles, style))
		case 18:
			style["transform"] = fmt.Sprintf("scale(1, -1) translate(%v, %v) rotate(-30, 0, 0)", sideLength/2, -tileHeight+sideLength/2)
			p.Svg.Rect(0, 0, sideLength, sideLength, utils.Merge(styles, style))
		case 19:
			style["transform"] = fmt.Sprintf("scale(-1, -1) translate(%v, %v) rotate(-30, 0, 0)", -tileWidth+sideLength/2, -tileHeight+sideLength/2)
			p.Svg.Rect(0, 0, sideLength, sideLength, utils.Merge(styles, style))
		}
	}
}