Plasma effect: Difference between revisions
Content added Content deleted
(Added Forth entry) |
Thundergnat (talk | contribs) 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. |
||
< |
<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}} |
||
< |
<syntaxhighlight lang="ceylon"> |
||
import javafx.application { |
import javafx.application { |
||
Application |
Application |
||
Line 497: | Line 497: | ||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Common Lisp}}== |
=={{header|Common Lisp}}== |
||
Line 503: | Line 503: | ||
{{libheader|simple-rgb}} |
{{libheader|simple-rgb}} |
||
plasma_demo.lisp: |
plasma_demo.lisp: |
||
< |
<syntaxhighlight lang="lisp">(require :lispbuilder-sdl) |
||
(require :simple-rgb) |
(require :simple-rgb) |
||
Line 570: | Line 570: | ||
(:quit-event () t)))))) |
(:quit-event () t)))))) |
||
(demo/plasma)</ |
(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. |
||
< |
<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</ |
plasma</syntaxhighlight> |
||
Line 622: | Line 622: | ||
=={{header|FreeBASIC}}== |
=={{header|FreeBASIC}}== |
||
< |
<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</ |
Loop</syntaxhighlight> |
||
=={{header|Go}}== |
=={{header|Go}}== |
||
Line 670: | Line 670: | ||
$ eog plasma2.gif |
$ eog plasma2.gif |
||
</pre> |
</pre> |
||
< |
<syntaxhighlight lang="go">package main |
||
import ( |
import ( |
||
Line 758: | Line 758: | ||
log.Fatal(err2) |
log.Fatal(err2) |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Gosu}}== |
=={{header|Gosu}}== |
||
[[File:Gosu_plasma.png|200px|thumb|right]] |
[[File:Gosu_plasma.png|200px|thumb|right]] |
||
{{trans|Java}} |
{{trans|Java}} |
||
< |
<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]] |
||
< |
<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 |
||
)</ |
)</syntaxhighlight> |
||
<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}} |
||
< |
<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: | ||
}); |
}); |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|JavaScript}}== |
=={{header|JavaScript}}== |
||
{{trans|Java}} |
{{trans|Java}} |
||
< |
<syntaxhighlight lang="javascript"><!DOCTYPE html> |
||
<html lang='en'> |
<html lang='en'> |
||
<head> |
<head> |
||
Line 1,036: | Line 1,036: | ||
</body> |
</body> |
||
</html></ |
</html></syntaxhighlight> |
||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
{{trans|Perl}} |
{{trans|Perl}} |
||
< |
<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}} |
||
< |
<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 |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Lua}}== |
=={{header|Lua}}== |
||
Needs LÖVE 2D Engine |
Needs LÖVE 2D Engine |
||
{{trans|C++}} |
{{trans|C++}} |
||
< |
<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}}== |
||
< |
<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} |
||
]</ |
]</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Outputs an image. |
Outputs an image. |
||
Line 1,190: | Line 1,190: | ||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
{{libheader|imageman}} |
{{libheader|imageman}} |
||
< |
<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")</ |
img.savePNG("plasma.png")</syntaxhighlight> |
||
=={{header|Ol}}== |
=={{header|Ol}}== |
||
< |
<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> |
|||
< |
<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}} |
||
< |
<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');</ |
$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}} |
||
< |
<syntaxhighlight lang="phix">-- demo\rosetta\plasma.exw |
||
include pGUI.e |
include pGUI.e |
||
Line 1,378: | Line 1,378: | ||
end procedure |
end procedure |
||
main()</ |
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: |
||
< |
<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()</ |
{} = wait_key()</syntaxhighlight> |
||
=={{header|Processing}}== |
=={{header|Processing}}== |
||
< |
<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(); |
||
}</ |
}</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}}=== |
||
< |
<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}} |
||
< |
<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()</ |
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 |
||
< |
<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)))</ |
((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 |
<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 |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Ring}}== |
=={{header|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 |
||
< |
<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}}== |
||
< |
<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=== |
||
< |
<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: | ||
}) |
}) |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Sidef}}== |
=={{header|Sidef}}== |
||
{{trans|Raku}} |
{{trans|Raku}} |
||
< |
<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')</ |
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}} |
||
< |
<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)</ |
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. |
||
< |
<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; |
||
]</ |
]</syntaxhighlight> |