Jump to content

Draw a sphere: Difference between revisions

m
now resizeable
m (now resizeable)
Line 2,649:
 
=={{header|Phix}}==
{{trans|Go}} (Go gets credit for the dot/normalize/drawSphere routines, but this draws on screen rather than to png file)
{{trans|Go}}
Sphere will resize to match the window.
<lang Phix>--
-- demo\rosetta\Draw_a_sphere.exw
Line 2,668 ⟶ 2,669:
end function
 
procedure drawSphere(integer rwidth, height, atom k, atom amb, sequence direction)
integer r = floor((min(width,height)-20)/2)
integer cx = floor(width/2)
integer cy = floor(height/2)
integer lum
for x=-r to r do
Line 2,677 ⟶ 2,681:
lum = and_bits(#FF,255*(power(iff(s<0?0:s),k)+amb)/(1+amb))
lum += lum*#100+lum*#10000
cdCanvasPixel(cddbuffer, x+r+10cx, y+r+10cy, lum)
end if
end for
Line 2,684 ⟶ 2,688:
 
function redraw_cb(Ihandle /*ih*/, integer /*posx*/, integer /*posy*/)
integer {width, height} = IupGetIntInt(canvas, "DRAWSIZE")
cdCanvasActivate(cddbuffer)
cdCanvasClear(cddbuffer)
drawSphere(160width,height, 1.5, 0.2, normalize({-30,-30,50}))
cdCanvasFlush(cddbuffer)
return IUP_DEFAULT
7,820

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.