basicprogramming.org


Welcome, Guest. Please login or register.
Did you miss your activation email?
Forum time; Jul 31. 2010, 04:51
Home Help Search Calendar Login Register
News: Have you got suggestions for BasicProgramming.org? Let's hear them!
Interested in creating your own programming language? Check out the QDepartment group!

+  BASIC programming forum
|-+  Basic Coding
| |-+  General Basic Programming
| | |-+  Mission of the Month (February)
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: 1 [2] Go Down Reply Print
Author Topic: Mission of the Month (February)  (Read 827 times)
Derek
Administrator
Hero Member
*****
Online Online

Posts: 1001



WWW
« Reply #15 on: Feb 14. 2008, 13:13 » Reply with quote

Hi,

Code:
#!/usr/bin/yabasic2008
// Windows users:
// remove the "draw" commands, remove the "fullscreen" tag from the "open window" command and change the size of the graphic window to suit the screen resolution.
gosub init
GetRandomPoint()
GetMidPointOfLine()
dot MidPoint(1), MidPoint(2)
draw
do
// GetRandomPoint()
RandomPoint(1) = MidPoint(1) // Make the start of the new line be the old mid point
RandomPoint(2) = MidPoint(2)
// pick a random vertex
Vertex = int(ran(3)) + 1
// find length of line from the point to the vertex
// Length = FindLength()
// ^Not needed^
// find middle of the line
GetMidPointOfLine()
// draw dot at the mid point
dot MidPoint(1), MidPoint(2)
draw
loop
end
label init
clear screen
print "Sierpinski's Triangle (kind of...)\n------------ --------\n\nWhen the graphic window appears click anywhere within it to mark the three      vertices.\n\nPress any key to continue."
repeat
until(inkey$ <> "")
open window 100, 100, fullscreen
// vertex positions
dim Vertices(3, 2)
for n = 1 to 3
repeat
key$ = inkey$(.1)
if left$(key$, 4) = "MB1u" print key$
until(left$(key$, 4) = "MB1u")
Vertices(n, 1) = mousex(key$)
Vertices(n, 2) = mousey(key$)
beep
next n
// triangle vertices(1, 1), vertices(1, 2), vertices(2, 1), vertices(2, 2), vertices(3, 1), vertices(3, 2)
// draw
dim RandomPoint(2)
dim MidPoint(2)
return

sub GetRandomPoint()
local ran1, ran2, ran3
repeat
ran1 = ran()
ran2 = ran()
until(ran1 + ran2 < 1)
ran3 = 1 - (ran1 + ran2)
RandomPoint(1) = int((Vertices(1, 1) * ran1) + (Vertices(2, 1) * ran2) + (Vertices(3, 1) * ran3))
RandomPoint(2) = int((Vertices(1, 2) * ran1) + (Vertices(2, 2) * ran2) + (Vertices(3, 2) * ran3))
end sub

sub FindLength()
local dx, dy
// sqrt((x2-x1)^2) + ((y2-y1)^2)
dx = abs(RandomPoint(1) - Vertices(Vertex, 1)) ^ 2
dy = abs(RandomPoint(2) - Vertices(Vertex, 2)) ^ 2
return sqrt(abs(dx - dy))
end sub

sub GetMidPointOfLine()
local SmallX, SmallY, x1, x2, y1, y2
x1 = RandomPoint(1)
x2 = Vertices(Vertex, 1)
y1 = RandomPoint(2)
y2 = Vertices(Vertex, 2)
SmallX = min(x1, x2)
SmallY = min(y1, y2)
MidPoint(1) = (abs(x1 - x2) / 2) + SmallX
MidPoint(2) = (abs(y1 - y2) / 2) + SmallY
end sub
Derek.
Report to moderator   Logged

wget http://*
PetrSchreiber
Full Member
***
Offline Offline

Posts: 100


WWW
« Reply #16 on: Feb 14. 2008, 14:39 » Reply with quote

Hi Derek,

tested on Windows, works great ( the program, Windows not necessairly but in last time also nicely Smiley ).
Good idea with 3 point "definition"!

PSnake, worked nicely for 6 steps, thanks.


Petr
Report to moderator   Logged

Pages: 1 [2] Go Up Reply Print 
« previous next »
Jump to:  
Atom RDF RSS 0.91 RSS 2.0


Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2008, Simple Machines LLC Valid XHTML 1.0! Valid CSS!