Skip to content

Commit

Permalink
Delimiters: Now they actually work as specified!
Browse files Browse the repository at this point in the history
  • Loading branch information
PhiloTFarnsworth committed May 20, 2021
1 parent 95da4f1 commit 54c65a8
Show file tree
Hide file tree
Showing 262 changed files with 59 additions and 22 deletions.
71 changes: 50 additions & 21 deletions BitSprite.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,18 +199,18 @@ func main() {
var foldX int
if strings.EqualFold(folding, "even") || strings.EqualFold(folding, "e") {
canvasWidth = (templateConfig.Width * 2)
foldY = (canvasWidth / 2)
foldY = templateConfig.Width
} else if strings.EqualFold(folding, "odd") || strings.EqualFold(folding, "o") {
canvasWidth = ((templateConfig.Width * 2) - 1)
foldY = ((canvasWidth / 2) + 1)
foldY = (canvasWidth / 2) + 1
} else {
canvasWidth = templateConfig.Width
foldY = canvasWidth
}

if strings.EqualFold(vertFold, "even") || strings.EqualFold(vertFold, "e") {
canvasHeight = templateConfig.Height * 2
foldX = (canvasHeight / 2)
foldX = templateConfig.Height
} else if strings.EqualFold(vertFold, "odd") || strings.EqualFold(vertFold, "o") {
canvasHeight = (templateConfig.Height * 2) - 1
foldX = (canvasHeight / 2) + 1
Expand Down Expand Up @@ -268,6 +268,11 @@ func main() {
resolutionNumber := i
delimitersRead := 0
for j := 0; j < len(templateArray); j++ {
if returnIndex(delimiters, j) != -1 {
delimitersRead = returnIndex(delimiters, j)
bitsRead = 0
resolutionNumber = randomArrays[delimitersRead][i]
}
if templateArray[j] == Bit {
//We take our increment, shift it by the bitsRead, finally checking whether it is even or odd. This way 0 = all inactive,
//255 = all active.
Expand All @@ -280,13 +285,7 @@ func main() {
} else {
newImage = append(newImage, templateArray[j])
}
if delimitersRead < len(delimiters) {
if j >= delimiters[delimitersRead] {
bitsRead = 0
resolutionNumber = randomArrays[delimitersRead][i]
delimitersRead++
}
}

}
//checks neighbors of active, colored pixels. If the neighboring pixel is a background, replace it with an outline
//pixel. Disabled by -outline=false
Expand All @@ -313,6 +312,7 @@ func main() {
}
}
}
//TODO: Reduce Option. Here we would run through the image again to reduce
var outfile *os.File
var canvas *image.RGBA
if individuals {
Expand All @@ -325,11 +325,17 @@ func main() {

//let's grab the base color for our image
var finalColors [PixelsDefined][]color.Color
for j := 0; j < len(delimiters)+1; j++ {
if j == 0 {
var placeholderIndex int
if len(delimiters) > 0 {
placeholderIndex = len(delimiters)
} else {
placeholderIndex = 1
}
for j := 0; j < placeholderIndex; j++ {
if len(delimiters) == 0 {
resolutionNumber = i
} else {
resolutionNumber = randomArrays[j-1][i]
resolutionNumber = randomArrays[j][i]
}
if !legacy {
for key, val := range chosenColors {
Expand All @@ -351,7 +357,6 @@ func main() {

//Finally, with colors and a template secured, we can write to our individual canvas and collective composite.
var pixelIndex int
delimitersRead = 0
for y := 0; y < canvasHeight; y++ {
for x := 0; x < canvasWidth; x++ {
//We want to start by converting our coordinate into an index position. When we fold,
Expand All @@ -369,23 +374,35 @@ func main() {
pixelIndex = (canvasWidth - x) + ((canvasHeight - y - 1) * templateConfig.Width) - 1
}
}

if y < foldX {
if returnIndex(delimiters, pixelIndex) != -1 {
delimitersRead = returnIndex(delimiters, pixelIndex)
}
} else {
//when we flip, we need to consider that we're reading upside down, so adjust
// our pixel index down
modifiedPixelIndex := x + ((canvasHeight - y) * templateConfig.Width)
if returnIndex(delimiters, modifiedPixelIndex) != -1 {
delimitersRead = returnIndex(delimiters, modifiedPixelIndex) - 1
} //Hacky hack for reading that last delimiter
if delimitersRead == -1 {
delimitersRead = 0
}
}

//A little messy, but we account for upScale here.
for j := 0; j < upScale; j++ {
for k := 0; k < upScale; k++ {
if individuals {
canvas.Set((x*upScale)+j, (y*upScale)+k, finalColors[newImage[pixelIndex]][delimitersRead])
canvas.Set((x*upScale)+j, (y*upScale)+k,
finalColors[newImage[pixelIndex]][delimitersRead])
}
composite.Set((x*upScale)+j+canvasWidth*upScale*(i%compositeWidth),
(y*upScale)+k+canvasHeight*upScale*(i/compositeWidth),
finalColors[newImage[pixelIndex]][delimitersRead])
}
}
//delimiter check
if delimitersRead < len(delimiters)-1 {
if pixelIndex >= delimiters[delimitersRead] {
delimitersRead++
}
}
}
}
//After building the sprite, we encode, then close the individual sprite file.
Expand Down Expand Up @@ -423,3 +440,15 @@ func mayCreateFolder(path string) {
log.Fatal(err)
}
}

// return index of matched value, otherwise return -1
func returnIndex(list []int, find int) int {
i := 0
for i < len(list) {
if find == list[i] {
return i
}
i++
}
return -1
}
10 changes: 9 additions & 1 deletion BitSprite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,19 @@ func TestDelimitedComposite(t *testing.T) {
Compare(t, gotFileName, wantFileName, testArgs)
}

func TestDelimitedCompositeVertFold(t *testing.T) {
fmt.Printf("TestDelimitedCompositeVert\n")
gotFileName := "/GenerationDirectory/Flower/FlowerSpriteSheet.png"
wantFileName := "/testResources/DelimitedFlowerVert.png"
testArgs := []string{"cmd", "-template=flowerDelimited", "-fold=e", "-vertfold=e", "-legacy=t", "-outname=Flower", "-randseed=f"}
Compare(t, gotFileName, wantFileName, testArgs)
}

func TestFace(t *testing.T) {
fmt.Printf("TestFace\n")
gotFileName := "/GenerationDirectory/face/faceSpriteSheet.png"
wantFileName := "/testResources/faceSS.png"
testArgs := []string{"cmd", "-template=face", "-legacy=f", "-color=#ff0000", "-accent=#00ff00", "-fill=#0000ff", "-fold=odd", "-outname=", "randseed=t"}
testArgs := []string{"cmd", "-template=face", "-legacy=f", "-color=#ff0000", "-accent=#00ff00", "-fill=#0000ff", "-fold=odd", "-outname=", "-randseed=t", "-vertfold=none"}
Compare(t, gotFileName, wantFileName, testArgs)
}

Expand Down
Binary file modified docs/FlowerDelimiterOutput.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/example/Individuals/0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/example/Individuals/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/example/Individuals/10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/example/Individuals/100.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/example/Individuals/101.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/example/Individuals/102.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/example/Individuals/103.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/example/Individuals/104.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/example/Individuals/105.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/example/Individuals/106.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/example/Individuals/107.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/example/Individuals/108.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/example/Individuals/109.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/example/Individuals/11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/example/Individuals/110.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/example/Individuals/111.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/example/Individuals/112.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/example/Individuals/113.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/example/Individuals/114.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/example/Individuals/115.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/example/Individuals/116.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/example/Individuals/117.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/example/Individuals/118.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/example/Individuals/119.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/example/Individuals/12.png
Binary file modified docs/example/Individuals/120.png
Binary file modified docs/example/Individuals/121.png
Binary file modified docs/example/Individuals/122.png
Binary file modified docs/example/Individuals/123.png
Binary file modified docs/example/Individuals/124.png
Binary file modified docs/example/Individuals/125.png
Binary file modified docs/example/Individuals/126.png
Binary file modified docs/example/Individuals/127.png
Binary file modified docs/example/Individuals/128.png
Binary file modified docs/example/Individuals/129.png
Binary file modified docs/example/Individuals/13.png
Binary file modified docs/example/Individuals/130.png
Binary file modified docs/example/Individuals/131.png
Binary file modified docs/example/Individuals/132.png
Binary file modified docs/example/Individuals/133.png
Binary file modified docs/example/Individuals/134.png
Binary file modified docs/example/Individuals/135.png
Binary file modified docs/example/Individuals/136.png
Binary file modified docs/example/Individuals/137.png
Binary file modified docs/example/Individuals/138.png
Binary file modified docs/example/Individuals/139.png
Binary file modified docs/example/Individuals/14.png
Binary file modified docs/example/Individuals/140.png
Binary file modified docs/example/Individuals/141.png
Binary file modified docs/example/Individuals/142.png
Binary file modified docs/example/Individuals/143.png
Binary file modified docs/example/Individuals/144.png
Binary file modified docs/example/Individuals/145.png
Binary file modified docs/example/Individuals/146.png
Binary file modified docs/example/Individuals/147.png
Binary file modified docs/example/Individuals/148.png
Binary file modified docs/example/Individuals/149.png
Binary file modified docs/example/Individuals/15.png
Binary file modified docs/example/Individuals/150.png
Binary file modified docs/example/Individuals/151.png
Binary file modified docs/example/Individuals/152.png
Binary file modified docs/example/Individuals/153.png
Binary file modified docs/example/Individuals/154.png
Binary file modified docs/example/Individuals/155.png
Binary file modified docs/example/Individuals/156.png
Binary file modified docs/example/Individuals/157.png
Binary file modified docs/example/Individuals/158.png
Binary file modified docs/example/Individuals/159.png
Binary file modified docs/example/Individuals/16.png
Binary file modified docs/example/Individuals/160.png
Binary file modified docs/example/Individuals/161.png
Binary file modified docs/example/Individuals/162.png
Binary file modified docs/example/Individuals/163.png
Binary file modified docs/example/Individuals/164.png
Binary file modified docs/example/Individuals/165.png
Binary file modified docs/example/Individuals/166.png
Binary file modified docs/example/Individuals/167.png
Binary file modified docs/example/Individuals/168.png
Binary file modified docs/example/Individuals/169.png
Binary file modified docs/example/Individuals/17.png
Binary file modified docs/example/Individuals/170.png
Binary file modified docs/example/Individuals/171.png
Binary file modified docs/example/Individuals/172.png
Binary file modified docs/example/Individuals/173.png
Binary file modified docs/example/Individuals/174.png
Binary file modified docs/example/Individuals/175.png
Binary file modified docs/example/Individuals/176.png
Binary file modified docs/example/Individuals/177.png
Binary file modified docs/example/Individuals/178.png
Binary file modified docs/example/Individuals/179.png
Binary file modified docs/example/Individuals/18.png
Binary file modified docs/example/Individuals/180.png
Binary file modified docs/example/Individuals/181.png
Binary file modified docs/example/Individuals/182.png
Binary file modified docs/example/Individuals/183.png
Binary file modified docs/example/Individuals/184.png
Binary file modified docs/example/Individuals/185.png
Binary file modified docs/example/Individuals/186.png
Binary file modified docs/example/Individuals/187.png
Binary file modified docs/example/Individuals/188.png
Binary file modified docs/example/Individuals/189.png
Binary file modified docs/example/Individuals/19.png
Binary file modified docs/example/Individuals/190.png
Binary file modified docs/example/Individuals/191.png
Binary file modified docs/example/Individuals/192.png
Binary file modified docs/example/Individuals/193.png
Binary file modified docs/example/Individuals/194.png
Binary file modified docs/example/Individuals/195.png
Binary file modified docs/example/Individuals/196.png
Binary file modified docs/example/Individuals/197.png
Binary file modified docs/example/Individuals/198.png
Binary file modified docs/example/Individuals/199.png
Binary file modified docs/example/Individuals/2.png
Binary file modified docs/example/Individuals/20.png
Binary file modified docs/example/Individuals/200.png
Binary file modified docs/example/Individuals/201.png
Binary file modified docs/example/Individuals/202.png
Binary file modified docs/example/Individuals/203.png
Binary file modified docs/example/Individuals/204.png
Binary file modified docs/example/Individuals/205.png
Binary file modified docs/example/Individuals/206.png
Binary file modified docs/example/Individuals/207.png
Binary file modified docs/example/Individuals/208.png
Binary file modified docs/example/Individuals/209.png
Binary file modified docs/example/Individuals/21.png
Binary file modified docs/example/Individuals/210.png
Binary file modified docs/example/Individuals/211.png
Binary file modified docs/example/Individuals/212.png
Binary file modified docs/example/Individuals/213.png
Binary file modified docs/example/Individuals/214.png
Binary file modified docs/example/Individuals/215.png
Binary file modified docs/example/Individuals/216.png
Binary file modified docs/example/Individuals/217.png
Binary file modified docs/example/Individuals/218.png
Binary file modified docs/example/Individuals/219.png
Binary file modified docs/example/Individuals/22.png
Binary file modified docs/example/Individuals/220.png
Binary file modified docs/example/Individuals/221.png
Binary file modified docs/example/Individuals/222.png
Binary file modified docs/example/Individuals/223.png
Binary file modified docs/example/Individuals/224.png
Binary file modified docs/example/Individuals/225.png
Binary file modified docs/example/Individuals/226.png
Binary file modified docs/example/Individuals/227.png
Binary file modified docs/example/Individuals/228.png
Binary file modified docs/example/Individuals/229.png
Binary file modified docs/example/Individuals/23.png
Binary file modified docs/example/Individuals/230.png
Binary file modified docs/example/Individuals/231.png
Binary file modified docs/example/Individuals/232.png
Binary file modified docs/example/Individuals/233.png
Binary file modified docs/example/Individuals/234.png
Binary file modified docs/example/Individuals/235.png
Binary file modified docs/example/Individuals/236.png
Binary file modified docs/example/Individuals/237.png
Binary file modified docs/example/Individuals/238.png
Binary file modified docs/example/Individuals/239.png
Binary file modified docs/example/Individuals/24.png
Binary file modified docs/example/Individuals/240.png
Binary file modified docs/example/Individuals/241.png
Binary file modified docs/example/Individuals/242.png
Binary file modified docs/example/Individuals/243.png
Binary file modified docs/example/Individuals/244.png
Binary file modified docs/example/Individuals/245.png
Binary file modified docs/example/Individuals/246.png
Binary file modified docs/example/Individuals/247.png
Binary file modified docs/example/Individuals/248.png
Binary file modified docs/example/Individuals/249.png
Binary file modified docs/example/Individuals/25.png
Binary file modified docs/example/Individuals/250.png
Binary file modified docs/example/Individuals/251.png
Binary file modified docs/example/Individuals/252.png
Binary file modified docs/example/Individuals/253.png
Binary file modified docs/example/Individuals/254.png
Binary file modified docs/example/Individuals/255.png
Binary file modified docs/example/Individuals/26.png
Binary file modified docs/example/Individuals/27.png
Binary file modified docs/example/Individuals/28.png
Binary file modified docs/example/Individuals/29.png
Binary file modified docs/example/Individuals/3.png
Binary file modified docs/example/Individuals/30.png
Binary file modified docs/example/Individuals/31.png
Binary file modified docs/example/Individuals/32.png
Binary file modified docs/example/Individuals/33.png
Binary file modified docs/example/Individuals/34.png
Binary file modified docs/example/Individuals/35.png
Binary file modified docs/example/Individuals/36.png
Binary file modified docs/example/Individuals/37.png
Binary file modified docs/example/Individuals/38.png
Binary file modified docs/example/Individuals/39.png
Binary file modified docs/example/Individuals/4.png
Binary file modified docs/example/Individuals/40.png
Binary file modified docs/example/Individuals/41.png
Binary file modified docs/example/Individuals/42.png
Binary file modified docs/example/Individuals/43.png
Binary file modified docs/example/Individuals/44.png
Binary file modified docs/example/Individuals/45.png
Binary file modified docs/example/Individuals/46.png
Binary file modified docs/example/Individuals/47.png
Binary file modified docs/example/Individuals/48.png
Binary file modified docs/example/Individuals/49.png
Binary file modified docs/example/Individuals/5.png
Binary file modified docs/example/Individuals/50.png
Binary file modified docs/example/Individuals/51.png
Binary file modified docs/example/Individuals/52.png
Binary file modified docs/example/Individuals/53.png
Binary file modified docs/example/Individuals/54.png
Binary file modified docs/example/Individuals/55.png
Binary file modified docs/example/Individuals/56.png
Binary file modified docs/example/Individuals/57.png
Binary file modified docs/example/Individuals/58.png
Binary file modified docs/example/Individuals/59.png
Binary file modified docs/example/Individuals/6.png
Binary file modified docs/example/Individuals/60.png
Binary file modified docs/example/Individuals/61.png
Binary file modified docs/example/Individuals/62.png
Binary file modified docs/example/Individuals/63.png
Binary file modified docs/example/Individuals/64.png
Binary file modified docs/example/Individuals/65.png
Binary file modified docs/example/Individuals/66.png
Binary file modified docs/example/Individuals/67.png
Binary file modified docs/example/Individuals/68.png
Binary file modified docs/example/Individuals/69.png
Binary file modified docs/example/Individuals/7.png
Binary file modified docs/example/Individuals/70.png
Binary file modified docs/example/Individuals/71.png
Binary file modified docs/example/Individuals/72.png
Binary file modified docs/example/Individuals/73.png
Binary file modified docs/example/Individuals/74.png
Binary file modified docs/example/Individuals/75.png
Binary file modified docs/example/Individuals/76.png
Binary file modified docs/example/Individuals/77.png
Binary file modified docs/example/Individuals/78.png
Binary file modified docs/example/Individuals/79.png
Binary file modified docs/example/Individuals/8.png
Binary file modified docs/example/Individuals/80.png
Binary file modified docs/example/Individuals/81.png
Binary file modified docs/example/Individuals/82.png
Binary file modified docs/example/Individuals/83.png
Binary file modified docs/example/Individuals/84.png
Binary file modified docs/example/Individuals/85.png
Binary file modified docs/example/Individuals/86.png
Binary file modified docs/example/Individuals/87.png
Binary file modified docs/example/Individuals/88.png
Binary file modified docs/example/Individuals/89.png
Binary file modified docs/example/Individuals/9.png
Binary file modified docs/example/Individuals/90.png
Binary file modified docs/example/Individuals/91.png
Binary file modified docs/example/Individuals/92.png
Binary file modified docs/example/Individuals/93.png
Binary file modified docs/example/Individuals/94.png
Binary file modified docs/example/Individuals/95.png
Binary file modified docs/example/Individuals/96.png
Binary file modified docs/example/Individuals/97.png
Binary file modified docs/example/Individuals/98.png
Binary file modified docs/example/Individuals/99.png
Binary file modified docs/example/flowerdelimitedSpriteSheet.png
Binary file modified testResources/DelimitedFlower.png
Binary file added testResources/DelimitedFlowerVert.png

0 comments on commit 54c65a8

Please sign in to comment.