func (o *drawing) Putchar(ch byte) { o.init() start := int(ch) - 32 if start < 0 || start > 96 { start = 3 } start *= 5 for i := 0; i < 5; i++ { for j := 0; j < 7; j++ { x, y := o.px+float64(i)*SPOTSIZE, o.py-float64(j)*SPOTSIZE var c byte = 0 // 50 if ((basic.Font[start+i] >> uint(j)) & 1) != 0 { c = 255 // 250 } o.canvas.PaintTriangle(int(x/100.0*WIDTH), int(y/100.0*HEIGHT), int((x+SPOTSIZE)/100.0*WIDTH), int(y/100.0*HEIGHT), int(x/100.0*WIDTH), int((y+SPOTSIZE)/100.0*HEIGHT), canvas.RGB(c, c, c)) } } o.px += SPOTSIZE * 7 if o.px > 100-MARGIN { o.px = MARGIN o.py -= SPOTSIZE * 10 if o.py < MARGIN { o.py = 100 - MARGIN } } }
func (o *drawing) fonttest(t *basic.Terp, _ []float64) float64 { o.init() x0, y0 := 5.0, 98.0 for i := 0; i < len(basic.Font); i++ { for j := 0; j < 8; j++ { x, y := x0+float64(i), y0-float64(j) var c byte = 50 if ((basic.Font[i] >> uint(j)) & 1) == 1 { c = 250 } o.canvas.PaintTriangle(int(x/100.0*0.5*WIDTH), int(y/100.0*0.5*HEIGHT), int((x+1)/100.0*0.5*WIDTH), int(y/100.0*0.5*HEIGHT), int(x/100.0*0.5*WIDTH), int((y+1)/100.0*0.5*HEIGHT), canvas.RGB(c/5, c, c/5)) } if i%5 == 4 { x0 += 1 } if i%60 == 59 { x0, y0 = 5-float64(i), y0-10 } } return 0.0 }
func main() { flag.Parse() // Special -l list command. if *list { for k, v := range superfractal.Builtin { Printf("%s\t%s\n", k, v) } return } c := canvas.NewCanvas(*width, *height) if *grid { c.Grid(*width/10, canvas.RGB(100, 100, 100)) } ifs := superfractal.ParseIfsParams(*params) switch *style { case 1: // Whole. c.Fill(0, 0, *width, *height, canvas.Blue) // c.WritePng(os.Stdout) // return c = ifs.WholeGame(c, *num) case 0: // Chaos. ifs.ChaosGame(c, *num, canvas.Green) } c.WritePng(os.Stdout) }
func (o *drawing) point(t *basic.Terp, args []float64) float64 { o.init() var r, g, b byte // Default is black. if len(args) > 2 { r, g, b = Decimal2RGB(args[2]) // Use given color. } o.canvas.Set(int(args[0]/100*WIDTH), int(args[1]/100*HEIGHT), canvas.RGB(r, g, b)) return 0 }
func (o *drawing) clear(t *basic.Terp, args []float64) float64 { o.init() var r, g, b byte // Default is black. if len(args) > 0 { r, g, b = Decimal2RGB(args[0]) // Use given color. } o.canvas.Fill(0, 0, WIDTH, HEIGHT, canvas.RGB(r, g, b)) return 0 }
func (o *drawing) triangle(t *basic.Terp, args []float64) float64 { o.init() var r, g, b byte // Default is black. if len(args) > 6 { r, g, b = Decimal2RGB(args[6]) // Use given color. } o.canvas.PaintTriangle(int(args[0]/100.0*WIDTH), int(args[1]/100.0*HEIGHT), int(args[2]/100.0*WIDTH), int(args[3]/100.0*HEIGHT), int(args[4]/100.0*WIDTH), int(args[5]/100.0*HEIGHT), canvas.RGB(r, g, b)) return 0 }
func main() { flag.Parse() // Special -l list command, listing short names for builtin IFSs. if *list { for k, v := range superfractal.Builtin { Printf("%s\t%s\n", k, v) } return } // Parse IFSs & construct initial Triptych. ifss := superfractal.ParseListOfIfsParams(*params) src := superfractal.NewTriptych(*numPanels, *width, *height) if *startTriang { // Special hack for demoing sier's traingles for i := 0; i < *numPanels; i++ { src.Panels[i].PaintTriangle(0, 0, 0, *height, *width, 0, canvas.White) } } else { // Fill initial Triptych with different colors. r, g, b := byte(255), byte(0), byte(0) for i := 0; i < *numPanels; i++ { if *mustWhite { r, g, b = byte(255), byte(255), byte(255) } src.Panels[i].Fill(0, 0, *width, *height, canvas.RGB(r, g, b)) // Rotate & dim the colors a bit, on each iteration. // TODO: something better than this. r, g, b = byte(0.96*float64(b)), byte(0.96*float64(r)), byte(0.96*float64(g)) } } // Loop for *num steps, creating successive superfractal approximations. for i := 0; i < *num; i++ { targ := superfractal.NewTriptych(*numPanels, *width, *height) targ.SuperStep(src, ifss) for j := 0; j < *numPanels; j++ { filename := Sprintf("%s.%03d.%03d.png", *base, i, j) canvas.Say(filename) f, err := os.Create(filename) if err != nil { panic(err) } targ.Panels[j].WritePng(f) f.Close() } src = targ } }
// MapImageTo maps one picture through an IFS onto another. func (o Affine) MapImageTo(src *canvas.Canvas, dest *canvas.Canvas, k int, done chan int) { for i := 0; i < src.Width; i++ { x := float64(i) / src.FWidth for j := 0; j < src.Height; j++ { r, g, b := src.Get(i, j) if r > 0 || g > 0 || b > 0 { y := float64(j) / src.FHeight x2, y2 := o.Apply(x, y) dest.FSet(x2, y2, canvas.RGB(r, g, b)) } } } done <- k }
func (h H) ServeHTTP(w http.ResponseWriter, r *http.Request) { // fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path)) strs := notnum.Split(r.URL.Path, -1) var nums []float64 for _, s := range strs { if s == "" { continue } f, err := strconv.ParseFloat(s, 64) if err != nil { panic(err) } nums = append(nums, f) } can := canvas.NewCanvas(*WIDTH, *HEIGHT) can.Grid(50, canvas.RGB(20, 20, 20)) for i := 0; i < len(nums)-8; i += 9 { x1 := int(nums[i+0]) y1 := int(nums[i+1]) x2 := int(nums[i+2]) y2 := int(nums[i+3]) x3 := int(nums[i+4]) y3 := int(nums[i+5]) red := byte(nums[i+6]) green := byte(nums[i+7]) blue := byte(nums[i+8]) can.PaintTriangle(x1, y1, x2, y2, x3, y3, canvas.RGB(red, green, blue)) } w.Header().Set("Content-Type", "image/png") can.WritePng(w) }