#!/bin/sh
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

for frame in $(seq 0 30); do
	a=$(echo "$frame / 60 * 8 * a(1)" | bc -l)
	# Max angle:
	# Can move 32 left/right.
	# Total had length 80.
	b=$(echo "c($a) * a(32/80)" | bc -l)
	s=$(echo "s($b)" | bc -l)
	c=$(echo "c($b)" | bc -l)
	out="../clock_top_${frame}.png"
	lx=$(echo "80 + $s * 64 - 0.5" | bc -l)
	ly=$(echo "32 + $c * 64 - 0.5" | bc -l)
	cx=$(echo "80 + $s * 80 - 0.5" | bc -l)
	cy=$(echo "32 + $c * 80 - 0.5" | bc -l)
	convert -size 160x160 \
		xc:transparent \
		+antialias \
		-stroke none -fill black \
		-draw 'rectangle 16,16 144,144' \
		-blur 8x8 \
		-strokewidth 2 \
		-stroke white -fill none \
		-draw "line 79.5,31.5 ${lx},${ly}" \
		\( \
			xc:transparent \
			-stroke none -fill white \
			-draw "circle ${cx},${cy} ${lx},${ly}" \
		\) \
		-compose dst-out -composite \
		"$out"
done
