Plasma effect: Difference between revisions

m
syntax highlighting fixup automation
(Added Forth entry)
m (syntax highlighting fixup automation)
Line 14:
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
#!/usr/bin/awk -f
 
Line 94:
printf("\n")
}
</syntaxhighlight>
</lang>
 
=={{header|C}}==
===ASCII version for 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<stdlib.h>
Line 137:
return 0;
}
</syntaxhighlight>
</lang>
 
===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.
<syntaxhighlight lang="c">
<lang C>
#include<graphics.h>
#include<stdlib.h>
Line 185:
return 0;
}
</syntaxhighlight>
</lang>
 
=={{header|C++}}==
Line 191:
 
Windows version.
<langsyntaxhighlight lang="cpp">
#include <windows.h>
#include <math.h>
Line 407:
return myWnd.Run( hInstance );
}
</syntaxhighlight>
</lang>
 
=={{header|Ceylon}}==
Be sure to import javafx.base, javafx.graphics and ceylon.numeric in your module file.
{{trans|Java}}
<langsyntaxhighlight lang="ceylon">
import javafx.application {
Application
Line 497:
}
 
}</langsyntaxhighlight>
 
=={{header|Common Lisp}}==
Line 503:
{{libheader|simple-rgb}}
plasma_demo.lisp:
<langsyntaxhighlight lang="lisp">(require :lispbuilder-sdl)
(require :simple-rgb)
 
Line 570:
(:quit-event () t))))))
 
(demo/plasma)</langsyntaxhighlight>
 
=={{header|Forth}}==
Line 576:
{{works with|gforth|0.7.3}}
Ouputs a PPM file.
<langsyntaxhighlight lang="forth">: sqrt ( u -- sqrt ) ( Babylonian method )
dup 2/ ( first square root guess is half )
dup 0= if drop exit then ( sqrt[0]=0, sqrt[1]=1 )
Line 616:
r> to outfile-id ;
 
plasma</langsyntaxhighlight>
 
 
Line 622:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">' version 12-04-2017
' compile with: fbc -s gui
' Computer Graphics Tutorial (lodev.org), last example
Line 658:
End If
 
Loop</langsyntaxhighlight>
 
=={{header|Go}}==
Line 670:
$ eog plasma2.gif
</pre>
<langsyntaxhighlight lang="go">package main
 
import (
Line 758:
log.Fatal(err2)
}
}</langsyntaxhighlight>
 
=={{header|Gosu}}==
[[File:Gosu_plasma.png|200px|thumb|right]]
{{trans|Java}}
<langsyntaxhighlight lang="gosu">
uses javax.swing.*
uses java.awt.*
Line 809:
}
}
</syntaxhighlight>
</lang>
 
=={{header|J}}==
[[File:J-viewmat-plasma.png|200px|thumb|right]]
<langsyntaxhighlight lang="j">require 'trig viewmat'
plasma=: 3 :0
'w h'=. y
Line 823:
xy2=. sin (Y +&.*:/ X)*32
xy1+xy2+y1+/x1
)</langsyntaxhighlight>
 
<syntaxhighlight lang ="j"> viewmat plasma 256 256</langsyntaxhighlight>
 
=={{header|Java}}==
[[File:plasma_effect_java.png|200px|thumb|right]]
{{works with|Java|8}}
<langsyntaxhighlight lang="java">import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
Line 911:
});
}
}</langsyntaxhighlight>
 
=={{header|JavaScript}}==
{{trans|Java}}
<langsyntaxhighlight lang="javascript"><!DOCTYPE html>
<html lang='en'>
<head>
Line 1,036:
 
</body>
</html></langsyntaxhighlight>
 
=={{header|Julia}}==
{{trans|Perl}}
<langsyntaxhighlight lang="julia">using Luxor, Colors
 
Drawing(800, 800)
Line 1,053:
 
@png plasma(800, 800)
</syntaxhighlight>
</lang>
 
=={{header|Kotlin}}==
{{trans|Java}}
<langsyntaxhighlight lang="scala">// version 1.1.2
 
import java.awt.*
Line 1,127:
f.isVisible = true
}
}</langsyntaxhighlight>
 
=={{header|Lua}}==
Needs L&Ouml;VE 2D Engine
{{trans|C++}}
<langsyntaxhighlight lang="lua">
_ = love.graphics
p1, p2, points = {}, {}, {}
Line 1,173:
_.points( points )
end
</syntaxhighlight>
</lang>
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">s = 400;
Image@Table[
hue = Sin[i/16] + Sin[j/8] + Sin[(i + j)/16] + Sin[Sqrt[i^2 + j^2]/8];
Line 1,184:
{i, 1.0, s},
{j, 1.0, s}
]</langsyntaxhighlight>
{{out}}
Outputs an image.
Line 1,190:
=={{header|Nim}}==
{{libheader|imageman}}
<langsyntaxhighlight Nimlang="nim">import math
import imageman
 
Line 1,206:
let rgb = to(ColorHSL([hue * 360, 1, 0.5]), ColorRGBF)
img[x, y] = rgb
img.savePNG("plasma.png")</langsyntaxhighlight>
 
=={{header|Ol}}==
<langsyntaxhighlight lang="scheme">
; creating the "plasma" image buffer
(import (scheme inexact))
Line 1,224:
(iota 256)))
(iota 256))))
</syntaxhighlight>
</lang>
<langsyntaxhighlight lang="scheme">
; rendering the prepared buffer (using OpenGL)
(import (lib gl1))
Line 1,251:
(glVertex2f 1 -1)
(glEnd)))
</syntaxhighlight>
</lang>
 
=={{header|Perl}}==
{{trans|Raku}}
<langsyntaxhighlight lang="perl">use Imager;
 
sub plasma {
Line 1,273:
 
my $img = plasma(400, 400);
$img->write(file => 'plasma-perl.png');</langsyntaxhighlight>
Off-site image: [https://github.com/SqrtNegInf/Rosettacode-Perl5-Smoke/blob/master/ref/plasma.png Plasma effect]
 
Line 1,279:
{{libheader|Phix/pGUI}}
{{trans|JavaScript}}
<langsyntaxhighlight Phixlang="phix">-- demo\rosetta\plasma.exw
include pGUI.e
 
Line 1,378:
end procedure
 
main()</langsyntaxhighlight>
And here's a simple console ditty, similar I think to C's ASCII version for Windows, though this also works on Linux:
<langsyntaxhighlight Phixlang="phix">sequence s = video_config()
for i=1 to s[VC_SCRNLINES]*s[VC_SCRNCOLS]-1 do
bk_color(rand(16)-1)
Line 1,386:
puts(1,"\xDF")
end for
{} = wait_key()</langsyntaxhighlight>
 
=={{header|Processing}}==
<langsyntaxhighlight lang="java">/**
Plasmas with Palette Looping
https://lodev.org/cgtutor/plasma.html#Plasmas_with_Palette_Looping_
Line 1,436:
}
updatePixels();
}</langsyntaxhighlight>
 
'''It can be played on line''' :<BR> [https://www.openprocessing.org/sketch/873932/ here.]
Line 1,442:
==={{header|Processing Python mode}}===
 
<langsyntaxhighlight lang="python">"""
Plasmas with Palette Looping
https://lodev.org/cgtutor/plasma.html#Plasmas_with_Palette_Looping_
Line 1,489:
pixels[i] = pal[(b + frameCount) % 127]
updatePixels()
</syntaxhighlight>
</lang>
 
=={{header|Python}}==
{{trans|Raku}}
 
<langsyntaxhighlight lang="python">import math
import colorsys
from PIL import Image
Line 1,511:
if __name__=="__main__":
im = plasma(400, 400)
im.show()</langsyntaxhighlight>
 
=={{header|Racket}}==
Line 1,517:
Uses `return-color-by-pos` from [[#Lisp]], because it was almost lift and shift
 
<langsyntaxhighlight lang="racket">#lang racket
;; from lisp (cos I could just lift the code)
(require images/flomap
Line 1,577:
(define plsm ((plasma-flomap) 300 300))
(animate (λ (t)
((colour-plasma plsm) t)))</langsyntaxhighlight>
 
=={{header|Raku}}==
Line 1,583:
[[File:Plasma-perl6.png|200px|thumb|right]]
{{works with|Rakudo|2018.09}}
<syntaxhighlight lang="raku" perl6line>use Image::PNG::Portable;
 
my ($w, $h) = 400, 400;
Line 1,613:
when 5/6..1 { $c, 0, $x }
} ).map: ((*+$m) * 255).Int
}</langsyntaxhighlight>
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
# Project : Plasma effect
 
Line 1,688:
d = sqrt(((a - c) * (a - c) + (b - d) * (b - d)))
return d
</syntaxhighlight>
</lang>
Output:
 
Line 1,698:
{{libheader|JRubyArt}}
JRubyArt is a port of Processing to the ruby language
<langsyntaxhighlight lang="ruby">
attr_reader :buffer, :palette, :r, :g, :b, :rd, :gd, :bd, :dim
 
Line 1,760:
update_pixels
end
</syntaxhighlight>
</lang>
 
=={{header|Rust}}==
<langsyntaxhighlight lang="rust">
extern crate image;
 
Line 1,845:
}
 
</syntaxhighlight>
</lang>
 
=={{header|Scala}}==
===Java Swing Interoperability===
<langsyntaxhighlight Scalalang="scala">import java.awt._
import java.awt.event.ActionEvent
import java.awt.image.BufferedImage
Line 1,906:
})
 
}</langsyntaxhighlight>
 
=={{header|Sidef}}==
{{trans|Raku}}
<langsyntaxhighlight lang="ruby">require('Imager')
 
class Plasma(width=400, height=400) {
Line 1,934:
var plasma = Plasma(256, 256)
plasma.generate
plasma.save_as('plasma.png')</langsyntaxhighlight>
Output image: [https://github.com/trizen/rc/blob/master/img/plasma-effect-sidef.png Plasma effect]
 
Line 1,940:
{{trans|Kotlin}}
{{libheader|DOME}}
<langsyntaxhighlight lang="ecmascript">import "graphics" for Canvas, Color, ImageData
import "dome" for Window
import "math" for Math
Line 2,003:
}
 
var Game = PlasmaEffect.new(640, 640)</langsyntaxhighlight>
 
=={{header|XPL0}}==
Translation of Lode's RGB plasma, provided by link at the top of this page.
<langsyntaxhighlight XPL0lang="xpl0">func real Dist(X1, Y1, X2, Y2);
int X1, Y1, X2, Y2;
return sqrt( float((X1-X2)*(X1-X2) + (Y1-Y2)*(Y1-Y2)) );
Line 2,025:
];
until KeyHit;
]</langsyntaxhighlight>
10,333

edits