• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#objective-cqtwindows誰得cocoapythonphprubygameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwittertestdomvb.netdirectxbtronarduinopreviewerゲームエンジン

A categorical programming language


Commit MetaInfo

修订版bf257c1099608d72ab27deef1d11796fb50587df (tree)
时间2022-06-19 10:47:34
作者Corbin <cds@corb...>
CommiterCorbin

Log Message

Fix up the aspect ratio somewhat for animations.

I can't make it perfect because information about monospace font
geometry isn't reliably available.

更改概述

差异

--- a/cammy-rpy/animate.py
+++ b/cammy-rpy/animate.py
@@ -21,10 +21,32 @@ def linear2sRGB(u):
2121 def channel(c):
2222 return int(255 * max(0.0, min(1.0, linear2sRGB(c))))
2323
24-def drawDisplay(cam, canvas, display):
25- displayWidth = caca.get_canvas_width(canvas)
26- displayHeight = caca.get_canvas_height(canvas)
24+def resize(displayWidth, displayHeight):
25+ bufferWidth = displayWidth * 2
26+ # Include a factor of 3/5 since monospaced fonts are extra-tall.
27+ bufferHeight = displayHeight * 2 * 5 // 3
2728 print "Canvas is %d x %d" % (displayWidth, displayHeight)
29+ print "Buffer is %d x %d" % (bufferWidth, bufferHeight)
30+ return displayWidth, displayHeight, bufferWidth, bufferHeight
31+
32+def rescale(width, height):
33+ woffset = width >> 1
34+ hoffset = height >> 1
35+ # Keep pixels square-ish, and let window flexibly scale.
36+ scale = min(width, height) >> 1
37+ ulx = -woffset / scale
38+ uly = -hoffset / scale
39+ lrx = (width - woffset) / scale
40+ lry = (height - hoffset) / scale
41+ print "Viewport is at (%f,%f) (upper left) to (%f,%f) (lower right)" % (
42+ ulx, uly, lrx, lry)
43+ return woffset, hoffset, scale
44+
45+def drawDisplay(cam, canvas, display):
46+ displayWidth, displayHeight, w, h = resize(
47+ caca.get_canvas_width(canvas),
48+ caca.get_canvas_height(canvas))
49+ woff, hoff, scale = rescale(w, h)
2850
2951 frames = 0
3052 t = 0.0
@@ -32,13 +54,11 @@ def drawDisplay(cam, canvas, display):
3254 while t < 20.0:
3355 event = rffi.make(caca.event_t.TO)
3456 while caca.get_event(display, caca.EVENT_RESIZE, event, 0):
35- displayWidth = caca.get_event_resize_width(event)
36- displayHeight = caca.get_event_resize_height(event)
57+ displayWidth, displayHeight, w, h = resize(
58+ caca.get_event_resize_width(event),
59+ caca.get_event_resize_height(event))
60+ woff, hoff, scale = rescale(w, h)
3761
38- w = displayWidth * 2
39- woff = w >> 1
40- h = displayHeight * 2
41- hoff = h >> 1
4262 # The masks are backwards from how one might expect.
4363 dither = caca.create_dither(24, w, h, 3 * w,
4464 0xff, 0xff00, 0xff0000, 0x0)
@@ -46,7 +66,7 @@ def drawDisplay(cam, canvas, display):
4666 buf = StringBuilder(w * h)
4767 for y in range(-hoff, h - hoff):
4868 for x in range(-woff, w - woff):
49- coords = P(P(F(x / w), F(y / h)), F(t))
69+ coords = P(P(F(x / scale), F(y / scale)), F(t))
5070 rgb = cam.execute(coords)
5171 r = rgb.first().f()
5272 g = rgb.second().first().f()
@@ -60,7 +80,7 @@ def drawDisplay(cam, canvas, display):
6080 stamp = nextStamp
6181
6282 with rffi.scoped_view_charp(buf.build()) as view:
63- caca.dither_bitmap(canvas, 0, 0, w, h, dither, view)
83+ caca.dither_bitmap(canvas, 0, 0, displayWidth, displayHeight, dither, view)
6484 caca.refresh_display(display)
6585 caca.free_dither(dither)
6686 frames += 1
--- a/hive/demo/anim/jupiter-storm.cammy
+++ b/hive/demo/anim/jupiter-storm.cammy
@@ -1 +1,5 @@
1-(comp (comp (pair/tensor f-add f-sin) f/div) h2rgb)
\ No newline at end of file
1+(comp
2+ (pair/tensor f-add (f/addpair f-sin (fun/const (f/divpair f/5 f/2))))
3+ (comp f/div h2rgb))
4+
5+A variation on the classic "Jupiter Storm" demo effect.
--- /dev/null
+++ b/hive/f/5.cammy
@@ -0,0 +1 @@
1+(f/addpair f/4 f-one)
\ No newline at end of file