Help with circles

Computer_Guy
07-18-2001, 06:47 PM
Is there a way to make a graphic go in a circle in a loop? I want to make several green circles go around a charcter for a cure spell in an RPG, and wasn't sure if a circle equation was easy to do, if you can help, many thanks to you...

JDT
07-18-2001, 10:34 PM
This example demonstrates a neet circle effect using the Circle() Function. There is also a circle method for some of the objects. If you are using a picturebox this should not be that hard.

Put a timer and a picturebox on the form and paste this code. Also put a small graphic in the picbox so you can see the circles flashing around it.

<pre><font color=blue>Option Explicit</font color=blue>

<font color=blue>Private Sub</font color=blue> Form_Load()

<font color=blue>With</font color=blue> Timer1
.Interval = 100
.Enabled = <font color=blue>True</font color=blue>
<font color=blue>End With</font color=blue>

Picture1.Move 50, 50, 400, 400

<font color=blue>With</font color=blue> Me
.Height = 5000
.Width = 5000
.Left = (Screen.Width / 2) - (Me.Width / 2)
.Top = (Screen.Height / 2) - (Me.Height / 2)
<font color=blue>End With</font color=blue>

<font color=blue>End Sub</font color=blue>

<font color=blue>Private Sub</font color=blue> Timer1_Timer()

<font color=blue>Dim</font color=blue> sngX <font color=blue>As Single</font color=blue>
<font color=blue>Dim</font color=blue> sngY <font color=blue>As Single</font color=blue>
<font color=blue>Dim</font color=blue> sngRadius <font color=blue>As Single</font color=blue>
<font color=blue>Dim</font color=blue> sngLimit <font color=blue>As Single</font color=blue>

ScaleMode = 3 <font color=green>'<---------------------------Set scale to pixels.</font color=green>
sngX = ScaleWidth / 2 <font color=green>'<-------------------Set X position.</font color=green>
sngY = ScaleHeight / 2 <font color=green>'<------------------Set Y position.</font color=green>

<font color=blue>If</font color=blue> sngX > sngY <font color=blue>Then</font color=blue>
sngLimit = sngY
<font color=blue>Else</font color=blue>
sngLimit = sngX
<font color=blue>End If</font color=blue>

<font color=blue>For</font color=blue> sngRadius = 100 <font color=blue>To</font color=blue> sngLimit <font color=blue>Step</font color=blue> 1 <font color=green>'<----Set radius.</font color=green>
Picture1.<font color=blue>Circle</font color=blue> (sngX, sngY), sngRadius, RGB(Rnd * 255, Rnd * 255, Rnd * 255)
<font color=blue>Circle</font color=blue> (sngX, sngY), sngRadius, RGB(Rnd * 255, Rnd * 255, Rnd * 255)
<font color=blue>Next</font color=blue> sngRadius

<font color=blue>End Sub</font color=blue></pre>


Good Luck

JDT

JDT
07-18-2001, 10:47 PM
Oh ya, play around with the Step in the For Loop to see some differences, like Step 5. And you can also change the starting value in the For Loop to a higher number for less circles and a lower number for more.

JDT

BillSoo
07-19-2001, 01:17 AM
....or did you mean you want an image of a circle to move in a circular orbit around the character?

"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder

andrewo
07-19-2001, 09:18 AM
im gonna use it for a sorta cheaper :) way of making splashes of water in my game, but I was wondering
if you could make it like light blue on the inner circles than the circles get larger and become darker..?

i am making a sorta of rpg
more of a boat game where you shoot other boats and its for the water effects of cannon balls hitting water

~

dcl3500
07-19-2001, 11:24 AM
BillSoo,

I don't know if he meant that or not, but could you share that with us. It could be pretty cool for getting attention on a form.

Don

Time is the best teacher; unfortunately it kills all its students.

BillSoo
07-19-2001, 12:17 PM
Well....it's a bit complicated because it depends somewhat on how you were drawing the circles in the first place...let's suppose the circle is a SHAPE control in the form of a circle. In other words, it's an object which we'll call shp. Let's also suppose, you want it to orbit a point designated by X, Y at a radius of R. These variables could change (ie. if the RPG character is walking or something). You could do something like:

<pre><font color=blue>Option Explicit</font color=blue>

<font color=blue>Const</font color=blue> PI = 3.14159265358979
<font color=blue>Dim</font color=blue> X#, Y#, R#

<font color=blue>Sub</font color=blue> Timer1_Timer()
<font color=green>'x,y and r are set outside this function somewhere...</font color=green>
<font color=blue>Static</font color=blue> theta# <font color=green>'angle in radians</font color=green>
<font color=blue>Dim</font color=blue> sx#, sy#

sx = Cos(theta) * R + X
sy = Sin(theta) * R + Y
shp.Move sx, sy
theta = theta + 5 * PI / 180 <font color=green>'increment by 5 degrees</font color=green>
<font color=blue>End Sub</font color=blue>

</pre>




"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder

Computer_Guy
07-19-2001, 02:43 PM
Hey BillSoo, yeah, I wanted the cureballs to orbit the character, I didn't think I made it that clear at first, anyway, just to clarify

Computer_Guy
07-19-2001, 02:49 PM
You said...

Const PI = 3.14 (jadda-jadda-jadda)

Does the computer have a thing where you could just say PI, or do you have to dimension it?

BillSoo
07-19-2001, 03:06 PM
I've been declaring my own PI constants (and TWOPI and HALFPI) since VB3. I don't know if they've since added it to the language, but I doubt it....



"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum