add funmode :^)
This commit is contained in:
		
							parent
							
								
									470115a126
								
							
						
					
					
						commit
						e4acdac3a5
					
				| 
						 | 
					@ -8,14 +8,31 @@ import (
 | 
				
			||||||
	"log"
 | 
						"log"
 | 
				
			||||||
	"net"
 | 
						"net"
 | 
				
			||||||
	"sync"
 | 
						"sync"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/SpeckiJ/Hochwasser/render"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var funmode = true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Flut asynchronously sends the given image to pixelflut server at `address`
 | 
					// Flut asynchronously sends the given image to pixelflut server at `address`
 | 
				
			||||||
//   using `conns` connections. Pixels are sent column wise, unless `shuffle`
 | 
					//   using `conns` connections. Pixels are sent column wise, unless `shuffle`
 | 
				
			||||||
//   is set. Stops when stop is closed.
 | 
					//   is set. Stops when stop is closed.
 | 
				
			||||||
// @cleanup: use FlutTask{} as arg
 | 
					// @cleanup: use FlutTask{} as arg
 | 
				
			||||||
func Flut(img *image.NRGBA, position image.Point, shuffle bool, address string, conns int, stop chan bool, wg *sync.WaitGroup) {
 | 
					func Flut(img *image.NRGBA, position image.Point, shuffle bool, address string, conns int, stop chan bool, wg *sync.WaitGroup) {
 | 
				
			||||||
	cmds := commandsFromImage(img, position)
 | 
						var cmds commands
 | 
				
			||||||
 | 
						if funmode {
 | 
				
			||||||
 | 
							// do a RGB split of white
 | 
				
			||||||
 | 
							imgmod := render.ImgReplaceColors(img, color.NRGBA{0xff, 0xff, 0xff, 0xff}, color.NRGBA{0xff, 0, 0, 0xff})
 | 
				
			||||||
 | 
							cmds = append(cmds, commandsFromImage(imgmod, image.Pt(position.X-10, position.Y-10))...)
 | 
				
			||||||
 | 
							imgmod = render.ImgReplaceColors(img, color.NRGBA{0xff, 0xff, 0xff, 0xff}, color.NRGBA{0, 0xff, 0, 0xff})
 | 
				
			||||||
 | 
							cmds = append(cmds, commandsFromImage(imgmod, image.Pt(position.X+10, position.Y))...)
 | 
				
			||||||
 | 
							imgmod = render.ImgReplaceColors(img, color.NRGBA{0xff, 0xff, 0xff, 0xff}, color.NRGBA{0, 0, 0xff, 0xff})
 | 
				
			||||||
 | 
							cmds = append(cmds, commandsFromImage(imgmod, image.Pt(position.X-10, position.Y+10))...)
 | 
				
			||||||
 | 
							cmds = append(cmds, commandsFromImage(img, position)...)
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							cmds = commandsFromImage(img, position)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if shuffle {
 | 
						if shuffle {
 | 
				
			||||||
		cmds.Shuffle()
 | 
							cmds.Shuffle()
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,6 +2,7 @@ package render
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"image"
 | 
						"image"
 | 
				
			||||||
 | 
						"image/color"
 | 
				
			||||||
	_ "image/gif" // register gif, jpeg, png format handlers
 | 
						_ "image/gif" // register gif, jpeg, png format handlers
 | 
				
			||||||
	_ "image/jpeg"
 | 
						_ "image/jpeg"
 | 
				
			||||||
	"image/png"
 | 
						"image/png"
 | 
				
			||||||
| 
						 | 
					@ -45,6 +46,19 @@ func ImgToNRGBA(img image.Image) *image.NRGBA {
 | 
				
			||||||
	return r
 | 
						return r
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func ImgReplaceColors(img *image.NRGBA, from, to color.NRGBA) *image.NRGBA {
 | 
				
			||||||
 | 
						b := img.Bounds()
 | 
				
			||||||
 | 
						r := image.NewNRGBA(b)
 | 
				
			||||||
 | 
						for x := b.Min.X; x < b.Max.X; x++ {
 | 
				
			||||||
 | 
							for y := b.Min.Y; y < b.Max.Y; y++ {
 | 
				
			||||||
 | 
								if img.At(x, y) == from {
 | 
				
			||||||
 | 
									r.SetNRGBA(x, y, to)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return r
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func ScaleImage(img image.Image, factor int) (scaled *image.NRGBA) {
 | 
					func ScaleImage(img image.Image, factor int) (scaled *image.NRGBA) {
 | 
				
			||||||
	b := img.Bounds()
 | 
						b := img.Bounds()
 | 
				
			||||||
	scaledBounds := image.Rect(0, 0, b.Max.X*factor, b.Max.Y*factor)
 | 
						scaledBounds := image.Rect(0, 0, b.Max.X*factor, b.Max.Y*factor)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -17,7 +17,7 @@ func pt(p fixed.Point26_6) image.Point {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func RenderText(text string, scale int, col color.Color) *image.NRGBA {
 | 
					func RenderText(text string, scale int, col, bgCol color.Color) *image.NRGBA {
 | 
				
			||||||
	// @incomplete: draw with texture via Drawer.Src
 | 
						// @incomplete: draw with texture via Drawer.Src
 | 
				
			||||||
	face := basicfont.Face7x13
 | 
						face := basicfont.Face7x13
 | 
				
			||||||
	stringBounds, _ := font.BoundString(face, text)
 | 
						stringBounds, _ := font.BoundString(face, text)
 | 
				
			||||||
| 
						 | 
					@ -25,7 +25,10 @@ func RenderText(text string, scale int, col color.Color) *image.NRGBA {
 | 
				
			||||||
	b := image.Rectangle{pt(stringBounds.Min), pt(stringBounds.Max)}
 | 
						b := image.Rectangle{pt(stringBounds.Min), pt(stringBounds.Max)}
 | 
				
			||||||
	img := image.NewNRGBA(b)
 | 
						img := image.NewNRGBA(b)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	draw.Draw(img, b, image.Black, image.Point{}, draw.Src) // fill with black bg
 | 
						// fill with black bg
 | 
				
			||||||
 | 
						if (bgCol != color.NRGBA{}) {
 | 
				
			||||||
 | 
							draw.Draw(img, b, image.NewUniform(bgCol), image.Point{}, draw.Src)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	d := font.Drawer{
 | 
						d := font.Drawer{
 | 
				
			||||||
		Dst:  img,
 | 
							Dst:  img,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -29,6 +29,7 @@ func RunREPL(f Fluter) {
 | 
				
			||||||
	mode := commandMode
 | 
						mode := commandMode
 | 
				
			||||||
	textSize := 4
 | 
						textSize := 4
 | 
				
			||||||
	textCol := color.NRGBA{0xff, 0xff, 0xff, 0xff}
 | 
						textCol := color.NRGBA{0xff, 0xff, 0xff, 0xff}
 | 
				
			||||||
 | 
						bgCol := color.NRGBA{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	scanner := bufio.NewScanner(os.Stdin)
 | 
						scanner := bufio.NewScanner(os.Stdin)
 | 
				
			||||||
	for scanner.Scan() {
 | 
						for scanner.Scan() {
 | 
				
			||||||
| 
						 | 
					@ -42,7 +43,7 @@ func RunREPL(f Fluter) {
 | 
				
			||||||
				continue
 | 
									continue
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			t := f.getTask()
 | 
								t := f.getTask()
 | 
				
			||||||
			t.Img = render.RenderText(inputStr, textSize, textCol)
 | 
								t.Img = render.RenderText(inputStr, textSize, textCol, bgCol)
 | 
				
			||||||
			f.applyTask(t)
 | 
								f.applyTask(t)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		case commandMode:
 | 
							case commandMode:
 | 
				
			||||||
| 
						 | 
					@ -94,6 +95,11 @@ func RunREPL(f Fluter) {
 | 
				
			||||||
						textCol = color.NRGBA{col[0], col[1], col[2], 0xff}
 | 
											textCol = color.NRGBA{col[0], col[1], col[2], 0xff}
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 | 
									if len(args) > 2 {
 | 
				
			||||||
 | 
										if col, err := hex.DecodeString(args[2]); err == nil {
 | 
				
			||||||
 | 
											bgCol = color.NRGBA{col[0], col[1], col[2], 0xff}
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			case "img":
 | 
								case "img":
 | 
				
			||||||
				if len(args) > 0 {
 | 
									if len(args) > 0 {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue