View Full Version : I hope this challenge gets a few entries
GnuVince
11-30-2002, 04:11 PM
OK, we've had a couple of challenge that haven't worked at all lately. So, I hope this is something that people are interested in making. The goal is quite simple: make a spiral. We need to see it being drawn:
* * * **** ******* ******* *******
* ... * * ... * * ... ** * ... ** * ... *******
* * * * * ** * ******* *******
***** ******* ******* ******* ******* *******
It can be made using any language (including the one you know the best), using any graphical toolkit you want.
Goodluck everyone
sedarious
11-30-2002, 08:03 PM
you want an ascii spiral or a graphical spiral???
GnuVince
11-30-2002, 08:16 PM
Any one will do. Go with a 3D one if you like!
inkedmn
11-30-2002, 08:17 PM
do i win?
python:
# Spiral.py
print """
* * * **** ******* ******* *******
* ... * * ... * * ... ** * ... ** * ... *******
* * * * * ** * ******* *******
***** ******* ******* ******* ******* *******
"""
;)
Tarkus
11-30-2002, 09:37 PM
Quick hack job... QB source Below
CONST SpiralWidth = 220
CONST SpiralStep = .01
CONST Pi = 3.141592654#
DIM GradStep AS SINGLE
DIM SpiralJumps AS SINGLE
DIM X AS SINGLE
DIM Y AS SINGLE
DIM S AS SINGLE
CLS
INPUT "Number of Divisions in Spiral (0=Exit)"; SpiralJumps
IF SpiralJumps = 0 THEN END
SpiralJumps = ABS(SpiralJumps)
SCREEN 12
GradStep = SpiralJumps * (Pi * 2) 'Spiral Jump * 2Radians
FOR T = GradStep TO 0 STEP -SpiralStep
X = SIN(T) * ((SpiralWidth / GradStep) * T) + 320
Y = COS(T) * ((SpiralWidth / GradStep) * T) + 240
FOR S = 0 TO 10000: NEXT S 'Slow it down so you can see it
PSET (X, Y), INT(RND * 16)
NEXT T
LoopA:
A$ = INKEY$ 'Wait for keypress
IF A$ = "" THEN GOTO LoopA:
CLS
A link to the zipped executable here (http://www.precimax.com/test/spiral.zip)
Or did you want a picture of it drawing?
Tarkus
12-07-2002, 03:02 AM
Come on people, this is a simple challenge... Does nobody have <30 minutes to spare?
jamessan
12-07-2002, 01:10 PM
Do you want it drawn in place with delays so that you can see it being drawn, or do you want it to look just like the display that you posted?
recluse
12-07-2002, 01:23 PM
I'd go for the drawn in place option, I think it would look better :)
jamessan
12-07-2002, 02:15 PM
That means I'll have to look some stuff up. I haven't done a lot of console stuff like that. Although it shouldn't take too long once I figure stuff out.
Halide
12-08-2002, 03:28 AM
Originally posted by Tarkus
Quick hack job... QB source Below
CONST SpiralWidth = 220
CONST SpiralStep = .01
CONST Pi = 3.141592654#
DIM GradStep AS SINGLE
DIM SpiralJumps AS SINGLE
DIM X AS SINGLE
DIM Y AS SINGLE
DIM S AS SINGLE
CLS
INPUT "Number of Divisions in Spiral (0=Exit)"; SpiralJumps
IF SpiralJumps = 0 THEN END
SpiralJumps = ABS(SpiralJumps)
SCREEN 12
GradStep = SpiralJumps * (Pi * 2) 'Spiral Jump * 2Radians
FOR T = GradStep TO 0 STEP -SpiralStep
X = SIN(T) * ((SpiralWidth / GradStep) * T) + 320
Y = COS(T) * ((SpiralWidth / GradStep) * T) + 240
FOR S = 0 TO 10000: NEXT S 'Slow it down so you can see it
PSET (X, Y), INT(RND * 16)
NEXT T
LoopA:
A$ = INKEY$ 'Wait for keypress
IF A$ = "" THEN GOTO LoopA:
CLS
Beware of the for...next delay loops ;) hehe
btw, I loved qbasic ... did a lot with it a few years ago
Tarkus
12-08-2002, 01:27 PM
Originally posted by Halide
Beware of the for...next delay loops ;) hehe
btw, I loved qbasic ... did a lot with it a few years ago
I used it because using the timer is really innacurate and it slows the program down because you can't set the step small enough.
Bender
12-11-2002, 04:25 AM
Here's a really cruddy hack done in Java (with Swing).
Source:
Main Method (http://excelsior.uccs.edu/j/jmorriso/Spiral.txt)
GUI (http://excelsior.uccs.edu/j/jmorriso/GSpiral.txt)
Spiral Generator (http://excelsior.uccs.edu/j/jmorriso/DrawSpiral.txt)
And here's an executable .jar for those who actually want to see it go.
Download Here (http://excelsior.uccs.edu/j/jmorriso/GSpiral.jar)
Could probably have been done a lot better, but it was fun to do regardless.
a_priebe47
04-22-2003, 11:29 PM
Well, I would've done it the same way as inkedmn. Although it would be cool to see someone code an algorithm that generates the spiral, rather then just making it print straight ASCII.
woodwind
06-07-2004, 03:12 PM
I solved this problem today, but it's on my Linux box, which won't have Internet access until my mom gets home with the new router. Ours got really hot today and the plastic started melting, no joke :P
I'll probably have the code posted by 10:30 PM forum time.
woodwind
06-07-2004, 04:57 PM
"""
Draws a spiral to the screen, traveling counterclockwise
Mike Nolan
7 June 2004
"""
import os
import time
spiral = map(list, [
"* ",
"* ",
"* ",
"* ",
"***** "])
# If there is a space anywhere in the line, it's not full
# Only reaches end if no spaces are found
def is_full():
for line in spiral:
if ' ' in line: return False
return True
# Width and height constants (0-based)
w = 13
h = 4
# Starting coordinates (0-based)
x = 4
y = 4
# There are four directions:
# Horizontal: forward (1), backward (2)
# Vertical: up (3), down (4)
# We begin moving horizontal forward
dir = 1
# Print the spiral
def print_spiral():
for line in spiral:
for c in line:
print c,
print ''
# OS-independent screen clear (win or posix)
def cls():
if os.name=='posix':
cmd = "clear"
else:
cmd = "cls"
os.system(cmd)
# Until the spiral is completely *'d
while not is_full():
if dir==1:
if x==w or spiral[y][x+1]=="*":
dir = 3
continue
else:
spiral[y][x+1] = "*"
x = x+1
elif dir==2:
if x==0 or spiral[y][x-1]=="*":
dir = 4
continue
else:
spiral[y][x-1] = "*"
x = x-1
elif dir==3:
if y==0 or spiral[y-1][x]=="*":
dir = 2
continue
else:
spiral[y-1][x] = "*"
y = y-1
elif dir==4:
if y==h or spiral[y+1][x]=="*":
dir = 1
continue
else:
spiral[y+1][x] = "*"
y = y+1
cls()
print_spiral()
time.sleep(0.05)
vBulletin® v3.7.0, Copyright ©2000-2009, Jelsoft Enterprises Ltd.