Using Graphics.spin
James Long
Posts: 1,181
Ok....I have to admit...I'm a little lost.
First let me explain what I'm trying to do.....then·maybe someone·can·help decide the best way to proceed.
I'm drawing things graphically on a screen. The screen is of equal porportion.(the pixels are of equal size)
I want to draw lines or small pie shaped peices around the inside of a circle. I do not want them to be drawn from the center...but start at a predetermined point from the center.· These will represent a dial type gauge.
I have tried several different methods to draw these...but my efforts have always ended up with a diagonal ellipse shape. I know it is my math....so you don't have to inform me of that.
I would like to use the graphics.spin or possibly a cordic to get the inner and outer starting/stopping point.
Anyone is welcome to help....I have seen some really neat thing with the propeller....but I really suck at graphics....at least so far.
I have looked at the graphics.spin....but I'm a little lost with the variables and instructions. I must be getting old.....it is getting harder to learn things, and I'm not joking. The light is just not coming on.
Thanks,
James L
First let me explain what I'm trying to do.....then·maybe someone·can·help decide the best way to proceed.
I'm drawing things graphically on a screen. The screen is of equal porportion.(the pixels are of equal size)
I want to draw lines or small pie shaped peices around the inside of a circle. I do not want them to be drawn from the center...but start at a predetermined point from the center.· These will represent a dial type gauge.
I have tried several different methods to draw these...but my efforts have always ended up with a diagonal ellipse shape. I know it is my math....so you don't have to inform me of that.
I would like to use the graphics.spin or possibly a cordic to get the inner and outer starting/stopping point.
Anyone is welcome to help....I have seen some really neat thing with the propeller....but I really suck at graphics....at least so far.
I have looked at the graphics.spin....but I'm a little lost with the variables and instructions. I must be getting old.....it is getting harder to learn things, and I'm not joking. The light is just not coming on.
Thanks,
James L
Comments
I would like to use the generic graphics.spin code included with the propeller....but I have no idea how to even start.
The code has very few notes.
James L
In general say you wanted to plot the points of a circle of radius R, located with center (x0, y0) you can always connect the dots later, and do this much faster, but the general idea is:
For angle = 0 to 360 step 10
x = R * cos ( angle )
y = R * sin ( angle )
plot ( x + x0, y + y0)
next angle
This pseudo code would draw 36 points around the center (x0, y0), but there are about 100 details about this that we need to address.
1. Where is the center of the screen? Usually 99.99% of the time its (0,0) and located at the TOP-LEFT corner NOT in the center of the screen.
2. What kind of coordinates are the screen and how does the plot function work? In most cases, the screen is an INTEGER matrix, and either Quadrant I or inverted Y Quadrant I (most common), thus Y increases downward NOT upward like a normal cartesian Quadrant I. And since the screen is integer the plot function usually truncates your coordinates... this is not good, thus before passing them into the function you might want to add (0.5) to round them, which gives better looking graphics OR write your OWN plot function that draws a cluster of pixels based on your desired pixels real center.
3. What's the aspect ratio of the screen?
So when you take all these things into consideration, then you will need a y-axis inversion, a translation to the "screen center" if you want the center of the screen to be (0,0) and not the top left corner, plus a x or y axis aspect ratio multiplier, and so forth. Its may seem complicated, but its all a series of steps to transform your desired image in mathematical space to an image in screen space. For example, the parallax drivers allow you to set the origin and to work with a quadrant I system rather than inverted. This is nice for rendering simple graphics, so you don't have to do the extra step yourself.
Andre'
·
I think I understand what you want. Try this code below and see if it is on the right track.
Basically you provide two radii, using the 'arc' function with modes '0' and '1' you can draw
from one radius point to the next radius point and step the Degree at what ever you desire.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Post Edited (Beau Schwabe (Parallax)) : 1/4/2007 5:17:37 AM GMT
There is no "how to" when it comes to graphics, there are a billion ways to do anything, so you have to be VERY specific for what you want, seems you just need to see some examples. So if you can I would suggest the book since it has dozens of them that show these exact things you are stuck on.
Andre'
Thanks....you do have a vast amount of knowledge that helps us unknowing get to where we are going.
Hey!...I rhymed..
No really. Beau ..I'll try that...and I think that is what I'm looking for by what I read in the code. This is not for a TV....but I think I can take the code....and decipher from there.
AndreL
I want to buy your book, I know it will come in handy. I guess I'll spring for it. Thanks for putting out a good starting point for us graphically challenged.
James L
Here is an alternative method that will accomplish the same task that does not use the 'arc' command. This would be useful if you wanted raw X/Y values to "send" to something
other than a TV as you suggest that you are doing.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Post Edited (Beau Schwabe (Parallax)) : 1/4/2007 5:28:21 AM GMT
I have a question about the last post.
This forumla has me somewhat confused.
Where does the 65535 come from?· I mean I know it is a value needed for the calculation......but I'm lost as to it's significance.
I'm intruiged by it ......
But thanks ...that is exactly what I was looking for. I have tried to figure out that formula for a week.....and could never get my expected result.
Edit:There is something else I notice......you use no external math object for any of this.
Wow....I'm just a real newbie I guess. That is unbelievable. I have much to learn. I feel little......[noparse]:)[/noparse]
Man...Parallax is great.......they are the bomb.
James L
Post Edited (James Long) : 1/4/2007 2:39:17 PM GMT
·
The formula...
x1 := X + (Cos(DEG2PROP(Deg))*R1)/65535
...Is basically what Andre was describing, except he is adding an offset when he·plots the points...
x = R * cos ( angle )
...I have included an offset in the·formula before any points are plotted...
x1 = x + cos ( angle ) * R
where:
"x" is the offset
"R" is the radius
"x1" is the computed location of X
If you look at "DEG2PROP(Deg)", this basically converts a Deg value (0-360) into a 13-bit angle used by the Propeller (0-8191)
Think of it as multiplying your degree value by 22.7555
Now look at "Cos(DEG2PROP(Deg))", the Sin and Cos function take a 13-bit angle value and convert it into a 16-Bit signed Sin or Cos value.
Remember a Sin or Cos value can only range from 1 to -1, with 16-bit resolution the Propeller returns a value from 65535 to -65535.
This is where the divide by 65535 comes in, but first we want to multiply the Sin or Cos value by the Radius before we divide. Doing so
gives us the best integer resolution for the final X or Y value.
"There is something else I notice......you use no external math object for any of this. Wow....I'm just a real newbie I guess. That is unbelievable."
That is because the Propeller has a pre-calculated (11-bit ) 1/4 Sin table already built-in, all you need to do in this circumstance is to look up the value.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Post Edited (Beau Schwabe (Parallax)) : 1/4/2007 4:49:22 PM GMT
You wouldn't believe how many lines of code that you saved. Also not having to do a sin or cos call to a different object.
I'm still extremely grateful.
James L
Glad that helped
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Could I ask.....is the result of the formula a whole number???
James L
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
What would be the proper way to include the sine table without including the whole graphics object.
The graphics object would be overkill....now that you instructed me the proper way to do the task.
Thanks,
James L
Without the graphics driver, this is all you need to obtain Sine and Cosine from a Degree value...·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
What is the Minimum code to use the "TV" and "Graphics" objects. I get a little confused on what is manditory to use the code and what is required to setup and run the objects.
Can someone help?
·
Well....something is causing problems.
The LCD display I'm using is a real pain to dispay on....it takes a huge amout of serial communication to display just a line.
But thanks....I'll keep hammering on...to see if I can find the problem......
Edit: Could I use the following......:
·x1 := || 41 + (Sin(DEG2PROP(deg))* 245)/65535
·y1 := || 136 + (Cos(DEG2PROP(deg))* 245)/65535
This would give me an absolute value....that should be available as x1[noparse][[/noparse]1] and such.
I have to send everyting in byte form.....
James L
Post Edited (James Long) : 1/5/2007 5:29:11 PM GMT
Much of what I outlined for James, is all that is necessary.....
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Post Edited (Beau Schwabe (Parallax)) : 1/5/2007 6:50:45 PM GMT
By adding 41, 136, or whatever, you are introducing an offset to either the X or the Y location. If this gets you out of the negative, then that's fine.
It all depends on what you want to do with your data.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
OK, so that is the basic outline for using graphics.. Thanks for your help.
Regards,
Eric
It was the absolute part I was asking about. The display I'm using doesn't seen to like signed integers. Although I found a major syntax error on my part.
x1[noparse][[/noparse]0] should have been x1.byte[noparse][[/noparse]0] etc.
I haven't tested with signed integers since I found the error....I've been taking a break......letting the bleading forehead scab over. Also thinking about a replacement keyboard. [noparse]:)[/noparse]
James L
I thought I would give an update.....I have found the secret......but thanks for all the help. There was more to my problem than I first realised.
Your formula works to the "T"......but I've encountered an interesting side effect.
Here is my code snipette:
·repeat deg from 110 to 70 step 10
··· x1 :=·· 41 + (Sin(DEG2PROP(deg))* R1)/65535
··· y1 :=· 132 + (Cos(DEG2PROP(deg))* R1)/65535
··· serial.tx(Set_xhy)
··· serial.tx(x1.byte[noparse][[/noparse]1])
··· serial.tx(x1.byte[noparse][[/noparse]0])
··· serial.tx(y1.byte[noparse][[/noparse]0])
··· serial.tx(print_string)
··· serial.str(num.tostr(deg, Num#DEC))
··· serial.tx(0)··
Here is what is wierd....the numbers written in the arc are backwards. I've tried to change the direction....but I can't.....it is quite funny. No matter what I do the 110 is where the 70 is to go.....
But thanks for the graphics 101 lesson......I promise I'll repay the effort somehow.
James L
Curious... Where is "Zero" Deg?· Far left or far right?
For your serial string output, try this to flip the result you are seeing.....
··· serial.str(num.tostr(180-deg, Num#DEC))
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Post Edited (Beau Schwabe (Parallax)) : 1/6/2007 3:28:02 AM GMT
Actually it is far left. But....I must say but ...I'm using the screen on it's side. I know...what a wierd thing.
I'll post a picture. when I get time.
James L
I'm building a gps tracking project and with just the bare minimum in graphics.spin, if I throw in a fullserialduplex and some (not much) gps parsing code, I run out of memory. I would like to use a composite video ready lcd but i don't see how.
any suggestions on how to get even a more bare minimum graphics.spin? reduce color depth?
thanks.
Most of the memory requirements are for the graphics bitmap... you could reduce the size somewhat by manually removing any graphics commands that you are not using in your application and likewise to the fullserialduplex object. I'm sure there are other options that I have not investigated that might provide a solution. I think Dennis Ferron recently figured out how to implement raster-based graphics rather than tile-based graphics. Using that method might give you the additional memory you are looking for.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.