Qbasicnews.com
June 20, 2019, 04:24:01 PM
 Pages: [1] 2 3 ... 5
 Author Topic: PSET Circle!  (Read 33848 times)
Rattrapmax6
__/--\__

Posts: 2577

 « on: March 16, 2005, 12:45:17 AM »

Okay, a simple game that shouldn't take but 5mins of your time.

Object: Make a circle using PSET
RULES:

1. Ten lines or under to be fair... (Can be done in six :wink: )
2. No use of colins " : " <- those
3. Any radius you want if its in the screen
4. Must be round if that makes since..
5. Only one PSET can be used..
6. QB or FB, just note on which, or use the matching Syntax tag.

Get all that? Now try it.. .. Good luck!
 Logged

Kevin (x.t.r.GRAPHICS)

Diroga
Been there, done that

Posts: 1087

 « Reply #1 on: March 16, 2005, 03:36:52 AM »

Code:
CLS
SCREEN 13
FOR i = 1 TO 361 STEP .5
oldx = x: oldy = y
x = INT(50 * (COS(rad * i))) + 160
y = INT(50 * (SIN(rad * i))) + 100
PSET (x, y), 15
NEXT
 Logged
Dr_Davenstein
Na_th_an

Posts: 2052

 « Reply #2 on: March 16, 2005, 05:54:52 AM »

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
 Logged
xteraco
Ancient QBer

Posts: 450

 « Reply #3 on: March 16, 2005, 06:14:54 AM »

here's mine

Code:

screen 13
dim as integer x, y, xmov, ymov
dim as double angle
x = 25 : y = 25
do : angle = angle + .01
xmov = x * sin(angle) + y * cos(angle)
ymov = y * sin(angle) - y * cos(angle)
pset (xmov + 160,ymov + 100),4 : loop

yay, its a circle  :bounce:

ah crap... no colons, well, i guess its back to the drawing board
 Logged

url=http://www.random-seed.net][/url]
xteraco
Ancient QBer

Posts: 450

 « Reply #4 on: March 16, 2005, 06:20:41 AM »

and w/ a little more work (3 minits) i've came up w/ the answer

Code:

screen 13
dim as integer xmov,ymov,angle
do
angle = angle + 1
xmov = 25 * sin(angle) + 25 * cos(angle)
ymov = 25 * sin(angle) - 25 * cos(angle)
pset (xmov + 160,ymov + 100),4
loop

does that qualify.... i win! :bounce:
uh, make this official freebasic submission
 Logged

url=http://www.random-seed.net][/url]
xteraco
Ancient QBer

Posts: 450

 « Reply #5 on: March 16, 2005, 06:35:38 AM »

ah, and here's my qbasic version

Code:

screen 13
for i = 1 to 360
xmov = 25 * sin(i) + 25 * cos(i)
ymov = 25 * sin(i) - 25 * cos(i)
pset (xmov + 160,ymov + 100),4
next

so, make it official, this is my qbasic submission
 Logged

url=http://www.random-seed.net][/url]
Sterling Christensen
Na_th_an

Posts: 1328

 « Reply #6 on: March 16, 2005, 06:37:21 AM »

Code:
SCREEN 13
PSET STEP(0, 0), 15

Sure the pixel may be square, but it's the best approximation possible of a circle with radius 0.5 pixels. :bounce:
 Logged
xteraco
Ancient QBer

Posts: 450

 « Reply #7 on: March 16, 2005, 06:41:59 AM »

well, Sterling beat me :normal:
 Logged

url=http://www.random-seed.net][/url]
KiZ
__/--\__

Posts: 2879

 « Reply #8 on: March 16, 2005, 01:13:48 PM »

Quote from: "rattrapmax6"
(Can be done in six :wink: )

Six? Six is for noobs j/k

Code:
SCREEN 13
FOR i = 1 TO 360
PSET (SIN(i * 3.14 / 180) * 30 + 160, COS(i * 3.14 / 180) * 30 + 100)
NEXT
 Logged
Meg
Ancient QBer

Posts: 483

 « Reply #9 on: March 16, 2005, 01:38:14 PM »

3 lines:
[syntax="QBASIC"]FOR i! = -.5 TO 360 STEP .5
IF i! = -.5 THEN SCREEN 13 ELSE PSET (160 + COS(i! * 3.14 / 180) * 50, 100 + SIN(i! * 3.14 / 180) * 50), 15
NEXT i![/syntax]
 Logged
Neo
Na_th_an

Posts: 2150

 « Reply #10 on: March 16, 2005, 01:55:51 PM »

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.
 Logged
Rattrapmax6
__/--\__

Posts: 2577

 « Reply #11 on: March 16, 2005, 02:11:34 PM »

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*...
 Logged

Kevin (x.t.r.GRAPHICS)

Meg
Ancient QBer

Posts: 483

 « Reply #12 on: March 16, 2005, 04:47:58 PM »

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.
 Logged
Rattrapmax6
__/--\__

Posts: 2577

 « Reply #13 on: March 16, 2005, 06:07:45 PM »

Quote from: "Dr_Davenstein"
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

AHH!!! A BIG BLUE BLOB!!!!  :lol:

Thats pretty cool!! :rotfl:  :wink:
 Logged

Kevin (x.t.r.GRAPHICS)

Mitth'raw'nuruodo
Ancient Guru

Posts: 515

 « Reply #14 on: March 16, 2005, 06:54:38 PM »

heh, its FB...

I think Sterling won.
[/code]
 Logged

i]"But...it was so beautifully done"[/i]
 Pages: [1] 2 3 ... 5