Plasma effect: Difference between revisions

Content added Content deleted
(Added Forth entry)
m (syntax highlighting fixup automation)
Line 14: Line 14:


=={{header|AWK}}==
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
#!/usr/bin/awk -f
#!/usr/bin/awk -f


Line 94: Line 94:
printf("\n")
printf("\n")
}
}
</syntaxhighlight>
</lang>


=={{header|C}}==
=={{header|C}}==
===ASCII version for Windows===
===ASCII version for Windows===
If you don't want to bother with Graphics libraries, try out this nifty implementation on Windows :
If you don't want to bother with Graphics libraries, try out this nifty implementation on Windows :
<syntaxhighlight lang="c">
<lang C>
#include<windows.h>
#include<windows.h>
#include<stdlib.h>
#include<stdlib.h>
Line 137: Line 137:
return 0;
return 0;
}
}
</syntaxhighlight>
</lang>


===Graphics version===
===Graphics version===
And here's the Graphics version, requires the [http://www.cs.colorado.edu/~main/bgi/cs1300/ WinBGIm] library. Prints out usage on incorrect invocation.
And here's the Graphics version, requires the [http://www.cs.colorado.edu/~main/bgi/cs1300/ WinBGIm] library. Prints out usage on incorrect invocation.
<syntaxhighlight lang="c">
<lang C>
#include<graphics.h>
#include<graphics.h>
#include<stdlib.h>
#include<stdlib.h>
Line 185: Line 185:
return 0;
return 0;
}
}
</syntaxhighlight>
</lang>


=={{header|C++}}==
=={{header|C++}}==
Line 191: Line 191:


Windows version.
Windows version.
<lang cpp>
<syntaxhighlight lang="cpp">
#include <windows.h>
#include <windows.h>
#include <math.h>
#include <math.h>
Line 407: Line 407:
return myWnd.Run( hInstance );
return myWnd.Run( hInstance );
}
}
</syntaxhighlight>
</lang>


=={{header|Ceylon}}==
=={{header|Ceylon}}==
Be sure to import javafx.base, javafx.graphics and ceylon.numeric in your module file.
Be sure to import javafx.base, javafx.graphics and ceylon.numeric in your module file.
{{trans|Java}}
{{trans|Java}}
<lang ceylon>
<syntaxhighlight lang="ceylon">
import javafx.application {
import javafx.application {
Application
Application
Line 497: Line 497:
}
}


}</lang>
}</syntaxhighlight>


=={{header|Common Lisp}}==
=={{header|Common Lisp}}==
Line 503: Line 503:
{{libheader|simple-rgb}}
{{libheader|simple-rgb}}
plasma_demo.lisp:
plasma_demo.lisp:
<lang lisp>(require :lispbuilder-sdl)
<syntaxhighlight lang="lisp">(require :lispbuilder-sdl)
(require :simple-rgb)
(require :simple-rgb)


Line 570: Line 570:
(:quit-event () t))))))
(:quit-event () t))))))


(demo/plasma)</lang>
(demo/plasma)</syntaxhighlight>


=={{header|Forth}}==
=={{header|Forth}}==
Line 576: Line 576:
{{works with|gforth|0.7.3}}
{{works with|gforth|0.7.3}}
Ouputs a PPM file.
Ouputs a PPM file.
<lang forth>: sqrt ( u -- sqrt ) ( Babylonian method )
<syntaxhighlight lang="forth">: sqrt ( u -- sqrt ) ( Babylonian method )
dup 2/ ( first square root guess is half )
dup 2/ ( first square root guess is half )
dup 0= if drop exit then ( sqrt[0]=0, sqrt[1]=1 )
dup 0= if drop exit then ( sqrt[0]=0, sqrt[1]=1 )
Line 616: Line 616:
r> to outfile-id ;
r> to outfile-id ;


plasma</lang>
plasma</syntaxhighlight>




Line 622: Line 622:


=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==
<lang freebasic>' version 12-04-2017
<syntaxhighlight lang="freebasic">' version 12-04-2017
' compile with: fbc -s gui
' compile with: fbc -s gui
' Computer Graphics Tutorial (lodev.org), last example
' Computer Graphics Tutorial (lodev.org), last example
Line 658: Line 658:
End If
End If


Loop</lang>
Loop</syntaxhighlight>


=={{header|Go}}==
=={{header|Go}}==
Line 670: Line 670:
$ eog plasma2.gif
$ eog plasma2.gif
</pre>
</pre>
<lang go>package main
<syntaxhighlight lang="go">package main


import (
import (
Line 758: Line 758:
log.Fatal(err2)
log.Fatal(err2)
}
}
}</lang>
}</syntaxhighlight>


=={{header|Gosu}}==
=={{header|Gosu}}==
[[File:Gosu_plasma.png|200px|thumb|right]]
[[File:Gosu_plasma.png|200px|thumb|right]]
{{trans|Java}}
{{trans|Java}}
<lang gosu>
<syntaxhighlight lang="gosu">
uses javax.swing.*
uses javax.swing.*
uses java.awt.*
uses java.awt.*
Line 809: Line 809:
}
}
}
}
</syntaxhighlight>
</lang>


=={{header|J}}==
=={{header|J}}==
[[File:J-viewmat-plasma.png|200px|thumb|right]]
[[File:J-viewmat-plasma.png|200px|thumb|right]]
<lang j>require 'trig viewmat'
<syntaxhighlight lang="j">require 'trig viewmat'
plasma=: 3 :0
plasma=: 3 :0
'w h'=. y
'w h'=. y
Line 823: Line 823:
xy2=. sin (Y +&.*:/ X)*32
xy2=. sin (Y +&.*:/ X)*32
xy1+xy2+y1+/x1
xy1+xy2+y1+/x1
)</lang>
)</syntaxhighlight>


<lang j> viewmat plasma 256 256</lang>
<syntaxhighlight lang="j"> viewmat plasma 256 256</syntaxhighlight>


=={{header|Java}}==
=={{header|Java}}==
[[File:plasma_effect_java.png|200px|thumb|right]]
[[File:plasma_effect_java.png|200px|thumb|right]]
{{works with|Java|8}}
{{works with|Java|8}}
<lang java>import java.awt.*;
<syntaxhighlight lang="java">import java.awt.*;
import java.awt.event.*;
import java.awt.event.*;
import java.awt.image.*;
import java.awt.image.*;
Line 911: Line 911:
});
});
}
}
}</lang>
}</syntaxhighlight>


=={{header|JavaScript}}==
=={{header|JavaScript}}==
{{trans|Java}}
{{trans|Java}}
<lang javascript><!DOCTYPE html>
<syntaxhighlight lang="javascript"><!DOCTYPE html>
<html lang='en'>
<html lang='en'>
<head>
<head>
Line 1,036: Line 1,036:


</body>
</body>
</html></lang>
</html></syntaxhighlight>


=={{header|Julia}}==
=={{header|Julia}}==
{{trans|Perl}}
{{trans|Perl}}
<lang julia>using Luxor, Colors
<syntaxhighlight lang="julia">using Luxor, Colors


Drawing(800, 800)
Drawing(800, 800)
Line 1,053: Line 1,053:


@png plasma(800, 800)
@png plasma(800, 800)
</syntaxhighlight>
</lang>


=={{header|Kotlin}}==
=={{header|Kotlin}}==
{{trans|Java}}
{{trans|Java}}
<lang scala>// version 1.1.2
<syntaxhighlight lang="scala">// version 1.1.2


import java.awt.*
import java.awt.*
Line 1,127: Line 1,127:
f.isVisible = true
f.isVisible = true
}
}
}</lang>
}</syntaxhighlight>


=={{header|Lua}}==
=={{header|Lua}}==
Needs L&Ouml;VE 2D Engine
Needs L&Ouml;VE 2D Engine
{{trans|C++}}
{{trans|C++}}
<lang lua>
<syntaxhighlight lang="lua">
_ = love.graphics
_ = love.graphics
p1, p2, points = {}, {}, {}
p1, p2, points = {}, {}, {}
Line 1,173: Line 1,173:
_.points( points )
_.points( points )
end
end
</syntaxhighlight>
</lang>


=={{header|Mathematica}} / {{header|Wolfram Language}}==
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<lang Mathematica>s = 400;
<syntaxhighlight lang="mathematica">s = 400;
Image@Table[
Image@Table[
hue = Sin[i/16] + Sin[j/8] + Sin[(i + j)/16] + Sin[Sqrt[i^2 + j^2]/8];
hue = Sin[i/16] + Sin[j/8] + Sin[(i + j)/16] + Sin[Sqrt[i^2 + j^2]/8];
Line 1,184: Line 1,184:
{i, 1.0, s},
{i, 1.0, s},
{j, 1.0, s}
{j, 1.0, s}
]</lang>
]</syntaxhighlight>
{{out}}
{{out}}
Outputs an image.
Outputs an image.
Line 1,190: Line 1,190:
=={{header|Nim}}==
=={{header|Nim}}==
{{libheader|imageman}}
{{libheader|imageman}}
<lang Nim>import math
<syntaxhighlight lang="nim">import math
import imageman
import imageman


Line 1,206: Line 1,206:
let rgb = to(ColorHSL([hue * 360, 1, 0.5]), ColorRGBF)
let rgb = to(ColorHSL([hue * 360, 1, 0.5]), ColorRGBF)
img[x, y] = rgb
img[x, y] = rgb
img.savePNG("plasma.png")</lang>
img.savePNG("plasma.png")</syntaxhighlight>


=={{header|Ol}}==
=={{header|Ol}}==
<lang scheme>
<syntaxhighlight lang="scheme">
; creating the "plasma" image buffer
; creating the "plasma" image buffer
(import (scheme inexact))
(import (scheme inexact))
Line 1,224: Line 1,224:
(iota 256)))
(iota 256)))
(iota 256))))
(iota 256))))
</syntaxhighlight>
</lang>
<lang scheme>
<syntaxhighlight lang="scheme">
; rendering the prepared buffer (using OpenGL)
; rendering the prepared buffer (using OpenGL)
(import (lib gl1))
(import (lib gl1))
Line 1,251: Line 1,251:
(glVertex2f 1 -1)
(glVertex2f 1 -1)
(glEnd)))
(glEnd)))
</syntaxhighlight>
</lang>


=={{header|Perl}}==
=={{header|Perl}}==
{{trans|Raku}}
{{trans|Raku}}
<lang perl>use Imager;
<syntaxhighlight lang="perl">use Imager;


sub plasma {
sub plasma {
Line 1,273: Line 1,273:


my $img = plasma(400, 400);
my $img = plasma(400, 400);
$img->write(file => 'plasma-perl.png');</lang>
$img->write(file => 'plasma-perl.png');</syntaxhighlight>
Off-site image: [https://github.com/SqrtNegInf/Rosettacode-Perl5-Smoke/blob/master/ref/plasma.png Plasma effect]
Off-site image: [https://github.com/SqrtNegInf/Rosettacode-Perl5-Smoke/blob/master/ref/plasma.png Plasma effect]


Line 1,279: Line 1,279:
{{libheader|Phix/pGUI}}
{{libheader|Phix/pGUI}}
{{trans|JavaScript}}
{{trans|JavaScript}}
<lang Phix>-- demo\rosetta\plasma.exw
<syntaxhighlight lang="phix">-- demo\rosetta\plasma.exw
include pGUI.e
include pGUI.e


Line 1,378: Line 1,378:
end procedure
end procedure


main()</lang>
main()</syntaxhighlight>
And here's a simple console ditty, similar I think to C's ASCII version for Windows, though this also works on Linux:
And here's a simple console ditty, similar I think to C's ASCII version for Windows, though this also works on Linux:
<lang Phix>sequence s = video_config()
<syntaxhighlight lang="phix">sequence s = video_config()
for i=1 to s[VC_SCRNLINES]*s[VC_SCRNCOLS]-1 do
for i=1 to s[VC_SCRNLINES]*s[VC_SCRNCOLS]-1 do
bk_color(rand(16)-1)
bk_color(rand(16)-1)
Line 1,386: Line 1,386:
puts(1,"\xDF")
puts(1,"\xDF")
end for
end for
{} = wait_key()</lang>
{} = wait_key()</syntaxhighlight>


=={{header|Processing}}==
=={{header|Processing}}==
<lang java>/**
<syntaxhighlight lang="java">/**
Plasmas with Palette Looping
Plasmas with Palette Looping
https://lodev.org/cgtutor/plasma.html#Plasmas_with_Palette_Looping_
https://lodev.org/cgtutor/plasma.html#Plasmas_with_Palette_Looping_
Line 1,436: Line 1,436:
}
}
updatePixels();
updatePixels();
}</lang>
}</syntaxhighlight>


'''It can be played on line''' :<BR> [https://www.openprocessing.org/sketch/873932/ here.]
'''It can be played on line''' :<BR> [https://www.openprocessing.org/sketch/873932/ here.]
Line 1,442: Line 1,442:
==={{header|Processing Python mode}}===
==={{header|Processing Python mode}}===


<lang python>"""
<syntaxhighlight lang="python">"""
Plasmas with Palette Looping
Plasmas with Palette Looping
https://lodev.org/cgtutor/plasma.html#Plasmas_with_Palette_Looping_
https://lodev.org/cgtutor/plasma.html#Plasmas_with_Palette_Looping_
Line 1,489: Line 1,489:
pixels[i] = pal[(b + frameCount) % 127]
pixels[i] = pal[(b + frameCount) % 127]
updatePixels()
updatePixels()
</syntaxhighlight>
</lang>


=={{header|Python}}==
=={{header|Python}}==
{{trans|Raku}}
{{trans|Raku}}


<lang python>import math
<syntaxhighlight lang="python">import math
import colorsys
import colorsys
from PIL import Image
from PIL import Image
Line 1,511: Line 1,511:
if __name__=="__main__":
if __name__=="__main__":
im = plasma(400, 400)
im = plasma(400, 400)
im.show()</lang>
im.show()</syntaxhighlight>


=={{header|Racket}}==
=={{header|Racket}}==
Line 1,517: Line 1,517:
Uses `return-color-by-pos` from [[#Lisp]], because it was almost lift and shift
Uses `return-color-by-pos` from [[#Lisp]], because it was almost lift and shift


<lang racket>#lang racket
<syntaxhighlight lang="racket">#lang racket
;; from lisp (cos I could just lift the code)
;; from lisp (cos I could just lift the code)
(require images/flomap
(require images/flomap
Line 1,577: Line 1,577:
(define plsm ((plasma-flomap) 300 300))
(define plsm ((plasma-flomap) 300 300))
(animate (λ (t)
(animate (λ (t)
((colour-plasma plsm) t)))</lang>
((colour-plasma plsm) t)))</syntaxhighlight>


=={{header|Raku}}==
=={{header|Raku}}==
Line 1,583: Line 1,583:
[[File:Plasma-perl6.png|200px|thumb|right]]
[[File:Plasma-perl6.png|200px|thumb|right]]
{{works with|Rakudo|2018.09}}
{{works with|Rakudo|2018.09}}
<lang perl6>use Image::PNG::Portable;
<syntaxhighlight lang="raku" line>use Image::PNG::Portable;


my ($w, $h) = 400, 400;
my ($w, $h) = 400, 400;
Line 1,613: Line 1,613:
when 5/6..1 { $c, 0, $x }
when 5/6..1 { $c, 0, $x }
} ).map: ((*+$m) * 255).Int
} ).map: ((*+$m) * 255).Int
}</lang>
}</syntaxhighlight>


=={{header|Ring}}==
=={{header|Ring}}==
<lang ring>
<syntaxhighlight lang="ring">
# Project : Plasma effect
# Project : Plasma effect


Line 1,688: Line 1,688:
d = sqrt(((a - c) * (a - c) + (b - d) * (b - d)))
d = sqrt(((a - c) * (a - c) + (b - d) * (b - d)))
return d
return d
</syntaxhighlight>
</lang>
Output:
Output:


Line 1,698: Line 1,698:
{{libheader|JRubyArt}}
{{libheader|JRubyArt}}
JRubyArt is a port of Processing to the ruby language
JRubyArt is a port of Processing to the ruby language
<lang ruby>
<syntaxhighlight lang="ruby">
attr_reader :buffer, :palette, :r, :g, :b, :rd, :gd, :bd, :dim
attr_reader :buffer, :palette, :r, :g, :b, :rd, :gd, :bd, :dim


Line 1,760: Line 1,760:
update_pixels
update_pixels
end
end
</syntaxhighlight>
</lang>


=={{header|Rust}}==
=={{header|Rust}}==
<lang rust>
<syntaxhighlight lang="rust">
extern crate image;
extern crate image;


Line 1,845: Line 1,845:
}
}


</syntaxhighlight>
</lang>


=={{header|Scala}}==
=={{header|Scala}}==
===Java Swing Interoperability===
===Java Swing Interoperability===
<lang Scala>import java.awt._
<syntaxhighlight lang="scala">import java.awt._
import java.awt.event.ActionEvent
import java.awt.event.ActionEvent
import java.awt.image.BufferedImage
import java.awt.image.BufferedImage
Line 1,906: Line 1,906:
})
})


}</lang>
}</syntaxhighlight>


=={{header|Sidef}}==
=={{header|Sidef}}==
{{trans|Raku}}
{{trans|Raku}}
<lang ruby>require('Imager')
<syntaxhighlight lang="ruby">require('Imager')


class Plasma(width=400, height=400) {
class Plasma(width=400, height=400) {
Line 1,934: Line 1,934:
var plasma = Plasma(256, 256)
var plasma = Plasma(256, 256)
plasma.generate
plasma.generate
plasma.save_as('plasma.png')</lang>
plasma.save_as('plasma.png')</syntaxhighlight>
Output image: [https://github.com/trizen/rc/blob/master/img/plasma-effect-sidef.png Plasma effect]
Output image: [https://github.com/trizen/rc/blob/master/img/plasma-effect-sidef.png Plasma effect]


Line 1,940: Line 1,940:
{{trans|Kotlin}}
{{trans|Kotlin}}
{{libheader|DOME}}
{{libheader|DOME}}
<lang ecmascript>import "graphics" for Canvas, Color, ImageData
<syntaxhighlight lang="ecmascript">import "graphics" for Canvas, Color, ImageData
import "dome" for Window
import "dome" for Window
import "math" for Math
import "math" for Math
Line 2,003: Line 2,003:
}
}


var Game = PlasmaEffect.new(640, 640)</lang>
var Game = PlasmaEffect.new(640, 640)</syntaxhighlight>


=={{header|XPL0}}==
=={{header|XPL0}}==
Translation of Lode's RGB plasma, provided by link at the top of this page.
Translation of Lode's RGB plasma, provided by link at the top of this page.
<lang XPL0>func real Dist(X1, Y1, X2, Y2);
<syntaxhighlight lang="xpl0">func real Dist(X1, Y1, X2, Y2);
int X1, Y1, X2, Y2;
int X1, Y1, X2, Y2;
return sqrt( float((X1-X2)*(X1-X2) + (Y1-Y2)*(Y1-Y2)) );
return sqrt( float((X1-X2)*(X1-X2) + (Y1-Y2)*(Y1-Y2)) );
Line 2,025: Line 2,025:
];
];
until KeyHit;
until KeyHit;
]</lang>
]</syntaxhighlight>