Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Not sure why it won't appear...
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
bass_maniac




PostPosted: Fri Sep 30, 2005 11:29 am   Post subject: Not sure why it won't appear...

Ok, here's the code,

code:
var radius : int
var centerx := maxx div 2
var centery := maxy div 2
var xDist, yDist := 0

put "Create a sphere with a radius of (pixels): " ..
get radius

cls
View.Set ("nocursor")
var sph1x : array 1 .. 2 * radius of int
var sph1y : array 1 .. 2 * radius of int
var sph1z : array 1 .. 2 * radius of int

for a : 1 .. 2 * radius
    for b : 1 .. 2 * radius
        xDist := a - centerx
        yDist := b - centery
        if sqrt (xDist ** 2 + yDist ** 2) <= radius then
            sph1x (a) := centerx + (a - radius)
            sph1y (b) := centery + (b - radius)
            drawdot (sph1x (a), sph1y (b), red)
            put sph1x (a), " ", sph1y (b)
        end if
    end for
end for


Basically what I want it to do is ask the user the radius of the circle and then draw a circle about the center of the screen. It checks every pixel within a box from (centerx - radius, centery - radius) to (centerx + radius, centery + radius). If that particular point is within radius distance of the center its coordinates are noted in sph1x and sph1y and that point should be drawn in red.

NOTE: I did not use drawfilloval because I need to know the coordinates of every pixel in the circle (for something later on in the program.)

If you know of another way to do the same thing that's easier, please let me know.
Sponsor
Sponsor
Sponsor
sponsor
ZeroPaladn




PostPosted: Fri Sep 30, 2005 11:54 am   Post subject: a suggestion

actually, you could use Draw.FillOval and the use What.DotColor to check to see if every pixel is the color you suggest, then put the x and y coordinates of the pixel into 2 arrays (or a 2d array if you can figure it out), that way you can call up the coordinates later in the program. try that out.
bass_maniac




PostPosted: Fri Sep 30, 2005 12:35 pm   Post subject: (No subject)

Thanks. That did work. I spent so much time thinking about this I'm suprised I didn't think of that.
ZeroPaladn




PostPosted: Fri Sep 30, 2005 1:14 pm   Post subject: :)

lolz, its ok if you want to think "outside the box" with that crazy code you had going there, but if something simple can do something very complcated (and it hurts the brain), then why do it complicated, unless you want a challenge.
jamonathin




PostPosted: Fri Sep 30, 2005 1:43 pm   Post subject: (No subject)

There's a problem with trying to make a bunch of dots make a circle.
You'd need sind and cosd functions to do that, like so. .
code:

View.Set("graphics:400;400,nobuttonbar,position:center;center")
var radius : int
var centerx := maxx div 2
var centery := maxy div 2
put "Create a sphere with a radius of (pixels): " ..
get radius
cls
for i : 1 .. radius
    for q : 1 .. 360
        drawdot (round (centerx - i * sind (q)), round (centery - i * cosd (q)), Rand.Int (1, maxcolor))
    end for
end for

And it's not a perfect circle, unless you spend way too much time on it, im shure is possible.

But you can also make cool looking things from that because you can shape every pixel. . .
Turing:

View.Set ("graphics:500;200,nobuttonbar,position:center;center")
colorback (black)
color (white)
cls

var radius : int
put "Create a sphere with a radius of (pixels 150 min, 600 max): " ..
get radius
if radius > 600 then
    radius := 600
elsif radius < 150 then
    radius := 150
end if

View.Set ("graphics:" + intstr (radius) + ";" + intstr (radius) + ",nobuttonbar,position:center;center")
var centerx := maxx div 2
var centery := maxy div 2
process thing
    var c : int := 1
    for i : 1 .. radius
        for q : 1 .. 360
            drawdot (round (centerx - i * sind (q)), round (centery - i * cosd (q)), Rand.Int (16, 28))
        end for
    end for
end thing

cls

loop
    fork thing
    Time.Delay (radius * 10)
    exit when hasch
end loop
Mr. T




PostPosted: Fri Sep 30, 2005 4:12 pm   Post subject: Alex's Opinion

Your second code doesn't work. Confused
beard0




PostPosted: Fri Sep 30, 2005 6:56 pm   Post subject: Re: Alex's Opinion

Pwned wrote:
Your second code doesn't work. :?


Yes it does - notice where the's an emoticon? He had "28))" and it got changed on him to "2Posted Image, might have been reduced in size. Click Image to view fullscreen.)" because 8) is the symbol to create that emoticon. Change it back and it works fine Posted Image, might have been reduced in size. Click Image to view fullscreen..
Cervantes




PostPosted: Fri Sep 30, 2005 8:24 pm   Post subject: Re: a suggestion

ZeroPaladn wrote:
put the x and y coordinates of the pixel into 2 arrays (or a 2d array if you can figure it out)


2 1D arrays are NOT the same as a 2D array. Unless the second dimension of the 2D array has only 2 elements, in which case they are similar.
Sponsor
Sponsor
Sponsor
sponsor
ZeroPaladn




PostPosted: Sat Oct 01, 2005 3:51 pm   Post subject: (No subject)

really, i thought that 2d arrays and 1d arrays were the same thing, cept for the fact that you can store 2 kinds of data in a 2D array Embarassed
beard0




PostPosted: Sat Oct 01, 2005 3:57 pm   Post subject: (No subject)

Nope. A 1D array is just a list. A 2d array is like a table, so that if each index goes from 0-9, you have 100 elements in your array.
ZeroPaladn




PostPosted: Sat Oct 01, 2005 4:00 pm   Post subject: (No subject)

you learn sumthing new everyday now dont we?
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 11 Posts ]
Jump to:   


Style:  
Search: