Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Challenge: Triangle Function
#11
Its still a 2d triangle. Just in a 3D environment.

A triangle can have no more than 2 dimensions. Thus it is 2D. Foo!
Reply
#12
true it's surface is planar. so is the surface of the world to a certain precision level ( of course it is a curved planar surface ). d'oh?
quote="NecrosIhsan"]
[Image: yagl1.png]
[/quote]
Reply
#13
Quote:
Code:
sub EqTri (x as integer, y as integer, s as integer)
    line (x,y-s*sqr(3)/2)-(x-s,y+s*sqr(3)/2)
    line (x,y-s*sqr(3)/2)-(x+s,y+s*sqr(3)/2)
    line (x-s,y+s*sqr(3)/2)-(x+s,y+s*sqr(3)/2)
end sub
screenres 640,480,32
EqTri(320,240,100)
sleep

Why not
Code:
sub EqTri (x as integer, y as integer, s as integer)
    line (x,y-s*sqr(3)/2)-(x-s,y+s*sqr(3)/2)
    line -(x+s,y+s*sqr(3)/2)
    line -(x,y-s*sqr(3)/2)
end sub
screenres 640,480,32
EqTri(320,240,100)
sleep

Or, even better
Code:
sub EqTri (x as integer, y as integer, s as integer)
    t=s*sqr(3)/2
    line (x,y-t)-(x-s,y+t)
    line -(x+s,y+t)
    line -(x,y-t)
end sub
screenres 640,480,32
EqTri(320,240,100)
sleep
Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
Reply
#14
Quote:
Code:
DECLARE SUB triangle (x!, y!, size!, angle!, c!)
'I assure you the triangles are equalateral. Your screen is just warped.

defsng a-z
SCREEN 13

FOR i = 10 TO 255
  w = 0
  FOR j = i - 10 TO i
    OUT 968, j
    OUT 969, w
    OUT 969, w
    OUT 969, w
    w = w + 6.3
  NEXT
  x = SIN(i / 35) * 50 + 160
  y = SIN(i / 25) * 50 + 100
  triangle x, y, SIN(i / 100) * 50 + 10, i * 10, i
  t = TIMER
  DO: LOOP WHILE TIMER - t < .05
NEXT

SLEEP

SUB triangle (xoff, yoff, size, angle, c)
  DIM x(2), y(2)
  FOR i = 0 TO 2
     x(i) = COS((i * 120 + angle) * 3.14159 / 180) * size + xoff
     y(i) = SIN((i * 120 + angle) * 3.14159 / 180) * size + yoff
  NEXT
  FOR i = 0 TO 2
    LINE (x(i), y(i))-(x((i + 1) MOD 3), y((i + 1) MOD 3)), c
  NEXT
END SUB

I still like this one the most, the angle feature is the best. As well as it supports color. Big Grin
Reply
#15
Hey, I made a weirdo! :lol:


Code:
Screen 12

Type Vector2D
    As Single X,Y
End Type

Dim As Vector2D P1=>(50,50),P2=>(150,150),P3=>(50,150)

For y=0 to 479
    For x=0 to 639
        
        If ((P2.X - X) * (P3.Y - Y) - (P3.X - X) * (P2.Y - Y)) / (P2.X - P1.X) * (P3.Y - P1.Y) - (P3.X - P1.X) * (P2.Y - P1.Y)>0 And _
           ((P3.X - X) * (P1.Y - Y) - (P1.X - X) * (P3.Y - Y)) / (P2.X - P1.X) * (P3.Y - P1.Y) - (P3.X - P1.X) * (P2.Y - P1.Y)>0 And _
           ((P1.X - X) * (P2.Y - Y) - (P2.X - X) * (P1.Y - Y)) / (P2.X - P1.X) * (P3.Y - P1.Y) - (P3.X - P1.X) * (P2.Y - P1.Y)>0 Then
           Pset(X,Y),14
        End If
        
    Next
Next

Sleep
Reply
#16
I thought the contest was for a function. :o
stylin:
Reply
#17
blah... It was supposed to make an equilateral triangle too. Confusedhifty:
Reply
#18
Quote:
Deleter Wrote:[my code]

Why not
[better code]

Or, even better
[even better code]

Because I didn't feel like optimizing it, ntm I had never known of that way of doing gfx. I consider myself one step more experienced now :wink:
[Image: freebasic.png]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)