PDA

View Full Version : Graphics.spin and other graphics questions

tmshaw
12-08-2009, 06:52 AM
Hello. Here is what I want to do: draw 2 large, filled white circles on the screen. Inside each is a smaller black circle that will move when I tilt the display (it has a built in accelerometer). I can't seem to figure out how to draw circles using graphics.spin...maybe you just can't and that is the answer I will have to be happy with. lol

I see that I can draw a "point" and set it to be sized between 1 and 15, but after 15 it starts doing squares... Where in the code is that determined? Can I change something to make bigger sizes of points?

Also, what if I wanted to draw semi-circles (circle cut in half)?

I see that there are vector definitions down in the "Dat" part of the graphics_demo.spin file. Those are in pasm code? Should I try to do my shapes that way?

Also, I am getting the Hydra Book and CD for Xmas, but until then, are there any tutorials on graphics that anyone knows of?

Bob Lawrence (VE1RLL)
12-08-2009, 10:56 AM
tmshaw said...
Also, I am getting the Hydra Book and CD for Xmas, but until then, are there any tutorials on graphics that anyone knows of?

Try this one from Bamse: Here is an article I wrote to explain how to write a graphics driver in 50 lines of code.

67.104.29.60/forums/default.aspx?m=277812&f=33&p=1 (http://67.104.29.60/forums/default.aspx?m=277812&f=33&p=1)

And his other one:

Multi Cog Tile Driver Tutorial

Post Edited (Bob Lawrence (VE1RLL)) : 12/8/2009 4:02:03 AM GMT

VIRAND
12-08-2009, 04:28 PM
Lets see...
gr.color(1) 'well you pick a color
CX:=128 'center of circle CX,CY
CY:=96
Repeat Y from 0 to R '***add a space before all these next lines:

X:= ^|| ((R*R)-(Y*Y)) ' ^|| is probably wrong, I mean use square root
gr.plot(CX+X,CY+Y) ' filled circle one quadrant
gr.line(CX+X,CY)

gr.line(CX-X,CY)

gr.line(CX-X,CY)
gr.plot(CX+X,CY-Y)
gr.line(CX+X,CY)

To make just the outside of circles, remove the gr.lines. Parts will be missing. These shoud fix it:
gr.plot(CX+Y,CY+X)
gr.plot(CX-Y,CY-X)
gr.plot(CX+Y,CY-X)
gr.plot(CX-Y,CY+X)

Double check my square root sign, which I really think is the wrong one.

I hope this math is correct, which I've used often before.
I tend to make dumb mistakes in code that I can't run now; if so, maybe you can get the general idea and fix them.
It uses pythgorean theorem which is simpler than a sine and cosine method.
You can make half circles by skipping some quadrant lines.
Also, sorry, but this is not a complete program, only what you need to make big circles.
You also need to define the var x,y,cx,cy,r and what another program uses to start GRAPHICS and TV objects.

Post Edited (VIRAND) : 12/8/2009 9:58:50 AM GMT

Beau Schwabe
12-09-2009, 12:37 AM
Your making this much more complex than it needs to be...

x := 0 'X center
y := 0 'Y center
c := 2 'circle Color
Fill := 1 '0 - don't Fill ; 1 - Fill

StartAngle := Angle(45)
StopAngle := Angle(270)

gr.color(c)
gr.arc(x, y, r, r, StartAngle, 1, StopAngle - StartAngle, Fill * 3)

PUB Angle(N) 'Helps make 13-bit angle conversion more human readable
Result := (N * 1024) / 45

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe (mailto:bschwabe@parallax.com)

IC Layout Engineer
Parallax, Inc.

Post Edited (Beau Schwabe (Parallax)) : 12/8/2009 5:48:27 PM GMT

tmshaw
12-09-2009, 05:49 AM
Awesome! You guys are the best!
I am now making circles like nobody's business!

One other quick question:
Where is the color of the background screen defined? So that I could change it to something other than black?

Beau Schwabe
12-09-2009, 12:51 PM
tmshaw.

Towards the beginning of the main PUB routine, you will see where the colors are defined ... The value set for 'Color 0' is the background color.

'init colors
repeat i from 0 to 63
colors[*i] := \$BB_07_1C_02
{
Color 3
| Color 2
| | Color 1
| | | Color 0
| | | |
colors[*i] := \$BB_06_1C_BB
}

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe (mailto:bschwabe@parallax.com)

IC Layout Engineer
Parallax, Inc.

Post Edited (Beau Schwabe (Parallax)) : 12/9/2009 5:56:11 AM GMT

tmshaw
12-09-2009, 02:02 PM
Thanks Beau. You are the King of Information. I am reading up on the various threads and links given here and de-silva's asm tutorials. Hopefully, I will have not so many questions from here on out. :)