Graphics.spin and other graphics questions
tmshaw
Posts: 14
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?
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?
Comments
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
And his other one:
Multi Cog Tile Driver Tutorial
http://forums.parallax.com/showthread.php?p=746260
Post Edited (Bob Lawrence (VE1RLL)) : 12/8/2009 4:02:03 AM GMT
gr.color(1) 'well you pick a color
CX:=128 'center of circle CX,CY
CY:=96
R:= 90 'radius 90
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.plot(CX-X,CY-Y) 'filled circle, opposite quadrant
gr.line(CX-X,CY)
gr.plot(CX-X,CY+Y) 'filled circle, remaining quadrants
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
IC Layout Engineer
Parallax, Inc.
Post Edited (Beau Schwabe (Parallax)) : 12/8/2009 5:48:27 PM GMT
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?
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.
See if this link helps.... http://forums.parallax.com/showthread.php?p=849087
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Post Edited (Beau Schwabe (Parallax)) : 12/9/2009 5:56:11 AM GMT