PSET Circle! - Printable Version +- Qbasicnews.com (http://qbasicnews.com/newforum) +-- Forum: QbasicNews.Com (http://qbasicnews.com/newforum/forum-3.html) +--- Forum: Challenges (http://qbasicnews.com/newforum/forum-10.html) +--- Thread: PSET Circle! (/thread-6492.html) Pages: 1 2 3 4 5 6 7 PSET Circle! - Neo - 03-16-2005 3 lines, using another algorithm: [syntax="QBASIC"]FOR I! = -0.5 TO 199.5 STEP .5 IF I! = -0.5 THEN SCREEN 13 ELSE PSET (((INT(I!) = I!) * 2 + 1) * SQR(10000 - (INT(I!) - 100) ^2) + 160, INT(I!) * 0.75), 15 NEXT I![/syntax] Doesn't draw the circle completely, in this case it needs some more code to optimize this block, but it draws the outlines which can be connected with line or by enhancing the above code. Advantage of this x = SQR(r^2-y^2) algorithm is that it's faster and doesn't require large loops. In these kind of challenges it's impossible to draw a full connected circle, because if you zoom in on the circles made with the COS/SIN algorithm you'll see the same as the algorithm above displays. PSET Circle! - Rattrapmax6 - 03-16-2005 :o Heh, 3 lines, I never thought of stuffing it like that,. oh well,. here was mine: [syntax="qbasic"]SCREEN 13 FOR a = 1 TO 360 x = 20 * COS(a * 3.14159265# / 180) y = 20 * SIN(a * 3.14159265# / 180) PSET (160 + x, 100 - y), a NEXT[/syntax] I wasn't planning to have a winner (more just a challange, all under 10 lines won), but Meg deserves to gets the highest points! 3 lines, *walks off scratching head*... PSET Circle! - Meg - 03-17-2005 Meh. My entry doesn't deserve any special mention, really. In order to cram it into three lines, I had to remove a lot of clarity. I'd never actually write it like that for a porgram. The idea for using a loop and a IF THEN ELSE IF ... ELSE line isn't even mine. I first came across it in the screensaver challenges, I think. Might have been Relsoft's, or somebody else's idea. Basically, the first few solutions all do exactly the same thing.. calculate X and Y based on trig functions from an angle converted to radians, then PSET at (x,y). I'm not sure what Neo's does, but it looks like he's using the formula for a circle to plot the points instead of SIN and COS. *peace* Meg. PSET Circle! - Rattrapmax6 - 03-17-2005 Quote:OK, why not? Code:```Screen 18, 32 Do While InKey\$=""    Y=(Y+1)Mod 480    For X = 0 to 639      If ABS(SQR((320-X)^2 + (240-Y)^2))<= 255 then PSet(X,Y),RGB(0,0,255-ABS(SQR((320-X)^2 + (240-Y)^2)))    Next Loop``` :o AHH!!! A BIG BLUE BLOB!!!! :lol: Thats pretty cool!! :rotfl: :wink: PSET Circle! - Mitthrawnuruodo - 03-17-2005 heh, its FB... I think Sterling won. [/code] PSET Circle! - Sterling Christensen - 03-17-2005 Quote:I think Sterling won. Lol, I was just joking. I don't think my submission counts, it's only valid on a technicality. He would have specified a minimum readius had it occured to him to. PSET Circle! - Rattrapmax6 - 03-17-2005 Quote:heh, its FB... I think Sterling won. [/code] Oh yeah, heh, nice try, but I said it had to be round, thats a small square.. :wink: PSET Circle! - Mitthrawnuruodo - 03-17-2005 Ah, but it's a point. And isn't a point round? Just cause the computer gives him a handicap on its res..... :lol: PSET Circle! - Diroga - 03-17-2005 does any one under stand the math behind the circle? just checking PSET Circle! - Neo - 03-17-2005 What a question... of course The math behind an ellipse is very simple. For an ellipse:(x / c) ^ 2 + (y / d) ^ 2 = r ^ 2 For a filled ellipse:(x / c) ^ 2 + (y / d) ^ 2 <= r ^ 2 For a negative ellipse:(x / c) ^ 2 + (y / d) ^ 2 > r ^ 2 That is the mathematical algebraic description of an ellipse (a circle has c = d = 1). A circle can also be written as a function of polar or parametric variables. Polar form:r = const Parametric:x = cos(tetha) * r y = sin(tetha) * r In both forms tetha ranging from 0 to 2 * PI. Rotated ellipses are easier to make using the parametric form, although for both the function and parametric form a rotation formula can be used. ~~~~~