-
-
Notifications
You must be signed in to change notification settings - Fork 13
Add display saver when no programs are running #234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+149
−0
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| set cc [C] | ||
|
|
||
| $cc cflags -O2 -Wall | ||
| $cc include <math.h> | ||
| $cc include <stdlib.h> | ||
|
|
||
| $cc code { | ||
| typedef struct BallState { | ||
| double x, y, vx, vy, lastT; | ||
| int initialized; | ||
| } BallState; | ||
|
|
||
| static BallState ball = {0, 0, 250.0, 200.0, 0, 0}; | ||
|
|
||
| static double random_bounce_factor() { | ||
| return 0.95 + ((double)rand() / RAND_MAX) * 0.1; | ||
| } | ||
|
|
||
| static char* updateBallPhysics(double t, double displayWidth, | ||
| double displayHeight, double radius) { | ||
| static char buffer[100]; | ||
| double dt = t - ball.lastT; | ||
|
|
||
| // Update position | ||
| double newX = ball.x + ball.vx * dt; | ||
| double newY = ball.y + ball.vy * dt; | ||
| double newVx = ball.vx; | ||
| double newVy = ball.vy; | ||
|
|
||
| // Collision detection and response | ||
| if (newX < radius) { | ||
| newX = radius; | ||
| newVx = fabs(ball.vx) * random_bounce_factor(); | ||
| } else if (newX > displayWidth - radius) { | ||
| newX = displayWidth - radius; | ||
| newVx = -fabs(ball.vx) * random_bounce_factor(); | ||
| } | ||
|
|
||
| if (newY < radius) { | ||
| newY = radius; | ||
| newVy = fabs(ball.vy) * random_bounce_factor(); | ||
| } else if (newY > displayHeight - radius) { | ||
| newY = displayHeight - radius; | ||
| newVy = -fabs(ball.vy) * random_bounce_factor(); | ||
| } | ||
|
|
||
| // Update ball state | ||
| ball.x = newX; | ||
| ball.y = newY; | ||
| ball.vx = newVx; | ||
| ball.vy = newVy; | ||
| ball.lastT = t; | ||
|
|
||
| // Return position as string | ||
| snprintf(buffer, 100, "%.2f %.2f", ball.x, ball.y); | ||
| return buffer; | ||
| } | ||
| } | ||
|
|
||
| $cc proc initBall {double displayWidth double displayHeight double t} void { | ||
| ball.x = displayWidth * 0.5; | ||
| ball.y = displayHeight * 0.5; | ||
| ball.lastT = t; | ||
| ball.initialized = 1; | ||
| } | ||
|
|
||
| $cc proc updateBall {double t double displayWidth double displayHeight double radius} char* { | ||
| return updateBallPhysics(t, displayWidth, displayHeight, radius); | ||
| } | ||
|
|
||
| $cc proc isBallInitialized {} int { | ||
| return ball.initialized; | ||
| } | ||
|
|
||
| set ballLib [$cc compile] | ||
| set radius 100 | ||
|
|
||
| When tag /nobody/ has a program & \ | ||
| display /disp/ has width /displayWidth/ height /displayHeight/ & \ | ||
| the clock time is /t/ { | ||
|
|
||
| if {![$ballLib isBallInitialized]} { | ||
| $ballLib initBall $displayWidth $displayHeight $t | ||
| return | ||
| } | ||
|
|
||
| # Update physics in C and get position | ||
| set pos [$ballLib updateBall $t $displayWidth $displayHeight $radius] | ||
| lassign $pos x y | ||
|
|
||
| Wish to draw a circle onto $disp with \ | ||
| center [list $x $y] \ | ||
| radius $radius \ | ||
| thickness 1 \ | ||
| color green \ | ||
| filled true | ||
| } | ||
|
|
||
| When tag /nobody/ has a program & display /disp/ has width /displayWidth/ height /displayHeight/ { | ||
| puts "Starting display-saver" | ||
|
|
||
| set cx [/ $displayWidth 2.0] | ||
| set cy [* $displayHeight 0.3] | ||
| set host [info hostname] | ||
| set msg "Welcome to Folk\n$host" | ||
|
|
||
| Wish to draw text onto $disp with \ | ||
| x $cx \ | ||
| y $cy \ | ||
| text $msg \ | ||
| color green \ | ||
| scale 80 | ||
|
|
||
| set borderPoints [list \ | ||
| [list 0 0] \ | ||
| [list $displayWidth 0] \ | ||
| [list $displayWidth $displayHeight] \ | ||
| [list 0 $displayHeight] \ | ||
| [list 0 0]] | ||
|
|
||
| Wish to draw a line onto $disp with points $borderPoints width 6 color white | ||
| } | ||
|
|
||
| Claim $this has a display saver |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| When tag /nobody/ has a program & /nobody/ has a display saver & \ | ||
| /disp/ has width /displayWidth/ height /displayHeight/ { | ||
| puts "Starting display-saver" | ||
|
|
||
| set cx [/ $displayWidth 2.0] | ||
| set cy [* $displayHeight 0.3] | ||
| set host [info hostname] | ||
| set msg "Welcome to Folk\n$host" | ||
|
|
||
| Wish to draw text onto $disp with \ | ||
| x $cx \ | ||
| y $cy \ | ||
| text $msg \ | ||
| color green \ | ||
| scale 80 | ||
|
|
||
| set borderPoints [list \ | ||
| [list 0 0] \ | ||
| [list $displayWidth 0] \ | ||
| [list $displayWidth $displayHeight] \ | ||
| [list 0 $displayHeight] \ | ||
| [list 0 0]] | ||
|
|
||
| Wish to draw a line onto $disp with points $borderPoints width 6 color white | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs to be
display /disp/