45
\$\begingroup\$

This is a graphical output challenge where the task is to give the shortest code per language.

Task

Your code should plot a single purple pixel (hex value #800080 or rgb(128, 0, 128)), moving clockwise round a circle. It should take exactly 60 seconds to make a full journey round the circle and should continue indefinitely. Nothing else should be shown on the screen or window except for the pixel. The width of the circle should be 0.75 (rounding suitably) the width of the screen or window and the background should be white. To prevent silly solutions, the screen or window should be at least 100 pixels wide.

Your code should be a full program.

Languages and libraries

You can use any language or library you like. However, I would like to be able to test your code if possible so if you can provide clear instructions for how to run it in Ubuntu that would be very much appreciated.

Missing top twenty languages. Help needed.

The following top twenty programming languages are currently missing any solution at all.

  • C, C++, C#, Python, PHP, Visual Basic .NET, Perl, Delphi/Object Pascal, Assembly, Objective-C, Swift, Pascal, Matlab/Octave, PL/SQL, OpenEdge ABL, R

Catalog

The Stack Snippet at the bottom of this post generates the catalog from the answers a) as a list of shortest solution per language and b) as an overall leaderboard.

To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:

## Language Name, N bytes

where N is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:

## Ruby, <s>104</s> <s>101</s> 96 bytes

If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the last number in the header:

## Perl, 43 + 2 (-p flag) = 45 bytes

You can also make the language name a link which will then show up in the snippet:

## [><>](http://esolangs.org/wiki/Fish), 121 bytes

<style>body { text-align: left !important} #answer-list { padding: 10px; width: 290px; float: left; } #language-list { padding: 10px; width: 290px; float: left; } table thead { font-weight: bold; } table td { padding: 5px; }</style><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="language-list"> <h2>Shortest Solution by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr> </thead> <tbody id="languages"> </tbody> </table> </div> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr> </thead> <tbody id="answers"> </tbody> </table> </div> <table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr> </tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr> </tbody> </table><script>var QUESTION_ID = 62095; var ANSWER_FILTER = "!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe"; var COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk"; var OVERRIDE_USER = 9206; var answers = [], answers_hash, answer_ids, answer_page = 1, more_answers = true, comment_page; function answersUrl(index) { return "https://api.stackexchange.com/2.2/questions/" + QUESTION_ID + "/answers?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + ANSWER_FILTER; } function commentUrl(index, answers) { return "https://api.stackexchange.com/2.2/answers/" + answers.join(';') + "/comments?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + COMMENT_FILTER; } function getAnswers() { jQuery.ajax({ url: answersUrl(answer_page++), method: "get", dataType: "jsonp", crossDomain: true, success: function (data) { answers.push.apply(answers, data.items); answers_hash = []; answer_ids = []; data.items.forEach(function(a) { a.comments = []; var id = +a.share_link.match(/\d+/); answer_ids.push(id); answers_hash[id] = a; }); if (!data.has_more) more_answers = false; comment_page = 1; getComments(); } }); } function getComments() { jQuery.ajax({ url: commentUrl(comment_page++, answer_ids), method: "get", dataType: "jsonp", crossDomain: true, success: function (data) { data.items.forEach(function(c) { if (c.owner.user_id === OVERRIDE_USER) answers_hash[c.post_id].comments.push(c); }); if (data.has_more) getComments(); else if (more_answers) getAnswers(); else process(); } }); } getAnswers(); var SCORE_REG = /<h\d>\s*([^\n,<]*(?:<(?:[^\n>]*>[^\n<]*<\/[^\n>]*>)[^\n,<]*)*),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/; var OVERRIDE_REG = /^Override\s*header:\s*/i; function getAuthorName(a) { return a.owner.display_name; } function process() { var valid = []; answers.forEach(function(a) { var body = a.body; a.comments.forEach(function(c) { if(OVERRIDE_REG.test(c.body)) body = '<h1>' + c.body.replace(OVERRIDE_REG, '') + '</h1>'; }); var match = body.match(SCORE_REG); if (match) valid.push({ user: getAuthorName(a), size: +match[2], language: match[1], link: a.share_link, }); else console.log(body); }); valid.sort(function (a, b) { var aB = a.size, bB = b.size; return aB - bB }); var languages = {}; var place = 1; var lastSize = null; var lastPlace = 1; valid.forEach(function (a) { if (a.size != lastSize) lastPlace = place; lastSize = a.size; ++place; var answer = jQuery("#answer-template").html(); answer = answer.replace("{{PLACE}}", lastPlace + ".") .replace("{{NAME}}", a.user) .replace("{{LANGUAGE}}", a.language) .replace("{{SIZE}}", a.size) .replace("{{LINK}}", a.link); answer = jQuery(answer); jQuery("#answers").append(answer); var lang = a.language; lang = jQuery('<a>'+lang+'</a>').text(); languages[lang] = languages[lang] || {lang: a.language, lang_raw: lang, user: a.user, size: a.size, link: a.link}; }); var langs = []; for (var lang in languages) if (languages.hasOwnProperty(lang)) langs.push(languages[lang]); langs.sort(function (a, b) { if (a.lang_raw > b.lang_raw) return 1; if (a.lang_raw < b.lang_raw) return -1; return 0; }); for (var i = 0; i < langs.length; ++i) { var language = jQuery("#language-template").html(); var lang = langs[i]; language = language.replace("{{LANGUAGE}}", lang.lang) .replace("{{NAME}}", lang.user) .replace("{{SIZE}}", lang.size) .replace("{{LINK}}", lang.link); language = jQuery(language); jQuery("#languages").append(language); } }</script>

\$\endgroup\$
  • 1
    \$\begingroup\$ what radius should the circle be? \$\endgroup\$ – Timothy Groote Oct 29 '15 at 14:40
  • 18
    \$\begingroup\$ Why should the pixel be purple? I would assume some languages like TI-Basic don't have color capabilities, which means they can't be used for the challenge for a pretty abitrary reason \$\endgroup\$ – Fatalize Oct 29 '15 at 14:42
  • 1
    \$\begingroup\$ @Fatalize that doesn't mean you can't golf the color into the program in some clever creative way to save bytes. \$\endgroup\$ – Timothy Groote Oct 29 '15 at 14:43
  • 3
    \$\begingroup\$ @TimothyGroote TI-BASIC has mainly only one color: black. Everything else is an off pixel. There are C(SE) calculators that have colors, but not everyone has one. \$\endgroup\$ – Conor O'Brien Oct 29 '15 at 14:53
  • 10
    \$\begingroup\$ I'm sure putting a purple cellofane over your screen does not add to your code size in bytes. i mean it worked vor the vectrex ;) \$\endgroup\$ – Timothy Groote Oct 29 '15 at 15:45

46 Answers 46

23
\$\begingroup\$

Processing, 101 97 96 bytes

4 bytes thanks to Flambino.

1 byte thanks to Kritixi Lithos.

float d;void draw(){background(-1);stroke(#800080);d+=PI/1800;point(50+cos(d)*38,50+sin(d)*38);}

This creates a default 100 by 100 pixel window with the required animation.

output window

Disclaimer: that image is not a GIF. Don't stare at it for a minute.

\$\endgroup\$
  • 2
    \$\begingroup\$ Does this implement the 60 seconds rule? \$\endgroup\$ – user9206 Oct 29 '15 at 15:12
  • 2
    \$\begingroup\$ @Lembik Yes. The default framerate is 60 fps, and I'm incrementing the angle π/1800 radians at a time. (It was π/3600 10 seconds ago because of my brain fart.) \$\endgroup\$ – PurkkaKoodari Oct 29 '15 at 17:21
  • 5
    \$\begingroup\$ @Pietu1998 That brainfart was due to the fact that pi is wrong \$\endgroup\$ – Cruncher Oct 29 '15 at 20:46
  • 2
    \$\begingroup\$ @Cruncher gotta love vi hart! \$\endgroup\$ – Tim Oct 29 '15 at 21:52
  • 16
    \$\begingroup\$ Hey, your GIF isn't working, I stared at it for a minute but nothing happened \$\endgroup\$ – Beta Decay Nov 1 '15 at 8:34
16
\$\begingroup\$

QB64, 79 bytes

QB64 is a QBasic emulator that adds some nice features. This program uses one (CLS,15) that isn't supported by vanilla QBasic.

SCREEN 7
DO
T=TIMER/9.55
PSET(COS(T)*75+99,SIN(T)*75+99),5
PLAY"c8"
CLS,15
LOOP

This is very loud. It uses the PLAY command to halt execution for a short while before clearing the screen; otherwise the pixel will flicker and become invisible.

Download QB64, load this file, click Run and then Start.

Here it is in action:

the program

I took some tricks (SCREEN 7 instead of SCREEN 13, and PSET instead of POKE) from @DLosc's answer, so credit is due. As in his answer, my magenta is actually #8B008B, which was deemed acceptable by the OP.

(The constant 9.55 is an approximation of 30/π = 9.54929658551. Is it close enough?)

\$\endgroup\$
  • \$\begingroup\$ Ha! Never thought of using PLAY for a delay. Could've sworn there was a code for a rest, but I'm not seeing it now in the help file. I did consider using (a function of) TIMER as the parameter, but never tried it to see if it was shorter. Kudos! \$\endgroup\$ – DLosc Oct 29 '15 at 19:46
  • 4
    \$\begingroup\$ Thank! I shamelessly lifted PSET from you, so kudos back :) It looks like a rest is n0 which is longer than c. Also, I like it as a bit of rule-bending: the OP said nothing else could be shown in the window, but never said my program couldn't loudly go BEEP BEEP BEEP BEEP. \$\endgroup\$ – Lynn Oct 29 '15 at 19:48
  • 1
    \$\begingroup\$ I have nothing against the beeps but I can't actually see a pixel moving around a circle when I try in linux. \$\endgroup\$ – user9206 Oct 29 '15 at 19:57
  • 1
    \$\begingroup\$ Here it is in action on my machine, which should be enough proof. \$\endgroup\$ – Lynn Oct 29 '15 at 19:59
  • 12
    \$\begingroup\$ I stared at the image for a while, because you said "here it is in action". \$\endgroup\$ – mbomb007 Oct 29 '15 at 20:07
14
\$\begingroup\$

Java, 449 443 439 bytes

Because I've always had stupid ideas. Like golfing in Java ;) .

import java.awt.*;import javax.swing.*;class F extends JFrame{F()throws Exception{setContentPane(new P());setSize(400,400);setVisible(0<1);for(;;Thread.sleep(100))repaint();}class P extends JPanel{double c;public void paintComponent(Graphics g){g.setColor(new Color(8388736));c=(c-0.1)%60;double t=0.104*c;g.fillRect((int)(180+Math.sin(t)*120),(int)(180+Math.cos(t)*120),1,1);}}public static void main(String[]x)throws Exception{new F();}}

Edit: Thanks for @Ypnypn for golfing 7 bytes!

Edit2: Thanks for @Franz D. for saving 3 bytes!

\$\endgroup\$
  • 7
    \$\begingroup\$ Java is winning the longest shortest code competition so far :) \$\endgroup\$ – user9206 Oct 29 '15 at 16:50
  • 1
    \$\begingroup\$ - You don't need to initialize member variables to zero, so you can save two bytes (~0.45%) by converting "c=0" to "c". \$\endgroup\$ – Franz D. Oct 29 '15 at 20:16
  • 1
    \$\begingroup\$ And you can save one more byte by initializing the color in hex, i.e. new Color(0x800080). \$\endgroup\$ – Franz D. Oct 29 '15 at 20:17
  • 1
    \$\begingroup\$ @FranzD. Even better - just use the decimal number 8388736. \$\endgroup\$ – Ypnypn Oct 29 '15 at 21:14
  • 1
    \$\begingroup\$ Get rid of JFrame, use Frame, allows you to remove javax import. \$\endgroup\$ – Magic Octopus Urn Nov 30 '16 at 15:41
14
\$\begingroup\$

Mathematica, 102 101 94 bytes

Animate[Graphics[{White,Disk[],{Purple,Point[{0,1}]}}~Rotate~-t],{t,0,2π},DefaultDuration->60]

Creates a white circle that is hidden and places a point that follows its edge from 0 to 2π. Mathematica's DefaultDuration option let's me set it to complete a loop every 60 seconds.

Here's a sped up version of the output:

EDIT: Change Circle to Disk to save 2 characters, added a negative sign to t to make it move clockwise.

EDIT: Saved 7 bytes by using the ~ operator (thanks to Mauris).

\$\endgroup\$
  • 14
    \$\begingroup\$ Further proof that Mathematica is just a programming language where you write some vague English words that sort of mean what you want, then add punctuation. (I hear you can use a~f~b instead of f[a,b], wouldn't that make your Rotate shorter?) \$\endgroup\$ – Lynn Oct 29 '15 at 20:36
  • 1
    \$\begingroup\$ You can also use prefix notation for Point@{0,1} and I don't think you need the list around Purple,Point.... \$\endgroup\$ – Martin Ender Oct 30 '15 at 8:48
  • 1
    \$\begingroup\$ @Mauris. To the untrained eye, Mathematica may indeed look like vague English words and punctuation. In reality, they are the names of specific, well-defined functions, settings and operators. The likelihood that a non-programmer could spin out workable code is zilch. \$\endgroup\$ – DavidC Oct 30 '15 at 9:27
  • 2
    \$\begingroup\$ @David: Haha, of course I'm aware -- I was just joking :) \$\endgroup\$ – Lynn Oct 30 '15 at 12:26
  • \$\begingroup\$ @Mauris, You fooled me! \$\endgroup\$ – DavidC Oct 30 '15 at 15:10
14
\$\begingroup\$

HTML, 235 290 295 354 347 bytes

<a><style>*{position:absolute;margin:0;box-sizing:border-box}body{height:100vh;width:100vh}a{left:12.5%;top:50%;width:75%;height:1px;border-left:1px solid purple;animation:r 60s infinite linear}@keyframes r{100%{transform:rotate(360deg

Save as a .html file and open in a browser, that doesn't need vendor prefixes, like Chrome or Firefox. Or try this fiddle.


This is a new version which is way shorter than my first attempt, that I had written 5 minutes before a meeting. The new size of the canvas is a square based on the viewport height. That works pretty well and is not restricted to a certain defined height. I'm very accurate about the settings in the challenge (75% size of its parent, purple and 1px). Therefore I need and can't discard or simplify the following rules:

* { margin: 0; box-sizing:border-box; }
a { left: 12.5%; }

Ungolfed

This is the ungolfed version with clean markup:

<!DOCTYPE html>
<html>

<head>
    <style>
        * {
            position: absolute;
        }

        body {
            margin: 0;
            height: 100vh;
            width: 100vh;
        }

        a {
            left: 12.5%;
            top: 50%;
            width: 75%;
            height: 1px;
            border-left: 1px solid purple;
            box-sizing: border-box;
            animation: r 60s infinite linear;
        }

        @keyframes r {
            100%{
                transform: rotate(360deg)
            }
        }
    </style>    
</head>
<body>
    <a></a>
</body>

Edits

  • Added 7 bytes. I thought nobody would notice, that there's a default easing on the animation. ;) I've set it to linear now.
  • Saved 59 bytes by throwing everything abort that the browser will handle automatically.
  • Saved 3 bytes by removing the trailing )}}. Thanks to toothbrush.
  • Saved 2 bytes by using 12% instead of 12px which is the same value corresponding to the size of the parent element.
  • Saved 55 bytes due to massive refactoring, also taken a lot of comments into account. Thanks a lot for all the contributions.
\$\endgroup\$
  • 1
    \$\begingroup\$ I just wanted to comment on the post, i would like to see a pure html/css solution (ty for submitting one) \$\endgroup\$ – dwana Oct 29 '15 at 15:12
  • 1
    \$\begingroup\$ Using fiddle the speed of the moving pixel is very uneven. It almost grinds to a halt when the pixel is on the far left. Any ideas why? \$\endgroup\$ – user9206 Oct 29 '15 at 15:27
  • 1
    \$\begingroup\$ @insertusernamehere :) I think the ungolfed version needs updating too now. \$\endgroup\$ – user9206 Oct 29 '15 at 15:38
  • 5
    \$\begingroup\$ You should go for the smallest working code irrespective of validity. Things like polluting the global namespace are par for the course while golfing. \$\endgroup\$ – John Dvorak Oct 29 '15 at 18:28
  • 2
    \$\begingroup\$ You can drop )}} from the end (the CSS parser will automatically end the blocks) \$\endgroup\$ – Toothbrush Oct 29 '15 at 20:08
14
\$\begingroup\$

TI-BASIC, 44 bytes

For the TI-84+ CSE/CE calculators, which support some limited BASIC color graphics.

AxesOff
ZSquare
While rand
Pt-Off(imag(Ans),real(Ans
7.5e^(-i6startTmr°
Pt-On(imag(Ans),real(Ans),13
End

The color here is magenta, or color 13 (one can also use the MAGENTA token).

I use rand instead of 1 for the infinite loop condition to provide a tiny bit of delay (~15 ms) between when the pixel is displayed and when it is turned off again.

Set your calculator to radian mode before running this program; I don't count this in the size because it's the default state. Also set Ans to 0 by entering a 0 before the program; this is also the default.

Thanks to @quartata for testing this program (I don't own a color calculator).

\$\endgroup\$
  • \$\begingroup\$ Naive idea: can you make the program call itself instead of using a while loop, and would that be shorter? \$\endgroup\$ – Lynn Oct 30 '15 at 12:31
  • \$\begingroup\$ @Mauris the while loop is 3 tokens, while a program name is longer usually \$\endgroup\$ – TheDoctor Oct 30 '15 at 20:03
  • 1
    \$\begingroup\$ @Mauris The While loop is actually 4 bytes, and it's possible to recurse in 3, but the stack runs out very quickly, after less than 300 calls. \$\endgroup\$ – lirtosiast Oct 31 '15 at 0:24
  • \$\begingroup\$ @Lembik Because you're fine with [codegolf.stackexchange.com/a/62203/39328], I won't change this to be smoother. \$\endgroup\$ – lirtosiast Oct 31 '15 at 15:56
13
\$\begingroup\$

Java, 339 308 289 287 bytes

import java.awt.*;class F extends Frame{{setSize(200,200);show();}int c;public void paint(Graphics g){g.setColor(new Color(8388736));g.fillRect((int)(99+Math.sin(--c*.01)*75),(int)(99+Math.cos(c*.01)*75),1,1);for(int i=0;++i<62864;)paint();}public static void main(String[] x){new F();}}

Thanks to @Peter Lenkefi, whose great solution got me started, and whose for-loop I shamelessly copied!

The main saving was due to switching to pure AWT and rendering directly in the Frame -- no need for a JPanel (or Canvas). I also made the counter an integer variable, updated by simple increment, and saved a few bytes twiddling the constants to be able to strip a digit here and there.

EDIT: Thanks to @Peter Lenkefi and @tobii for their suggestions in the comments. Beating HTML would be nice -- does anyone know how to reliably pause execution in Java without using sleep() and having to catch exceptions?

EDIT 2: JAVA BEATS HTML (currently at 290 bytes!) :D Timing is now machine-dependent, but ~60 seconds for a full circle on my machine, which is OK according to @Lembik. Thanks again to @PeterLenkefi for his suggestion -- my answer is more than half his :)

EDIT 3: @Ajay suggested to remove the "re" from "repaint". Two bytes less. We're getting there :)

\$\endgroup\$
  • 1
    \$\begingroup\$ We have to get it under HTML (so <290 right now) \$\endgroup\$ – Peter Lenkefi Oct 29 '15 at 23:05
  • 1
    \$\begingroup\$ @PeterLenkefi: Unfortunately, I can't save the braces of the cast; casting the sin/cos result directly breaks the computation. Your repaint inside paint() is incredibly dirty :) \$\endgroup\$ – Franz D. Oct 30 '15 at 8:45
  • 1
    \$\begingroup\$ @Troyseph I meant for golfing ;) I don't use java for anything. \$\endgroup\$ – Peter Lenkefi Oct 30 '15 at 14:41
  • 1
    \$\begingroup\$ Using int c,i and omitting the int in for(int i=.. should save some more. \$\endgroup\$ – Marco13 Nov 2 '15 at 11:25
  • 1
    \$\begingroup\$ You don't even need the class declaration for F, you can just extend the Frame class inline: new Frame(){...}. \$\endgroup\$ – Magic Octopus Urn Dec 1 '16 at 20:03
9
\$\begingroup\$

Haskell, 143 136 bytes

This uses the gloss package:

import Graphics.Gloss
main=animate(InWindow""(100,100)(0,0))white$ \t->color(makeColor 0.5 0 0.5 1).rotate(t*6).translate 38 0$circle 1

The prettier version is

import Graphics.Gloss

purple :: Color
purple = makeColor 0.5 0.0 0.5 1.0

main :: IO ()
main = animate (InWindow "" (100,100) (0,0)) white $ \t ->
    color purple . rotate (t * 6) . translate 38 0 $ circle 1
\$\endgroup\$
  • \$\begingroup\$ You can remove some whitespace. \$\endgroup\$ – rightfold Oct 30 '15 at 12:21
  • \$\begingroup\$ @Elyse Indeed, thanks. I also removed two unneeded .0. \$\endgroup\$ – Frerich Raabe Oct 30 '15 at 12:28
8
\$\begingroup\$

HTML (CSS?), 167 bytes

Inspired by insertusernamehere's answer

<style>body{position:fixed;left:50%;top:12%;width:1px;height:75vmin;border-top:1px solid #800080;animation:r 60s infinite linear}@keyframes r{to{transform:rotate(1turn

Ungolfed:

body {
    position: fixed;
    left: 50%;
    top: 12%;
    width: 1px;
    height: 75vmin;
    border-top: 1px solid #800080;
    animation: r 60s infinite linear;
}
@keyframes r {
    to {
        transform: rotate(1turn);
    }
}

\$\endgroup\$
  • \$\begingroup\$ Just a FYI, HTML + CSS is not usually considered a programming language, however it is up to the OP. \$\endgroup\$ – GamrCorps Oct 30 '15 at 3:49
  • 1
    \$\begingroup\$ It doesn't do anything on Firefox 41.0.2. \$\endgroup\$ – n̴̖̋h̷͉̃a̷̭̿h̸̡̅ẗ̵̨́d̷̰̀ĥ̷̳ Oct 30 '15 at 7:19
  • 1
    \$\begingroup\$ Just tested on Firefox 41.0.2, Win 10. Works fine for me. \$\endgroup\$ – Lachlan Arthur Oct 30 '15 at 7:28
  • 1
    \$\begingroup\$ Works for me in 41.0.2 in ubuntu. \$\endgroup\$ – user9206 Oct 30 '15 at 8:04
  • \$\begingroup\$ +1 Good thinking to just animate the body itself. :) \$\endgroup\$ – insertusernamehere Oct 30 '15 at 18:32
7
\$\begingroup\$

QBasic, 106

SCREEN 7
COLOR 5,15
DO
t=TIMER
CLS
PSET(99+99*COS(i),99+99*SIN(i))
i=i+ATN(1)/75
1IF TIMER<t+.1THEN 1
LOOP

Tested on QB64, which says it has a Linux version (though I've only tried it on Windows).

  • SCREEN 7 sets the graphics mode.
  • COLOR 5,15 sets dark magenta as foreground color and bright white as background color.
  • DO ... LOOP is an infinite loop. Usually you would see it as DO WHILE ... LOOP (or you can put LOOP WHILE instead, or use UNTIL for a negated condition), but you can also leave the condition out, in which case it loops forever.
  • TIMER is the number of seconds since midnight, as a floating-point value.
  • CLS = CLear Screen.
  • PSET SETs a Point to a color, foreground color by default.
  • i starts at zero and counts up by pi/300 each time through the loop, thus completing a full circle after 600 repetitions. We calculate pi as 4*arctan(1).
  • The last line waits until 0.1 seconds have elapsed. The idiom that I learned from my QBasic books was t# = TIMER: WHILE TIMER < t# + 0.1: WEND. But we don't need double-precision numbers (marked with #) for a 0.1-second difference, and it turns out that the IF cond THEN [GOTO] line syntax is 1 character shorter than a WHILE ... WEND loop.

The loop repeats 600 times in 60 seconds, thus completing a full circle.

Caveats

  • Color 5, dark magenta, is #8B008B instead of the requested #800080 (cleared with the OP).
  • Screen mode 7 is 320x200, and so the circle has diameter 198, which isn't >= 0.75 of the width but is >= 0.75 of the height (also cleared with the OP).
  • If you run this on DOS QBasic, it's fullscreen, so the "pixel" isn't actually a single pixel on the monitor (unless you happen to have a 320x200 monitor). But it should be close enough. QB64 runs in a window that uses the exact dimensions, and thus the pixel is a literal pixel.
  • In QB64 at least, this takes more like 65 seconds to make a complete revolution. I don't really know why; it must be either rounding errors or overhead on the loop, though I've tried mitigating both without success. In theory, the code should work correctly as-is. In practice, one can tweak the amount by which i is incremented until a revolution is close enough to 60 seconds. (Try a denominator of 69 or 68.)
  • No pretty picture here. :( LICEcap's quality wasn't good enough to capture a single pixel accurately.
\$\endgroup\$
  • \$\begingroup\$ This code works perfectly for me in Linux. Thank you. \$\endgroup\$ – user9206 Oct 29 '15 at 20:08
  • \$\begingroup\$ This actually runs in QBasic 4.5, but the background is not really white :) . Here is a GIF of it compiling and running: codegolf.square7.ch/altqb.gif \$\endgroup\$ – mınxomaτ Oct 29 '15 at 20:57
  • \$\begingroup\$ @mınxomaτ Odd, color 15 should give either white or light gray according to everything I thought I knew... that looks like light cyan (color 11). What does SCREEN 8 instead of 7 do? \$\endgroup\$ – DLosc Oct 29 '15 at 21:52
  • \$\begingroup\$ Same greenish background. But you're right, according to spec it should be white. I also tried color 7 (grey) and it came out as grey. So your solution is absolutely ok, but there's something wrong with my DOS. \$\endgroup\$ – mınxomaτ Oct 29 '15 at 21:59
7
\$\begingroup\$

mIRC script, 184 bytes

alias g {
window -p @m -1 -1 100 128
f
}
alias f {
inc %s 1
set %o $calc(%s *38/360)
clear @m
drawdot -r @m $rgb(128,0,128) 1 $calc($cos(%o)*38+50) $calc($sin(%o)*38+52)
.timer 1 1 f
}

This is optimised for mIRC in Wine. Start mIRC, press Alt + R then paste this, close the editor and run it with /g

Preview

The timing on the gif might be off.

\$\endgroup\$
  • \$\begingroup\$ This is a new one on me! It would be great if you could make an animated gif of it running. \$\endgroup\$ – user9206 Oct 30 '15 at 16:16
  • \$\begingroup\$ It was one of the first languages that I used/got me interested in coding! \$\endgroup\$ – Varis Oct 30 '15 at 17:48
6
\$\begingroup\$

R, 170 bytes

library(animation);for(i in 1:60){par(mar=rep(0,4));plot.new();t=2*pi*(1-i)/60;points(3*cos(t)/8+.5,3*sin(t)/8+.5,pch=19,col="#800080");ani.record()};repeat{ani.replay()}

It relies on package animation. And here 's a gif to show it works:

In a window

Invalid Solution saving to a gif (139 bytes):

animation::saveGIF({for(i in 1:60){par(mar=rep(0,4));plot.new();t=2*pi*(1-i)/60;points(3*cos(t)/8+.5,3*sin(t)/8+.5,pch=19,col="#800080")}})

This one requires ImageMagick to be installed. The result is saved to a gif.

![Round and round it goes

\$\endgroup\$
  • \$\begingroup\$ This is great however.. the challenge needs the code to write to the screen/window. \$\endgroup\$ – user9206 Oct 30 '15 at 10:39
  • \$\begingroup\$ Oh I didn't understand that. \$\endgroup\$ – plannapus Oct 30 '15 at 10:40
  • 1
    \$\begingroup\$ Here it is, in a window. \$\endgroup\$ – plannapus Oct 30 '15 at 10:51
6
\$\begingroup\$

Ruby with Shoes, 159 bytes

Shoes.app{animate{background stroke white
fill purple
r=0.75*c=self.width/2
t=Time.now
m=Math
rect c+r*m.sin(a=(t.sec+t.usec*1e-6)*m::PI/30),c-r*m.cos(a),2,2}}

The pixel is actually the tip of an analog clock's seconds hand. So this one is absolutely precise.

Ruby with Shoes, 134 bytes

m=Math
Shoes.app{animate{|f|r=0.75*c=self.width/2
background stroke white
fill purple
rect c+r*m.sin(a=f*m::PI/360),c-r*m.cos(a),2,2}}

This is a frames-per-seconds based alternative, inspired by the other answers. Although the documentation says the default fps is 10, practical tests shows it is actually 12.

Both solutions take “The width of the circle should be 0.75 (rounding suitably) the width of the screen or window” literally: calculate based on window width, so the pixel occasionally may leave the bottom of a non-square window. Not sure how such case is expected to be handled. (Use minimum of width and height? Walk on oval path?) The window starts with default 600 x 500 size and is resizable.

\$\endgroup\$
  • \$\begingroup\$ Very pleased to see a Ruby solution! Now we need Python, Perl,.... \$\endgroup\$ – user9206 Oct 30 '15 at 10:06
5
\$\begingroup\$

D, 286 280 bytes

(392 if written normally)

import simpledisplay,std.math;void main(){auto w=new SimpleWindow(100,100);auto c=50;auto r=c*2/3;int t;auto y=600/PI;w.eventLoop(50,{auto p=w.draw();p.clear;p.outlineColor=Color(128,0,128);p.drawPixel(Point(c+cast(int)(r*cos(t/y)),c+cast(int)(r*sin(t/y))));if(++t==1200)t=0;});}

Or the way I originally wrote it without golfing:

import simpledisplay, std.math;

void main() {
        auto window = new SimpleWindow(100, 100);
        auto c = window.width/2;
        auto r = c*2/3;
        int t;
        float cycle = 20*60/(PI*2);
        window.eventLoop(50, {
                auto p = window.draw();
                p.clear;
                p.outlineColor = Color(128, 0, 128);
                p.drawPixel(Point(c + cast(int) (r*cos(t/cycle)), c + cast(int) (r*sin(t/cycle))));
                if(++t == 20*60)
                        t = 0;
        });
}

Depends on simpledisplay.d and color.d located here: https://github.com/adamdruppe/arsd

Just download those two individual files and put them in your same directory as the above code, then: dmd yourfile.d simpledisplay.d color.d to compile and then just run it.

My little library was written to make quick animations like this fairly simple so this plays well to its strengths! Alas, I kinda like long identifier names and didn't provide a Point constructor that takes float so that adds 18 bytes casting and.... idk a couple dozen spelling out my method names.

\$\endgroup\$
  • 1
    \$\begingroup\$ The first argument to eventLoop btw is a millisecond timer. If it is non-zero, it automatically makes a timer for you and calls the function with zero args provided at that interval. (eventLoop can also take functions with MouseEvent or KeyEvent args to handle user input). So 50 millisecond interval = 20 frames per seconds, so 20 * 60 = cycle in 60 seconds. \$\endgroup\$ – Adam D. Ruppe Oct 29 '15 at 17:13
  • \$\begingroup\$ I think the way you have written the answer the leaderboard code picks up 392 instead of 280. \$\endgroup\$ – user9206 Oct 29 '15 at 21:53
5
\$\begingroup\$

C#, 379 365 bytes

using System.Windows.Forms;using static System.Math;class P:Form{static void Main(){var f=new P();var p=new PictureBox();f.SetBounds(0,0,1000,1000);f.Controls.Add(p);f.Show();for(var i=0d;;i+=PI/3000){p.SetBounds((int)(Cos(i)*375+500),(int)(Sin(i)*375+500),1,1);p.CreateGraphics().Clear(System.Drawing.Color.FromArgb(-8388480));System.Threading.Thread.Sleep(10);}}}

Depends on System.Windows.Forms and System.Drawing to run. Output is in a 1000x1000 window.

\$\endgroup\$
  • \$\begingroup\$ Can save some bytes using var \$\endgroup\$ – pinkfloydx33 Oct 31 '15 at 11:06
  • \$\begingroup\$ Save another byte using static import on system math \$\endgroup\$ – pinkfloydx33 Oct 31 '15 at 12:51
  • \$\begingroup\$ you can declare your code in the System namespace and remove all other references to system and save i think 10 bytes \$\endgroup\$ – Phaeze Sep 28 '17 at 22:50
5
\$\begingroup\$

SVG, 177 bytes

<svg><g transform=translate(75,75)><circle id=x r=.5 cx=56 fill=#800080><animateTransform xlink:href=#x attributeName=transform type=rotate to=360 dur=60s repeatCount=indefinite

Invalid markup from hell to breakfast, but it runs (in Chrome at least). Like a HTML5 canvas, the default size for an SVG appears to be 300x150, so that's what this is assuming.

Edit: Whoops, I'd accidentally left in a duration of 6 instead of 60. Fixed that, but also found that 0.5 works as just .5, so no change in the byte count.

\$\endgroup\$
5
\$\begingroup\$

X86 Machine-code - 150 146 149 133 127 bytes

Golfed version:

        00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
        --------------------------------------------------------------------
0000    B0 13 CD 10 BA C9 03 88 F1 BE 76 01 F3 6E B0 0F - °.Í.ºÉ.ˆñ¾v.ón°.
0010    49 68 00 A0 07 F3 AA 64 66 A1 6C 04 66 A3 80 01 - Ih. .óªdf¡l.f£€.
0020    64 66 A1 6C 04 66 2B 06 80 01 66 50 89 E5 D9 EB - df¡l.f+.€.fP‰åÙë
0030    D8 C0 DA 4E 00 DE 34 D9 FB BB 7D 01 DE 0F DE 47 - ØÀÚN.Þ4Ùû»}.Þ.ÞG
0040    FE DF 5E 02 DE 0F DE 47 FE DF 5E 00 5F 69 FF 40 - þß^.Þ.ÞGþß^._iÿ@
0050    01 58 01 C7 BB 88 01 8B 0F 39 CF 74 C3 30 C0 AA - .X.Ç»ˆ.‹.9ÏtÃ0Àª
0060    4F 89 3F 89 CF B0 0F AA 31 C0 FE C4 CD 16 74 B0 - O‰?‰Ï°.ª1ÀþÄÍ.t°
0070    B8 03 00 CD 10 C3 20 00 20 44 04 64 00 4B 00    - ¸..Í.Ã . D.d.K.

'Ungolfed', source version:

; golfCrcl.asm
;
; - 16 bit implementation of an animated pixel that circumscribes a circle.
; - 127 bytes .COM file
;
;   - enhzflep -
;   31 Oct 2015 - initial
;               - set closest colour to desired #800080
;    2/3 Nov 2015 - removed unnecessary instuctions, used BX register to index mem by fpu
;               - removed .data section alignment, better register use in curPixel/lastPixel compares and calcs, reusing value of si after palette setting
[section .text]
[bits 16]
[org 0x100]
EntryPoint:
;   mov     fs, bx          ; bx is 0 on entry. Set fs seg register to this

    ; set graphics mode 320x200
    mov     al, 0x13
    int     0x10

    ; set colour #0 to be as close to the desired one as possible
    ; the vga palette registers are 6 bits by default (some models allow switching to 8 bits)
    ; therefore, we cant represent all of the 16.7m colours that we can in 24bit modes
    ; we're limited to 'just' 64*64*64 = 262,144 (256k) colours. Unfortunately, #800080 is not
    ; a colour we can represent exactly in mode13 or any other mode with 6 bit regs.
    mov     dx, 0x3c9
    mov     cl, dh
    mov     si, desiredCol
    rep     outsb                           ; cx now=0 and si now points to totalTicksNeeded

    ; clear the screen to white
    mov     al, 0x0f                        ; index of a colour thats already FF,FF,FF
;   xor     cx, cx                          ; cx = 0 - its zeroed by the rep outsb instruction above.
    dec     cx                              ; cx = FFFF
    push    word 0xA000                     ; segment of video memory
    pop     es                              ; pop it into es
    rep     stosb                           ; es:[di] = 0F, inc di, dec cx. If cx != 0 then repeat.

    ; setup the timing stuff
    mov     eax, [fs:0x046C]                ; 32 bit value updated at 18.2Hz by bios
    mov     [initialTicks], eax

.drawLoop:
    mov     eax, [fs:0x046C]                ; 32 bit value updated at 18.2Hz by bios
    sub     eax, [initialTicks]             ; eax = curTime-startTime (in increments of 1/18.2 of a second --- 182 = 10 seconds)

    push    eax                             ; number of elapsed clock ticks - ready to be loaded by fpu. Also stack space for calc result
    mov     bp, sp                          ; get pointer to last element pushed onto the stack
    fldpi                                   ; st0 = pi
    fadd    st0                             ; st0 = 2pi
    fimul   long [bp]                       ; (currentTick/requiredTicks) * 2pi
;   fidiv   word [totalTicksNeeded]
    fidiv   word [si]                       ; si still points to totalTicksNeeded after setting the palette earlier
    fsincos                                 ; st0 = cos(old_st0), st1 = sin(old_st0)

    mov     bx, radius
    fimul   word [bx]                       ;   fimul word [radius] -  cos(angle)*radius
    fiadd   word [bx-2]                     ;   fiadd word [origin] -  origin + cos(angle)*radius
    fistp   word [bp+2]                     ; ---- X-coord -------

    fimul   word [bx]                       ;   fimul   word [radius]
    fiadd   word [bx-2]                     ;   fiadd   word [origin]
    fistp   word [bp+0]                     ;  ---- Y-coord -------

    ;---------------
    pop     di                              ; calculated Y-coord
    imul    di, 320                         ; multiply it by the screen width
    pop     ax                              ; calculated X-coord
    add     di, ax                          ; di = x + (pixels_per_row * y_coord)

    mov     bx, lastIndex
    mov     cx, [bx]                        ; get the mem index for the last pixel
    cmp     di, cx                          ; check if we're indexing the same pixel as last time through the loop
    je      .drawLoop                       ; if so, return to start of loop - no need to delete and redraw the pixel in the same spot.

    xor     al, al                          ; col index 0
    stosb                                   ; draw our purple pixel
    dec     di                              ; stosb advanced di to the next pixel, undo this (stosb followed by dec di is still shorter than mov es:[di], al)
    mov     [bx], di                        ; save the pixel's mem address
    mov     di, cx                          ; restore index of pixel drawn last time through the loop
    mov     al, 0x0f                        ; pal index of white
    stosb                                   ; erase the last pixel

    ; check for a keystroke
    xor     ax, ax
    inc     ah
    int     0x16
    jz      .drawLoop                           ; loop if no keys pressed

.drawingDone:
    ; set text mode 80x25
    mov     ax, 0x3
    int     0x10

    ; program exit
    ret                                     ; Dos pushes a 0000 onto the stack and copies CD 20 to offset 0 of our code-seg
                                            ; before it invokes our program. ret jumps back to that CD 20 (int 0x20) instruction

; Since this is a .COM file, all program, data and stack exist in the same segment. 
; Using .text and .data sections only improves program readability - doing so only has minor effects on the binary produced.
;
; In this case, the assembler word aligns anything in the data section. This may have the effect of adding a padding byte,
; which we really dont need/want here. Data is machine-word aligned to improve the speed of access for the hardware. Machine-word
; is used to refer to the size of an int. In the case of 16 bit code, this will generally be 16 bits, 32 bit code has 32 bit words
; and so on. This code is 16 bit, so things should be aligned to word boundaries for maximum execution speed
;
;[section .data]
desiredCol          db  0x80/4, 0x00, 0x80/4        ; palette registers are only 6 bit.
totalTicksNeeded    dw  1092
origin              dw  100
radius              dw  75

; ticks/second = 18.2
; totalTime = 60 seconds
; totalTicks = 1092 (18.2 * 60)
; degreesPerTick = 360 / 1092 = 0.3296703
; timerTicksAddr = 0040:006C (0000:046C) dword
[section .bss]
initialTicks    resd    1
lastTickValue   resd    1
lastIndex       resw    1

Downloadable, base64 encoded version

data:application/octet-stream;base64,sBPNELrJA4jxvnYB826wD0loAKAH86pkZqFsBGajgAFkZqFsBGYrBoABZlCJ5dnr2MDaTgDeNNn7u30B3g/eR/7fXgLeD95H/t9eAF9p/0ABWAHHu4gBiw85z3TDMMCqT4k/ic+wD6oxwP7EzRZ0sLgDAM0QwyAAIEQEZABLAA==

Copy and paste this address into your browser. Rename the resulting file golfcrcl.com and run in a DOS environment, i.e DosBox.

\$\endgroup\$
  • \$\begingroup\$ This is great! Tested and works perfectly. \$\endgroup\$ – user9206 Oct 30 '15 at 20:52
  • 1
    \$\begingroup\$ Oh snap! Just realized that you specified a colour to use and I totally ignored it. :oops: I'll fix that a little later. The colour index should be 0x5C, instead of 0x09 (assuming dosbox sets the pallette correctly, otherwise, I'll just remap colour 1) \$\endgroup\$ – enhzflep Oct 30 '15 at 21:00
4
\$\begingroup\$

Mathematica 208 185 139 bytes

Moves a purple pixel around an array used as an Image.

Method 1 139 bytes

n=900;Dynamic@Refresh[t=DateValue@"Second";ReplacePixelValue[Image@Array[1&,{n,n}],
400{Cos[z=Pi/30t],Sin@z}+450->Purple],UpdateInterval->1]

Method 2 154 bytes

Plots a pixel along a circular path in 60 seconds.

Dynamic@Refresh[t=DateValue@"Second";Graphics[{AbsolutePointSize@.01,Purple, 
Point[{Cos[z=Pi/30t],Sin@z}]},PlotRange->1,ImageSize->Full],UpdateInterval->1]

Method 3 193 bytes

This draws a clock, with ticks and labels in white, for which the second hand is a pixel.

Dynamic@Refresh[ClockGauge[AbsoluteTime[],TicksStyle->White, 
GaugeMarkers->{None,None,Graphics[{White,Disk[],Purple, 
AbsolutePointSize[.01],Point@{3,0}}]},PlotTheme->"Minimal"],UpdateInterval->1]
\$\endgroup\$
  • \$\begingroup\$ I see, basic LTR confusion... But anyways, you can remove the space between 30 and t. \$\endgroup\$ – LegionMammal978 Nov 1 '15 at 12:36
4
\$\begingroup\$

Obj-C++ / Cocoa, 777 678 668 657 643 628 bytes

#include <Cocoa/Cocoa.h>
float r;@implementation V:NSView-(void)drawRect:(NSRect)d{CGContext*c=(CGContext*)NSGraphicsContext.currentContext.graphicsPort;CGContextSetRGBFillColor(c,.5,0,.5,1);CGContextFillRect(c,(CGRect){cos(r)*38+50,sin(r-=pi/300)*38+50,1,1});[NSTimer scheduledTimerWithTimeInterval:.1 target:self selector:@selector(x)userInfo:0 repeats:0];}-(void)x{self.needsDisplay=1;}@end
int main(){NSRect b={0,0,100,100};NSWindow*w=[[NSWindow alloc]initWithContentRect:b styleMask:1 backing:2 defer:0];[w orderFront:0];w.backgroundColor=[NSColor whiteColor];w.contentView=[[V alloc]initWithFrame:b];[NSApp run];return 0;}

So this is probably the worst way to do anything, but I figured I'd try.

Can be compiled on a Mac (mine anyway) with g++ -framework Cocoa file.mm and run from the terminal (ctrl-C to quit, since it's not an app).

screenshot

Edit: Saved 99 bytes: Fixed main() to run on OS X 10.10 (1st version only ran on 10.8), skipped translate/rotate in favor of plain trig calculations, stopped bothering with window placement, and other small stuff.

Edit: Saved another 10 bytes: Changed to just orderFront to display the window. Doesn't actually make it the front window, though, but neither did orderFrontAndMakeKey, so...

Edit: Saved another 11 bytes: Skipped NSMakeRect and found a digit that just had to go.

Edit: Saved another 14 bytes: Didn't need to assign the NSTimer instance to anything, and can apparently skip initializing r to zero.

Edit: Saved another 15 bytes: I can't stop. Send help.

\$\endgroup\$
  • \$\begingroup\$ Thank you. Obj-C++ is the clear winner in the longest shortest code competition currently! \$\endgroup\$ – user9206 Nov 1 '15 at 19:48
  • 14
    \$\begingroup\$ +1 for also winning the most animated non-animated image competition. \$\endgroup\$ – Lynn Nov 1 '15 at 19:52
4
\$\begingroup\$

Javascript / Processingjs, 175 173 156 153 152 bytes

var s=256,e,h,m;void setup(){size(s,s);h=s/2;}void draw(){background(-1);m=-millis()*(PI/36000);stroke(h,0,h);e=s/2*0.75;point(h+sin(m)*e,h+cos(m)*e);}

To run : either visit http://www.openprocessing.org/sketch/226733 to see it in action using processing.js, or download processing 2.0 from processing.org, paste the code into the processing IDE, select Javascript mode and watch it go.

\$\endgroup\$
  • \$\begingroup\$ Lol, you posted Processing 20 seconds before me. \$\endgroup\$ – PurkkaKoodari Oct 29 '15 at 14:51
  • \$\begingroup\$ Is the header wrong in this answer? It doesn't show up in the leaderboard. \$\endgroup\$ – user9206 Oct 29 '15 at 14:56
  • 1
    \$\begingroup\$ Missed that, i'm on it now. \$\endgroup\$ – Timothy Groote Oct 29 '15 at 15:08
  • 1
    \$\begingroup\$ it should now meet the 60 seconds requirement \$\endgroup\$ – Timothy Groote Oct 29 '15 at 15:44
  • 1
    \$\begingroup\$ background(-1) is one byte shorter than background(255) \$\endgroup\$ – Cows quack Apr 23 '17 at 15:25
3
\$\begingroup\$

Elm, 274 bytes

import Color exposing (..)
import Graphics.Collage exposing (..)
import Time exposing (..)
main=Signal.map((\t->collage 200 200 [move(75*cos(-2*pi*t/60),75*sin(-2*pi*t/60))(filled(rgb 128 0 128)(circle 2)),outlined(solid black)(square 200)])<<inSeconds)(every(0.01*second))

Try or edit it in your browser:

Note that if we get rid of the imports and drawing the outline around the canvas, we're down to 149 bytes, but that's probably cheating!

\$\endgroup\$
  • \$\begingroup\$ Whoops, fixed! I got impatient during testing \$\endgroup\$ – jmite Oct 30 '15 at 6:01
  • 1
    \$\begingroup\$ This is very nice and it's great to get something in a functional language. We just need Haskell and Scala now! \$\endgroup\$ – user9206 Oct 30 '15 at 9:48
  • 2
    \$\begingroup\$ @Lembik I just added a Haskell version \$\endgroup\$ – Frerich Raabe Oct 30 '15 at 11:38
3
\$\begingroup\$

C#, 301 bytes

using System.Windows.Forms;using System.Drawing;class P:Form{static void Main(){Application.Run(new P());}P(){Paint+=(o,e)=>{var g=e.Graphics;g.Clear(Color.White);g.TranslateTransform(150,150);g.RotateTransform(System.DateTime.Now.Second*6);g.FillRectangle(Brushes.Purple,105,0,1,1);Invalidate();};}}

Depends on default size metrics; size and position may be a bit off depending on a number of factors. May or may not flicker horribly; to solve that, add the following:

SetStyle(ControlStyles.OptimizedDoubleBuffer|ControlStyles.AllPaintingInWmPaint,true);
\$\endgroup\$
3
\$\begingroup\$

Lua + Löve, 189 characters

t=0
m=math
l=love
g=l.graphics
function l.update(d)t=t+d end
function l.draw()a=t*m.pi/30
g.setBackgroundColor(255,255,255)g.setColor(127,0,127)g.point(400+225*m.cos(a),300+225*m.sin(a))end

love.update() receives as parameter the time elapsed since previous frame. Draws in the default 800 x 600 window at fixed coordinates, as the window is not resizable anyway.

\$\endgroup\$
  • \$\begingroup\$ The first lua answer! Thank you. \$\endgroup\$ – user9206 Oct 31 '15 at 15:40
3
\$\begingroup\$

Python 2 + Pygame, 221 198 193

exec'from %s import*;'*3%('math','pygame','time')
_,p,D=[255],128,display
S=D.set_mode(_*2)
while 1:S.fill(_*3);S.set_at(map(lambda f:int(p+f(pi*(time()%60)/30)*96),(cos,sin)),(p,0,p));D.flip()
\$\endgroup\$
  • 1
    \$\begingroup\$ Pythontastically awesome! \$\endgroup\$ – user9206 Oct 31 '15 at 10:37
  • \$\begingroup\$ Now we just need a python+turtle solution too. \$\endgroup\$ – user9206 Oct 31 '15 at 14:35
3
\$\begingroup\$

C (using SDL1.2), 237 233

#include <SDL.h>
#define P(f)(int)(128+96.0*f(3.14*((int)(.001*SDL_GetTicks())%60)/30))
main(){SDL_Surface*s=SDL_SetVideoMode(255,255,32,0);while(1){int*p=s->pixels;memset(p,255,260100);p[P(cos)+s->w*P(sin)]=0x800080FF;SDL_Flip(s);}}

Compiles & run using gcc -I/usr/include/SDL snippet.c -lSDL -lm && ./a.out

\$\endgroup\$
  • \$\begingroup\$ Awesomely great! I thought no one would do it. \$\endgroup\$ – user9206 Nov 1 '15 at 13:36
2
\$\begingroup\$

ActionScript 2.0, 151 bytes

Unfortunately, Adobe Flash isn't freeware, and Google informs that it doesn't work on Linux without a VM or Wine (and even with Wine, it only mostly works). Still, I wanted to see how well it would do on this task. Pretty well, it turns out.

createEmptyMovieClip("p",0)
p._x=p._y=r=200
p.beginFill(0x800080)
p.moveTo(r,0)
p.lineTo(r-1,0)
p.lineTo(r,1)
onEnterFrame=function(){p._rotation+=.25}

The basic idea: create a new movie clip object, position it at (200, 200), and then draw a dot2 in it 200 pixels farther right. Now the movie clip is 200 pixels wide and 1 pixel high. The pivot point is the original coordinates where we started, so when we modify the _rotation property, the dot moves in a circle around the point (200, 200). Conveniently, _rotation is in degrees; 0.25 degrees/frame * 24 frames/second * 60 seconds/minute = 360 degrees/minute.

To run from scratch if you have Flash, create a new Flash document1, open the Actions panel, and paste the above code. No further customization is required, assuming the default white background, 550x400 canvas, and 24 fps. Hit Ctrl-Enter and watch it go.

If you don't have Flash itself, you can still view the results with the free Flash Player, which should come with most modern browsers. Download the SWF file here. If you can't play it, try downloading this HTML page as well and opening it, with the SWF file in the same directory.

1 Tested on Adobe Flash CS4 Professional, choosing "Flash File (ActionScript 2.0)" when asked what type of new file to create.

2 Actually a small triangle, as you'll see if you zoom in on it enough. It was the golfiest way I could find to draw a dot.

\$\endgroup\$
2
\$\begingroup\$

JavaScript w/jQuery, 205 bytes

y=75;with($('<canvas/>').appendTo(document.body)[0].getContext('2d')){fillStyle='#800080';translate(y,y);(f=function(){clearRect(-y,-y,y*2,y*2);fillRect(0,56,1,1);rotate(Math.PI/300);setTimeout(f,100)})()}

jsfiddle, snippet below

This is maybe not quite by the book. The default size of a canvas (in Chrome at least) is 300x150, so I've centered the circle on 75x75. I could center it on 150x75, and make its radius 113px (~75% of width), but it'd be outside the canvas some of the time, so I chose ~75% of height instead.

But it's not particularly short anyway, so meh'

y=75;with($('<canvas/>').appendTo(document.body)[0].getContext('2d')){fillStyle='#800080';translate(y,y);(f=function(){clearRect(-y,-y,y*2,y*2);fillRect(0,56,1,1);rotate(Math.PI/300);setTimeout(f,100)})()}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

\$\endgroup\$
2
\$\begingroup\$

Blitz 2D/3D, 126 bytes

Graphics 180,180
ClsColor 255,255,255
Color 128,0,128
While 1
Cls
ang#=ang+3
Plot 90+67*Cos(ang),90+67*Sin(ang)
Delay 500
Wend

Unfortunately, this language is only supported on Windows (though it may run in Wine).

\$\endgroup\$
2
\$\begingroup\$

Javascript ES6, 202 bytes

a=0;with((D=document).body.appendChild(D.createElement`canvas`).getContext`2d`)with(Math)setInterval((f=t=>t(a+=PI/6e3)*60+75)=>fillRect(f(cos,clearRect(0,0,150,150),fillStyle=`#800080`),f(sin),1,1),10)

Tested in Firefox 41.

Like the other (almost) pure Javascript answer, the circle is centered at 75x75 since the canvas elements default size is 300x150 as defined by the HTML specs.

\$\endgroup\$
2
\$\begingroup\$

Matlab, 141 136

I just submit this for you, Lembik, to have a complete list.

v=-100:100;
[y,x,m]=ndgrid(v,v,0);
n=75;
while 1;
    pause(1);
    c=m;
    c(x+i*y==round(n))=1;
    imshow(c);
    colormap([1,1,1;.5,0,.5]);
    n=n*exp(pi*i/30);
end

Old version:

v=-100:100;
[x,y,m]=ndgrid(v,v,0);
while 1;
c=m;
c(x+i*y==round(75*(-1)^(s/30)))=1;
imshow(c);
colormap([1,1,1;.5,0,.5]);
s=mod(s-1,60);
pause(1);
end
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy