Dark Bit Factory & Gravity
PROGRAMMING => Other languages => Yabasic => Topic started by: rain_storm on September 26, 2007
-
This is a very fast fake phong shaded circle drawing routine that can handle ovals and even cones (move the highlight to a point outside of the circle to produce cones) use it freely
# FAKE PHONG SHADED CIRCLES
open window 640, 512
circles = 255
sub pcircle(a,b,c,d,g,h)
doubpi = pi*2
x = a+c/g
y = b+d/h
f = pi/30
for e = f to doubpi step f
gtriangle x,y to a+cos(e)*c,b+sin(e)*d to a+cos(e+f)*c,b+sin(e+f)*d
next
end sub
label loop
setdispbuf draw
draw = 1 - draw
setdrawbuf draw
for c = 0 to circles
centerx = ran(640)
centery = ran(512)
radiusx = ran(50) + 25
radiusy = ran(50) + 25
r = ran(255)
g = ran(255)
b = ran(255)
l = ran(0.6)
setrgb 1, r, g, b
setrgb 2, l*r, l*g, l*b
setrgb 3, l*r, l*g, l*b
pcircle(centerx,centery, radiusx,radiusy, 3,-3)
next
goto loop
Here is the same routine but with an extra parameter that allows you to rotate the ovals
sub pcircle(a,b, c,d, g,h, r)
doubpi = pi*2
x = a + (c/g) * cos(r)
y = b + (d/h) * sin(r)
f = pi/30
for e = f+r to doubpi+r step f
gtriangle x,y to a+cos(e)*c,b+sin(e)*d to a+cos(e+f)*c,b+sin(e+f)*d
next
end sub
-
Very nice Rain!
-
Yep, that's an accepted technique that lots and lots of yabasic programmers have used to draw shaded circles, the first person to use them in this way (as far as I know) was Xalthorn.
I used them myself in lots of demos, would be nice to see you do some real effect out of them :)
-
Aha, found it.
http://members.iinet.net.au/~jimshaw/Yabasic/yabres/demos/rafryer/balldemo.txt
EDIT: OMG, I've just looked at that code, the lookuptables for sin and cos (and all the other arrays) are dimmed inside the sub at the end of the program but are used earlier in the main code!!! I remember yabasic having some crazy behaviour but that's going too far.
-
Hehe, like the longer the listing the slower it ran...
It certainly had some strange quirks!