SyntaxBomb - Indie Coders

Languages & Coding => SmallBASIC => Topic started by: bplus on February 26, 2020, 19:20:37

Title: Diagonal Eggs
Post by: bplus on February 26, 2020, 19:20:37

'copy from round157 2020-02-26 Syntax Bomb,
' https://www.syntaxbomb.com/index.php/topic,6677.msg347040125.html#msg347040125
' BASIC-256 trans to SmallBASIC b+ 2020-02-26

const w = 530: const h = 870
wh = window()
wh.setsize (w, h)
cls
k1 = .25 * h : k2 = .5 * h : k3 = .75 * h
j = .25 * w
y2 = k1 : y3 = k2 : y4 = k3
for x1 = 0 to w
  x2 = j
  for y1 = 0 to h
    x2 = x2 + .5
    x12 = (x1 - x2)^2
    y12 = (y1 - y2)^2
    y13 = (y1 - y3)^2
    y14 = (y1 - y4)^2
    xy1 = (x12 + y12)^.5
    xy2 = (x12 + y13)^.5
    xy3 = (x12 + y14)^.5
    r = xy1 % 255
    g = xy2 % 255
    b = xy3 % 255
    pset x1, y1, rgb(r, g, b)
  next
  showpage
next

Title: Re: Diagonal Eggs
Post by: bplus on February 26, 2020, 19:43:33
Aurel:
QuoteYes it is not very smart always share your code.

Yeah so code can sit and stagnate :P

Here is Diagonal Eggs on the move horizontally:

'copy from round157 2020-02-26 Syntax Bomb,
' https://www.syntaxbomb.com/index.php/topic,6677.msg347040125.html#msg347040125
' BASIC-256 trans to SmallBASIC b+ 2020-02-26
' from Diagonal Eggs, let's see if we can do something with it?
' Diagonal Eggs 2.bas b+ 2020-02-26
' Yes, Diagonal Eggs On The Move Horizontally

const w = 500: const h = 500
wh = window()
wh.setsize (w, h)
cls
k1 = .25 * h : k2 = .5 * h : k3 = .75 * h
j = .25 * w
y2 = k1 : y3 = k2 : y4 = k3
dx = 1
while 1
  cls
  for x1 = a to w + a
    x2 = j
    for y1 = 0 to h
      x2 = x2 + .5
      x12 = (x1 - x2)^2
      y12 = (y1 - y2)^2
      y13 = (y1 - y3)^2
      y14 = (y1 - y4)^2
      xy1 = (x12 + y12)^.5
      xy2 = (x12 + y13)^.5
      xy3 = (x12 + y14)^.5
      r = xy1 % 255
      g = xy2 % 255
      b = xy3 % 255
      pset x1 - a, y1, rgb(r, g, b)
    next
  next
  print a
  showpage
  a = a + 5 * dx
  IF a >= 500 OR a <= -500 THEN dx = -dx
wend   


EDIT: Translating to QB64 showed some errors in SB code I had, moving diagonally was creating hole.
Title: Re: Diagonal Eggs
Post by: Aurel [banned] on February 27, 2020, 07:17:36
He he...
I don't talk about our graphic examples Mark
i have one guy on my old forum who selling some kind of lottery programs.
He don't want to share his code with me..
Title: Re: Diagonal Eggs
Post by: round157 on February 27, 2020, 10:29:14
Quote from: bplus on February 26, 2020, 19:20:37


Ha....the program was not written by me.

I only used the screenshot on this webpage:
https://imaginary.org/fr/users/joel-kahn
Title: Re: Diagonal Eggs
Post by: bplus on February 27, 2020, 14:49:16
Quote from: round157 on February 27, 2020, 10:29:14
Quote from: bplus on February 26, 2020, 19:20:37


Ha....the program was not written by me.

I only used the screenshot on this webpage:
https://imaginary.org/fr/users/joel-kahn

I knew that (I was just referencing the source I was translating from), I am getting impression neither you nor Aurel write code anymore, resting on our laurels are we?

I believe the secret to quality is quantity, I mean even the worst coder has got to get lucky sometime. ;-)) If they keep at it that is; and don't get cold and stiff from spending their days chatting about code.

I liked the coloring in this code and hoped to get some insight and make it be more dynamic. I was also hoping to show on QB64 how fast it runs but it's only about twice as fast, dang! it pauses between screens also. But in QB64 I can take a whole different graphics approach for more dynamic eggs, in SB too I guess.

You guys want to give it a shot? Get the ellipsis to move, resize, change color, change tilts,... actually make them egg shaped!

Well alittle bit of chat can be motivating. Looking forward to seeing your SmallBASIC code, bye!
Title: Re: Diagonal Eggs
Post by: Aurel [banned] on February 28, 2020, 06:42:49
QuoteI am getting impression neither you nor Aurel write code anymore, resting on our laurels are we?

Well, i don't for round157 but i am busy with one GUI program in OxygenBasic and with few new function for my new
innterpreter.
But is you insist i can make something in SB  ;)
Title: Re: Diagonal Eggs
Post by: round157 on February 28, 2020, 08:53:56
Quote from: bplus on February 27, 2020, 14:49:16

Well alittle bit of chat can be motivating.

Actually, Blitz3D and BlitzMax were installed on my hard disk. In fact, I also owned AppGameKit. But really busy in real life. Nowadays you can treat me as a read-only visitor of this forum.


Title: Re: Diagonal Eggs
Post by: bplus on February 28, 2020, 16:05:21
QuoteBut really busy in real life.

Yeah, I know life can be a handful or a dozen.
Title: Re: Diagonal Eggs
Post by: bplus on February 28, 2020, 16:15:12
Man what is wrong with these eggs?

Update: Besides the s-l-o-w way I am drawing them to skip the heavy math:
'Dinosaur Eggs.bas for SmallBASIC v0.12.13

def rand(lo, hi) = (rnd * (hi - lo + 1)) \ 1 + lo
def rdir = iff(rnd < .5, -1, 1)

nEggs = 5
DIM e(nEggs - 1)
FOR i = 0 TO nEggs - 1
  e(i).x1 = rand(0, xmax)
  e(i).dx1 = rand(1, 5)
  e(i).ddx1 = rdir
  e(i).y1 = rand(0, ymax)
  e(i).dy1 = rand(1, 5)
  e(i).ddy1 = rdir
  e(i).r1 = rand(50, 100)
  e(i).red1 = 225
  e(i).grn1 = 225
  e(i).blu1 = 225
  e(i).d = .9  * e(i).r1
  e(i).a = rnd * pi * 2
  e(i).da = rnd * pi / 12 - pi / 24
  e(i).x2 = e(i).x1 + e(i).d * cos(e(i).a)
  e(i).y2 = e(i).y1 + e(i).d * sin(e(i).a)
  e(i).r2 = .3 * e(i).r1
  e(i).red2 = rand(100, 180)
  e(i).grn2 = rand(100, 180)
  e(i).blu2 = rand(100, 180)
next

while 1
  cls
  for i = 0 to nEggs - 1
    drawEgg e(i).x1, e(i).y1, e(i).r1, e(i).x2, e(i).y2, e(i).r2, e(i).red1, e(i).grn1, e(i).blu1, e(i).red2, e(i).grn2, e(i).blu2
    e(i).x1 = e(i).x1 + e(i).dx1 * e(i).ddx1
    if e(i).x1 < 0 or e(i).x1 > xmax then
      e(i).ddx1 = e(i).ddx1 * -1
      if e(i).x1 < 0 then e(i).x1 = 0
      if e(i).x1 > xmax then e(i).x1 = xmax
    end if
    e(i).y1 = e(i).y1 + e(i).dy1 * e(i).ddy1
    if e(i).y1 < 0 or e(i).y1 > ymax then
      e(i).ddy1 = e(i).ddy1 * -1
      if e(i).y1 < 0 then e(i).y1 = 0
      if e(i).y1 > ymax then e(i).y1 = ymax
    end if
    e(i).a = e(i).a + e(i).da
    e(i).x2 = e(i).x1 + e(i).d * cos(e(i).a)
    e(i).y2 = e(i).y1 + e(i).d * sin(e(i).a)   
  next
  showpage
wend

sub drawEgg(x1, y1, r1, x2, y2, r2, red1, grn1, blu1, red2, grn2, blu2)
  'yeah allot of redundancy but beats trying to figure out the math
  local dx, dy, dist, maxr, fr1, fr2, r, cr1, cr2
  dx = x2 - x1
  dy = y2 - y1
  dist = sqr(dx * dx + dy * dy)
  if dist > 0 then
    dx = dx / dist
    dy = dy / dist
  else
    dx = 0 : dy = 0
  end if
  if r1 >= r2 then maxr = r1 else maxr = r2
  fr1 = r1 / maxr : fr2 = r2 / maxr
  for r = maxr to 0 step -1
    midInk red1, grn1, blu1, red2, grn2, blu2, r / maxr
    cr1 = fr1 * r : cr2 = fr2 * r
    dr = (cr1 - cr2) / dist
    for d = 0 to dist
      circle x1 + d * dx, y1 + d * dy, cr1 + d * dr filled
    next
  next
end

sub midInk(r1, g1, b1, r2, g2, b2, fr)
  color rgb(r1+(r2-r1)*fr, g1+(g2-g1)*fr, b1+(b2-b1)*fr)
end

Title: Re: Diagonal Eggs
Post by: Aurel [banned] on February 28, 2020, 16:19:58
WOW
my chicken don't have such a colorful eggs  :D
when i say that i work on something ,here is ...
Title: Re: Diagonal Eggs
Post by: bplus on February 28, 2020, 17:10:14
Must be pretty far along for loading images into buttons.
Title: Re: Diagonal Eggs
Post by: Aurel [banned] on February 28, 2020, 19:01:28
Heh..yes  :D
No is not ,but that is just what you see on given image ,you don't see source code
and i can bet with you that you maybe will understand about 50% of code only.
GUI programming is very different than what you doing in basic-s.

by the way ..what is my goal with this , i would try to build simple code editor without need for
external sxintilla control in a scilexer.dll.
On this i have in plan to put whole my new interpreter into one exe.
Title: Re: Diagonal Eggs
Post by: round157 on February 29, 2020, 01:40:48
Quote from: Aurel on February 28, 2020, 19:01:28
On this i have in plan to put whole my new interpreter into one exe.

You are developing an interpreter of a language? I am curious. What will be the name of this programming language?
Title: Re: Diagonal Eggs
Post by: Aurel [banned] on February 29, 2020, 07:06:57
heh currently is micro(A)
Title: Re: Diagonal Eggs
Post by: round157 on February 29, 2020, 12:28:28
Quote from: Aurel on February 29, 2020, 07:06:57
heh currently is micro(A)

Nice project!
Title: Re: Diagonal Eggs
Post by: Aurel [banned] on March 03, 2020, 20:53:31
I hope that would be...

@something for Bplus
Mark do you see how is removed my honest reply to STATIC ignorant reply to
my WOW..that one is a nice
please... one more reason to me not use that forum, i mean to not post anything there.
Title: Re: Diagonal Eggs
Post by: bplus on March 03, 2020, 23:03:24
Quote from: Aurel on March 03, 2020, 20:53:31
I hope that would be...

@something for Bplus
Mark do you see how is removed my honest reply to STATIC ignorant reply to
my WOW..that one is a nice
please... one more reason to me not use that forum, i mean to not post anything there.


Yeah pretty abrupt sorry to see that, but did you see the post before all was removed (not just yours)?

He posted a warning not to reply on that board it was meant to be for code posted by Librarian. It was a new board on forum and they don't have all the nuances worked out yet, nobody was supposed to be able to post there.

So now to maybe get back on track, don't leave all your diagonal eggs in one basket.
Title: Re: Diagonal Eggs
Post by: Aurel [banned] on March 04, 2020, 07:20:10
Yeah ..back on track
example work fine  ;)
i even tried it on TOY interpreter but not work there  >:(