|
Post by zzz000abc on Jan 27, 2019 20:47:09 GMT
open"abc"for graphics as #1 #1 "home;place 100 50;down;turn 90;size 2" #1 "go 100;posxy x y" print "1",x,y y1=y for i=2 to 6 #1 "turn 60;go 100;posxy x y" if i=4 then y2=y if i=2 then x2=x if i=5 then x1=x print i,x,y next xx=(x2+x1)/2:yy=(y2+y1)/2 print "Centre ";xx,yy print "InCircle radius=y2-yy=yy-y1 ";y2-yy print "CircumCircle radius=x2-xx=xx-x1 ";xx-x1 #1 "color red" #1 "place ";xx;" ";yy;";circle ";y2-yy #1 "color blue" #1 "place ";xx;" ";yy;";circle ";x2-xx wait
|
|
|
Post by B+ on Jan 28, 2019 2:24:34 GMT
' Hexagon.txt for JB v2 B+ 2019-01-27 global H$, XMAX, YMAX, PI H$ = "gr" XMAX = 1200 YMAX = 700 PI = acs(-1) nomainwin WindowWidth = XMAX + 8 WindowHeight = YMAX + 32 UpperLeftX = (DisplayWidth - XMAX) / 2 'or delete if XMAX is 1200 or above UpperLeftY = (DisplayHeight - YMAX) / 2 'or delete if YMAX is 700 or above
open "Hexagons any where, any radius" for graphics_nsb_nf as #gr #gr "setfocus" #gr "trapclose quit" #gr "down" #gr "fill black" #gr "size 2" for h = 1 to 5 x = x + rand(150, 250) : y = rand(150, YMAX - 150) : CircumRadius = rand(25, 100) #gr "place ";x;" ";y #gr "color red" #gr "circle ";CircumRadius #gr "color blue" #gr "circle ";CircumRadius * sqr(3)/2 #gr "color white" call hex x, y, CircumRadius next wait
sub quit H$ close #H$ end end sub
function rand(lo, hi) rand = int((hi - lo + 1) * rnd(0)) + lo end function
sub hex x, y, r 'Imagine a pie with center at x, y and radius r. 'From the center, cut it into 6 pieces of equal size, 360 / 6 = 60 degrees and in radians it is 2*PI/6 = PI/3 'Connect the endpoints of each cut crossing over the crust edge, that makes a hexagon!
' 4*pi/3 5*pi/3 ' 240 300 ' \ / ' 3*pi/3 180 -- x,y -- 0 = 360 6*pi/3 ' / \ ' 120 60 ' 2*pi/3 pi/3
'the first cut has an endpoint at 0 degrees or radians x1 = x + r * cos(0) y1 = y + r * sin(0) for i = 1 to 6 'the next end points, 6th takes us back to 6*PI/3 = 2*PI (360 degrees) 'next endpoint, sin and cos use radian units for angles not degrees
'for x's location (around a circle) always use cos function x2 = x + r * cos(i * PI/3) 'calc the endpoint x
'for y's location (around a circle) always use sin function y2 = y + r * sin(i * PI/3) 'calc the endpoint y
#gr "line ";x1;" ";y1;" ";x2;" ";y2 'connect the endpoints x1 = x2 : y1 = y2 'set last endpoint to next endpoint next end sub
|
|