I am using the propeller in a class project and I am trying to draw a vector based on a starting point, angle, and magnitude. I am going to use this to make a wheel spin using the tv and the graphics objects.
You could succeed with steps == 1 or steps == 2 ; and check the arcmode you will need!
PUB arc(x, y, xr, yr, angle, anglestep, steps, arcmode)
'' Draw an arc
''
'' x,y - center of arc
'' xr,yr - radii of arc
'' angle - initial angle in bits[noparse][[/noparse]12..0] (0..$1FFF = 0°..359.956°)
'' anglestep - angle step in bits[noparse][[/noparse]12..0]
'' steps - number of steps (0 just leaves (x,y) at initial arc position)
'' arcmode - 0: plot point(s)
'' 1: line to point(s)
'' 2: line between points
'' 3: line from point(s) to center
Yes run the graphics demo and also look at graphics.spin you can draw circles as deSilva suggests and you can draw lines with plot and line functions there is also a function called vec which will draw a vector sprite (some image made from vectors defined in the dat section) at whatever scale, position and rotation you require.
I used the vec function to create some clock type graphical elements see:
For a wheel you could make a vector sprite like a star for the spokes and use arc for the rim, then move the rim and move and rotate the spokes for the rotation effect as it rolls. Using PI in there somewhere will make it look more realistic.
Thank you all for your suggestions. I have used the graphics demo and the plot/line, arc, and·vec commands in the graphics object. I have also tried modifying the graphics demo. My problem is that I haven’t been able to figure out exactly how to draw what I need to draw with the vector and vector arc commands. I can't really figure out what the different numbers do within the sprite definition. Another problem with modifying the graphics demo is that all of the objects (the little dogs and stars) rotate around a center point, while remaining upright. I need one object to rotate around its center. Could anyone post a better description, or a different method, of how to draw the sprites?
PUB vec(x, y, vecscale, vecangle, vecdef_ptr)
Draw a vector sprite
x,y - center of vector sprite
vecscale - scale of vector sprite ($100 = 1x)
vecangle - rotation angle of vector sprite in bits[noparse][[/noparse]12..0]
vecdef_ptr - address of vector sprite definition
Vector sprite definition:
word $8000|$4000+angle 'vector mode + 13-bit angle (mode: $4000=plot, $8000=line)
word length 'vector length
... 'more vectors
...
word 0 'end of definition
So when defining a sprite you start at 0,0 if you do $8000 + 13bit angle then it will draw a line from 0,0 in that direction. If you did $4000 + 13bit angle then it will draw a point and the next vector will be drawn from there.
After the angle and type is defined the length of the vector.
The example from the demo of a triangle:
vecdef word $4000+$2000/3*0 ' draws a point at an angle zero degrees (notice * 0) from 0,0
word 50 ' a distance 50 away
word $8000+$2000/3*1+1 ' draws a line at an angle of 360/3 degrees from that point
word 50 ' of length 50
word $8000+$2000/3*2-1 ' draws a line at an angle of 2/3 360 degrees from that point
word 50 ' length 50
word $8000+$2000/3*0 ' finishes with another horizontal line (angle 0)
word 50 ' length 50
word 0 ' finish vector sprite
All angles are from the horizontal CCW. 0,0 in the sprite is the point that will be positioned at x,y as defined in the command vec.
If you draw your spokes comming out from 0,0 then any rotation will make them rotate around their centre.
Please do some experimentation and do actually read what is in graphics.spin to better understand it.
Graham
p.s. The pointer in my program is a vector sprite.
I have been trying to draw an octagon using the pub.vec method but I am confused about how the angle is calculated the "$2000/3*1+1" makes no sense to me why nit just use the number 4? I have been experimenting with other whole numbers to divide by but I need an angle of 270 degrees and with the formula stated before I cannot use floating point numbers, What magic numbers do you have to get 360 degrees around a point?
the divide and multiply are done before the addition so it is ($2000/3*1) + 1
The angle is stored in 13 bits, this is %1111111111111 or $1FFF
zero represents both 0 degrees and 360 degrees so $1FFF represents just less than 360 and $2000 (which is $1FFF + 1) represents 360 degrees as well numerically but cannot be used because it is more than 13 bits however it can be divided up and used like in this case. The +1, and -1 used are to ensure that the total comes to 180 degrees, the total angle within a triangle accounting for the lack of fractional values I think.
Aaron,
I've been fooling around a bit, here's what I came up with for some spokes. I converted to 360 degrees to make it easier to read at a cost of resolution for angle.
-Martin
repeat
gr.colorwidth(3,2)
repeat k from 0 to 359
gr.clear
gr.vec(0, 0, 100, $1fff * k / 360 , @vecdef) ' draw angle converted to 360 (much resolution loss)
gr.copy(display_base)
waitcnt(clkfreq/100 + cnt)
.
.
.
' ALL angles are with respect to center, not last point
' All distances are from center as well
vecdef word $4000 + ($1fff * 0 / 360) ' set a point at 0 degrees from center
word 30 ' at distance of 30
word $8000 + ($1fff * 0 / 360) ' draw a line of 50 at 0 deg from center
word 50
word $4000 + ($1fff * 30 / 360) ' set a point 30 degrees from center, distance 30
word 30
word $8000 + ($1fff * 30 / 360) ' draw a line 30 degrees off from cente, distance of 50,
word 50
word $4000 + ($1fff * 60 / 360)
word 30
word $8000 + ($1fff * 60 / 360)
word 50
' up to 330 degees.........
word 0
An alternate means to use one line draw at various angles from your loop:
repeat
gr.colorwidth(3,2)
repeat k from 0 to 359
gr.clear
repeat i from 0 to 360 step 30 ' draw a vector every 30 degrees based on k + i
gr.vec(0, 0, 100, $1fff * (k +i) / 360 , @vecdef) ' draw angle converted to 360 (much resolution loss)
gr.copy(display_base)
waitcnt(clkfreq/100 + cnt)
' ALL angles are with respect to center, not last point
' All distances are from center as well
vecdef word $4000 + ($1fff * 0 / 360) ' set a point at 0 degrees from center
word 30 ' at distance of 30
word $8000 + ($1fff * 0 / 360) ' draw a line of 50 at 0 deg from center
word 50
word 0 ' end of defination
Graham Stabler said...
...... you can draw circles as deSilva suggests ...
NEVER DID I SUGGEST SUCH A THING!
What I hinted to was a not very popular creative use of arc, such as:
centerX := 100
centerY := 100
length := 50
repeat
repeat angle from 0 to 360
gr.copy(...)
gr.clear ' line got lost during posting - will make it much more instructive!
gr.arc(centerX , centerY , length, length, angle*$2000/360 , 0, 1, 3)
thank you all for your help. another student, my professor, and I figured it out. in case your courious my project is to make a simulation of an old fashion musical tuner (the kind that uses a spinning wheel that spins at the eye's refresh rate when you're in tune). now i just have to work out the hardware, it should be easy though.
Comments
Good luck in your class project.
Baggers.
PS, don't forget to post pics of the finished project.
Perry
I used the vec function to create some clock type graphical elements see:
http://forums.parallax.com/showthread.php?p=682917
For a wheel you could make a vector sprite like a star for the spokes and use arc for the rim, then move the rim and move and rotate the spokes for the rotation effect as it rolls. Using PI in there somewhere will make it look more realistic.
Graham
So when defining a sprite you start at 0,0 if you do $8000 + 13bit angle then it will draw a line from 0,0 in that direction. If you did $4000 + 13bit angle then it will draw a point and the next vector will be drawn from there.
After the angle and type is defined the length of the vector.
The example from the demo of a triangle:
All angles are from the horizontal CCW. 0,0 in the sprite is the point that will be positioned at x,y as defined in the command vec.
If you draw your spokes comming out from 0,0 then any rotation will make them rotate around their centre.
Please do some experimentation and do actually read what is in graphics.spin to better understand it.
Graham
p.s. The pointer in my program is a vector sprite.
The angle is stored in 13 bits, this is %1111111111111 or $1FFF
zero represents both 0 degrees and 360 degrees so $1FFF represents just less than 360 and $2000 (which is $1FFF + 1) represents 360 degrees as well numerically but cannot be used because it is more than 13 bits however it can be divided up and used like in this case. The +1, and -1 used are to ensure that the total comes to 180 degrees, the total angle within a triangle accounting for the lack of fractional values I think.
Graham
I've been fooling around a bit, here's what I came up with for some spokes. I converted to 360 degrees to make it easier to read at a cost of resolution for angle.
-Martin
An alternate means to use one line draw at various angles from your loop:
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
StampPlot - GUI and Plotting Software
Southern Illinois University Carbondale, Electronic Systems Technologies
Post Edited (Martin Hebel) : 10/26/2007 2:11:45 AM GMT
What I hinted to was a not very popular creative use of arc, such as:
Post Edited (deSilva) : 10/29/2007 5:17:48 PM GMT
Looks like I need to upgrade my graphics.spin it doesn't even have an arc command.
Graham
But - oops - did I delete the gr.clear as well? Sorry, the gr.clear should have stayed in it... darn on the fly editing of working code.
Graham
Indeed gr.arc(centerX , centerY , length, length, angle*$2000/360 , 0, 1, 3)
is not trivial...