Sunflower fractal
Sunflower fractal is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
Draw Sunflower fractal
Go
This uses the Go Graphics library for rendering 2D graphics in pure Go. The image produced, when viewed with (for example) EOG, is similar to the Ring entry.
<lang go>package main
import (
"github.com/fogleman/gg" "math"
)
func main() {
dc := gg.NewContext(400, 400) dc.SetRGB(1, 1, 1) dc.Clear() dc.SetRGB(0, 0, 1) c := (math.Sqrt(5) + 1) / 2 numberOfSeeds := 3000 for i := 0; i <= numberOfSeeds; i++ { fi := float64(i) fn := float64(numberOfSeeds) r := math.Pow(fi, c) / fn angle := 2 * math.Pi * c * fi x := r*math.Sin(angle) + 200 y := r*math.Cos(angle) + 200 fi /= fn / 5 dc.DrawCircle(x, y, fi) } dc.SetLineWidth(1) dc.Stroke() dc.Fill() dc.SavePNG("sunflower_fractal.png")
}</lang>
Microsoft Small Basic
<lang smallbasic>' Sunflower fractal - 24/07/2018
GraphicsWindow.Width=410 GraphicsWindow.Height=400 c=(Math.SquareRoot(5)+1)/2 numberofseeds=3000 For i=0 To numberofseeds r=Math.Power(i,c)/numberofseeds angle=2*Math.Pi*c*i x=r*Math.Sin(angle)+200 y=r*Math.Cos(angle)+200 GraphicsWindow.DrawEllipse(x, y, i/numberofseeds*10, i/numberofseeds*10) EndFor </lang>
- Output:
Ring
<lang ring>
- Project : Sunflower fractal
- Date : 2018/07/24
- Author : Gal Zsolt (~ CalmoSoft ~)
- Email : calmosoft@gmail.com
load "guilib.ring"
paint = null
new qapp
{ win1 = new qwidget() { setwindowtitle("Sunflower fractal") setgeometry(100,100,320,500) label1 = new qlabel(win1) { setgeometry(10,10,400,400) settext("") } new qpushbutton(win1) { setgeometry(100,400,100,30) settext("draw") setclickevent("draw()") } show() } exec() }
func draw
p1 = new qpicture() color = new qcolor() { setrgb(0,0,255,255) } pen = new qpen() { setcolor(color) setwidth(1) } paint = new qpainter() { begin(p1) setpen(pen)
c = (sqrt(5) + 1) / 2 numberofseeds = 3000 for i = 0 to numberofseeds r = pow(i, c ) / (numberofseeds) angle = 2 * 3.14 * c * i x = r * sin(angle) + 100 y = r * cos(angle) + 100 drawellipse(x, y, i / (numberofseeds / 10), i / (numberofseeds / 10)) next
endpaint() } label1 { setpicture(p1) show() }
</lang> Output: