несколько простых прожек

Post Reply
vtl

несколько простых прожек

Post by vtl » Sun Dec 28, 2008 6:39 pm

вот решил выложить, что написал на налодоннике. с языком только познакомился. программки элементарные, не делал никакой оптимизации, куча переменных для настройки, всё на понятность. далее код.

Code: Select all

//------------------------------------------------------------
//multiscroller %)
//------------------------------------------------------------

w = get_window_xsize
h = get_window_ysize

init_vars

draw:

  clear(0)
  draw_stripes
  frame(25)

go draw

//------------------------------------------------------------
//рисовать цветные полосы
//------------------------------------------------------------

draw_stripes:

  if (alpha > 256)
  {
    alpha = 0
  }

  i = num - 1
  while(i >= 0)
  {
    offset = csin(alpha + deltas[ i ]) * amp / 128
    grad_y1 = -20 + offset
    grad_y2 = 20 + offset

    grad_col1 = colors1[ i ]
    grad_col2 = colors2[ i ]
    double_grad

    i - 1
  }

  alpha + dalpha

ret

//------------------------------------------------------------
//инициализация всего и вся
//------------------------------------------------------------

init_vars:

  num = 5
  deltas = new_array(num)
  colors1 = new_array(num)
  colors2 = new_array(num)
  bar_h = h / 8
  dalpha = 2
  alpha = 0
  grad_steps = 10
  amp = h / 2 - bar_h / 2

  i = 0
  while(i < num)
  {
    deltas[ i ] = -bar_h * i / 2
    i + 1
  }

  colors1[ 0 ] = #5F0000
  colors2[ 0 ] = #FF1010
  colors1[ 1 ] = #005F00
  colors2[ 1 ] = #10FF10
  colors1[ 2 ] = #00005F
  colors2[ 2 ] = #1010FF
  colors1[ 3 ] = #5F5F00
  colors2[ 3 ] = #FFFF10
  colors1[ 4 ] = #5F005F
  colors2[ 4 ] = #FF10FF

ret

//------------------------------------------------------------
//зеркальный градиент
//------------------------------------------------------------

double_grad:

  temp1 = grad_steps

  grad_steps / 2
  grad_y2 = grad_y1 + (grad_y2 - grad_y1) / 2
  vert_grad

  temp2 = grad_y2 - grad_y1
  grad_y1 = grad_y2
  grad_y2 = grad_y1 + temp2
  temp2 = grad_col1
  grad_col1 = grad_col2
  grad_col2 = temp2
  vert_grad

grad_steps = temp1

ret

//------------------------------------------------------------
//вертикальный градиент
//------------------------------------------------------------

vert_grad:

  z = 0
  step_h = (grad_y2 - grad_y1) / grad_steps
  step_c = 255 / (grad_steps - 1)
  while(z < grad_steps)
  {
    fbox(-w / 2, grad_y1 + z * step_h, w, step_h, get_blend(grad_col1, grad_col2, z * step_c) )
    z + 1
  }

ret

Code: Select all

//------------------------------------------------------------
//навеяно darwinia :)
//------------------------------------------------------------

h = get_window_ysize
w = get_window_xsize

init_vars

draw:

  clear(0)
  draw_mans
  frame(40)

goto draw

//------------------------------------------------------------
//рисовать человеков
//------------------------------------------------------------

draw_mans:

  i = 0
  while (i < num)
  {
    pixi(man, x[i], y[i], sz[i], 0)
    x[i] = x[i] + sp[i]
    if (x[i] > w / 2 + manw * sz[i] / 2 )
    {
      setnew
    }
    i + 1
  }

ret

//------------------------------------------------------------
//задать все
//------------------------------------------------------------

init_vars:

  num = 10
  x = new_array(num)
  y = new_array(num)
  sz = new_array(num)
  sp = new_array(num)
  minsp = 1
  maxsp = 11
  minsz = 1
  maxsz = 6

  b = #007f00
  s = #00ff00

  man = "
...sssss...
...sbbbs...
...sbbbs...
ssssbbbssss
sbbbbbbbbbs
sbbbbbbbbbs
sbbbbbbbbbs
ssssbbbssss
...sbbbs...
ssssbbbssss
sbbbbbbbbbs
sbbbbbbbbbs
sbbbbbbbbbs
sbbbs.sbbbs
sbbbs.sbbbs
sbbbs.sbbbs
sssss.sssss
"
  make_pixi (man)
  manh = get_pixi_ysize(man)
  manw = get_pixi_xsize(man)

  i = 0
  while (i < num)
  {
    setnew
    i + 1
  }

ret

//------------------------------------------------------------
//создать нового человека
//------------------------------------------------------------

setnew:

  newone
  x[i] = x1
  y[i] = y1
  sp[i] = sp1
  sz[i] = sz1

ret 

//------------------------------------------------------------
//задать новые значения
//------------------------------------------------------------

newone:

  sz1 = minsz + (maxsz - minsz) * rand / 32767
  sp1 = minsp + (maxsp - minsp) * rand / 32767
  x1 = -w / 2 - manw * sz1 / 2
  y1 = -h / 2 + manh * sz1 / 2 + (h - manh * sz1) * rand / 32767

ret

Code: Select all

//------------------------------------------------------------
//навеяно minimalistic demo из стандартных примеров :)
//------------------------------------------------------------

w = get_window_xsize
h = get_window_ysize
rand_max = 32767

init_star
place_stars
init_house
place_houses
init_tree

f = 0
draw:

draw_back
draw_stars
draw_moon
draw_houses
draw_trees
frame(100)

goto draw

//------------------------------------------------------------
//нарисовать деревья
//------------------------------------------------------------

draw_trees:

  treex = get_pixi_xsize(tree)
  treey = get_pixi_ysize(tree)
  tcount = w / treex / 2
  tscale = 3

  i = 0
  while(i < tcount)
  {
    fpixi(tree, -w / 2 + treex + treex * i * 2, h / 2 - treey, 1, 0, 0)
    i + 1
  }

  treex / tscale
  treey / tscale
  tcount = w / treex / 2 - 1

  i = 0
  while(i < tcount)
  {
    fpixi(tree, -w / 2 + treex * tscale + treex * i * 2, h / 4 + treey * 5 / 2, 1, 0, 1)
    i + 1
  }

ret

//------------------------------------------------------------
//нарисовать дома
//------------------------------------------------------------

draw_houses:

  i = 1
  while (i <= hcount)
  {
    fpixi(house, -w / 2 + i * get_pixi_xsize(house), h/4 - get_pixi_ysize(house) / 2, 1, 0, housesf[i])
    i + 1
  }

ret

//------------------------------------------------------------
//нарисовать луну
//------------------------------------------------------------

draw_moon:

  i = 0
  while(i < 6)
  {
    circle_x = w / 4
    circle_y = -h / 4
    circle_steps = 128
    circle_color = #f0f070
    if (i != 0)
    {
      transp(60 - 10 * i)
      circle_r = 32 + i * 4 + 1 + csin(256 / 16 * f) * 2 / 128
    }
    else
    {
      circle_r = 32
    }
    circle
    i + 1
  }
  transp(256)

  circle_r = 8
  circle_x = w / 4 + 32 * 2 / 5
  circle_y = -h / 4 - 32 * 2 / 5
  circle_steps = 8
  circle_color = #f0f0b0
  circle

ret

//------------------------------------------------------------
//нарисовать фон
//------------------------------------------------------------

draw_back:

  grad_y1 = -h / 2
  grad_y2 = h / 4
  grad_steps = (grad_y2 - grad_y1) / 10
  grad_col1 = #000000
  grad_col2 =  #9000cf
  grad

  grad_y1 = h / 4
  grad_y2 = h / 2
  grad_steps = (grad_y2 - grad_y1) / 5
  grad_col1 = #002f00
  grad_col2 =  #00cf00
  grad

ret

//------------------------------------------------------------
//нарисовать звезды
//------------------------------------------------------------

draw_stars:

  i = 0
  while(i < scount)
  {
    fpixi(star, starsx[i], starsy[i], 1, 0, starsf[i] + f)
    i + 1
  }

  f + 1
  if (f > sfcount)
  {
    f = 0
  }

ret

//------------------------------------------------------------
//разместить дома
//------------------------------------------------------------

place_houses:

  hcount = w / get_pixi_xsize(house) - 1
  housesf = new_array(hcount)

  i = 0
  while(i < hcount)
  {
    housesf[i] = get_pixi_frames(house) * rand / 32767
    i + 1
  }

ret

//------------------------------------------------------------
//разместить звезды
//------------------------------------------------------------

place_stars:

  step = 8
  var = 4
  scount = (w - step * 2) / step
  sfcount = get_pixi_frames(star)
  starsy = new_array(scount)
  starsx = new_array(scount)
  starsf = new_array(scount)

  i =  0
  while(i < scount)
  {
    starsx[ i ] = -w / 2 + (i + 1) * step + (-rand_max  + rand * 2) * var / rand_max 
    starsy[ i ] = -h / 2 + step + (h / 2 + h / 4 - 2 * step) * rand / rand_max
    starsf[ i ] = sfcount * rand / rand_max
    i + 1
  }

ret

//------------------------------------------------------------
//дома
//------------------------------------------------------------

init_house:

  b = #000000
  r = #ff0000
  y= #ffff00

  house = "
..b..
.bbb.
bbbbb
.bbb.
.byb.
.bbb.
+
.bbb.
.byb.
bbbbb
.bbb.
.bbb.
.bbb.
+
.....
..b..
.bbb.
bbbbb
brbyb
bbbbb
+
.....
.....
......
.bbb.
bbbbb
bbbbb
+
.....
.....
..b..
.bbb.
bbrbb
.bbb.
+
bbbbb
.b.b.
.b.b.
bbbbb
brbyb
bbbbb
+
.bbb.
bbbbb
b.b.b
b.b.b
b.b.b
bbbbb
+
..r..
..b..
..b..
..b..
.bbb.
bbbbb
+
.b.b.
bbbbb
brbrb
bbbbb
bybyb
bbbbb
+
.rrr.
.bbb.
.yyy.
.bbb.
.yyy.
.bbb.
+
.....
.....
.....
.....
yryry
bbbbb
+
bbbbb
bybyb
bb.bb
b...b
b...b
b...b
+
..b..
.bbb.
..b..
..b..
..b..
..b..
+
..y..
..b..
r.b.r
b.b.b
.bbb.
..b..
"
  make_pixi(house)

ret

//------------------------------------------------------------
//звезда
//------------------------------------------------------------

init_star:

  O = #FFFFFF
  o = #A0A0A8

  star = "
..o..
.oOo.
oOOOo
.oOo.
..o..
+
..o..
..o..
ooOoo
..o..
..o..
+
.....
..o..
.oOo.
..o..
.....
+
.....
.....
..O..
.....
.....
+
.....
.....
..o..
.....
.....
+
.....
.....
..O..
.....
.....
+
.....
.o.o.
..O..
.o.o.
.....
+
o...o
.o.o.
..O..
.o.o.
o...o
+
o...o
.OoO.
.oOo.
.OoO.
o...o
+
o...o
.o.o.
..O..
.o.o.
o...o
+
.....
.o.o.
..O..
.o.o.
.....
+
.....
.....
..O..
.....
.....
+
.....
.....
..o..
.....
.....
+
.....
.....
..O..
.....
.....
+
.....
..o..
.oOo.
..o..
.....
+
..o..
..o..
ooOoo
..o..
..o..
"
  make_pixi(star)

ret

//------------------------------------------------------------
//дерево
//------------------------------------------------------------

init_tree:

  g = #a0f030
  d = #80c010
  k = #7d7d30

  tree = "
...........g...........
..........ggg..........
.........ggggg.........
........ggggggg........
...........g...........
..........ggg..........
.........ggggg.........
........ggggggg........
.......ggggggggg.......
......ggggggggggg......
.....ggggggggggggg.....
....ggggggggggggggg....
...........g...........
..........ggg..........
.........ggggg.........
........ggggggg........
.......ggggggggg.......
......ggggggggggg......
.....ggggggggggggg.....
....ggggggggggggggg....
...ggggggggggggggggg...
..ggggggggggggggggggg..
.ggggggggggggggggggggg.
ggggggggggggggggggggggg
..........kkk..........
..........kkk..........
..........kkk..........
..........kkk..........
..........kkk..........
..........kkk..........
..........kkk..........
..........kkk..........
..........kkk..........
+
...d...
..ddd..
...d...
..ddd..
.ddddd.
...d...
..ddd.
.ddddd.
ddddddd
...k...
...k...
...k...
"
  make_pixi(tree)

ret

//------------------------------------------------------------
//круг
//------------------------------------------------------------

circle:

  z = 0
  while(z < circle_steps)
  {
  triangle(circle_x, circle_y, circle_x + ccos(256 * z / circle_steps) * circle_r / 128, circle_y + csin(256 * z / circle_steps) * circle_r / 128, circle_x + ccos(256 * (z + 1) / circle_steps) * circle_r / 128, circle_y + csin(256 * (z + 1) / circle_steps) * circle_r / 128, circle_color)
    z + 1
  }

ret

//------------------------------------------------------------
//вертикальный градиент
//------------------------------------------------------------

grad:

  z = 0
  step_h = (grad_y2 - grad_y1) / grad_steps
  step_c = 255 / (grad_steps - 1)
  while(z < grad_steps)
  {
    fbox(-w / 2, grad_y1 + z * step_h, w, step_h, get_blend(grad_col1, grad_col2, z * step_c) )
    z + 1
  }

ret

User avatar
goglus
Posts: 122
Joined: Tue Dec 04, 2007 4:19 pm
Contact:

Re: несколько простых прожек

Post by goglus » Sun Dec 28, 2008 8:13 pm

суперски!
отдичные проги, 2 первые просяться в раздел маленьких эффектов, как раз собираюсь на wiki из такой раздел сделать

Zuf
Posts: 110
Joined: Fri Dec 21, 2007 7:30 pm
Location: Msc
Contact:

Re: несколько простых прожек

Post by Zuf » Sun Dec 28, 2008 8:15 pm

Ну вот видите как здорово )

User avatar
vtl
Posts: 31
Joined: Sun Dec 28, 2008 6:41 pm
Location: Saint Petersburg, Russia
Contact:

Re: несколько простых прожек

Post by vtl » Sun Dec 28, 2008 8:45 pm

забыл момент, все-таки расчитано на на 240х320, особенно последний пример.

User avatar
goglus
Posts: 122
Joined: Tue Dec 04, 2007 4:19 pm
Contact:

Re: несколько простых прожек

Post by goglus » Sun Dec 28, 2008 9:20 pm

вот и сделал то что давно собирался

http://wiki.pixi.su/examples:mini_effects

User avatar
vtl
Posts: 31
Joined: Sun Dec 28, 2008 6:41 pm
Location: Saint Petersburg, Russia
Contact:

Re: несколько простых прожек

Post by vtl » Sun Dec 28, 2008 9:44 pm

о, будет что почитать. у меня еще одна идейка появилась немного побольше, может скоро сделаю.

User avatar
goglus
Posts: 122
Joined: Tue Dec 04, 2007 4:19 pm
Contact:

Re: несколько простых прожек

Post by goglus » Sun Dec 28, 2008 11:43 pm

ждем с нетерпением

User avatar
vtl
Posts: 31
Joined: Sun Dec 28, 2008 6:41 pm
Location: Saint Petersburg, Russia
Contact:

Re: несколько простых прожек

Post by vtl » Mon Dec 29, 2008 2:03 am

оформлю в отдельную темку, но пока еще альфа.

User avatar
Al_Rado
Posts: 239
Joined: Tue Dec 04, 2007 2:33 pm
Location: Krasnodar
Contact:

Re: несколько простых прожек

Post by Al_Rado » Mon Dec 29, 2008 10:42 am

2 vtl: велкам ту зе пикси-комьюнити! :)
Прикольные эффекты, поддерживаю комменты на русском )
ВекторКодПиксельПолигон - ВотЧтоЯЛюблю!

User avatar
J3d1
Posts: 175
Joined: Wed Oct 15, 2008 4:49 am
Location: г. Абакан, Хакасия
Contact:

Re: несколько простых прожек

Post by J3d1 » Tue Dec 30, 2008 5:37 am

Vtl: Отличное начало! Нашего полку прибыло )))

Post Reply