|
- Forum - iziBasic
Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 257
Topic # 1413 |
Filled-In Triangles |
21/05/2006 @ 10:14 by Garfield
|
Hi
I want to draw filled-in triangles and I can't work out how to do it.
I can obviously draw outlined triangles using three LINETO statements, but how do you get a filled-in triangle?
I'm sure once you tell me I'll kick myself, but right now I'm at a loss.
Thanks.
|
|
|
Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Answer n° 1 -------- 21/05/2006 @ 16:56 by Ktimaster
visitor |
You may want to concider putting this into a .rsrc file... That is if you dont intend to draw it programatically |
|
|
Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Answer n° 2 -------- 21/05/2006 @ 17:04 by Garfield
visitor |
I do actually want to draw them programmatically.
In fact, triangles are the building blocks of just about any shape. If you can draw triangles you can draw anything - squares, pentagons, stars, even circles!
BBC Basic (this goes back some time now) used to have a command for drawing triangles for this very reason. It didn't have a command for drawing squares as you would simply draw two triangles, and there was nothing that couldn't be drawn.
Does anyone have a routine that draws a filled-in triangle? Perhaps it's something worth including in a future version of iziBasic?
Thanks.
|
|
|
Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Answer n° 3 -------- 21/05/2006 @ 17:13 by bh77a
visitor |
I have thought about this in the past but haven't tried anything yet.
If you are needing them to draw circles, you can find some sample routines for the midpoint circle algorithm and ellipses a few posts down the forum.
Have you considered looking at the Palm API to see if there might be something that could be rolled into a PP applet? |
|
|
Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Answer n° 4 -------- 21/05/2006 @ 17:18 by Ktimaster
visitor |
Well I do have a Theory and it should work,
Rather then using 3 Line Statements you could use Just 1!!!
Line statements can be Stacked on top of each other I am putting this in RAW form and you can design a loop to build this as a function in your Programs.(With Just 1 Line Statement) Upside Down Triangle LINE 50,50 to 100,50 LINE 51,51 to 99,51 LINE 52,52 to 98,52 LINE 53,53 to 97,53
etc... Normal Triangle LINE 50,50 to 100,50 Line 49,49 to 99,49 (I would type the code but I am away from home)
|
|
|
Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Answer n° 5 -------- 21/05/2006 @ 17:35 by bh77a
visitor |
Alternatively, you could try... ...
X=50:Y=20:A=20:B=70:C=70:D=70
LINE X,Y TO A,B LINE A,B TO C,D LINE C,D TO X,Y
WHILE A <= C LINE X,Y TO A,B A=A+1 WEND
...
This seems to draw a small triangle quicly. If you wanted to speed it up for a larger triangle, you could try reversing the fill process to meet it in the middle...
... WHILE C >= A LINE X,Y TO C,D C=C-1 WEND ...
Hope this helps... |
|
|
Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Answer n° 6 -------- 21/05/2006 @ 17:37 by Garfield
visitor |
OK, I see how you can use single lines to build a triangle. This is good if, again, you know what triangle you want to draw.
The only problem is, what if you're simply given three random coordinates? How do you calculate the horizontal (or vertical) lines that need to be drawn to create that triangle?
|
|
|
Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Answer n° 7 -------- 21/05/2006 @ 17:46 by bh77a
visitor |
Hi Garfield,
Check out answer #5 right before your last post. It should work with any coordinates you throw at it. :)
bh77a |
|
|
Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Answer n° 8 -------- 21/05/2006 @ 18:12 by Ktimaster
visitor |
Nicely done bh77a That is exactly what I was thinking |
|
|
Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Answer n° 9 -------- 21/05/2006 @ 21:32 by Garfield
visitor |
I may have got it wrong, but from what I can see the code in answer #5 only works if B=D.
Take the following:
X=20 : Y=20 : A=40 : B=70 : C=70 : D=40
Your code won't work with these figures.
Will it?
|
|
|
Warning: A non-numeric value encountered in /web5/aldweb/www/aldweb_com/www/thread.php on line 497
Answer n° 10 -------- 21/05/2006 @ 21:59 by bh77a
visitor |
You are correct, my example will only work with one side being either horizontal or vertical. I see the need for a flood fill function here...
Anyways, I will look into it a bit more and see what I can come up with. Be sure to share with us if you find the solution. |
|
|
topic active
topic closed
Sticky
New message -
Correct message
Close topic
Make sticky
|
|