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
  • 19
    \$\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

2
\$\begingroup\$

PHP, 291 295 bytes

I don't know whether this qualifies, but here is something:

function d($y,$a){$s=strrev(str_pad("
",140));echo"\033[0G".str_repeat($s,abs($y-30)).str_pad("\033[35m■",80+$a*sqrt(abs(pow(30,2)-pow($y,2)))*2,' ',STR_PAD_LEFT)."
".str_repeat($s,abs(30+$y))."\033[120A";usleep(5e5);}for(;;){for($y=30;$y>-30;--$y)d($y,1);for($y=-30;$y<=30;++$y)d($y,-1);}

Runs as a PHP-file from command line, like:

php what_is_this.php

In Action

This examples GIF runs 10 times faster than the original code (usleep(5e4) instead of usleep(5e5)):

enter image description here


Notes

  • As I can't output one single pixel, I supersized it to this .
  • One cycle should be approx. 1 minute.
  • Yes, your whole console output is purple. ;)
  • You need a large terminal window. If you're on OS X zoom out at least one or two times using CMD + - (Restore using CMD + 0).
  • It doesn't know anything about 75%. Could be simulated by adding blank lines before and after the output.

Yes, it is rounding heavily and yes I think this can be golfed more, but I'm too tired right now. :)


Ungolfed

function d($y,$a){
    $s = strrev(str_pad("\n",140));
    echo "\033[0G";
    echo str_repeat($s, abs($y-30));
    echo str_pad("\033[35m■", 80 + $a * sqrt(abs(pow(30,2) - pow($y,2)))*2,' ', STR_PAD_LEFT) . "\n";
    echo str_repeat($s, abs(30+$y));
    echo "\033[120A";
    usleep(500000);
}

for(;;){      
    for($y = 30; $y > -30; --$y) {
        d($y,1);
    }
    for ($y = -30; $y <= 30; ++$y) {
        d($y,-1);
    }
}

Edits

  • Saved 4bytes by throwing some {} over board.
\$\endgroup\$
  • \$\begingroup\$ A PHP solution! I thought it would never come :) \$\endgroup\$ – user9206 Oct 31 '15 at 8:20
2
\$\begingroup\$

Tcl/Tk, 174

grid [canvas .c -bg #FFF -he 202 -w 202]
.c cr r 0 0 0 0 -outline #800080 -t p
while 1 {after 167;incr A;.c coo p [lmap r {cos sin cos sin} {expr 75*$r\($A/57.3)+77}]
update}

Tcl/Tk, 168

grid [canvas .c -bg #FFF -he 202 -w 202]
.c cr o 0 0 0 0 -f #800080 -t p
while 1 {after 167;incr A;.c coo p [lmap r {cos sin cos sin} {expr 75*$r\($A/57.3)+77}]
update}

Tcl/Tk, 172

grid [canvas .c -bg #FFF -he 202 -w 202]
set p [.c cr o 0 0 0 0 -f #800080]
while 1 {after 167;incr A;.c coo $p [lmap r {cos sin cos sin} {expr 75*$r\($A/57.3)+77}]
update}

Tcl/Tk, 173

grid [canvas .c -bg #FFF -he 202 -w 202]
set p [.c cr o 0 0 0 0 -f #800080]
while 1 {after 167;incr A;.c coo $p [lmap r {1.57 0 1.57 0} {expr 75*sin($A/57.3+$r)+77}]
update}

Tcl/Tk, 195

proc P {y\ 0} {expr 75*sin($::A/57.3+($y?0:1.57))+77}
grid [canvas .c -bg #FFF -he 202 -w 202]
set p [.c cr o 0 0 0 0 -f #800080]
while 1 {after 167;incr ::A;.c coo $p [P] [P 1] [P] [P 1]
update}

Tcl/Tk, 204

proc P {A y\ 0} {expr 75*sin($A/57.3+($y?0:1.57))+77}
grid [canvas .c -bg #FFF -he 202 -w 202]
set p [.c cr o 0 0 0 0 -f #800080]
while 1 {after 167;.c coo $p [P [incr A]] [P $A 1] [P $A] [P $A 1]
update}

Tcl/Tk, 210

proc P {A y\ 0} {expr 75*[expr $y?"sin":"cos"]($A/57.3)+77}
grid [canvas .c -bg #FFF -he 202 -w 202]
set p [.c cr o 0 0 0 0 -f #800080]
while 1 {after 167;.c coo $p [P [incr A]] [P $A 1] [P $A] [P $A 1]
update}

Tcl/Tk, 214

proc P {A y\ 0} {expr 75*[expr $y?"sin":"cos"]($A*3.14/180)+77}
grid [canvas .c -bg #FFF -he 202 -w 202]
set p [.c cr o 0 0 0 0 -f #800080]
while 1 {after 167;.c coo $p [P [incr A]] [P $A 1] [P $A] [P $A 1]
update}

enter image description here

\$\endgroup\$
  • \$\begingroup\$ Instructions for running: create the file pixround.tcl, paste my code and then save. Then on your graphical environment,open a console, go to the file you created's directory and type wish pixround.tcl and you should see the see pixel doing its round trip. \$\endgroup\$ – sergiol Sep 29 '17 at 1:07
  • \$\begingroup\$ I run your 168-byte code with Tk 8.6.6. I see a black pixel instead of a purple one. Your screenshot also has a black pixel. I checked by using xmag to magnify the pixel. \$\endgroup\$ – kernigh Nov 26 '17 at 22:35
  • 1
    \$\begingroup\$ @kernigh: fixed. At the expense of some bytes. \$\endgroup\$ – sergiol Nov 26 '17 at 23:23
1
\$\begingroup\$

Matlab, 104 103 102 bytes

figure('Color','w');while 1;plot(3*exp(toc*pi/30i),'Co',[.5 0 .5]);axis([-4 4 -4 4],'off');drawnow;end

Smallest I could get it with the colour requirements. If you had gone for magenta rather than purple it would be 12 bytes shorter :).

figure('Color','w');                        %Start with a white background
while 1
         3*exp(toc*pi/30i)                  %This bit makes the point - e^(theta/i)
    plot(                 ,'Co',[.5 0 .5]); %This plots it
    axis([-4 4 -4 4],'off');                %Make the axis 33% larger than the circle and invisible
    drawnow;                                %Update within the loop
end

Basically it creates a figure which has a white background. Then in a forever loop it plots a figure which is a single point of a complex number which has a magnitude of 3 and an angle of the current time normalised to a 60 second circle. The colour of the plotted point is purple (#7f007f). Once plotted, the axis are set to limits of +/-4 which means the circle drawn will be 75% of the axis size. The axes are then turned off (made invisible) and the figure updated. This gives a nice point moving around a circle in real time.

I've corrected the code so that it rotates clockwise (it was going anticlockwise before) and in the process saved a byte :). The wonders of -j*n = n/j.

\$\endgroup\$
1
\$\begingroup\$

GLSL (Shadertoy), 180 165 142 bytes

void mainImage(out vec4 a,in vec2 b){float r=-iGlobalTime/9.55;a=floor(vec2(cos(r),sin(r))*135.+vec2(180))==floor(b)?vec4(.5,0,.5,1):vec4(1);}

Try it out by pasting it here. Can't golf the built-in variables unfortunately.

I have never written anything WebGL/OpenGL, but I figured why not? Seems to work, but it's probably horrible.

Edit 1: Saved 15 bytes by skipping a variable, though it means the circle is no longer centered horizontally in the canvas, just offset the same as it is vertically.

Edit 2: Saved 23 bytes by also making it resolution dependent. Shadertoy's canvas is 640x360 by default.

\$\endgroup\$
  • \$\begingroup\$ @Lembik You're welcome - it's a neat challenge! Plus, I got to flail helplessly about in a language I've never tried - fun! :) \$\endgroup\$ – Flambino Oct 31 '15 at 14:58
1
\$\begingroup\$

javascript/html/css 343 202 182

s=document.getElementById('c').style
i=0
setInterval(function(){s.left=52+50*Math.cos(i+=.005)+'px'
s.top=52+50*Math.sin(i)+'px'},50)
b{color:#800080;position:absolute}
<b id=c>.</b>

\$\endgroup\$
  • \$\begingroup\$ If you look at the question or the other answers you will see how to set out the headers so your result can be put in the leaderboard. Having said that I think it is buggy currently. The dot jumps from one side to the other at least using the code snippet. \$\endgroup\$ – user9206 Oct 30 '15 at 20:32
  • \$\begingroup\$ You can save 4 bytes by dropping the var keyword and space. Globals are ok for golfing \$\endgroup\$ – Flambino Oct 31 '15 at 10:26
  • \$\begingroup\$ There are a couple of other minor changes which can reduce the code size: pastebin.com/1GPCA227 (By the way, the color code should be #800080.) \$\endgroup\$ – manatwork Oct 31 '15 at 12:09
1
\$\begingroup\$

SpecBAS, 103 bytes

1LET r=SCRh*.75/2,a=0:DO:PLOT INK 3;r*COS a+SCRw/2,r*SIN a+SCRh/2:INC a,TAU/60000:WAIT SCREEN:CLS:LOOP

INK 11 in SpecBAS isn't quite the right colour but it's close. Other than that, this is pretty standard stuff. A single pixel isn't easy to see on an 800x480 screen though!

\$\endgroup\$
  • 1
    \$\begingroup\$ Sinclair BASIC! We are close to the source now... :) \$\endgroup\$ – user9206 Nov 2 '15 at 12:18
  • 1
    \$\begingroup\$ I wrote an interpreter a while ago (actually still am) and I'm always looking out for fun stuff to do with it - this site is an absolute goldmine :) \$\endgroup\$ – ZXDunny Nov 3 '15 at 13:09
1
\$\begingroup\$

Python 2, 173 bytes

exec"from %s import*;"*3%("time","math","turtle")
color("#800080")
pu()
shape("square")
shapesize(.1)
while 1:r=screensize()[0]*.75;a=-time()%60/9.55;goto(r*cos(a),r*sin(a))

Here's an answer which uses the turtle module. Unfortunately I can't remember how big the turtle's square pen is, so I hope I scaled it down right (I'm passing .1 into shapesize).

As a bonus, here's an invalid 163 byte version which skips out on the math module but the turtle blinks a lot:

from time import*
from turtle import*
color("#800080")
pu()
shape("square")
shapesize(.1)
speed(0)
while 1:ht();home();rt(time()%60*6);fd(screensize()[0]*.75);st()
\$\endgroup\$
  • \$\begingroup\$ Turtles all the way down! \$\endgroup\$ – user9206 Nov 2 '15 at 17:06
1
\$\begingroup\$

VB.NET, 361 395 452 bytes

Thanks @ClickRick for pointing out all the unnecessary white-space :-)

Module m
Sub Main()
Dim f As New Form
f.BackColor=Color.White
f.MinimumSize=New Size(100,100)
f.ClientSize=New Size(100,100)
AddHandler f.Paint,Sub(r,g)
Dim u=Date.Now.Ticks/10000000/9.55,k=CInt(Cos(u)*37.5+37.5),l=CInt(Sin(u)*37.5+37.5)
g.Graphics.FillRectangle(Brushes.Magenta,k,l,1,1)
f.Invalidate()
End Sub
Application.Run(f)
End Sub
End Module

This is a console application that creates a form. This saves a lot of designer generated clutter.

Add a reference to System.Drawing.dll and System.Windows.Forms.dll. Add user Imports for System.Drawing, System.Windows.Forms and System.Math namespaces.

I shamelessly ripped the position calculation from Mauris' QB64 answer (https://codegolf.stackexchange.com/a/62126/20520), but based the calculation on Date.Now.Ticks instead, which needs to be converted to seconds by dividing by 10 million!

The form is refreshed by a timer and the dot is painted directly to the form in its Paint event. This saves a lot of initialization code for any picturebox or similar.

From user12864's answer in C# (https://codegolf.stackexchange.com/a/62433/20520) I got the idea of invalidating the form in its own paint handler, which is a horrible thing to do but gets rid of any need for a timer. The timer solution looked a lot prettier due to all the flickering induced by this solution...but length over style in Code Golf I guess :-)

Unfortunately, the forms have a larger default MinimumSize than 100,100, which needs to be adjusted to fullfill the requirement. You also need to set ClientSize instead of Size to correctly scale the "active" drawing surface.

Believe it or not, GDI+ does not have a simple DrawPoint function. You draw a point by drawing a filled 1x1 rectangle.

Application.Run() starts the message loop for the form and shows it.

\$\endgroup\$
  • \$\begingroup\$ 34 redundant spaces. Gotta love auto-format :D \$\endgroup\$ – ClickRick Nov 2 '15 at 14:06
  • \$\begingroup\$ @ClickRick Wups, yeah you're right about that. First code-golf submission, it shows I guess ;-) \$\endgroup\$ – Jens Nov 2 '15 at 14:35
1
\$\begingroup\$

Qt Quick via qmlscene, 315

import QtQuick 2.5
Rectangle {id:p;visible:true;property double t: 0.0; Rectangle{width: 4;y: p.height / 2 + .75*p.height/2*Math.sin(p.t);x: p.width / 2 + .75*p.height/2*Math.cos(p.t);height: 4;color: "#800080"}NumberAnimation {target: p;property: "t";from: 0; to:3.14159*2;duration: 60000;loops: -1;running: true}}
\$\endgroup\$
  • \$\begingroup\$ Another language I had never heard of! Thank you. \$\endgroup\$ – user9206 Nov 7 '15 at 7:13
1
\$\begingroup\$

Progress ABL, character Interface, 445 bytes

A couple of comments:

I have no way in ABL to really work with pixels. It could possibly be done by creating a rectangle that's 1 x 1 pixel and moving it around. But even that would be cumbersome. Instead I choose to use a period character (.): hence this solution is for character interface and not a graphic client. Maybe I'll come back with a graphical solution some other time...

Since the space of one character is higher than it is wide I've set the screen size to 65 columns by 20 rows. Roughly estimating a square.

Purple colour is another problem. From start I'm limited to 16 preset colors and none match the purple I need. Changing the colors in character mode is done by editing a init file used when starting the program. Therefore I instead set the period to "color 13" - 255,0,255 by default. Not the wanted purple but at least a purple color.

Another dilemma is the absence of sine and cosine functions or anything remotely like that (rotate etc). To bypass this I choose to call an external Windows DLL - meaning this specific solution only works in Windows environments. However if there are any similar Linux libraries available it should be easy enough to port.

Of course I've been "inspired" by solutions in other languages to pull this off...

My main ways of reducing size:

  • Shortening certain statements, ie DISP instead of DISPLAY.
  • Global definitions (preprocessors).
  • Whitespace and line breaks

This is my first attempt at Golf so I might very well be doing something wrong here - like byte count or otherwise. Please tell me if so!

Solution:

&GLOB v DEF VAR
&GLOB e EXTERNAL "MSVCRT40.DLL" CDECL: 
PROCE cos {&e} DEF INPUT PARAM v AS DO. DEF RETURN PARAM r AS DO. END. PROCE sin {&e} DEF INPUT PARAM v AS DO. DEF RETURN PARAM r AS DO. END. {&v} c AS C FORM "x". {&v} t AS DE. {&v} i AS DE. {&v} j AS DE. c=".". REPEAT: t=t - 0.1. DISP c NO-LABEL WITH FRAM f SIZE 65 BY 20. c:FGC=13. RUN cos(T, OUTPUT i). RUN sin(t, OUTPUT j). c:ROW=10 + i * 7.5. c:COLUMN=30 + j * 26.3. PAUSE 1. END

Ungolfed:

&GLOBAL-DEFINE v DEFINE VARIABLE
&GLOBAL-DEFINE e EXTERNAL "MSVCRT40.DLL" CDECL: 


PROCEDURE cos {&e} 
    DEFINE INPUT PARAM v AS DOUBLE. 
    DEFINE RETURN PARAM r AS DOUBLE. 
END. 

PROCEDURE sin {&e} 
    DEF INPUT PARAM v AS DOUBLE. 
    DEF RETURN PARAM r AS DOUBLE. 
END. 

{&v} c AS CHARACTER FORMAT "x". 
{&v} t AS DECIMAL. 
{&v} i AS DECIMAL. 
{&v} j AS DECIMAL. 

c = ".". 

REPEAT: 
    t = t - 0.1. 
    DISPLAY c NO-LABEL WITH FRAM f SIZE 65 BY 20. 
    c:FGCOLOR = 13. 
    RUN cos(T, OUTPUT i). 
    RUN sin(t, OUTPUT j). 
    c:ROW = 10 + i * 7.5. 
    c:COLUMN = 30 + j * 26.3. 
    PAUSE 1. 
END

(All lines normally end with period or colon (colon for start of blocks) but the compiler lets this slip on the very last line...)

The preprocessor statements are basically pre run/compile replacements so {&v} in the part {&v} t AS DE. is replaced with DEF VAR rewriting the entire line to

DEF VAR t AS DE. 
\$\endgroup\$
1
\$\begingroup\$

SmileBASIC, 70 bytes

G=99@L
A=A+1745E-6GCLS
GPSET G+COS(A)*G,G+G*SIN(A),#PURPLE
WAIT
GOTO@L

Luckily #PURPLE is exactly FF800080
1745E-6 is an approximation of 2pi/(60*60)

\$\endgroup\$
1
\$\begingroup\$

Processing, 101 100 bytes

float r;void draw(){background(-1);translate(50,50);stroke(#800080);rotate(r+=PI/1800);point(0,38);}

Instead of the sin/cos calculations, this uses the translate and rotate methods. Funnily enough, it ends up being 101 bytes just like Pietu1998's Processing code.1

I wish rotate calls would stack so I could skip r, but the transformation matrix is reset on each frame. Boo.

1: Well, at the time of writing it's the same, but there are 4 bytes to be saved in Pietu1998's, so it wins.

Edit: Saved a byte thanks to Kritixi Lithos

\$\endgroup\$
  • \$\begingroup\$ background(-1) is one byte shorter than background(255) \$\endgroup\$ – Cows quack Apr 23 '17 at 15:22
  • \$\begingroup\$ @KritixiLithos Thanks - updated this answer as well as the other one you commented on \$\endgroup\$ – Flambino Apr 23 '17 at 15:52
1
\$\begingroup\$

LOGO, 58 bytes

A language of turtle graphics.

settimer 1 50[setpixel 7 arc2 .3 99 setpixel "purple]ht pu

Unfortunately, I can't find any webpage (LOGO interpreter) support settimer, and this one does not support turtle-graphics. However you can download UCBLogo or FMSLogo and test.

Alternatively, this version is compatible with JSLogo (which can be try online):

setpc "purple
forever[pe setpensize 9 bk 99 rt 1 fd 99 ppt setpensize 1 fd 0 wait 10]

Because the pixel almost can't be seen, you can use this version instead:

setpc "purple
forever[pe setpensize 9 bk 99 rt 1 fd 99 ppt setpensize 5 fd 0 wait 1]

Which increases the pixel size and make it moves 10x faster.


Explanation:

settimer 1 50[   For each 50 millisecond, do:
setpixel 7       Set the color under the turtle to white (color 7). Alternatively: "white (6 bytes) or [255 255 255] (too many bytes)
arc2 .3 99       Rotate 0.3 degrees around a circle with radius 99
setpixel "purple Set the pixel under the turtle to purple (800080).
                 Color magenta (FF00FF, if allowed) would takes much less bytes (just 1 bytes: "5")
]                End instruction-list.
ht               Hide the turtle. Avoid drawing the turtle on the screen together with the pixel.
pu               Pen-up. Avoid the turtle leave a trail while moving.
\$\endgroup\$
1
\$\begingroup\$

Pascal (FPC), 216 bytes

Uses Graph,Crt;Var
a:Real;b,c:integer;Begin
b:=0;
InitGraph(b,c,'');SetRGBPalette(1,$80,0,$80);repeat
a:=a+Pi/500;b:=Trunc(60+50*sin(a));c:=Trunc(60+50*cos(a));PutPixel(b,c,1);Delay(60);PutPixel(b,c,0);until 1<0
End.

Ungolfed code and explanation here on TIO. Can't run on TIO, however.

\$\endgroup\$
  • \$\begingroup\$ Need <s> Pascal now. \$\endgroup\$ – user202729 Oct 30 '17 at 4:34
1
\$\begingroup\$

Ruby+RMagick+FFmpeg, 203 bytes

include Magick
a=ImageList.new
600.times{|i|Draw.new.fill('purple').translate(80,80).rotate(i*0.6).point(60,0).draw(a.new_image(160,160))}
a.delay=10
a.write'c.gif'
system'ffplay -loop 0 c.gif'

Run with ruby -rrmagick circle.rb; I count 193 bytes in the file, plus 10 bytes to edit ruby circle.rb into ruby -rrmagick circle.rb. This is longer than Ruby with Shoes (134 bytes).

Before running this program, you must install ImageMagick, ffmpeg, ruby, then run gem install rmagick. Ubuntu user would need some dev packages. The program takes a few minutes to save the c.gif file, then displays it in ffplay's window. It leaves c.gif in the current directory.

Commented version

require 'rmagick'
include Magick  # for Magick::ImageList, Magick::Draw

# Draw 600 frames.
a = ImageList.new
600.times {|i|
  Draw.new
    .fill('purple')     # Set fill color to #800080.
    .translate(80, 80)  # Move origin to center of circle.
    .rotate(i * 0.6)    # Rotate axes by 0...360 degrees.
    .point(60, 0)       # Draw pixel in fill color.
    .draw(a.new_image(160, 160))
  # Draw image of 160x160 pixels on the default white background.
}

# Set delay between frames to 10 ticks.
# By default, 100 ticks = 1 second.
# Therefore, 600 frames at 10 ticks = 60 seconds.
a.delay = 10

a.write 'c.gif'
system 'ffplay -loop 0 c.gif'

If I use a.animate, then RMagick displays the animation in its own window, but the timing is too slow. The circle takes about 66 seconds, not the correct 60 seconds.

To get the correct timing, I must add 36 bytes by deleting a.animate and adding code to save a .gif and display it in another program. If I run firefox c.gif or chrome c.gif, the timing is correct, but the white box of 160x160 pixels appears in the center of a much larger window, so the circle seems too small in the window. I run ffplay -loop 0 c.gif to get both the correct timing and the correct window size.

ImageMagick also comes with shell commands, so it might be possible to translate this answer into shell script, but I have not done so.

\$\endgroup\$
0
\$\begingroup\$

Haskell 265 bytes

Runs in a terminal and prints a @ which changes position.

It takes about 64 seconds to do a full loop but 999999 can be changed to fix this. If someone can be bothered working out the right number then feel free to change it.

import Control.Concurrent
f _ _ _ 0=[]
f a 0 x y=(g a x)++f a(-1)x(y-1)
f a b x y="\n"++f a(b-1)x(y-1)
g _ 0="\n"
g 0 x="\27[1;35m@"++g(-1)(x-1)
g a x=' ':g(a-1)(x-1)
main=h 0
h i=threadDelay 999999>>putStrLn(f(round$(sin i)*w+w)(round$(cos i)*w+w)(w*2+1)(w*2+1))>>h(i+0.1)
\$\endgroup\$
  • 1
    \$\begingroup\$ Pretty sure an @ doesn't count as a purple pixel. \$\endgroup\$ – nwp Nov 1 '15 at 11:07
  • \$\begingroup\$ It certainly doesn't. \$\endgroup\$ – user9206 Nov 1 '15 at 11:18
  • \$\begingroup\$ True, but nor does codegolf.stackexchange.com/a/62124/19083. It all depends on your terminal font anyway. \$\endgroup\$ – HEGX64 Nov 2 '15 at 22:39

Your Answer

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