-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.spwn
131 lines (110 loc) · 3.65 KB
/
index.spwn
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
extract obj_props
// https://github.com/SpeckyYT/SPWN-canvas
canvas = import '../canvas/canvas.spwn'
// https://github.com/SpeckyYT/SPWN-speed
speed = import '../speed/speed.spwn'
screen = ?g
let WIDTH = 36
let HEIGHT = 28
let FWIDTH = WIDTH + 2 // 1: \n | 2: \r\n
let PIXELSIZE = 10/HEIGHT
let SLICEH = 1
let PIXELS = WIDTH * HEIGHT
let SPEED = speed(1)
let STARTFROM = 0 // the frame it should start the animation form
let MAXGENFRAMES = -1 // maximal amount of frames to draw
let STARTDELAY = 2 // the time it waits to start playing
let ENDDELAY = 3 // the time it waits to stop playing
let DELTATIME = 1/20 // 20 fps
let USEGROUPS = false // if false, it puts the colors on the x positions and doesn't use groups
let SCALING = 10/(HEIGHT-SLICEH) // the scaling of the pixels
let badCanvas = canvas::new(
0, 0,
WIDTH, HEIGHT-SLICEH,
$.floor(100*SCALING)/100,
screen
)
let previousFrame = []
for _ in ..PIXELS {
previousFrame.push('0') // GD's colors default to white
}
// https://raw.githubusercontent.com/kevinjycui/bad-apple/master/april-fools/input.txt
let file = $.readfile('input.txt')
for index in ..(1/0) {
if MAXGENFRAMES >= 0 && index >= MAXGENFRAMES {break}
$.print(index, ' frames done')
let currentFrame = []
for _ in ..(1/0) {
if currentFrame.length >= HEIGHT {break}
let seekIndex =
STARTFROM * FWIDTH * HEIGHT + // BASE INDEX
index * FWIDTH * HEIGHT + // FRAME INDEX
currentFrame.length * FWIDTH // LINE INDEX
let line = file.substr(seekIndex,seekIndex+WIDTH)
if line.length < WIDTH {break}
currentFrame.push(line)
}
if currentFrame.length >= HEIGHT {
let toPush = []
for i in (WIDTH*SLICEH)..PIXELS {
if i / WIDTH > HEIGHT + SLICEH {break}
let y = HEIGHT - $.floor(i / WIDTH) - 1
let x = i % WIDTH
if x >= badCanvas.colors.length {continue}
if y >= badCanvas.colors[x].length {continue}
let char = currentFrame[y][x]
let key = x + y * WIDTH
if char == previousFrame[key] {continue}
previousFrame[key] = char
let mirroredY = badCanvas.colors[x].length-(y+1)
let color = switch char {
case '0': 255
case '1': 0
else: 128
}
toPush.push([
badCanvas.colors[x][mirroredY],
color,
])
}
if toPush.length == 0 {continue}
if USEGROUPS {
call_with_delay(index * DELTATIME + STARTDELAY, !{
for push in toPush {
colorG = push[0]
color = push[1]
colorG.set(color,color,color)
}
})
} else {
for i in ..toPush.length {
colorG = toPush[i][0]
color = toPush[i][1]
$.add(obj{
OBJ_ID: 899,
X: (index * DELTATIME + STARTDELAY) * (30 * SPEED),
Y: 30*i,
DURATION: 0,
TRIGGER_RED: color,
TRIGGER_GREEN: color,
TRIGGER_BLUE: color,
TARGET_COLOR: colorG,
})
}
}
} else {
$.add(obj{
OBJ_ID: 1,
X: (index * DELTATIME + STARTDELAY + ENDDELAY) * (30 * SPEED),
Y: -30,
})
break
}
}
hide_player()
screen.lock_to_player(true,false)
toggle_bg_effect(false)
-> screen.move(-45,0,1)
for color in [BG,GROUND,LINE] {
color.set(0,0,0)
}