Автор: Alex Zolotov
scr = 0 FREQ = 4000 per = new_array( 60 ) p = 0 per[ p ] = 1712 p + 1 per[ p ] = 1616 p + 1 per[ p ] = 1524 p + 1 per[ p ] = 1440 p + 1 per[ p ] = 1356 p + 1 per[ p ] = 1280 p + 1 per[ p ] = 1208 p + 1 per[ p ] = 1140 p + 1 per[ p ] = 1076 p + 1 per[ p ] = 1016 p + 1 per[ p ] = 960 p + 1 per[ p ] = 906 p + 1 per[ p ] = 856 p + 1 per[ p ] = 808 p + 1 per[ p ] = 762 p + 1 per[ p ] = 720 p + 1 per[ p ] = 678 p + 1 per[ p ] = 640 p + 1 per[ p ] = 604 p + 1 per[ p ] = 570 p + 1 per[ p ] = 538 p + 1 per[ p ] = 508 p + 1 per[ p ] = 480 p + 1 per[ p ] = 453 p + 1 per[ p ] = 428 p + 1 per[ p ] = 404 p + 1 per[ p ] = 381 p + 1 per[ p ] = 360 p + 1 per[ p ] = 339 p + 1 per[ p ] = 320 p + 1 per[ p ] = 302 p + 1 per[ p ] = 285 p + 1 per[ p ] = 269 p + 1 per[ p ] = 254 p + 1 per[ p ] = 240 p + 1 per[ p ] = 226 p + 1 per[ p ] = 214 p+1 per[ p ] = 202 p+1 per[ p ] = 190 p+1 per[ p ] = 180 p+1 per[ p ] = 170 p+1 per[ p ] = 160 p+1 per[ p ] = 151 p+1 per[ p ] = 143 p+1 per[ p ] = 135 p+1 per[ p ] = 127 p+1 per[ p ] = 120 p+1 per[ p ] = 113 p+1 per[ p ] = 107 p+1 per[ p ] = 101 p+1 per[ p ] = 95 p+1 per[ p ] = 90 p+1 per[ p ] = 85 p+1 per[ p ] = 80 p+1 per[ p ] = 75 p+1 per[ p ] = 71 p+1 per[ p ] = 67 p+1 per[ p ] = 63 p+1 per[ p ] = 60 p+1 per[ p ] = 56 p+1 if ( get_window_xsize != get_pixi_xsize( scr ) ) | ( get_window_ysize != get_pixi_ysize( scr ) ) { //Resize main screen: resize_pixi( scr, get_window_xsize, get_window_ysize ) } scr_xsize = get_pixi_xsize( scr ) scr_ysize = get_pixi_ysize( scr ) scr_hx = scr_xsize / 2 scr_hy = scr_ysize / 2 cx = 16 cy = 16 cells = new_array( cx * cy ) tcells = new_array( cx * cy ) cell_size = 8 if scr_xsize <= 160 { cell_size = 6 } cx_size = cx * cell_size tick = 256 sound = new_string( cx * cy * tick ) //8bit sound sound_volume( 16 ) snd_ID = send_sound( sound, FREQ, 1, 1 ) //Draw mode: DM = 0 //Global note: NOTE = -1 start: clear( BLACK ) px = 10000 py = 10000 handle_pen_keys( { px = gpx py = gpy if px < -( cx_size / 2 ) { DM + 1 DM & 1 } if px > cx_size / 2 { NOTE = ( gpy + 64 ) / cell_size } }, { px = gpx py = gpy if px > cx_size / 2 { NOTE = ( gpy + 64 ) / cell_size } }, 0 ) p = 0 TLOOP: tcells[ p ] = cells[ p ] p + 1 if p < cx * cy { go TLOOP } p = 0 y = 0 YLOOP: x = 0 XLOOP: rx = x * cell_size - ((cx*cell_size)/2) ry = y * cell_size - ((cy*cell_size)/2) v = tcells[ p ] fbox( rx + 1, ry + 1, cell_size - 2, cell_size - 2, get_color( v-64, v, v-64 ) ) if v > 0 { cells[ p - 1 ] = ( tcells[ p - 1 ] + v/8 + 3 ) & 255 cells[ p - cx ] = ( tcells[ p - cx ] + v/8 + 3 ) & 255 cells[ p + 1 ] = ( tcells[ p + 1 ] + v/8 + 3 ) & 255 cells[ p + cx ] = ( tcells[ p + cx ] + v/8 + 3 ) & 255 //cells[ p ] = tcells[ p ] / 2 } if ( px >= rx ) & ( py >= ry ) & ( px < rx+cell_size ) & ( py < ry+cell_size ) { if DM = 0 { tcells[ p ] = 254 tcells[ p + 1 ] = 254 tcells[ p - 1 ] = 254 cells[ p ] = 254 cells[ p + 1 ] = 254 cells[ p - 1 ] = 254 } if DM = 1 { pp = p DMLOOP: tcells[ pp ] = 0 cells[ pp ] = 0 pp + 1 if pp < p + cx*8 { go DMLOOP } } } p + 1 x + 1 if x < cx { go XLOOP } y + 1 if y < cy { go YLOOP } RENDER_SOUND p = 0 p2 = get_sound_status( snd_ID ) p2 = p2 / tick p2 = p2 * tick ycenter = ( ( cy * cell_size ) / 2 ) + ( scr_hy - ( cy * cell_size ) / 2 ) / 2 prev_v = ycenter + sound[ p2 ] / 8 DLOOP: v = ycenter + sound[ p2 ] / 8 //line( p - scr_hx - 2, prev_v, p - scr_hx, v, GREEN ) prev_v = v dot( p - scr_hx, v, GREEN ) p + 2 p2 + 1 if p < scr_xsize { go DLOOP } box( -(cx*cell_size)/2 - 2, -(cy*cell_size)/2 - 2, cx*cell_size + 3, cy*cell_size + 3, #308030 ) print( "DM:$DM NOTE:$NOTE", -( ( cx * cell_size ) / 2 ), -( ( cx * cell_size ) / 2 ) - 11, YELLOW ) print( "", -( ( cx * cell_size ) / 2 ) - 64, 0, RED ) print( "PIXI RETRO MELODICS", -scr_hx+2, -scr_hy+2, GREEN ) print( "SELECT NOTE HERE", cx_size/2 + 4, -8, #808080 ) print( "CHANGE BRUSH TYPE", -cx_size/2 - 52, -12, #808080 ) frame( 100 ) go start RENDER_SOUND: p = 0 noise = 0 SLOOP1: if ( p % cx = 0 ) { noise = cells[ p ] / 8 } p2 = p * tick p3 = p2 + tick down = ( cells[ p ] / 32 ) & 1 down * sin( cells[ p ] ) vol = cells[ p ] & 7 type = cells[ p ] & 1 note = cells[ p ] & 63 if note < 0 { note = 0 } if note > 59 { note = 59 } if NOTE >= 0 { note = NOTE + 10 } delta = ( ( 3546894 / FREQ ) * 1024 ) / per[ note ] dp = 0 noise - 2 if noise < 0 { noise = 0 } if 1 { SLOOP2: sound[ p2 ] = ( ( csin( dp / 32 ) / 2 ) * vol ) / 8 dp + delta delta - down p2 + 1 if p2 < p3 { go SLOOP2 } } p2 = p * tick p3 = p2 + tick if noise { SLOOP3: sound[ p2 ] = sound[ p2 ] + ( ( ( rand & 127 ) - 64 ) * noise ) / 32 p2 + 1 if p2 < p3 { go SLOOP3 } } p + 1 if p < ( cx * cy ) { go SLOOP1 } ret
