Post by B+ on Nov 23, 2018 17:23:41 GMT
honkytonk:
Well this is a forum dedicated to learning JB so here are some tests attempting to "paint" in code some recent "tips".
"But where is the code for these pretty drawings?"
Well this is a forum dedicated to learning JB so here are some tests attempting to "paint" in code some recent "tips".
'pline test 2018-11-23 B+ p stands for probability or percent fill line
' p = 0 to 1 to compare to RND(0) numbers eg, .5 will be line 50% filled with dots
global H$, XMAX, YMAX, PI
H$ = "gr"
XMAX = 500
YMAX = 500
PI = acs(-1)
nomainwin
WindowWidth = XMAX + 8
WindowHeight = YMAX + 32
UpperLeftX = (DisplayWidth - XMAX) / 2
UpperLeftY = (DisplayHeight - YMAX) / 2
open "Pline Test" for graphics_nsb_nf as #gr
#gr "trapclose quit"
#gr "down"
#gr "color black"
'test pline down the screen p is distance right over max right
call stext 15, 20, "Test pline"
for i = 0 to XMAX
call pline i, 30, i, YMAX, i/XMAX
next
call pause 1000
#gr "fill white"
' good now wave it
call stext 15, 20, "Now Color Wave it."
r = rnd(0) : g = rnd(0)* rnd(0) : b = rnd(0) * rnd(0) * rnd(0)
for i = 0 to XMAX
c = c + .25
#gr "color ";125 + 125 * sin(r * c);" ";125 + 125 * sin(g * c);" ";125 + 125 * sin(b * c)
call pline i, 30, i, YMAX, sin(i/(8*PI))
next
call pause 1000
#gr "fill white"
#gr "color black"
'now in a circle with
cx = XMAX / 2 : cy = YMAX / 2
r1 = 50 : r2 = 200 : stepper = 2*PI/360
for i = 1 to 3
if i = 1 then call stext 15, 20, "12 Rays at 30 Degree Intervals."
if i = 2 then call stext 15, 20, " 4 Rays at 90 Degree Intervals."
if i = 3 then call stext 15, 20, "Overlap 4 Rays and 12 Rays. Hey, might be nice clock face!"
for a = 0 to 2 * PI step stepper
scan
x1 = cx + r1 * cos(a)
y1 = cy + r1 * sin(a)
x2 = cx + r2 * cos(a)
y2 = cy + r2 * sin(a)
if i = 1 or i = 3 then
p = .8 * cos(a * 6 - PI/2) ' 12 rays
call pline x1, y1, x2, y2, p
end if
if i = 2 or i = 3 then
p = .4 * cos(a * 2 - PI/2) ' 4 rays
call pline x1+1, y1+1, x2, y2, p
end if
next
call pause 4000 : #gr "fill white"
next
[TimesUp]
timer 0
#gr "fill blue"
#gr "size 1"
'hey looks like clock face
for a = 0 to 2 * PI step stepper
x1 = cx + r1 * cos(a)
y1 = cy + r1 * sin(a)
x2 = cx + r2 * cos(a)
y2 = cy + r2 * sin(a)
#gr "color cyan"
p = .4 * cos(a * 6 - PI/2) ' 12 rays
call pline x1, y1, x2, y2, p
#gr "color yellow"
p = .4 * cos(a * 2 ) ' 4 rays
call pline x1+1, y1+1, x2, y2, p
next
#gr "color black"
now$ = time$()
call stext 15, 20, mid$(now$, 1, 5)
hours = val(mid$(now$, 1, 2))
mins = val(mid$(now$, 4, 2))
hours = hours + (mins / 60)
if hours > 12 then hours = hours - 12
ha = hours * (2 * PI) / 12
ma = mins * (2 * PI) / 60
#gr "size 4"
#gr "color yellow"
call aline cx, cy, ma, r2
#gr "color cyan"
call aline cx, cy, ha, 2/3 * r2
#gr "flush"
timer 1000 * 60, [TimesUp]
wait
sub pline x1, y1, x2, y2, p
dx = x2 - x1
dy = y2 - y1
d = sqr(dx * dx + dy * dy)
for i = 0 to d
scan
if rnd(0) < abs(p) then #gr "set ";x1 + i/d * dx;" ";y1 + i/d * dy
next
end sub
sub aline x, y, a, d
x1 = x + d * cos(a - PI/2)
y1 = y + d * sin(a - PI/2)
#gr "line ";x;" ";y;" ";x1;" ";y1
end sub
sub stext x, y, message$ 'note: have to reset fore or back color after ink
#gr "place ";x;" ";y;";|";message$
end sub
sub pause mil 'tsh version has scan built-in
t0 = time$("ms")
while time$("ms") < t0 + mil : scan : wend
end sub
sub quit H$
close #H$
end
end sub